Commit Graph

3188 Commits

Author SHA1 Message Date
robert-hh
9d0aefe719 samd/boards/SEEED_WIO_TERMINAL: Enable using the 32kHz crystal.
That was missing from the configuration.
2022-11-08 23:26:24 +11:00
robert-hh
fadfc30547 samd/README: Update README to reflect recent changes to the port.
Most of the content of README.md became obsolete and was replaced by the
documentation of MicroPython.  Instead, README.md now shows build
instructions like the other ports.
2022-11-08 23:25:39 +11:00
robert-hh
144e5ec645 samd/mcu/samd51: Use an additional manifest.py for SAMD51 boards.
Including the uasyncio scripts and the drivers for DHT, DS18x20 and
onewire.  The uasyncio scripts need about 8k of flash and are not included
for the SAMD21 boards by default.
2022-11-08 23:22:26 +11:00
Damien George
5987130afd webassembly/Makefile: Change compiler optimisation from O3 to Os.
Emscripten strongly advises the use of optimisation when compiling with
ASYNCIFY enabled.  Testing the difference betwen O3 and Os for various
configurations gives:

    flags                      firmware.wasm   micropython.js  perf
    -O3 -s ASYNCIFY            1342003          212845         0 (baseline)
    -O3 -s ASYNCIFY -s WASM=0        -         7064750         -30%
    -O3                         367131          196569         +140%
    -O3 -s WASM=0                    -         2818260         +30%
    -Os -s ASYNCIFY            1135450          213064         +40%
    -Os -s ASYNCIFY -s WASM=0        -         6239768         -30%
    -Os                         295028          196569         +180%
    -Os -s WASM=0                    -         2271358         +30%

The first row is prior to this commit.  The second and third columns show
firmware size (add them to get the total size).  The fourth column shows
the approximate change in performance compared to the baseline.  The
performance was measured using run-perfbench.py and the error was large, up
to 20%, although general trends in the change in performance could still be
seen.

In summary, using using Os instead of O3 makes it a little bit faster in
all cases, and smaller output (wasm/js) in all cases.

Signed-off-by: Damien George <damien@micropython.org>
2022-11-07 17:18:42 +11:00
Damien George
1ed740b152 webassembly/README: Update README to describe new stdout behaviour.
Signed-off-by: Damien George <damien@micropython.org>
2022-11-07 17:18:31 +11:00
Nicholas H.Tollervey
db978d7155 webassembly: Dispatch micropython-print via document not mp_js_stdout. 2022-11-07 15:09:56 +11:00
Damien George
2d406f2226 webassembly: Support piping in a program on stdin.
The performance benchmark suite can now be run on the webassembly port.

Signed-off-by: Damien George <damien@micropython.org>
2022-11-03 23:35:22 +11:00
Damien George
7a505d57dc webassembly: Change "stack" argument to "heapsize".
Because that's what mp_js_init() takes as its argument.

Signed-off-by: Damien George <damien@micropython.org>
2022-11-03 18:47:48 +11:00
Damien George
d65edaa232 webassembly: Use Date's now() instead of getTime().
Using now() is a bit faster because it doesn't need to create a new Date.

Signed-off-by: Damien George <damien@micropython.org>
2022-11-03 18:47:48 +11:00
Damien George
46bb52adf6 webassembly: Add support for VFS and enable VFS_POSIX.
This gets filesystem support working.

Signed-off-by: Damien George <damien@micropython.org>
2022-11-01 13:53:06 +11:00
Damien George
54478eb9e7 webassembly/mpconfigport: Use MICROPY_CONFIG_ROM_LEVEL_EXTRA_FEATURES.
This simplifies the config file.  This is not a no-op, it does enable a few
new features to bring the port in line with this config level.

Signed-off-by: Damien George <damien@micropython.org>
2022-11-01 13:10:45 +11:00
robert-hh
7775523b2d esp32/machine_pwm: Verify PWM is active when config methods are called.
Checks are added for pwm.freq(), pwm_duty(), pwm_duty_u10() and
pwm.duty_u16().  This avoids a core dump on ESP32C3, and misleading error
messages on Xtensa ESP32 devices.
2022-10-31 11:54:46 +11:00
Ihor Nehrutsa
5b2929a0e6 esp32/machine_pin: Fix size of machine_pin_irq_handler array.
Set the size of machine_pin_irq_handler array to GPIO_NUM_MAX:
- Min GPIO_NUM_MAX is 22 for IDF_TARGET_ESP32C3.
- Max GPIO_NUM_MAX is 49 for IDF_TARGET_ESP32S3.

The MP_REGISTER_ROOT_POINTER entry must be hard-coded, because the location
that it's evaluated by the compiler does not include the relevant IDF
header to get a definition of GPIO_NUM_MAX.
2022-10-31 11:42:20 +11:00
Mark Grosen
12f9948151 esp32/machine_i2c: Fix clocks and timeouts for ESP32-C3, ESP32-S3.
Each SoC family has its own clocks and timings/timeouts. For I2C, the
default source clock is either APB (ESP32, ESP32-S2) or XTAL (ESP32-S3,
ESP32-C3) as shown in the datasheets.  Since
machine_i2c.c/machine_hw_i2c_init() uses the default clk_flags (0), the
alternate low-power clock source is never selected in ESP-IDF
i2c.c/i2c_param_config().  There is not an API in i2c.c to get the source
clock frequency, so a compile-time value is used based on SoC family.

Also, the maximum timeout is different across the SoC families, so use the
I2C_LL_MAX_TIMEOUT constant to eliminate the warning from
i2c_set_timeout().

With these changes, the following results were obtained.  The I2C SCL
frequencies were measured with a Saleae logic analyzer.

ESP32 (TTGO T Dislay)
    I2C(0, scl=22, sda=21, freq=101781)  Measured: 100KHz
    I2C(0, scl=22, sda=21, freq=430107)  Measured: 400KHz
    I2C(0, scl=22, sda=21, freq=1212121) Measured: 941KHz

ESP32-S3 (TTGO T-QT)
    I2C(0, scl=34, sda=33, freq=111111)  Measured: 107KHz
    I2C(0, scl=34, sda=33, freq=444444)  Measured: 400KHz
    I2C(0, scl=34, sda=33, freq=1111111) Measured: 842KHz

ESP32-C3 (XIAO ESP32C3)
    I2C(0, scl=7, sda=6, freq=107816)  Measured: 103KHz
    I2C(0, scl=7, sda=6, freq=444444)  Measured: 380KHz
    I2C(0, scl=7, sda=6, freq=1176470) Measured: 800KHz

(ESP32-S2 board was not available for testing.)
2022-10-28 19:06:41 +11:00
Damien George
6643b4f0cc samd/machine_timer: Use extmod version of machine.Timer.
Signed-off-by: Damien George <damien@micropython.org>
2022-10-27 14:45:24 +11:00
Damien George
0159085666 renesas-ra/machine_timer: Use extmod version of machine.Timer.
Signed-off-by: Damien George <damien@micropython.org>
2022-10-27 14:44:12 +11:00
Damien George
98cbace299 mimxrt/machine_timer: Use extmod version of machine.Timer.
Signed-off-by: Damien George <damien@micropython.org>
2022-10-27 14:43:03 +11:00
Damien George
cd35b8a2a3 extmod/machine_timer: Move stm32's implementation of machine.Timer here.
So it can be reused by other ports.

Signed-off-by: Damien George <damien@micropython.org>
2022-10-27 14:32:43 +11:00
Damien George
e8f5cfe0e1 nrf: Rename MICROPY_PY_MACHINE_TIMER to MICROPY_PY_MACHINE_TIMER_NRF.
So that it doesn't clash with the extmod version.

Also make the default for this enabled, so that most boards do not need to
configure it.

Signed-off-by: Damien George <damien@micropython.org>
2022-10-27 14:30:58 +11:00
robert-hh
65fa7fd8bb mimxrt/machine_timer: Use soft-timer implementation for machine.Timer.
This releases the hardware timers for other tasks, which need a higher
resolution and faster response.  And it is less port-specific code.
2022-10-27 14:09:29 +11:00
robert-hh
9d2e179fa5 mimxrt: Fix CPU freeze when calling __WFE() in MICROPY_EVENT_POLL_HOOK.
This issue affected i.MX RT 1052, 1062 and 1064.  It seems to be addressed
by Errata ERR006223, which also mentions i.MX RT101x and 102x, but these
devices worked well even without the change.  As a side effect, the current
consumption at an idle REPL drops significantly with this fix.

Fixes issue #7235.
2022-10-27 14:06:12 +11:00
robert-hh
e20bb98392 mimxrt/machine_pin: Add the Pin.toggle() method.
For consistency with other ports, even if this method is undocumented at
the moment.
2022-10-27 14:05:33 +11:00
robert-hh
fcccfc176b samd/modmachine: Add machine.softreset().
For consistency with other ports.
2022-10-25 23:49:52 +11:00
robert-hh
a1eebc507e samd/machine_spi: Register SerCom objects as root pointers.
Protect SerCom (UART, SPI, I2C) objects from getting freed by the GC when
they go out of scope without being deinitialized.  Otherwise the ISR of a
Sercom may access an invalid data structure.
2022-10-25 23:48:37 +11:00
robert-hh
d74215a313 samd/machine_spi: Implement spi.deinit() and simplify sercom_deinit_all.
The sercom_deinit_all() function does not need the object pointers.
2022-10-25 23:46:00 +11:00
robert-hh
9c2bc379f1 samd/machine_uart: Use a finaliser to tidy up UART on soft reset.
And use the common sercom_table, saving a few bytes of RAM.
2022-10-25 23:44:49 +11:00
robert-hh
474233c250 samd/machine_pwm: Serialize fast update of PWM settings.
Any update of freq or duty_cycle requires the previous PWM cycle to be
finished.  Otherwise the new settings are not accepted.

Other changes in this commit:
- Report the set duty cycles even when the PWM is not yet started.
- pwm.freq(0) stops the pwm device, instead of raising an expception.
- Clear the duty cycle value cache on soft reset.
2022-10-25 23:42:14 +11:00
robert-hh
ac1e31267b samd/boards: Rework the pins.csv files.
Changes are:
- Remove the LED_Pxxx definitions from pins.csv, now that the LED class is
  gone.
- Remove the '-' lines.
- Add default lines for USB and SWCLK, SWDIO.
2022-10-25 23:40:28 +11:00
robert-hh
a6760bd4ef samd/modmachine: Replace the LED class by the Signal class.
It simplifies and improves the code.  The LED_Pxxx lines of the board.csv
lines can still be used, but will be taken as Pin definitions.
2022-10-25 23:39:41 +11:00
robert-hh
4d38ab652e samd: Make ADC, DAC, PWM, SPI objects consistent in how they print out.
All of ADC, DAC, Pin, PWM and SPI looked different before this change.
2022-10-25 23:36:01 +11:00
robert-hh
e5cf3fab95 samd/machine_pin: Change the pin handling and naming/numbering.
Pin numbers are now the MCU port numbers in the range:

    PA0..PA31:  0..31
    PB0..PB31: 32..63
    PC0..PC31: 64..95
    PD0..PD31: 96..127

Pins can be denoted by the GPIO port number, the name as defined in
pins.csv or a string in the form Pxnn, like "PA16" or "PD03".

The pins.c and pins.h files are now obsolete.  The pin objects are part of
the AF table.

As result of a simplification, the code now supports using pin names or
numbers instead of pin objects for modules like UART, SPI, PWM, I2C, ADC,
pininfo.
2022-10-25 23:34:07 +11:00
robert-hh
e7aa9700ca samd/boards/SEEED_WIO_TERMINAL: Declare more pins for SEEED WIO board.
Defining all pins from the external 40 Pin connector, and some internal
pins like the one for SD and LCD.
2022-10-25 23:28:34 +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
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
2251cb774b samd/machine_uart: Implement uart.txdone() and uart.flush().
Using the stream method for uart.flush().

uart.txdone() returns True, if the uart not busy, False otherwise.

uart.flush() waits until all bytes have been transmitted or a timeout
triggers.  The timeout is determined by the buffer size and the baud rate.

Also fix two inconsistencies when not using txbuf:
- Report in ioctl as being writeable if there is room in the tx buffer,
  only if it is configured.
- Print the txbuf size if configured.
2022-10-25 23:11:57 +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
f0399d35e4 samd/modmachine: Get the bootloader magic address from the lib.
Instead of being hard-coded, and then it works for all MCUs.

That fits except for a Sparkfun SAMD51 Thing Plus (known) bug, which uses
192k - 4 as magic address.  Therefore, that address is set as well to avoid
a problem when this bug is fixed by Sparkfun.
2022-10-25 23:09:04 +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
4c9e4c3310 samd/mcu/samd51: Enable FAT support for SAMD51.
Tested with a SD card connected to a SAMD51 board.  The SEEED WIO terminal
has a SD-Card reader built-in.

Also a side change to remove a few obsolete lines from Makefile.
2022-10-25 23:07:23 +11:00
robert-hh
fe31fca462 samd/mcu/samd51: Enable onewire support for SAMD51. 2022-10-25 23:07:01 +11:00
robert-hh
a7113e95d7 samd/modmachine: Add machine.dht_readinto and enable on SAMD51. 2022-10-25 23:06:44 +11:00
robert-hh
0d3f0d7470 samd/boards/SPARKFUN_SAMD51_THING_PLUS: Add board files for Thing Plus.
That device uses an SAMD51J20 MCU with 256k RAM and 1024k flash.
2022-10-25 22:42:17 +11:00
robert-hh
64e3c351de samd/modmachine: Add machine.reset_cause(). 2022-10-25 22:41:31 +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
edc3f3d0d3 samd/clock_config: Extend the range of machine.freq().
The value given for machine.freq(f) is extend to the range of 1_000_000 to
200_000_000.  Frequencies below 48 MHz will be forced to an integer
fraction of 48 MHz.  At frequencies below 8 MHz USB is switched off.  The
power consumption e.g. of ADAFRUIT_ITSYBITSY_M4_EXPRESS drops to about
1.5 mA at 1 MHz.

Since the peripheral frequency is dropped as well, timing e.g. of PWM,
UART, I2C and SPI is affected and frequency/baud rate has to set again
after a frequency change below 48 MHz.
2022-10-25 22:38:45 +11:00
Jim Mussared
5ee1cb2771 stm32/boards/ARDUINO_PORTENTA_H7: Revert to single-precision float.
Using repr C is incompatible with double-precision floats on 32-bit arch.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-25 14:46:04 +11:00
Damien George
8874a09119 extmod/mbedtls: Enable elliptic curve DH and DSA cryptography.
This is necessary to access sites that only support these protocols.

The rp2 port already has ECDH enabled, so this just adds ECDSA there.  The
other ports now gain both ECDH and ECDSA.  The code size increase is:

- rp2 (PICO_W): +2916 bytes flash, +24 bytes BSS
- stm32 (PYBD_SF6): +20480 bytes flash, +32 bytes data, +48 bytes BSS
- mimxrt (TEENSY41): +20708 bytes flash, +32 bytes data, +48 bytes BSS
- unix (standard x86-64): +39344 executable, +1744 bytes data, +96 BSS

This is obviously a large increase in code size.  But there doesn't seem to
be any other option because without elliptic curve cryptography devices are
partially cut off from the internet.  For use cases that require small
firmware size, they'll need to build custom firmware with a custom mbedtls
config.

Signed-off-by: Damien George <damien@micropython.org>
2022-10-22 19:08:21 +11:00
Damien George
9347545f9e extmod/mbedtls: Enable MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE.
This was already enabled on all ports except mimxrt.  Now it's enabled on
all of them.

Signed-off-by: Damien George <damien@micropython.org>
2022-10-22 19:06:21 +11:00
Damien George
b337678964 extmod/mbedtls: Add common configuration file, and use it in all ports.
This is a no-op change.

Signed-off-by: Damien George <damien@micropython.org>
2022-10-22 19:06:21 +11:00
Damien George
67f98ba10c extmod/btstack: Update BTstack bindings to work with latest BTstack.
The following multi-tests pass (eg with PYBD_SF6+LEGO_HUB_NO6):

    ble_gap_advertise.py
    ble_gap_connect.py
    ble_gap_device_name.py
    ble_gattc_discover_services.py
    ble_gatt_data_transfer.py
    perf_gatt_char_write.py
    perf_gatt_notify.py
    stress_log_filesystem.py

These are the same tests that passed prior to this BTstack update.

Also tested on the unix port using H4 transport.

Signed-off-by: Damien George <damien@micropython.org>
2022-10-22 14:28:25 +11:00
iabdalkader
93f3910fe7 nrf: Rename machine I2C, PWM, SPI, UART types consistently across ports.
This renames:
- machine_hard_i2c_type -> machine_i2c_type
- machine_hard_pwm_type -> machine_pwm_type
- machine_hard_spi_type -> machine_spi_type
- machine_hard_uart_type -> machine_uart_type
2022-10-22 12:58:54 +11:00
iabdalkader
5e90ec2331 zephyr: Rename machine I2C and SPI types consistently across ports.
This renames:
- machine_hard_i2c_type -> machine_i2c_type
- machine_hard_spi_type -> machine_spi_type
2022-10-22 12:58:21 +11:00
iabdalkader
bfa6f34404 renesas-ra: Rename machine SPI type consistently across ports.
This renames:
- machine_hard_spi_type -> machine_spi_type
2022-10-22 12:57:58 +11:00
iabdalkader
e275a58ac1 samd: Rename machine I2C type consistently across ports.
This renames:
- machine_hw_i2c_type -> machine_i2c_type
2022-10-22 12:57:32 +11:00
iabdalkader
22ad45fda6 rp2: Rename machine I2C type consistently across ports.
This renames:
- machine_hw_i2c_type -> machine_i2c_type
2022-10-22 12:56:58 +11:00
iabdalkader
427670c210 esp32: Rename machine I2C and SPI types consistently across ports.
This renames:
- machine_hw_i2c_type -> machine_i2c_type
- machine_hw_spi_type -> machine_spi_type
2022-10-22 12:56:10 +11:00
iabdalkader
af4ba6d1b4 stm32: Rename machine I2C and SPI types consistently across ports.
This renames:
- machine_hard_i2c_type -> machine_i2c_type
- machine_hard_spi_type -> machine_spi_type
2022-10-22 12:54:42 +11:00
Damien George
89b3207376 unix/modffi: Move header includes inside MICROPY_PY_FFI guard.
So ffi.h is not needed if this module is disabled.

Signed-off-by: Damien George <damien@micropython.org>
2022-10-14 14:36:17 +11:00
robert-hh
92d9118038 rp2/fatfs_port: Fix the modification date of files.
It was off by 2000 % 128 == 80 years.

Addresses issue #9535.
2022-10-12 00:31:38 +11:00
Jim Mussared
b25087fc6f samd/Makefile: Split up SRC_C variables.
This improves clarity a bit, but also ensures that only the required files
are added to SRC_QSTR.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-12 00:10:18 +11:00
Jim Mussared
a2aceb5007 nrf/Makefile: Split up SRC_C variables.
This improves clarity a bit, but also ensures that only the required files
are added to SRC_QSTR.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-12 00:09:55 +11:00
Jim Mussared
43bcfb148b mimxrt/Makefile: Split up SRC_C variables.
This improves clarity a bit, but also ensures that only the required files
are added to SRC_QSTR.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-12 00:08:49 +11:00
Jim Mussared
d6d8722558 extmod: Make extmod.mk self-contained.
This makes it so that all a port needs to do is set the relevant variables
and "include extmod.mk" and doesn't need to worry about adding anything to
OBJ, CFLAGS, SRC_QSTR, etc.

Make all extmod variables (src, flags, etc) private to extmod.mk.

Also move common/shared, extmod-related fragments (e.g. wiznet, cyw43,
bluetooth) into extmod.mk.

Now that SRC_MOD, CFLAGS_MOD, CXXFLAGS_MOD are unused by both extmod.mk
(and user-C-modules in a previous commit), remove all uses of them from
port makefiles.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-11 23:31:49 +11:00
Jim Mussared
87011f6353 extmod/extmod.mk: Make extmod.mk handle GIT_SUBMODULES.
This applies to nimble, btstack, axtls, mbedtls, lwip.

Rather than having the ports individually manage GIT_SUBMODULES for these
components, make extmod.mk append them when the relevant feature is
enabled.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-11 23:29:09 +11:00
Jim Mussared
065af04a4e unix/Makefile: Don't use _MOD variable names.
This conflicts with the triple-usage of these variables for user-C-modules
and extmod source.

For CFLAGS_MOD, just use CFLAGS directly. For SRC, use SRC_C directly as
the relevant files are all guarded by the preprocessor anyway.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-11 23:27:01 +11:00
Jim Mussared
3cc6decfc4 py/py.mk: Make user-C-module handling self-contained in py.mk.
Removes the need for the port to add anything to OBJS or SRC_QSTR.

Also makes it possible for user-C-modules to differentiate between code
that should be processed for QSTR vs other files (e.g. helpers and
libraries).

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-11 23:23:18 +11:00
Jim Mussared
67d05ed02b ports: Make generated pin.c handling more consistent across ports.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-11 23:18:46 +11:00
Jim Mussared
17f2783e4a all: Use += rather than = everywhere for CFLAGS/LDFLAGS/LIBS.
This avoids a surprise where an = can cancel out an earlier +=.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-11 23:17:41 +11:00
Jim Mussared
8e912a501a unix: Enable sys.executable.
Gives the absolute path to the unix micropython binary.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
2022-10-11 18:10:30 +11:00
robert-hh
366c801b35 samd/machine_pin: Change the printing of Pin and LED objects.
It now prints lines like:

    Pin("D9", mode=IN, pull=PULL_UP, GPIO=PA07)

or

    LED("LED")

showing for consistency the names as given in pins.csv.  For pins, the GPIO
numer is printed as well for a reference.
2022-10-06 23:14:21 +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
4cf527eb05 samd/main: Initialize readline on start up.
Somehow that was forgotten.
2022-10-06 23:14:21 +11:00
robert-hh
65f99e371d samd/boards: Use the same linker file for all SAMD51x19 variants. 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
387025f5d1 samd/mcu: Enable the math module on SAMD51. 2022-10-06 23:11:02 +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
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
b001730462 samd/Makefile: Fix a dependency problem with "make -j".
The build directory was not created before attempting to create the
generated files in it.
2022-10-06 23:08:00 +11:00
robert-hh
560170de02 samd/samd_flash: Remove obsolete printf's and return values instead.
Returning values is much more useful.
2022-10-06 23:06:43 +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
a415752173 samd/machine_bitstream: Add the machine.bitstream() function.
The SAMD21 implementation is an adaption of @jimmo's code for STM32Lxx.
The only changes are the addresses and names of the port registers and the
timing parameters.

SAMD21: The precision is about +/-25ns at 48MHz clock frequency.  The first
two cycles are about 40-60 ns longer than set.  But still good enough to
drive a neopixel device.

SAMD51: The precision is about +/-30ns at 120MHz clock frequency.  Good
enough to drive a neopixel device.
2022-10-06 23:00:00 +11:00
robert-hh
fd7b57dd22 samd/mphalport: Use CYCCNT for SAMD51's mp_hal_ticks_cpu().
And use mp_hal_ticks_us() for SAM21's mp_hal_ticks_cpu().  The SAMD21 has
no CYCCNT register, and the SysTick register has only a 1 ms span (== 48000
count range).
2022-10-06 22:59:02 +11:00
robert-hh
a9304af8fa samd/boards: Add missing/lost board config and pin definitions.
Fixes are:
- Pin definitions for ADAFRUIT_FEATHER_Mx_EXPRESS and
  ADAFRUIT_ITSYBITSY_M4_EXPRESS.
- For ADAFRUIT_ITSYBITSY_M0_EXPRESS, change the MISO/MOSI name.
- For MINISAM_M4, add the default SPI pins.
- For boards with 32k crystal, add the XOSC32K setting.
2022-10-06 22:58:09 +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
37449df821 samd/modutime: Enable time.time() based on systick_ms().
Allowing to set a time and retrieve the time.  It is based on systick_ms()
with the precision of the MCU clock.  Unless that is based on a crystal,
the error seen was about 0.5% at room temperature.
2022-10-06 22:57:11 +11:00
robert-hh
7da7663902 samd/mphalport: Add a mp_hal_ticks_ms_64() function.
Returning a 64 bit number.  This will be used by the utime module and the
machine.UART module for timeout avoiding overflow.
2022-10-06 22:56:58 +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
robert-hh
029e9af457 samd/modmachine: Add machine.time_pulse_us.
Software based. Resolution:
- +/-2 microseconds on SAMD51.
- +/-4 microseconds on SAMD21.
2022-10-06 22:55:45 +11:00
robert-hh
f5da77b5ce samd/machine_dac: Add the machine.DAC class.
It suuports 1 channel @ 10 bit for SAMD21, 2 channels @ 12 bit for SAMD51.

Instantiation by:

    dac = machine.DAC(ch) # 0 or 1

Method write:

    dac.write(value)

The output voltage range is 0..Vdd.
2022-10-06 22:55:10 +11:00
robert-hh
aa2d746ef4 samd/machine_led: Optimise size of the machine.LED class.
By reducing the methods to on(), off(), toggle() and call, and using the
method implementation of the machine.Pin class.

The code size reduction is 756 byte.
2022-10-06 22:54:11 +11:00
robert-hh
6e2dff6bae samd/modsamd: Add pininfo() function to the samd module.
samd.pininfo() returns the data stored in the pin af table for a pin.
Using a small script, a nice representation of the table can be created.
2022-10-06 22:53:28 +11:00
robert-hh
7a2f2d88f7 samd/machine_wdt: Add the machine.WDT class. 2022-10-06 22:53:06 +11:00
robert-hh
32c973d554 samd/machine_timer: Add machine.Timer based on the shared soft-timer. 2022-10-06 22:52:39 +11:00
robert-hh
3625388d8c samd/samd_isr: Change the way a Sercom ISR is registered and called.
Code size diff: +12 Bytes
BSS diff: -12 Bytes
RAM usage: +16 Bytes
Speed increase: a few clock cycles per call
Style improvement: ++
2022-10-06 22:52:10 +11:00
robert-hh
009c51c13f samd/mpconfigport: Enable a few more MicroPython features.
Additional features are:
- Support executing .mpy files.
- Allow const().
- Enable auto-indent in REPL.
- Enable enumerate, min/max, attrtuple, input.
2022-10-06 22:51:34 +11:00