Wykres commitów

32 Commity (805c750164aed86db3875402bf26e7b12cbe85b1)

Autor SHA1 Wiadomość Data
robert-hh cfaa9a4997 samd/Makefile: Move the math lib files from mpconfigmcu.mk to Makefile.
They are used by both SAMD21 and SAMD51.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-06-27 14:58:07 +10:00
robert-hh 909fe30dfd samd: Set the LFS type in mpconfigmcu.mk instead of mpconfigboard.mk.
SAMD21: set the filesystem type to LFS1.

SAMD51: the type is already set to LFS2, support is now dropped for LFS1.
It has not been used and dropping it saves 10 k of flash.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-06-27 14:57:41 +10:00
Jim Mussared f5f9edf645 all: Rename UMODULE to MODULE in preprocessor/Makefile vars.
This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:11 +10:00
robert-hh 2a38531d73 samd/mcu: Reduce the startup time after hard reset.
With Crystal: set the crystal startup wait time to 1 second.  It was 2
seconds before, and that seeemed too long.

With USB-Sync: scan for up to 1 second for the USB to be registered and
carry on with boot as soon as it it.  Before, the code just waited for
500ms.

Side change: improve related comments.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22 18:41:48 +10:00
robert-hh 315eb949da samd: Rearrange the MCU-specific loader files.
Such that they are easier to adapt.  The maximum code size is set by:

    MICROPY_HW_CODESIZE=xxxK

in mpconfigmcu.mk for the MCU family as default or in mpconfigboard.mk for
a specific board.  Setting the maximum code size allows the loader to error
out if the code gets larger than the space dedicated for it.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22 18:36:29 +10:00
Damien George b1229efbd1 all: Fix spelling mistakes based on codespell check.
Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 18:03:06 +10:00
Damien George d7cb53cb60 samd/modutime: Use extmod version of time module.
No API or functional change.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 15:11:51 +10:00
robert-hh 05bb26010e samd: Always provide the machine.RTC class.
Even if boards do not have a clock crystal.  In that case, the clock
quality will be very poor.

Always having machine.RTC means that the date/time can be set in a way that
is consistent with other ports.

This commit also removes the special code in modutime.c for devices without
the RTC class.

Signed-off-by: Damien George <damien@micropython.org>
2023-03-13 12:44:34 +11:00
robert-hh b110266897 samd/moduos: Add uos.urandom() using the phase-jitter rng.
This RNG passes many of the Diehard tests and also the AIS31 test suite.
The RNG is quite slow, delivering 200bytes/s.

Tested on boards with and without a crystal.
2023-02-21 23:17:44 +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 76cf98c35b samd/mcu: Implement a hardware seed for the SAMD21 random module.
By using the phase jitter between the DFLL48M clock and the FDPLL96M clock.
Even if both use the same reference source, they have a different jitter.
SysTick is driven by FDPLL96M, the us counter by DFLL48M.  As a random
source, the us counter is read out on every SysTick and the value is used
to accumulate a simple multiply, add and xor register.  According to tests
it creates about 30 bit random bit-flips per second.  That mechanism will
pass quite a few RNG tests, has a suitable frequency distribution and
serves better than just the time after boot to seed the PRNG.
2023-02-21 23:15:29 +11:00
robert-hh 7e0b1bc95d samd/mcu: Use the FDPLL96M clock for the SAMD21 CPU.
Allowing to increase the clock a little bit to 54Mhz.  Not much of a gain,
but useful for generating a RNG entropy source from the jitter between
DFLL48M and FDPLL96M.
2023-02-21 23:15:00 +11:00
robert-hh 60ab556385 samd/mcu: Rework the comments in clock_config.c.
For more clarity. clock_config.c is not overly readable, so comments are
important.
2023-02-21 23:14:45 +11:00
robert-hh 4598b89ce9 samd: Add Pin.board and Pin.cpu classes to Pin.
For compatibility with other ports.  Code increase up to ~1250 bytes for
SAMD21.  The feature is configurable via MICROPY_PY_MACHINE_PIN_BOARD_CPU
in case flash memory is tight.
2023-02-17 17:27:21 +11:00
David Lechner 3446d440f6 shared/runtime/gchelper: Drop cpu directive from ARM asm helpers.
This drops the `.cpu` directive from the ARM gchelper_*.s files.  Having
this directive breaks the linker when targeting older CPUs (e.g. `-mthumb
-mthumb-interwork` for `-mcpu=arm7tdmi`).  The actual target CPU should be
determined by the compiler options.

The exact CPU doesn't actually matter, but rather the supported assembly
instruction set.  So the files are renamed to *_thumb1.s and *thumb2.s to
indicate the instruction set support instead of the CPU support.

Signed-off-by: David Lechner <david@pybricks.com>
2023-01-28 15:51:38 +11:00
Jim Mussared f34eedeb1b samd/Makefile: Set MPY_CROSS_FLAGS.
Otherwise this port will be unable to freeze `@native`/`@viper` code.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-11-17 22:10:41 +11:00
Jim Mussared 92c35efb63 samd: Move MCU-specific CFLAGS to mpconfigmcu.mk.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-11-17 22:10:40 +11:00
robert-hh fc9d66fac6 samd/machine_rtc: Add the machine.RTC class.
Methods implemented are:
- rtc.init(date)
- rtc.datetime([new_date])
- rtc.calibration(value)

The presence of this class can be controlled by MICROPY_PY_MACHINE_RTC.  If
the RTC module is used, the time module uses the RTC as well.

For boards without a 32kHz crystal, using RTC makes no sense, since it will
then use the ULP32K oscillator, which is not precise at all.  Therefore, it
will by default only be enabled for boards using a crystal, but can be
enabled in the respective mpconfigboard.h.
2022-10-25 23:20:09 +11:00
robert-hh be31fde012 samd/mcu: Make some settings in mpconfigmcu.h conditional.
And set the default for MICROPY_PY_MATH as 1 for both MCU types.
2022-10-25 23:13:58 +11:00
robert-hh ddd41b8bbf samd/clock_config: Document the #defines use in init_clocks().
Which may be set in the respective mpconfigboard.h files.
2022-10-25 23:10:27 +11:00
robert-hh 03075a6839 samd/modmachine: Implement machine.lightsleep().
Which just sets the CPU clock to 200kHz and switches the peripheral clock
off.  There are two modes:

    machine.lightsleep(duration_ms)

and

    machine.lightsleep()

In any mode any configured pin.irq() event will terminate the sleep.

Current consumption in lightsleep for some boards:
- 1.5 - 2.5 mA when supplied trough an active USB
  (Seeed XIAO w/o power LED, Adafruit ItsyBitsy)
- 0.8 - 2 mA when supplied through Gnd/+5V (Vusb)
  (Seeed XIAO w/o power LED, Adafruit ItsyBitsy)
- < 1 mA for SAMD51 when supplied trough a battery connector
  (Sparkfun Thing SAMD51 plus)

Related change: move the calls to SysTick_Config() into set_cpu_freq().  It
is required after each CPU freq change to have ticks_ms run at the proper
rate.
2022-10-25 23:07:27 +11:00
robert-hh 1c32cec7f1 samd/clock_config: Support changing machine.freq() for SAMD21.
The range is 1MHz - 48 MHz.  Note that below 8 MHz there is no USB support.
The frequency will be set to an integer fraction of 48 MHz.  And after
changing the frequency, the peripherals like PWM, UART, I2C, SPI have to be
reconfigured.

Current consumption e.g. of the Seeed Xiao board at 1 MHz is about 1.5 mA,
mostly caused by the on-board LED (green LED with 1k resistor at 3.3V).
2022-10-25 22:40:16 +11:00
robert-hh 972212907d samd/mcu: Use lf2s for SAMD51 and lfs1 for SAMD21.
Using lfs1 gives a smaller code, but lfs2 has more features.
2022-10-06 23:14:21 +11:00
robert-hh 9f4df86016 samd/boards: Move the flash filesystem definitions to the linker files.
They used to be in mpconfigmcu.h, but have to be different for different
chip variants, like the SAMD51x20.
2022-10-06 23:14:08 +11:00
robert-hh 00dcf04643 samd/mcu: Add floating point suport for SAMD21 devices.
For consistency it should be there.
2022-10-06 23:10:49 +11:00
robert-hh d9338aabc5 samd: Change the symbol names for the peripheral clocks.
From APB_FREQ to DFLL48M_FREQ, and from apb_freq to peripheral_freq.
2022-10-06 23:10:08 +11:00
robert-hh 85fb8b8b02 samd/pin_af: Simplify the pin-af-table handling.
Changes are:
- The pin-af-table-SAMDxx.csv file are moved to the mcu directories with
  the name as pin-af-table.csv.
- The handling in Makefile and pin_af.c is simplified.
2022-10-06 23:05:46 +11:00
robert-hh 20e7313453 samd/clock_config: Add HW_DFLL_USB_SYNC and HW_MCU_OSC32KULP extensions.
Two new compile flags are:

MICROPY_HW_DFLL_USB_SYNC: Effective only if DFLL48 does not run from the
crystal.  It will synchronize the DFLL48M clock with the USB's SOF pulse.
If no USB is connected, it will fall back to open loop mode.  The DFLL48M
clock is then pretty precise, but with a higher clock jitter at SAMD51
devices.

MICROPY_HW_MCU_OSC32KULP: Effective only if the devics uses a crystal as
clock source.  Run the MCU clock from the ULP 32kHz oszillator instead of
the crystal.  This flag was added to cater for a interference problem of
the crystal and Neopixel/Debug pins at Adafruit FEATHER Mx boards, which
causes the board to crash.  Drawback: ticks_ms() and time.time() vs. than
ticks_us() and the peripherals like PWM run at not synchronous clocks.
2022-10-06 23:03:08 +11:00
robert-hh f00356a486 samd/clock_config: Split clock_config.c to separate SAMD21/SAMD51 files.
And put the file into the mcu directory.  The file got a little bit long
and hard to read.
2022-10-06 23:01:58 +11:00
robert-hh 929dfc66a3 samd/mpconfigport: Restructure to use ROM feature levels.
Changes are:
- Set the feature level for each MCU: CORE features for SAMD21, and EXTRA
  features for SAMD51.
- Remove all definitions that are included in the core feature level.
- Keep the default settings for feature level and float, to make the choice
  obvious.
2022-10-06 23:00:44 +11:00
robert-hh 9a567b04e7 samd/machine_uart: Support buffered TX for UART.
It can be enabled/disabled by a configuration switch.  The code size
increase is 308 bytes, but it requires RAM space for buffers, the larger
UART object and root pointers.
2022-10-06 22:57:37 +11:00
robert-hh aa6dbbcffd samd/mcu: Factor out MCU policy for SAMD21 and SAMD51.
Which contains a mpconfigmcu.h, mpconfigmcu.mk and manifest.py file for
each MCU group.  That looks better than the previous choice.
2022-10-06 22:56:13 +11:00