Wykres commitów

393 Commity (master)

Autor SHA1 Wiadomość Data
Krzysztof Adamski e7f7094ef6 rp2/machine_rtc: Check return value from rtc_set_datetime.
The rtc_set_datetime() from pico-sdk will validate the values in the
datetime_t structure and refuse to set the time if they aren't valid. It
makes sense to raise an exception if this happens instead of failing
silently which might be confusing (as an example, see:
https://github.com/micropython/micropython/pull/6928#issuecomment-860166044
).
2021-06-15 00:06:26 +10:00
Krzysztof Adamski 37d01d4be3 rp2/machine_rtc: Add initial support for RTC.
Initial support for machine.RTC on rp2 port. It only supports datetime()
method and nothing else. The method gets/returns a tuple of 8 items, just
like esp32 port, for example, but the usec parameter is ignored as the RP2
RTC only works up to seconds precision.

The Pico RTC isn't very useful as the time is lost during reset and there
seems to be no way to easily power up just the RTC clock with a low current
voltage, but still there seems to be use-cases for that, see issues #6831,
and a Thonny issue #1592. It was also requested for inclusion on v1.15
roadmap on #6832.

Signed-off-by: Krzysztof Adamski <k@japko.eu>
2021-06-12 23:02:54 +10:00
Damien George 4404dababb rp2/CMakeLists.txt: Include tinyusb_common in PICO_SDK_COMPONENTS.
So the TinyUSB headers can be found during qstr processing.

Fixes issue #7236.

Signed-off-by: Damien George <damien@micropython.org>
2021-05-11 12:46:18 +10:00
Damien George d0de16266f rp2/mpthreadport: Add mp_thread_deinit to reset core1 on soft reset.
Any code running on core1 should be stopped on soft-reset (the GC heap is
reset so if code continues to run on core1 it will see corrupt memory).

Signed-off-by: Damien George <damien@micropython.org>
2021-05-09 00:08:30 +10:00
Damien George 8172c2e9c5 rp2: Move manifest.py to boards directory.
To match other ports.

Signed-off-by: Damien George <damien@micropython.org>
2021-05-04 23:39:24 +10:00
robert-hh 1e2f0d2809 rp2/tusb_port: Add the device unique-id to the USB id.
The number shown in the USB id is now the same as that returned by
machine.unique_id().  All 8 bytes are inserted as hex into the USB id.  A
usb id at /dev/serial/by-id then looks like:

    usb-MicroPython_Board_in_FS_mode_e469b03567342f37-if00
2021-05-02 23:38:01 +10:00
Jan Jurgen Griesfeller d80a037e6b rp2/boards: Add board definition for SparkFun Pro Micro board. 2021-05-02 23:23:27 +10:00
Jan Jurgen Griesfeller 3c918d0f58 rp2/boards: Add board definition for SparkFun Thing Plus RP2040. 2021-05-02 23:22:46 +10:00
Damien George e9e9c76ddf all: Rename mp_keyboard_interrupt to mp_sched_keyboard_interrupt.
To match mp_sched_exception() and mp_sched_schedule().

Signed-off-by: Damien George <damien@micropython.org>
2021-04-30 15:13:43 +10:00
Tim Radvan f842a40df4 rp2/rp2_pio: Add fifo_join support for PIO.
The PIO state machines on the RP2040 have 4 word deep TX and RX FIFOs.  If
you only need one direction, you can "merge" them into either a single 8
word deep TX or RX FIFO.

We simply add constants to the PIO object, and set the appropriate bits in
`shiftctrl`.

Resolves #6854.

Signed-off-by: Tim Radvan <tim@tjvr.org>
2021-04-17 00:45:38 +10:00
jahr 7ca686684e rp2: Add support for building different board configurations.
This change allows to build firmware for different rp2-based boards,
following how it is done in other ports like stm32 and esp32.  So far only
the original Pico and Adafruit Feather RP2040 are added.  Board names
should match (sans case) those in pico-sdk/src/boards/include/boards/.

Usage: Pico firmware can be build either using make as previously (it is
the default board) or by `make BOARD=PICO`.  Feather is built by `make
BOARD=ADAFRUIT_FEATHER_RP2040`.  Only the board name and flash drive size
is set, pin definition is taken from the appropriate pico-sdk board
definition.  Firmware is saved in the directory build-BOARD_NAME.
2021-04-12 21:40:32 +10:00
robert-hh 1be74b94b6 rp2/machine_uart: Add buffered transfer of data with rxbuf/txbuf kwargs.
Instantiation and init now support the rxbuf and txbuf keywords for setting
the buffer size.  The default size is 256 bytes.  The minimum and maximum
sizes are 32 and 32766 respectively.

uart.write() still includes checks for timeout, even if it is very unlikely
to happen due to a) lack of flow control support and b) the minimal timeout
values being longer than the time it needs to send a byte.
2021-04-12 21:31:08 +10:00
robert-hh 22554cf8e2 rp2/rp2_pio: Add StateMachine restart,rx_fifo,tx_fifo helper functions.
StateMachine.restart: Restarts the state machine
StateMachine.rx_fifo: Return the number of RX FIFO items, 0 if empty
StateMachine.tx_fifo: Return the number of TX FIFO items, 0 if empty

restart() seems to be the most useful one, as it resets the state machine
to the initial state without the need to re-initialise/re-create.  It also
makes PIO code easier, because then stalling as an error state can be
unlocked.

rx_fifo() is also useful, for MP code to check for data and timeout if no
data arrived.  Complex logic is easier handled in Python code than in PIO
code.

tx_fifo() can be useful to check states where data is not processed, and is
mostly for symmetry.
2021-04-11 22:41:54 +10:00
robert-hh 6f06dcaee5 rp2/moduos: Implement uos.urandom().
The implementation samples rosc.randombits at a frequency lower than the
oscillator frequency.  This gives better random values.  In addition, for
an 8-bit value 8 samples are taken and fed through a 8-bit CRC,
distributing the sampling over the byte.  The resulting sampling rate is
about 120k/sec.

The RNG does not include testing of error conditions, like the ROSC being
in sync with the sampling or completely failing.  Making the interim value
static causes it to perform a little bit better in short sync or drop-out
situations.

The output of uos.urandom() performs well with the NIST800-22 test suite.
In my trial it passed all tests of the sts 2.1.2 test suite.  I also ran a
test of the random data with the Common Criteria test suite AIS 31, and it
passed all tests too.
2021-04-09 18:24:38 +10:00
Damien George 2c9af1c1d7 rp2/rp2_pio: Validate state machine frequency in constructor.
Fixes issue #7025.

Signed-off-by: Damien George <damien@micropython.org>
2021-04-09 18:06:10 +10:00
Damien George 5dcc9b3b16 py/py.cmake: Introduce MICROPY_INC_CORE as a list with core includes.
Signed-off-by: Damien George <damien@micropython.org>
2021-04-09 13:08:35 +10:00
Damien George 0fabda31de py/py.cmake: Move qstr helper code to micropy_gather_target_properties.
Signed-off-by: Damien George <damien@micropython.org>
2021-04-09 13:08:35 +10:00
Tim Radvan 4f53f462ca rp2: Import uarray instead of array in rp2 module.
Some forum users noticed that `sm.exec()` took longer the more was present
on the flash filesystem connected to the RP2040.  They traced this back to
the `array` import inside `asm_pio()`, which is causing MicroPython to scan
the filesystem.

uarray is a built-in module, so importing it shouldn't require scanning the
filesystem.

We avoid moving the import to the top-level in order to keep the namespace
clean; we don't want to accidentally expose `rp2.array`.
2021-04-07 10:06:18 +10:00
Damien George 2d8aecd2ad rp2/CMakeLists.txt: Enable USB enumeration fix.
This is a workaround for errata RP2040-E5, and is needed to make USB more
reliable on certain USB ports.

Signed-off-by: Damien George <damien@micropython.org>
2021-04-06 11:40:02 +10:00
Liam Fraser ca3d51f122 rp2: Don't advertise remote wakeup for USB serial.
This USB feature is currently not supported.  With this flag enabled (and
the feature not implemented) the USB serial will stop working if there is a
delay of more than about 2 seconds between messages, which can occur with
USB autosuspend enabled.

Fixes issue #6866.
2021-03-31 13:50:21 +11:00
Phil Howard 0cf12dd59c rp2: Add support for USER_C_MODULES to CMake build system.
The parts that are generic are added to py/ so they can be used by other
ports that use CMake.

py/usermod.cmake:

* Creates a usermod target to hang user C/CXX modules from.
* Gathers sources from user C/CXX modules and libs for QSTR scan.

ports/rp2/CMakeLists.txt:

* Includes py/usermod.cmake.
* Links the resulting usermod library to the MicroPython target.

py/mkrules.cmake:

Add cxxflags to qstr.i.last custom command for CXX modules:

* MICROPY_CPP_FLAGS so CXX modules will find includes.
* -DNO_QSTR to fix fatal error missing "genhdr/qstrdefs.generated.h".

Usage:

The rp2 port can be linked against user C modules by running:

make USER_C_MODULES=/path/to/module/micropython.cmake

CMake will print a list of included modules.

Co-authored-by: Graham Sanderson <graham.sanderson@raspberrypi.org>
Co-authored-by: Michael O'Cleirigh <michael.ocleirigh@rivulet.ca>
Signed-off-by: Phil Howard <phil@pimoroni.com>
2021-03-31 00:26:01 +11:00
Phil Howard ccc388f157 rp2/mpthreadport.h: Cast core_state to _mp_state_thread_t.
Required for user C++ code to build successfully against ports/rp2.

Signed-off-by: Phil Howard <phil@pimoroni.com>
2021-03-31 00:25:51 +11:00
Damien George a9140ab09b rp2: Use core-provided cmake fragments instead of custom ones.
Signed-off-by: Damien George <damien@micropython.org>
2021-03-14 15:53:18 +11:00
Damien George dcaf702578 rp2/modmachine: Enable machine.Signal class.
Fixes issue #6863.

Signed-off-by: Damien George <damien@micropython.org>
2021-03-14 00:19:04 +11:00
Damien George 8010b15968 rp2: Enabled more core Python features.
This brings the port's configuration closer to the stm32 and esp32 ports.

Signed-off-by: Damien George <damien@micropython.org>
2021-03-14 00:17:22 +11:00
Kevin Köck af45d511f1 rp2: Enable uerrno module.
Fixes #6991.
2021-03-13 23:34:50 +11:00
Andrew Scheller b6489425c6 rp2/rp2_flash: Prevent MICROPY_HW_FLASH_STORAGE_BASE being set negative. 2021-03-12 00:57:29 +11:00
robert-hh c675452566 rp2/modmachine: Re-init UART for REPL on frequency change.
When UART is used for REPL and the MCU frequency is changed, the UART
has to be re-initialised.  Besides that the UART may have to be recreated
after a frequency change, but with USB REPL this is not a problem.

Thanks to @HermannSW for spotting and providing the change.
2021-03-12 00:49:30 +11:00
robert-hh 11cf742524 rp2/modmachine: Allow changing CPU clock frequency.
Using the standard machine.freq().

The safe ranges tested were 10 and 12-270MHz, at which USB REPL still
worked.  Requested settings can be checked with the script:
pico-sdk/src/rp2_common/hardware_clocks/scripts/vcocalc.py.  At frequencies
like 300MHz the script still signaled OK, but USB did not work any more.
2021-03-12 00:48:46 +11:00
robert-hh 0461640983 rp2/rp2_pio: Fix sm.get(buf) to not wait after getting last item.
sm.get(buf) was waiting for one item more than the length of the supplied
buffer.  Even if this item was not stored, sm_get would block trying to get
an item from the RX fifo.

As part of the fix, the edge case for a zero length buffer was moved up to
the section where the function arguments are handled.  In case of a zero
length buffer, sm.get() now returns immediately that buffer.
2021-03-12 00:39:26 +11:00
robert-hh a075e0b7d8 rp2/rp2_pio: Allow more than 8 consecutive pins for PIO out/set/sideset.
The bitmasks supplied for initialization of out/set/sideset were only 8 bit
instead of 32.  This resulted in an error, that not more than 8 consecutive
pins would get initialized.

Fixes issue #6933.
2021-03-12 00:26:32 +11:00
robert-hh da85cb014a rp2/machine_uart: Add support for inverted TX and RX lines.
Usage as in the other ports:

    keyword "invert"
    constants: INV_TX and INV_RX

Sample: uart = UART(1, invert=UART.INV_TX | UART.INV_RX)
2021-03-11 18:27:53 +11:00
robert-hh 8ade163fff rp2/machine_uart: Add timeout/timeout_char to read and write. 2021-03-11 18:19:15 +11:00
StereoRocker 8610bababe rp2: Enable VfsFat class for FAT filesystem support.
Allows interfacing with SD cards, for example.
2021-03-11 17:56:21 +11:00
Damien George 53f5bb05a9 rp2,stm32: Enable MICROPY_PY_UBINASCII_CRC32 to get ubinascii.crc32().
These ports already have uzlib enabled so this additional ubinascii.crc32
function only costs about 90 bytes of flash.

Signed-off-by: Damien George <damien@micropython.org>
2021-02-23 10:13:25 +11:00
Damien George c9260dda23 rp2: Use local tinyusb instead of the one in pico-sdk.
So that all MicroPython ports that use tinyusb use the same version.  Also
requires fewer submodule checkouts when building rp2 along with other ports
that use tinyusb.

Signed-off-by: Damien George <damien@micropython.org>
2021-02-12 12:56:28 +11:00
Damien George 1f800cac3c rp2/micropy_rules.cmake: Fix makemoduledefs vpath to work with abs path.
In particular the firmware can now be built in a build directory that lives
outside the source tree, and the py/modarray.c file will still be found.

See issue #6837.

Signed-off-by: Damien George <damien@micropython.org>
2021-02-05 01:10:30 +11:00
Damien George 7f7b4f2bc6 rp2/machine_adc: Only initialise the ADC periph if not already enabled.
Otherwise it resets the ADC peripheral each time a new ADC object is
constructed, which can reset other state that has already been set up.

See issue #6833.

Signed-off-by: Damien George <damien@micropython.org>
2021-02-04 10:55:43 +11:00
Damien George 195e7dfa06 rp2/modmachine: Implement additional functions incl unique_id and idle.
Added functions in the machine module are:
- unique_id (returns 8 bytes)
- soft_reset
- idle
- lightsleep, deepsleep (not power saving at the moment)
- disable_irq, enable_irq
- time_pulse_us

Signed-off-by: Damien George <damien@micropython.org>
2021-02-02 22:14:22 +11:00
Tim Radvan 7a9027fd5d rp2/rp2_pio: Add JMP PIN support for PIO.
PIO state machines can make a conditional jump on the state of a pin: the
`JMP PIN` command.  This requires the pin to be configured with
`sm_config_set_jmp_pin`, but until now we didn't have a way of doing that
in MicroPython.

This commit adds a new `jmp_pin=None` argument to `StateMachine`.  If it is
not `None` then we try to interpret it as a Pin, and pass its value to
`sm_config_set_jmp_pin`.

Signed-off-by: Tim Radvan <tim@tjvr.org>
2021-02-02 11:32:48 +11:00
graham sanderson 52d3ae707d rp2/memmap_mp.ld: Update for latest SDK. 2021-02-02 10:59:10 +11:00
Andrew Scheller c9210a65df rp2/machine_pin: Change N_GPIOS to NUM_BANK0_GPIOS for pico-sdk compat.
This fixes machine_pin.c to build against the new pico-sdk coming down the
pipeline, whilst still working with the existing version.
2021-02-02 09:50:55 +11:00
Damien George 469345e728 rp2: Add new port to Raspberry Pi RP2 microcontroller.
This commit adds a new port "rp2" which targets the new Raspberry Pi RP2040
microcontroller.

The build system uses pure cmake (with a small Makefile wrapper for
convenience).  The USB driver is TinyUSB, and there is a machine module
with most of the standard classes implemented.  Some examples are provided
in the examples/rp2/ directory.

Work done in collaboration with Graham Sanderson.

Signed-off-by: Damien George <damien@micropython.org>
2021-01-30 00:42:29 +11:00