aboutsummaryrefslogtreecommitdiff
path: root/ports/rp2
AgeCommit message (Collapse)Author
2021-04-17rp2/rp2_pio: Add fifo_join support for PIO.Tim Radvan
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-12rp2: Add support for building different board configurations.jahr
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-12rp2/machine_uart: Add buffered transfer of data with rxbuf/txbuf kwargs.robert-hh
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-11rp2/rp2_pio: Add StateMachine restart,rx_fifo,tx_fifo helper functions.robert-hh
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-09rp2/moduos: Implement uos.urandom().robert-hh
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-09rp2/rp2_pio: Validate state machine frequency in constructor.Damien George
Fixes issue #7025. Signed-off-by: Damien George <damien@micropython.org>
2021-04-09py/py.cmake: Introduce MICROPY_INC_CORE as a list with core includes.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-04-09py/py.cmake: Move qstr helper code to micropy_gather_target_properties.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-04-07rp2: Import uarray instead of array in rp2 module.Tim Radvan
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-06rp2/CMakeLists.txt: Enable USB enumeration fix.Damien George
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-03-31rp2: Don't advertise remote wakeup for USB serial.Liam Fraser
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-31rp2: Add support for USER_C_MODULES to CMake build system.Phil Howard
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-31rp2/mpthreadport.h: Cast core_state to _mp_state_thread_t.Phil Howard
Required for user C++ code to build successfully against ports/rp2. Signed-off-by: Phil Howard <phil@pimoroni.com>
2021-03-14rp2: Use core-provided cmake fragments instead of custom ones.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-03-14rp2/modmachine: Enable machine.Signal class.Damien George
Fixes issue #6863. Signed-off-by: Damien George <damien@micropython.org>
2021-03-14rp2: Enabled more core Python features.Damien George
This brings the port's configuration closer to the stm32 and esp32 ports. Signed-off-by: Damien George <damien@micropython.org>
2021-03-13rp2: Enable uerrno module.Kevin Köck
Fixes #6991.
2021-03-12rp2/rp2_flash: Prevent MICROPY_HW_FLASH_STORAGE_BASE being set negative.Andrew Scheller
2021-03-12rp2/modmachine: Re-init UART for REPL on frequency change.robert-hh
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-12rp2/modmachine: Allow changing CPU clock frequency.robert-hh
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-12rp2/rp2_pio: Fix sm.get(buf) to not wait after getting last item.robert-hh
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-12rp2/rp2_pio: Allow more than 8 consecutive pins for PIO out/set/sideset.robert-hh
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-11rp2/machine_uart: Add support for inverted TX and RX lines.robert-hh
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-11rp2/machine_uart: Add timeout/timeout_char to read and write.robert-hh
2021-03-11rp2: Enable VfsFat class for FAT filesystem support.StereoRocker
Allows interfacing with SD cards, for example.
2021-02-23rp2,stm32: Enable MICROPY_PY_UBINASCII_CRC32 to get ubinascii.crc32().Damien George
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-12rp2: Use local tinyusb instead of the one in pico-sdk.Damien George
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-05rp2/micropy_rules.cmake: Fix makemoduledefs vpath to work with abs path.Damien George
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-04rp2/machine_adc: Only initialise the ADC periph if not already enabled.Damien George
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-02rp2/modmachine: Implement additional functions incl unique_id and idle.Damien George
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-02rp2/rp2_pio: Add JMP PIN support for PIO.Tim Radvan
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-02rp2/memmap_mp.ld: Update for latest SDK.graham sanderson
2021-02-02rp2/machine_pin: Change N_GPIOS to NUM_BANK0_GPIOS for pico-sdk compat.Andrew Scheller
This fixes machine_pin.c to build against the new pico-sdk coming down the pipeline, whilst still working with the existing version.
2021-01-30rp2: Add new port to Raspberry Pi RP2 microcontroller.Damien George
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>