micropython/ports/renesas-ra
Maarten van der Schrieck 3bca93b2d0 ports: Fix sys.stdout.buffer.write() return value.
MicroPython code may rely on the return value of sys.stdout.buffer.write()
to reflect the number of bytes actually written. While in most scenarios a
write() operation is successful, there are cases where it fails, leading to
data loss. This problem arises because, currently, write() merely returns
the number of bytes it was supposed to write, without indication of
failure.

One scenario where write() might fail, is where USB is used and the
receiving end doesn't read quickly enough to empty the receive buffer. In
that case, write() on the MicroPython side can timeout, resulting in the
loss of data without any indication, a behavior observed notably in
communication between a Pi Pico as a client and a Linux host using the ACM
driver.

A complex issue arises with mp_hal_stdout_tx_strn() when it involves
multiple outputs, such as USB, dupterm and hardware UART. The challenge is
in handling cases where writing to one output is successful, but another
fails, either fully or partially. This patch implements the following
solution:

mp_hal_stdout_tx_strn() attempts to write len bytes to all of the possible
destinations for that data, and returns the minimum successful write
length.

The implementation of this is complicated by several factors:
- multiple outputs may be enabled or disabled at compiled time
- multiple outputs may be enabled or disabled at runtime
- mp_os_dupterm_tx_strn() is one such output, optionally containing
  multiple additional outputs
- each of these outputs may or may not be able to report success
- each of these outputs may or may not be able to report partial writes

As a result, there's no single strategy that fits all ports, necessitating
unique logic for each instance of mp_hal_stdout_tx_strn().

Note that addressing sys.stdout.write() is more complex due to its data
modification process ("cooked" output), and it remains unchanged in this
patch. Developers who are concerned about accurate return values from
write operations should use sys.stdout.buffer.write().

This patch might disrupt some existing code, but it's also expected to
resolve issues, considering that the peculiar return value behavior of
sys.stdout.buffer.write() is not well-documented and likely not widely
known. Therefore, it's improbable that much existing code relies on the
previous behavior.

Signed-off-by: Maarten van der Schrieck <maarten@thingsconnected.nl>
2023-12-22 10:32:46 +11:00
..
boards renesas-ra/boards/ARDUINO_PORTENTA_C33: Fix incorrect I2C pins. 2023-11-17 15:40:33 +11:00
fsp_cfg renesas-ra/fsp_cfg: Add common FSP config files. 2023-09-14 23:51:30 +10:00
lwip_inc renesas-ra: Tune lwip buffers and timing to improve network performance. 2023-10-03 10:17:51 +11:00
mbedtls extmod/mbedtls: Enable certificate time/date validation by default. 2023-12-01 15:08:11 +11:00
ra renesas-ra: Add support for RA6M5, and add machine PWM, DAC, SDCard. 2023-06-27 12:30:25 +10:00
Makefile ports: Switch build to use common lib/libm list of source files. 2023-12-08 15:42:41 +11:00
RA4M1_hal.h renesas-ra: Add support for RA6M5, and add machine PWM, DAC, SDCard. 2023-06-27 12:30:25 +10:00
RA4W1_hal.h renesas-ra: Add support for RA6M5, and add machine PWM, DAC, SDCard. 2023-06-27 12:30:25 +10:00
RA6M1_hal.h renesas-ra: Add support for RA6M5, and add machine PWM, DAC, SDCard. 2023-06-27 12:30:25 +10:00
RA6M2_hal.h renesas-ra: Add support for RA6M5, and add machine PWM, DAC, SDCard. 2023-06-27 12:30:25 +10:00
RA6M5_hal.h renesas-ra: Add support for RA6M5, and add machine PWM, DAC, SDCard. 2023-06-27 12:30:25 +10:00
README.md renesas-ra/boards/ARDUINO_PORTENTA_C33: Add support for Portenta C33. 2023-09-15 00:10:47 +10:00
boardctrl.c
boardctrl.h
build_all_boards.sh
extint.c
extint.h
factoryreset.c
factoryreset.h
fatfs_port.c
flash.c
flash.h
flashbdev.c renesas-ra: Add support for RA6M5, and add machine PWM, DAC, SDCard. 2023-06-27 12:30:25 +10:00
gccollect.c
gccollect.h
help.c
irq.c
irq.h ports: Move definitions of ATOMIC_SECTION macros to mphalport.h. 2023-12-01 14:37:48 +11:00
led.c
led.h
machine_adc.c extmod/machine_adc: Factor ports' ADC Python bindings to common code. 2023-10-23 17:16:45 +11:00
machine_dac.c renesas-ra: Add support for RA6M5, and add machine PWM, DAC, SDCard. 2023-06-27 12:30:25 +10:00
machine_i2c.c renesas-ra: Consolidate MICROPY_PY_MACHINE_I2C option. 2023-11-30 16:11:11 +11:00
machine_pin.c renesas-ra/boards/make-pins.py: Update to use tools/boardgen.py. 2023-11-03 14:18:54 +11:00
machine_pwm.c extmod/machine_pwm: Remove header file and move decls to .c file. 2023-10-20 16:24:46 +11:00
machine_rtc.c extmod/modmachine: Clean up decls of machine types to use common ones. 2023-10-26 16:20:53 +11:00
machine_sdcard.c renesas-ra: Add support for RA6M5, and add machine PWM, DAC, SDCard. 2023-06-27 12:30:25 +10:00
machine_spi.c extmod/modmachine: Consolidate mem, i2c and spi headers to modmachine.h. 2023-10-26 17:40:22 +11:00
machine_uart.c extmod/machine_uart: Factor ports' UART Python bindings to common code. 2023-10-26 10:46:42 +11:00
main.c extmod/modmachine: Clean up decls of machine types to use common ones. 2023-10-26 16:20:53 +11:00
modmachine.c extmod/modmachine: Provide common bindings for 6 bare-metal functions. 2023-11-30 16:11:11 +11:00
modmachine.h extmod/modmachine: Provide common bindings for 6 bare-metal functions. 2023-11-30 16:11:11 +11:00
modos.c extmod/modmachine: Clean up decls of machine types to use common ones. 2023-10-26 16:20:53 +11:00
modtime.c
mpbthciport.c extmod/modmachine: Clean up decls of machine types to use common ones. 2023-10-26 16:20:53 +11:00
mpbthciport.h renesas-ra: Add Bluetooth support using NimBLE. 2023-09-14 23:50:47 +10:00
mpconfigboard_common.h renesas-ra: Consolidate MICROPY_PY_MACHINE_I2C option. 2023-11-30 16:11:11 +11:00
mpconfigport.h ports: Move definitions of ATOMIC_SECTION macros to mphalport.h. 2023-12-01 14:37:48 +11:00
mpconfigport.mk
mphalport.c ports: Fix sys.stdout.buffer.write() return value. 2023-12-22 10:32:46 +11:00
mphalport.h ports: Move definitions of ATOMIC_SECTION macros to mphalport.h. 2023-12-01 14:37:48 +11:00
mpnetworkport.c renesas-ra: Tune lwip buffers and timing to improve network performance. 2023-10-03 10:17:51 +11:00
mpnimbleport.c renesas-ra: Add Bluetooth support using NimBLE. 2023-09-14 23:50:47 +10:00
mpnimbleport.h renesas-ra: Add Bluetooth support using NimBLE. 2023-09-14 23:50:47 +10:00
mpthreadport.c py/modthread: Return thread id from start_new_thread(). 2023-09-03 18:49:18 +10:00
mpthreadport.h
pendsv.c
pendsv.h
pin.h renesas-ra/boards/make-pins.py: Update to use tools/boardgen.py. 2023-11-03 14:18:54 +11:00
powerctrl.c extmod/modmachine: Provide common bindings for 6 bare-metal functions. 2023-11-30 16:11:11 +11:00
powerctrl.h extmod/modmachine: Provide common bindings for 6 bare-metal functions. 2023-11-30 16:11:11 +11:00
powerctrlboot.c
pybthread.c
pybthread.h
qstrdefsport.h
ra_hal.c
ra_it.c
ra_it.h
rng.c renesas-ra: Add RNG driver. 2023-09-14 23:50:47 +10:00
rng.h renesas-ra: Add RNG driver. 2023-09-14 23:50:47 +10:00
rtc.h extmod/modmachine: Clean up decls of machine types to use common ones. 2023-10-26 16:20:53 +11:00
spi.h renesas-ra: Add support for RA6M5, and add machine PWM, DAC, SDCard. 2023-06-27 12:30:25 +10:00
storage.c
storage.h
systick.c
systick.h
timer.c
timer.h
uart.c renesas-ra: Add TinyUSB support. 2023-09-14 23:50:45 +10:00
uart.h extmod/modmachine: Clean up decls of machine types to use common ones. 2023-10-26 16:20:53 +11:00
usbd.c shared/tinyusb: Add a helper for hex string conversion. 2023-11-16 14:59:48 +11:00
usrsw.c
usrsw.h

README.md

The Renesas RA port

This is a port of MicroPython to the Renesas RA family of microcontrollers. Currently supported features are:

  • Filesystem on the internal flash using FatFs.
  • time module with sleep, time, and ticks functions.
  • os module with VFS support.
  • machine module with the following classes: Pin, ADC, PWM, DAC, I2C, SPI, SoftI2C, SoftSPI, UART, RTC, SDCard.
  • sdcard module for MCUs without native machine.SDCard support.

Currently supported board product names are:

  • EK-RA6M2
  • RA4M1 CLICKER
  • EK-RA6M1
  • EK-RA4M1
  • EK-RA4W1

Please refer to the quick reference of renesas-ra port for more information about the boards.

Build instructions

  • MicroPython cross-compier The MicroPython cross-compiler must be built first, which will be used to pre-compile (freeze) built-in Python code. THis cross-compiler is built and run on the host machine, using:

    $ make -C mpy-cross
    

    This command should be executed from the root directory of this repository. All other commands below should be executed from the ports/renesas-ra/ directory.

  • Arm compiler An Arm compiler is required for the build, along with the associated binary utilities. The default compiler is arm-none-eabi-gcc, which is available for Linux, Mac and Windows hosts via https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads. The compiler can be changed using the CROSS_COMPILE variable when invoking make.

  • Protocol buffer compiler Building for the ARDUINO_PORTENTA_C33 board will build the esp_hosted driver, that depends on the Protocol Buffer Compiler being installed. On Debian/Ubuntu, this can be installed with sudo apt-get install protobuf-compiler.

  • Obtain submodules First the submodules must be obtained using:

    $ make submodules
    
  • Build binary image .hex Then to build for a given board subdirectory name, run:

    $ make BOARD=EK_RA6M2 clean
    $ make BOARD=EK_RA6M2
    

    The default board subdirectory name is EK_RA6M2 (which is for EK-RA6M2 board) but any of the names of the subdirectories in the boards/ directory can be passed as the argument to BOARD=; for example RA4M1_CLICKER, EK_RA4M1, EK_RA4W1 and EK_RA6M1. The above command should produce binary images firmware.hex in the build-EK_RA6M2/` subdirectory (or the equivalent directory for the board specified).

Supported/Unsupprted funtions

Please refer to the renesas-ra quick reference.

Known issues

all boards

  • machine.lightsleep(time_ms) and machine.deepsleep(time_ms) raise uncaught exceptions.

    machine.deepsleep(1000) Uncaught exception in ExtInt interrupt handler line 16 TypeError:

RA4M1-CLICKER

  • mpremote: mount command is not available due to limited memory resources.

EK-RA4M1

  • mpremote: mount command is not available due to limited memory resources.

EK-RA4W1

  • mpremote: "Execution: timeout waiting for remote" error happens when importing a file on /remote.