Commit Graph

159 Commits

Author SHA1 Message Date
Jim Mussared
6d460d33dc samd/boards/SEEED_XIAO: Rename to SEEED_XIAO_SAMD21.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-12-15 14:18:44 +11:00
robert-hh
17ab2f671b samd: Support entering bootloader via USB CDC 1200bps touch. 2022-12-14 12:50:04 +11:00
robert-hh
e69313f89c samd: Add a vref=num option to the ADC and DAC constructor.
ADC: The argument of vref=num is an integer. Values for num are:

    SAMD21:
    0  INT1V   1.0V voltage reference
    1  INTVCC0 1/1.48 Analog voltage supply
    2  INTVCC1 1/2 Analog voltage supply (only for VDDANA > 2.0V)
    3  VREFA   External reference
    4  VREFB   External reference

    SAMD51:
    0  INTREF  internal bandgap reference
    1  INTVCC1 Analog voltage supply
    2  INTVCC0 1/2 Analog voltage supply (only for VDDANA > 2.0v)
    3  AREFA   External reference A
    4  AREFB   External reference B
    5  AREFC   External reference C (ADC1 only)

DAC: The argument of vref=num is an integer. Suitable values:

    SAMD21:
    0  INT1V   Internal voltage reference
    1  VDDANA  Analog voltage supply
    2  VREFA   External reference

    SAMD51:
    0  INTREF Internal bandgap reference
    1  VDDANA Analog voltage supply
    2  VREFAU Unbuffered external voltage reference (not buffered in DAC)
    4  VREFAB Buffered external voltage reference (buffered in DAC).
2022-12-14 12:48:24 +11:00
robert-hh
a73dcb3d22 samd/machine_uart: Fix uart.deinit() and save some RAM.
Changes in this commit:
- Do not deinit IRQ when uart.deinit() is called with an inactive object.
- Remove using it for the finaliser.  There is another machanism for soft
  reset, and it is not needed otherwise.
- Do not tag the UART buffers with MP_STATE_PORT, it is not required.
2022-12-14 12:46:20 +11:00
robert-hh
f78dd25a2c samd/machine_uart: Check the UART TX pin assignment.
Check, if TX is at Pad 0 (SAMD51), or Pad 0 or 2 (SAMD21).
2022-12-14 12:45:51 +11:00
robert-hh
5b1fd8802a samd/machine_uart: Simplify machine_uart_any() and machine_uart_read().
Remove the call to uart_drain_rx_fifo().  It is not required, and may cause
a race condition.
2022-12-14 12:43:34 +11:00
robert-hh
4199f986ad samd/machine_uart: Fix IRQ flag setting and clearing.
Clearing the DRE flag for the transmit interrupt at the end of a
uart.write() also cleared the RXC flag disabling the receive interrupt.

This commit also changes the flag set/clear mechanism in the driver for SPI
as well, even if it did not cause a problem there.  But at least it saves a
few bytes of code.
2022-12-14 12:42:34 +11:00
robert-hh
fcd1788937 samd: Avoid under-/overflow in I2C and SPI baudrate calculations.
Applies to both SPI and I2C.  The underflow caused high baudrate settings
resulting in the lowest possible baudrate.  The overflow resulted in
erratic baudrates, not just the lowest possible.
2022-12-14 12:41:42 +11:00
robert-hh
43fc133dbd samd/mpconfigport: Use __WFE() in MICROPY_EVENT_POLL_HOOK.
Like WFI, WFE also responds to a hardware interrupt, and using WFE speeds
up at least spi.read().  Power consumption at an idle REPL is unchanged.
2022-12-14 12:40:22 +11:00
robert-hh
3cc359c204 samd/mpconfigport: Support MICROPY_HW_SOFTSPI_MIN_DELAY.
Bringing the SoftSPI baudrate up to about 500 kHz.
2022-12-14 12:39:54 +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
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
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
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
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
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
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
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
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
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