Commit Graph

16 Commits

Author SHA1 Message Date
Damien George
38e7b842c6 ports: Implement simple write polling for stdout.
This is a best-effort implementation of write polling.  It's difficult to
do correctly because if there are multiple output streams (eg UART and USB
CDC) then some may not be writeable while others are.  A full solution
should also have a return value from mp_hal_stdout_tx_strn(), returning the
number of bytes written to the stream(s).  That's also hard to define.

The renesas-ra and stm32 ports already implement a similar best-effort
mechanism for write polling.

Fixes issue #11026.

Signed-off-by: Damien George <damien@micropython.org>
2023-03-23 13:51:17 +11:00
robert-hh
4160ec087b samd/mcu: Set the SAMD21 us-counter to 2 MHz for better resolution.
It turned out that the result of calling ticks_us() was always either odd
or even, depending on some internal state during boot.  So the us-counter
was set to a 2 MHz input and the result shifted by 1.  The counting period
is still long enough, since internally a (now) 63 bit value is used for us.
2023-02-21 23:17:12 +11:00
robert-hh
ca63ead2d8 samd/mphalport: Add a timeout to mp_hal_stdout_tx_strn().
If USB CDC is connected and the board sends data, but the host does not
receive the data, the device locks up.  This is fixed in this commit by
having a timeout of 500ms, after which time the transmission is skipped.
2022-11-09 11:15:24 +11:00
robert-hh
e33db80a59 samd/clock_config: Extend the SAMD51 us-counter to 60 bit.
This removes the difference in the time.ticks_us() range between SAMD21 and
SAMD51.

The function mp_hal_ticks_us_64() is added and used for:
- SAMD51's mp_hal_ticks_us and mp_hal_delay_us().
  For SAMD21, keep the previous methods, which are faster.
- mp_hal_ticks_ms() and mp_hal_tick_ms_64(), which saves some bytes
  and removes a potential race condition every 50 days.

Also set the us-counter for SAMD51 to 16 MHz for a faster reading of the
microsecond value.

Note: With SAMD51, mp_hal_ticks_us_64() has a 60 bit range only, which is
still a long time (~36000 years).
2022-10-25 23:26:14 +11:00
robert-hh
e9a76310ec samd/mphalport: Fix USB endpoint handling ignoring Ctrl-C.
Porting PR #8040 by @hoihu to SAMD, following the commit
5873390226.

One small addition: before executing keyboard interrupt, the input buffer
is cleared.
2022-10-06 23:08:22 +11:00
robert-hh
15212ae8d4 samd/moduos: Add uos.dupterm(). 2022-10-06 22:49:19 +11:00
robert-hh
d693758ab2 samd/machine_pwm: Add the machine.PWM class.
Features are:
- 3 to 5 different frequency groups.
- Freq range of 1Hz - 24 MHz.
- Duty rate stays stable on freq change.

Keyword options to the PWM constructor:
- device=n Select a specific PWM device.  If no device is specified, a free
           device is chosen, if available at that pin.
- freq=nnnn
- duty_u16=nnnn
- duty_ns=nnnn
- invert=True/False Allowing two outputs on the same device/channel to have
                    complementary signals.

If both freq and duty are provided, PWM output will start immediately.

Pins at the same device have the same frequency.  If the PWM output number
exceeds the number of channels at the PWM device, the effctive channel_no
is output_no % channel_count.  So with a channel count of 4, output 7 is
assigned to channel 3.  Pins at a certain channel have the same frequency
and duty rate, but may be seperately inverted.
2022-10-06 22:42:55 +11:00
robert-hh
3d9940bc28 samd/mphalport: Add pin open-drain funcs, and improve delay and ticks.
The changes in this commit are:
- Add an interface for pin open-drain mode.
- Improve ticks_us() by using the us-counter.
- Improve ticks_cpu() by using the CPU's SysTick.
2022-10-06 22:35:06 +11:00
robert-hh
85afed569d samd: Remove the existing provisional support for REPL on UART.
It was only partially working and will be rpelaced later by a full
machine.UART class implementation.
2022-10-06 22:29:06 +11:00
Peter van der Burg
cd2223b8fe samd: Integrate latest asf4, add help, more time funcs and uPy features.
- Makefile: update to use new ASF4 files, support frozen manifest, and
  include source files in upcoming commits
- boards/manifest.py: add files to freeze
- boards/samd51p19a.ld: add linker script for this MCU
- help.c: add custom help text
- main.c: execute _boot.py, boot.py and main.py on start-up
- modules/_boot.py: startup file to freeze
- modutime.c: add gmtime, localtime, mktime, time functions
- mpconfigport.h: enabled more features for sys and io and modules
- mphalport.h: add mp_hal_pin_xxx macros
- mphalport.c: add mp_hal_stdio_poll
2021-11-19 11:05:05 +11:00
Damien George
e9e9c76ddf all: Rename mp_keyboard_interrupt to mp_sched_keyboard_interrupt.
To match mp_sched_exception() and mp_sched_schedule().

Signed-off-by: Damien George <damien@micropython.org>
2021-04-30 15:13:43 +10:00
Damien George
ede6b86a08 samd/mphalport: Fix USB CDC tx handling to work reliably.
Signed-off-by: Damien George <damien@micropython.org>
2021-02-12 14:09:01 +11:00
Damien George
69661f3343 all: Reformat C and Python source code with tools/codeformat.py.
This is run with uncrustify 0.70.1, and black 19.10b0.
2020-02-28 10:33:03 +11:00
Damien George
abe2caf6df py/scheduler: Move clearing of kbd traceback to mp_keyboard_interrupt.
This is a more logical place to clear the KeyboardInterrupt traceback,
right before it is set as a pending exception.  The clearing is also
optimised from a function call to a simple store of NULL.
2020-02-07 16:08:31 +11:00
Damien George
9efb36bfa6 py/scheduler: Move mp_keyboard_interrupt from lib/utils to py core.
This function is tightly coupled to the state and behaviour of the
scheduler, and is a core part of the runtime: to schedule a pending
exception.  So move it there.
2020-02-07 16:08:26 +11:00
Damien George
5f9bd11527 samd: Add new port to Microchip SAMDxx microcontrollers.
Initially supporting SAMD21 and SAMD51.
2019-07-01 17:19:18 +10:00