Wykres commitów

14272 Commity (dbb0019666a3270b0ed032e2cb9479eadc599c46)

Autor SHA1 Wiadomość Data
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
robert-hh 4ef2da176f samd/main: Use the common execution mode of boot.py and main.py.
Behaviour is:
- Do not execute main.py if boot.py failed.
- On a forced exit, do a soft reset.
2022-10-06 22:50:56 +11:00
robert-hh 45bf25a002 samd/moduos: Add uos.urandom() for SAMD51.
Based on the hardware RNG.
2022-10-06 22:50:29 +11:00
robert-hh 15212ae8d4 samd/moduos: Add uos.dupterm(). 2022-10-06 22:49:19 +11:00
robert-hh 94d27ae28f samd/machine_i2c: Add the machine.I2C class.
Using the common API.  Tested with SAMD21 and SAMD51 boards.
2022-10-06 22:49:06 +11:00
robert-hh aa870708ac samd/machine_spi: Add the machine.SPI class.
Suported by both SAMD21 and SAMD51.  It follows the generic API, except for
the bits=nn option, which is not implemented (yet).
2022-10-06 22:48:44 +11:00
robert-hh b33f204529 samd/machine_uart: Add the machine.UART class.
All board pins that have UART's assigned can be used.  Baud rate range is
75 Baud to ~2 MBaud.

No flow control yet, and only RX is buffered.  TX buffer and flow control
may be added later for SAMD51 with its larger RAM and Flash.
2022-10-06 22:48:12 +11:00
robert-hh 7d281f6165 samd/modmachine: Add disable_irq(), enable_irq() and idle() to machine.
No specific features.
2022-10-06 22:47:52 +11:00
robert-hh 4b6f6ccf88 samd/machine_pin: Add pin.irq() to the machine.Pin class.
Its API conforms to the docs.  There are 16 IRQ channels available, which
will be used as assignable to the GPIO numbers.  In most cases, the irq
channel is GPIO_no % 16.
2022-10-06 22:46:53 +11:00
robert-hh a9eef1b276 samd/samd_isr: Rework the interrupt tables.
Changes are:
- Have two separate tables for SAM21 and SAMD51.
- Use a short table for SAMD21.
- Add a comment to each line telling what it's for, making further use
  easier.
- Add preliminary handlers/entries for PendSV, EIC and Sercom.  These will
  be replaced later when the respecitve modules are added.
2022-10-06 22:46:10 +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 5c7e93ec48 samd/machine_adc: Add the machine.ADC class.
With the method read_u16().  Keyword arguments of the constructor are:
- bits=n    The resolution; default is 12.
- average=n The average of samples, which are taken and cumulated.  The
            default value is 16.  Averaging by hw is faster than averaging
            in code.

The ADC runs at a clock freq 1.5 MHz.  A single 12 bit conversion takes
8 microseconds.
2022-10-06 22:41:44 +11:00
robert-hh 6765d4bbd6 samd/pin_af: Add the pin af table and its helper functions.
The pin af table is a representation of the MUX table from the data sheet.
It provides information for each pin about the supported device functions.

That information is needed by pin.irq, machine.ADC, machine.PWM,
machine.UART, machine.SPI and machine.I2C.  For each of these, the table
tells for each pin, which device number, af number and pad number is
assigned.  Using the table gives a straight, uniform access to the
information, where the benefit outweights the size of the table, which is
not that large.

The tables are MCU-specific.  It is not required to tell for each board,
which and where each of the above devices is available.  That makes addding
boards easy.

Note: The information for DAC and I2S was not included, since it affects
only a few pins.
2022-10-06 22:39:17 +11:00
robert-hh 6c037af086 samd/boards: Create pin_af_table.c from pin_af_table_SAMDxx.csv files.
This step just creates the table.  The firmware cannot be built at this
commit.  The next commit will complete the pin-af mechanism.
2022-10-06 22:38:45 +11:00
robert-hh 4013577af2 samd/modmachine: Enable SoftSPI and SoftI2C. 2022-10-06 22:38:33 +11:00
robert-hh e8615f5813 samd/machine_pin: Allow specifying a pin or LED by its name as a string.
The names are defined in pins.csv.
2022-10-06 22:37:46 +11:00
robert-hh 33eaf739d2 samd/machine_pin: Add OPEN_DRAIN mode for pins.
Changes in this commit are:
- Use mphal_xx functions whenever possible.
- Remove obsolete includes.
- Clean up traces of a non-functional pin.irq() from earlier builds.
  Pin.irq() will be added in further commits in a working manner.
2022-10-06 22:37:05 +11:00
robert-hh 98ae312640 samd/samd_isr: Extend systick_ms to 64 bit.
By adding a 32 bit overflow counter.  This allows it to be used for the
time functions.
2022-10-06 22:36:26 +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 5af54ad61f samd/modmachine: Allow changing the CPU freq with machine.freq(f).
SAMD51 only.  Accepted values are 48_000_000 to 200_000_000.  The range
specified by Atmel is 96_000_000 to 120_000_000.
2022-10-06 22:34:42 +11:00
robert-hh b4d29fd47a samd/clock_config: Set up the clock configuration.
Clock settings:
- GCLK0: 48 MHz (SAMD21) or 120 MHz(SAMD51).
- GCLK1: 32768 Hz for driving the PLL.
- GCLK2: 48 MHz for tzhe peripheral clock.
- GCLK3: 1 MHz (SAMD21) or 8 MHz (SAMD51) for the µs ticks timer.
- GCLK8: 1 kHz for WDT (SAMD21 only).

If a 32 kHz crystal is present, it will be used as clock source.  Otherwise
the DFLL48M in open-loop mode is used.

GCLK0 for SAM51 can be changed between 48 MHz and 200 MHz.  The specified
range is 96 MHz - 120 MHz.
2022-10-06 22:33:31 +11:00
robert-hh 949a808076 samd/boards: Add ADAFRUIT_FEATHER_M4_EXPRESS and _ITSYBITSY_M0_EXPRESS.
These two boards are used for testing, so it is favorable to have them
added early.

The full test set is:
- ADAFRUIT_FEATHER_M4_EXPRESS: SAMD51 with 32kHz crystal.
- ADAFRUIT_ITSYBITSY_M0_EXPRESS: SAMD21 without crystal.
- ADAFRUIT_ITSYBITSY_M4_EXPRESS: SAMD51 without crystal.
- SEEED_XIAO: SAM21 with 32kHz crystal.
2022-10-06 22:32:01 +11:00
robert-hh c4f7c0b8a2 samd/Makefile: Alphabetically sort the source code files in Makefile. 2022-10-06 22:31:03 +11:00
robert-hh a5d5ecbf84 samd/boards: Move mcu-specific settings into a mpconfig_samdXX.h file.
Located at the boards directory. That way, the mpconfigboard.h files are
almost empty, just setting the board name and the MCU name.
2022-10-06 22:30:37 +11:00
robert-hh 0420799a84 samd/boards: Replace pins.c and pins.h by pins.csv.
The files pins.c and pins.h are generated during the build process from
pins.csv, using a make-pins.py script.
2022-10-06 22:29:49 +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
Damien George 46d02c2469 tools/mpremote: Bump version to 0.4.0.
Signed-off-by: Damien George <damien@micropython.org>
2022-10-06 01:02:39 +11:00
Jim Mussared f13134e403 tools/mpremote: Fix argument handling for follow and add help strings.
Fixes in this commit are:
- Make --follow the default for "run" (accidentally changed in 68d094358).
- Add help strings for "repl": --capture --inject-file --inject-code
- Update help strings for "run".
- Fix encoding for --inject-code (accidentally broken in 68d094358).
- Remove ability to --no-follow for "eval". It was there previously because
  it shared the same code path with "exec" and "run", but makes no sense
  for "eval", so might as well remove.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-06 00:58:31 +11:00
Damien George 95c614e2b6 esp32/machine_hw_spi: Use auto DMA channel on S2, S3, C3 chips.
Auto DMA channel is supported in IDF v4.4, and is required to be used on S3
chips, so use this simpler configuration option where possible.

Fixes issue #8634.

Signed-off-by: Damien George <damien@micropython.org>
2022-10-04 17:43:48 +11:00
Angus Gratton 0e35c4de9b tools: Add pre-commit support.
Tweak the existing codeformat.py and verifygitlog.py to allow them to be
easily called by pre-commit.

(This turned out to be easier than using any existing pre-commit hooks,
without making subtle changes in the formatting.)

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2022-10-04 14:52:48 +11:00
Angus Gratton bdac8272d8 tools: Add note about uncrustify versions.
Uncrustify versions are not mutually compatible:

1. Version 0.73 or newer produce slightly different formatting. It may be
possible to tweak these by adding more config items, but this will cause
older versions to error out with 'Unknown option'.

2. Version 0.75 prints a range of deprecation warnings due to config file
changes, and returns a non-zero exit code. These are actually fixable
as most are the default value, and pp_indent has changed from 'true' to '1'
which is backwards compatible. However issue 1 remains, so probably better
to have it fail explicitly.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2022-10-04 14:34:54 +11:00
Damien George 0ee877a207 esp32/machine_i2s: Add I2S finaliser which calls deinit().
So that the FreeRTOS resources can be freed, eg on soft reset.

Fixes issue #9366.

Signed-off-by: Damien George <damien@micropython.org>
2022-10-04 11:47:06 +11:00
Jim Mussared 7705b9b9d5 tools/pyboard.py: Handle unsupported fs command.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-01 22:44:24 +10:00
Jim Mussared 12ca918eb2 tools/mpremote: Add `mpremote mip install` to install packages.
This supports the same package sources as the new `mip` tool.
 - micropython-lib (by name)
 - http(s) & github packages with json description
 - directly downloading a .py/.mpy file

The version is specified with an optional `@version` on the end of the
package name. The target dir, index, and mpy/no-mpy can be set through
command line args.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-01 22:44:24 +10:00
Jim Mussared 68d094358e tools/mpremote: Use argparse for command line parsing.
No functional change other than to allow slightly more flexibility in how
--foo arguments are specified.

This removes all custom handling for --foo args in all commands and
replaces it with per-command argparse configs.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-01 22:44:24 +10:00
Jim Mussared 413a69b94b tools/mpremote: Simplify dispatch of commands.
No functional change.

This makes each built-in command defined by just a handler method and
simplifies a lot of the logic around tracking the board state.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-01 22:44:24 +10:00