Commit Graph

14146 Commits

Author SHA1 Message Date
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
Jim Mussared 0e8dfaf538 py/modsys: Add support for sys.executable.
Only intended to be used on Unix and other "OS" ports.  Matches CPython.
This should give the absolute path to the executing 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:26 +11:00
Jim Mussared c44b3927b8 py/objstr: Add a helper to set mp_obj_str_t data.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-11 17:50:19 +11:00
Jim Mussared 4fc543c829 CODECONVENTIONS.md: Update pre-commit instructions.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-11 17:47:05 +11:00
Jim Mussared b8982ec5f9 tools/verifygitlog.py: Add additional help for subject line issues.
This check used to just show the regular expression that failed to match,
but the rules are pretty subtle and hard to interpret from the regular
expression alone.

Add some basic checks for the main things that go wrong:
 - Missing capitalisation.
 - Missing full-stop.
 - Missing path.
 - Single-word subject.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-07 00:26:31 +11:00
Jim Mussared f6d06b3ce0 tools/verifygitlog.py: Ignore comment lines in commit messages.
The "signed-off" check assumes that the Signed-off-by: line is the last,
but there may me many lines of comments after this.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-07 00:19:40 +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
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