Added board definition for the Sparkfun MicroMod RP2040.
Mostly followed the format for pins from the MicroMod nRF52840 board
definition, as MicroMod tries to standardize pins across
microcontrollers.
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>
Commit 8a917ad252 added the gpio_reset_pin()
call to make sure that pins that were used as ADC inputs could subsequently
be used as digital IO. But calling gpio_reset_pin() will enable the
pull-up on the pin and so pull it high for a brief period. Instead use
rtc_gpio_deinit() which will just reconfigure the pin as a digital IO and
do nothing else.
Fixes issue #7079 (see also #5771).
Signed-off-by: Damien George <damien@micropython.org>
This is handy for remote characteristics because it allows for
the PacketBuffer binding code to have the correct max size. This
PR also adds checks so we don't write outside the outgoing buffer.
For an unconnected TCP socket, poll should return WR|HUP and read should
raise ENOTCONN. This is implemented by this commit and now the following
tests pass on esp32: extmod/usocket_tcp_basic.py,
net_hosted/connect_poll.py.
Signed-off-by: Damien George <damien@micropython.org>
This change allows running the tests in tests/basics/ without any failures
(but some tests are still skipped).
Signed-off-by: Damien George <damien@micropython.org>
This fixes `error: variable 'subpkg_tried' might be clobbered by 'longjmp'
or 'vfork' [-Werror=clobbered]` when compiling on ppc64le and aarch64 (and
possibly other architectures/toolchains).
This function includes the UART prescaler in the calculation (if it has
one, eg on H7 and WB MCUs).
Signed-off-by: Damien George <damien@micropython.org>
The STM32WB has a problem when address resolution is enabled: under certain
conditions the MCU can get into a state where it draws an additional 10mA
or so and eventually ends up with a broken BLE RX path in the silicon. A
simple way to reproduce this is to enable address resolution (which is the
default for NimBLE) and start the device advertising. If there is enough
BLE activity in the vicinity then the device will at some point enter the
bad state and, if left long enough, will have permanent BLE RX damage.
STMicroelectronics are aware of this issue. The only known workaround at
this stage is to not enable address resolution, which is implemented by
this commit.
Work done in collaboration with Jim Mussared aka @jimmo.
Signed-off-by: Damien George <damien@micropython.org>
Prior to this commit, if C2 was busy (eg lots of BLE activity) then it may
not have had time to respond to the notification on the IPCC_CH_MM channel
by the time additional memory was available to put on that buffer. In such
a case C1 would modify the free buffer list while C2 was potentially
accessing it, and this would eventually lead to lost memory buffers (or a
corrupt linked list). If all buffers become lost then ACL packets
(asynchronous events) can no longer be delivered from C2 to C1.
This commit fixes this issue by waiting for C2 to indicate that it has
finished using the free buffer list.
Work done in collaboration with Jim Mussared aka @jimmo.
Signed-off-by: Damien George <damien@micropython.org>
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.
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.
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.
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.
STM32L476RG MCU of NUCLEO_L476RG board has 6 UART/USART units in total
(USART1, USART2, USART3, UART4, UART5 and LPUART1), but only UART2,
connected to REPL, was defined and available in Python code.
Defined are all 5 remaining UART/USART units including LPUART1.
Signed-off-by: Alexander Ziubin aziubin@googlemail.com
This commit simplifies the customisation of the main MicroPython execution
loop (4 macros are reduced to 2), and allows a board to have full control
over the execution (or not) of boot.py and main.py.
For boards that use the default start-up code, there is no functional
change in this commit.
Signed-off-by: Damien George <damien@micropython.org>
This update to the PR retains the earlier board rev (with a rename) so
that backward binary compatibility is not lost for the earlier board
revision. The primary name 'vina-d51' is retained for the latest
revision to make it easy for customers to select the proper UF2
download - because the name matches the commercial name.
Details:
Replace bdmicro_vina_d51 with bdmicro_vina_d51_pcb7 (revision 7 of
PCB) with boardfiles unmodified. Add _pcb7 to the workflow build.
Replace bdmicro_vina_d51 boardfile content with latest PCB updates
(revision 10 ov PCB). Add minimal comments in the board files to make
it clear which PCB revision is implemented. Update the USB PID to
reflect an updated board revision.
Per CPython everything which comes after the command, module or file
argument is not an option for the interpreter itself. Hence the processing
of options should stop when encountering those, and the remainder be passed
as sys.argv. Note the latter was already the case for a module or file but
not for a command.
This fixes issues like 'micropython myfile.py -h' showing the help and
exiting instead of passing '-h' as sys.argv[1], likewise for
'-X <something>' being treated as a special option no matter where it
occurs on the command line.
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`.
Support for C++ was added in 97960dc7de but
that commit didn't include the C++ exception handling table in the binary
firmware image. This commit fixes that.
Signed-off-by: Damien George <damien@micropython.org>
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>
ESP-01 header renamed to AUX, and expanded to 12 pins from 8
pins. Pins 1-8 still accommodate the ESP-01, with expansion to full
SERCOM 4-pad support to allow for SPI and I2C on that expansion port
with additional GPIO control.
Update pins.c with additional signals provided AUX_1-8, along with
UART, SPI, I2C name usage as aliases to appropriate AUX_1-8
signals. Additionally, add several alternate names specific to several
expansion modules - the ESP-01, and the ATW-01 using the WINC_1500
(SPI) w/interrupt and control needed for the WINC - with assignments
to module pin positions.
Re-work SERCOM assignments to accommodate the above from other parts
of the board, which required moving a SERCOM or two around in order to
accommodate the 4-pad sercom pin mapping on the AUX port.
Built and tested using latest from 'main':
Adafruit CircuitPython 6.2.0-rc.0-70-ga1562430f-dirty on 2021-04-05;
BDMICRO VINA-D51 with samd51n20
After this change, the following program works for me on the MIMXRT1010-EVK:
```python
import pwmio
import board
p = pwmio.PWMOut(board.D13, frequency=1_000_000, variable_frequency=True)
p.duty_cycle = 32868
while True:
pass
```
Querying and varying the duty_cycle and frequency work as well.
The lowest frequency obtainable is about 2kHz; there is an additional
divider which would allow lower PWM frequencies (I think 1kHz is important
for servos?)
Something odd happens with very low duty cycles, such as
```python
>>> p.frequency = 2000
>>> p.duty_cycle = 2
```
instead of a symmetrical waveform, it's asymmetrical. With `duty_cycle=4`,
the effect disappears. The reason for this is probably hidden in the
datasheet, but could affect servos or other things that count pulse
widths.
It's a bit of a pitfall with user C modules that including them in the
build does not automatically enable them. This commit changes the docs and
examples for user C modules to encourage writers of user C modules to
enable them unconditionally. This makes things simpler and covers most use
cases.
See discussion in issue #6960, and also #7086.
Signed-off-by: Damien George <damien@micropython.org>
It was noticed that the esp32 port didn't build ulab correctly. The
problem was a multiple defintion of the 'mp_hal_stdout_tx_str' and
'mp_hal_stdout_tx_strn_cooked' functions.
They were defined in stdout_helpers.c but also in the
ports/esp32/mphalport.c.
Fixed by removing stdout_helpers.c from the build.
Signed-off-by: Michael O'Cleirigh <michael.ocleirigh@rivulet.ca>
Support for User C and C++ modules was lost due to upgrading the esp32 to
the latest CMake based IDF from the GNUMakefile build process.
Restore the support for the esp32 port by integrating with the approach
recently added for the rp2 port.
Signed-off-by: Michael O'Cleirigh <michael.ocleirigh@rivulet.ca>
This allows more options to be overridden to 0 in an mpconfigboard.mk.
Improved:
* FRAMEBUFFERIO, FULL_BUILD, BITOPS, PWMIO, RGBMATRIX, OTARYIO, PULSEIO, WATCHDOG
Still problematic (pull requests welcome):
* RP2PIO & NEOPIXEL_WRITE, possibly only if a status neopixel is defined
* BITBANGIO, possibly only if BUSIO is enabled
* RTC
Incidentally, with RP2PIO & NEOPIXEL_WRITE, BITBANGIO, and RTC re-enabled I get
```
323956 bytes used, 720524 bytes free in flash firmware space out of 1044480 bytes (1020.0kB).
12072 bytes used, 250072 bytes free in ram for stack and heap out of 262144 bytes (256.0kB).
```
Closes#4515
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.
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>
Set the betweenTransferDelay to the SCK low-time, to avoid long pauses
between bytes (transfers) while preventing the last SCK cycle in a byte
from being a runt pulse.
Compared to an earlier revision of this change, which just set the delays
all to zero, this doesn't break using an AirLift, which was sensitive
to the runt pulses (the simple loopback-wire test didn't detect the problem)
without this, the baud rate could be wrong; in my testing, it was
low by a factor of 2 when requesating baudrate=1_000_000 (1MHz).
When passing the baudrate in to LPSPI_MasterInit, the setting is made
automatically, but LPSPI_MAster_SetBaudRate just returns it via the
out-parameter tcrPrescaleValue.
There are DNP resistors on the MIMXRT1010-EVK board (see SCH-45852)
that lead to these pins on the arduino-style header not being connected
through. In theory someone could populate them, but as it the presence
of these names in the pins module caused problems when they didn't work
as expected.
Closes#3012
This commit simplifies and cleans up the bare-arm port, and adds just
enough system and library code to make it execute on an STM32F405 MCU.
The mpconfigport.h configuration is simplified to just specify those
configuration values that are different from the defaults. And the
addition of -fdata-sections and -ffunction-sections means the final
firmware is smaller than it previously was, by about 4200 bytes.
A README is also added.
Signed-off-by: Damien George <damien@micropython.org>
This switches stage2 to C and uses Jinja to change the C code based
on flash settings from https://github.com/adafruit/nvm.toml. It
produces the fastest settings for the given set of external flashes.
Flash size is no longer hard coded so switching flashes with similar
capabilities but different sizes should *just work*.
This PR also places "ITCM" code in RAM to save the XIP cache for
code execution. Further optimization is possible. A blink code.py
still requires a number of flash fetches every blink.
Fixes#4041
The I2C.c for RP2040 included a special case for writes <=2 bytes to match the MicroPython implementation,
however RP2040 does support 1 and 2 byte reads, with only 0 bytes being the exception.
Signed-off-by: Philip Howard <phil@pimoroni.com>
The GNU Make dir command uses spaces as item separator so it does not
work for e.g building the STM32 port on Cygwin with a default Arm
installation in "c:/program files (x86)/GNU Arm Embedded Toolchain".
Fix by using POSIX dirname on a quoted path instead.
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.
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.
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.
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.
Until a time is set, the RTC is not running, and rtc_get_datetime()
returns false without assigning to the out-parameter.
In CircuitPython, this would manifest as arbitrary values being returned,
since uninitialized storage on the stack was being converted into a timestamp.
The rp2040 is _very_ marginal for mp3 playback, and currently sometimes triggers a bug that gives garbled audio output. However, it does work for some limited situations.
This allows the user to enable wake-up sources using the EWUP bits, on F7
MCUs.
Disabling the wake-up sources while clearing the wake-up flags follows the
reference manual and ST examples.
state.reset_mode is updated by `MICROPY_BOARD_BEFORE_SOFT_RESET_LOOP` but
not passed to `init_flash_fs`, and so factory reset is not executed on
boards that do not have a bootloader. This bug was introduced by
4c3976bbcaFixes#6903.
A corrupt filesystem may lead to a request for a block which is out of
range of the block device limits. Return an error instead of passing the
request down to the lower layer.
Any two consecutive pins can be used for an IncrementalEncoder
Testing performed: Put a synthesized (few hundred counts per second) quadrature signal into GP2/3 and read the encoder out. Performed filesystem operations at the same time to stress test it.
The reasons for not using common_hal_rp2pio_statemachine_readinto are commented on.
This can be used where the standard API calls for a list of pins, to check that they satisfy the requirements of the rp2pio state machine, e.g.,
```python
def __init__(self, pin_a, pin_b):
if not rp2pio.pins_are_sequential([pin_a, pin_b]):
raise ValueError("Pins must be sequential")
```
Presumably, switching it to generic hurt performance a bit.
I verified that the build-raspberry_pi_pico/boot2_padded_checksummed.S
built file has the same checksum as the old
bs2_default_padded_checksummed.S
.. all the necessary steps to transform it into a padded, checksummed
file are now done by the build system.
Since it is assigned by "?=", it _should_ be the case that individual
builds can override it.
I did not "test" this per se, but it gives the same content and checksum
(except for the identifying comment with a path) as #4302.
Two of the defaults have also changed in this commit:
- MICROPY_HW_RFCORE_BLE_LSE_SOURCE changed from 1 to 0, which configures
the LsSource to be LSE (needed due to errata 2.2.1).
- MICROPY_HW_RFCORE_BLE_VITERBI_MODE changed from 0 to 1, which enables
Viterbi mode, following all the ST examples.
Signed-off-by: Damien George <damien@micropython.org>
* Always clear the peripheral interrupt so we don't hang when full
* Store the ringbuf in the object so it gets collected when we're alive
* Make UART objects have a finaliser so they are deinit when their
memory is freed
* Copy bytes into the ringbuf from the FIFO after we read to ensure
the interrupt is enabled ASAP
* Copy bytes into the ringbuf from the FIFO before measuring our
rx available because the interrupt is based on a threshold (not
> 0). For example, a single byte won't trigger an interrupt.
This adds I2SOut and PDMIn support via PIO.
StateMachines can now:
* read and read while writing
* transfer in 1, 2 or 4 byte increments
* init pins based on expected defaults automatically
* be stopped and restarted
* rxfifo can be cleared and rxstalls detected (good for tracking when
the reading code isn't keeping up)
Fixes#4162
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>
Add LPUART1 as a standard UART. No low power features are supported, yet.
LPUART1 is enabled as the next available UART after the standard U(S)ARTs:
STM32WB: LPUART1 = UART(2)
STM32L0: LPUART1 = UART(6)
STM32L4: LPUART1 = UART(6)
STM32H7: LPUART1 = UART(9)
On all ports: LPUART1 = machine.UART('LP1')
LPUART1 is enabled by defining MICROPY_HW_LPUART1_TX and
MICROPY_HW_LPUART1_RX in mpconfigboard.h.
Signed-off-by: Chris Mason <c.mason@inchipdesign.com.au>
This commit fixes two issues on the esp32:
- it enables machine.soft_reset() to be called in main.py;
- it enables machine.reset_cause() to correctly identify a soft reset.
The former is useful in that it enables soft resets in applications that
are started at boot time. The support is patterned after the stm32 port.
This commit implements basic NVS support for the esp32. It follows the
pattern of the esp32.Partition class and exposes an NVS object per NVS
namespace. The initial support provided is only for signed 32-bit integers
and binary blobs. It's easy (albeit a bit tedious) to add support for
more types.
See discussions in: #4436, #4707, #6780
This enables -Os for compilation, but still keeps full assertion messages.
With IDF v4.2, -Os changes the GENERIC firmware size from 1512176 down to
1384640, and the GENERIC_SPIRAM firmware is now 1452320 which fits in the
allocated partition.
Signed-off-by: Damien George <damien@micropython.org>
So that mboot can be used to program encrypted/signed firmware to regions
of flash that are not the main application, eg that are the filesystem.
Signed-off-by: Damien George <damien@micropython.org>
Since the datasheet cast some doubt on the strength of the "rosc_hw->randombit",
I use the SHA256 hash function to create a high quality random seed
from random values of uncertain entropy, as well as to generate a sequence
of random values from that seed using SHA256 as a cryptographically-secure
random number generator.
In practice, it produces over 100kB/s of random data which does not
have any gross problems according to _PractRand_.
The default for these is to enable them, but they can now be disabled
individually by a board configuration.
Signed-off-by: Damien George <damien@micropython.org>
If a board defines USBD_VID then that will be used instead of the default.
And then the board must also define all USBD_PID_xxx values that it needs.
Signed-off-by: Damien George <damien@micropython.org>
The following simple usocket example throws an error EINVAL on connect
import usocket
s = usocket.socket()
s.connect(usocket.getaddrinfo('www.micropython.org', 80)[0][-1])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 22] EINVAL
Fixing the context parameter in calls of net_context_get_family() and
net_context_get_type(), the connect works fine.
Tested on a nucleo_h743zi board.
Refactors the zephyr build infrastructure to build MicroPython as a
cmake target, using the recently introduced core cmake rules.
This change makes it possible to build the zephyr port like most other
zephyr applications using west or cmake directly. It simplifies building
with extra cmake arguments, such as specifying an alternate conf file or
adding an Arduino shield. It also enables building the zephyr port
anywhere in the host file system, which will allow regressing across
multiple boards with the zephyr twister script.
Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
Disables frozen source modules in the zephyr port. They are deprecated
in the makefile rules and not implemented in the new cmake rules.
Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
The underlying OS (the ESP-IDF) uses it's own internal errno codes and so
it's simpler and cleaner to use those rather than trying to convert
everything to the values defined in py/mperrno.h.
It's now replaced by cmake/idf.py. But a convenience Makefile is still
provided with traditional targets like "all" and "deploy".
Signed-off-by: Damien George <damien@micropython.org>
This commit adds support for building the esp32 port with cmake, and in
particular it builds MicroPython as a component within the ESP-IDF. Using
cmake and the ESP-IDF build infrastructure makes it much easier to maintain
the port, especially with the various new ESP32 MCUs and their required
toolchains.
Signed-off-by: Damien George <damien@micropython.org>
This allows changing the baudrate of the UART without reinitialising it
(reinitialising can lead to spurious characters sent on the TX line).
Signed-off-by: Damien George <damien@micropython.org>
Also found a race condition between timer_disable and redraw, which
would happen if I debugger-paused inside common_hal_rgbmatrix_timer_disable
or put a delay or print inside it. That's what pausing inside reconstruct
fixes.
So that the "right timer" can be chosen, `timer_allocate` now gets the `self`
pointer. It's guaranteed at this point that the pin information is accurate,
so you can e.g., find a PWM unit related to the pins themselves.
This required touching each port to add the parameter even though it's
unused everywhere but raspberrypi.
On i.MX the SysTick IRQ cannot wake the CPU from a WFI so the CPU was
blocked on WFI waiting for USB data in mp_hal_stdin_rx_chr() even though it
had already arrived (because it may arrive just after calling the check
tud_cdc_available()). This commit fixes this problem by using SEV/WFE to
indicate that there has been a USB event.
The mp_hal_stdout_tx_strn() function is also fixed so that it doesn't
overflow the USB buffers.
Signed-off-by: Damien George <damien@micropython.org>
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>
START_SEC was changed in e0905e85a7.
Also, update the error message to mention how to format the partition at
the REPL, and make the total message shorter to save a bit of flash.
Signed-off-by: Damien George <damien@micropython.org>
@Jerryneedell noticed that this problem affected strips short enough
to not use the DMA peripheral, thanks for the hot tip!
Instead of checking for background tasks after every byte transfer,
try up to 32 transfers before attending to background tasks.
This fixes the problem I was seeing on my 5-pixel circuit.
Closes#4135.
Add SMPS mode pin to Raspi Pico pins.c; see section "4.3. Using the ADC" of the Pico datasheet for discussion.
Driving this pin high forces the onboard regulator into a lower noise PWM mode.
This makes all the following work:
* normal microcontroller.reset()
* reset into safe mode or UF2 bootloader via microcontroller.on_next_reset()
* reset into UF2 bootloader via the "1200 baud trick"
The implementation of reset_cpu is from micropython.
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>
The "word" referred to by BYTES_PER_WORD is actually the size of mp_obj_t
which is not always the same as the size of a pointer on the target
architecture. So rename this config value to better reflect what it
measures, and also prefix it with MP_.
For uses of BYTES_PER_WORD in setting the stack limit this has been
changed to sizeof(void *), because the stack usually grows with
machine-word sized values (eg an nlr_buf_t has many machine words in it).
Signed-off-by: Damien George <damien@micropython.org>
To simplify config, there's no need to specify MP_PLAT_PRINT_STRN if it's
the same as the default definition in py/mpconfig.h.
Signed-off-by: Damien George <damien@micropython.org>
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>
Default to just calling python since that is most commonly available: the
official installer or zipfiles from python.org, anaconda, nupkg all result
in python being available but not python3. In other words: the default
used so far is wrong. Note that os.name is 'posix' when running the python
version which comes with Cygwin or MSys2 so they are not affected by this.
However of all possible ways to get Python on Windows, only Cygwin provides
no python command so update the default way for running tests in the
README.
With mboot encrpytion and fsload enabled, the DEBUG build -O0 compiler
settings result in mboot no longer fitting in the 32k sector. This commit
changes this to -Og which also brings it into line with the regular stm32
build.
MCUs with device-only USB peripherals (eg L0, WB) do not implement (at
least not in the ST HAL) the HAL_PCD_DisconnectCallback event. So if a USB
cable is disconnected the USB driver does not deinitialise itself
(usbd_cdc_deinit is not called) and the CDC driver can stay in the
USBD_CDC_CONNECT_STATE_CONNECTED state. Then if the USB was attached to
the REPL, output can become very slow waiting in usbd_cdc_tx_always for
500ms for each character.
The disconnect event is not implemented on these MCUs but the suspend event
is. And in the situation where the USB cable is disconnected the suspend
event is raised because SOF packets are no longer received.
The issue of very slow output on these MCUs is fixed in this commit (really
worked around) by adding a check in usbd_cdc_tx_always to see if the USB
device state is suspended, and, if so, breaking out of the 500ms wait loop.
This should also help all MCUs for a real USB suspend.
A proper fix for MCUs with device-only USB would be to implement or somehow
synthesise the HAL_PCD_DisconnectCallback event.
See issue #6672.
Signed-off-by: Damien George <damien@micropython.org>
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>
Add "make submodules" to commands when building for the first time.
Otherwise, on a first time build, the submodules have not been checked out
and a lot of `fatal error: nrfx.h: No such file or directory` errors are
printed.
It practically does the same as qstr_from_str and was only used in one
place, which should actually use the compile-time MP_QSTR_XXX form for
consistency; qstr_from_str is for runtime strings only.
Don't clear the IPCC channel flag until we've actually handled the incoming
data, or else the wireless firmware may clobber the IPCC buffer if more
data arrives. This requires masking the IRQ until the data is handled.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
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>
It's enabled by default to retain the existing behaviour. A board can
disable this option if it manages mounting the filesystem itself, for
example in frozen code.
Signed-off-by: Damien George <damien@micropython.org>
Changes are:
- refactor to use new _create_element function
- support extended version of MOUNT element with block size
- support STATUS element
Signed-off-by: Damien George <damien@micropython.org>
This new element takes the form: (ELEM_TYPE_STATUS, 4, <address>). If this
element is present in the mboot command then mboot will store to the given
address the result of the filesystem firmware update process. The address
can for example be an RTC backup register.
Signed-off-by: Damien George <damien@micropython.org>
Instead it is now passed in as an optional parameter to the ELEM_MOUNT
element, with a compile-time configurable default.
Signed-off-by: Damien George <damien@micropython.org>
The superblock for littlefs is in block 0 and 1, but block 0 may be erased
or partially written, so block 1 must be checked if block 0 does not have a
valid littlefs superblock in it.
Prior to this commit, if block 0 did not contain a valid littlefs
superblock (but block 1 did) then the auto-detection would fail, mounting a
FAT filesystem would also fail, and the system would reformat the flash,
even though it may have contained a valid littlefs filesystem. This is now
fixed.
Signed-off-by: Damien George <damien@micropython.org>
Totally untested, change request based on change made in #2581.
It might be my first PR in CircuitPython core...
Maybe this should be confirmed by @jamesbowman
Those are the two boards that seems supported:
* Metro M4 Express
* Metro nRF52840 Express
The only Metro that this PR concern:
* Metro M4 AirLift Lite
Other Metro I found and are maybe not supported:
* Metro ESP32-S2
* Metro M0 Express
* Metro M7 1011
* Fix a typo in the Makefile that prevented the debug build to be actually
enabled when BTYPE=debug is used.
* Add a missing header in modmachine.c that is used when a debug build is
created.
This commit improves some FTP implementation details for better
compatibility with FTP clients:
* The PWD command now puts quotes around the directory name before
returning it. This fixes BBEdit’s FTP client, which performs a PWD after
each CWD and gets confused if the returned directory path is not
surrounded by quotes.
* The FEAT command is now allowed before logging in. This fixes the lftp
client, which send FEAT first and gets confused (tries to use TLS) if the
server responds with 332.
With MICROPY_FLOAT_IMPL_FLOAT the results of utime.time(), gmtime() and
localtime() change only every 129 seconds. As one consequence
tests/extmod/vfs_lfs_mtime.py will fail on a unix port with LFS support.
With this patch these functions only return floats if
MICROPY_FLOAT_IMPL_DOUBLE is used. Otherwise they return integers.
The RP2040 is new microcontroller from Raspberry Pi that features
two Cortex M0s and eight PIO state machines that are good for
crunching lots of data. It has 264k RAM and a built in UF2
bootloader too.
Datasheet: https://pico.raspberrypi.org/files/rp2040_datasheet.pdf
To match the definition of GENERATE_PACK_DFU, so a board can customise the
location/name of this file if needed.
Signed-off-by: Damien George <damien@micropython.org>
To have at least one board configured with MBOOT_ENABLE_PACKING, for CI
testing purposes and demonstration of the feature.
Signed-off-by: Damien George <damien@micropython.org>
This commit adds support to stm32's mboot for signe, encrypted and
compressed DFU updates. It is based on inital work done by Andrew Leech.
The feature is enabled by setting MBOOT_ENABLE_PACKING to 1 in the board's
mpconfigboard.mk file, and by providing a header file in the board folder
(usually called mboot_keys.h) with a set of signing and encryption keys
(which can be generated by mboot_pack_dfu.py). The signing and encryption
is provided by libhydrogen. Compression is provided by uzlib. Enabling
packing costs about 3k of flash.
The included mboot_pack_dfu.py script converts a .dfu file to a .pack.dfu
file which can be subsequently deployed to a board with mboot in packing
mode. This .pack.dfu file is created as follows:
- the firmware from the original .dfu is split into chunks (so the
decryption can fit in RAM)
- each chunk is compressed, encrypted, a header added, then signed
- a special final chunk is added with a signature of the entire firmware
- all chunks are concatenated to make the final .pack.dfu file
The .pack.dfu file can be deployed over USB or from the internal filesystem
on the device (if MBOOT_FSLOAD is enabled).
See #5267 and #5309 for additional discussion.
Signed-off-by: Damien George <damien@micropython.org>
Prior to this fix, the final piece of data in a compressed file may have
been lost when decompressing.
Signed-off-by: Damien George <damien@micropython.org>