[nRF52] Fix for buffered stdio

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
User avatar
FoldedToad
Posts: 8
Joined: Sat Feb 23, 2019 11:50 pm

[nRF52] Fix for buffered stdio

Post by FoldedToad » Wed Apr 24, 2019 7:29 pm

It appears the current port of nRF does not support buffered stdio.
Hopefully, this will fix that issue and allow support for buffered stdio.

Normally, buffered stdio is optioned in the ./port/nrf/mpconfigport.h file as shown below.

Code: Select all

#define MICROPY_PY_SYS_STDFILES     (1)
#define MICROPY_PY_SYS_STDIO_BUFFER (1)
 
While this is necessary, the subsequent build failed using current main branch.
The problem is that the GEN genhdr pre-processing for nRF does not include all the necessary directories when scanning for QSTR definitions.

The fix bellow is modeled after other ports' Makefiles (stm32 for example) are constructed.
This has been successfully tested on a PCA10040 board.

Code: Select all

diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile
index 80110f9..2ff01b7 100644
--- a/ports/nrf/Makefile
+++ b/ports/nrf/Makefile
@@ -158,6 +158,7 @@ SRC_LIB += $(addprefix lib/,\
 	utils/pyexec.c \
 	utils/interrupt_char.c \
 	timeutils/timeutils.c \
+	utils/sys_stdio_mphal.c \
 	)
 
 ifeq ($(MICROPY_FATFS), 1)
@@ -304,7 +305,7 @@ $(BUILD)/$(OUTPUT_FILENAME).elf: $(OBJ)
 	$(Q)$(SIZE) $@
 
 # List of sources for qstr extraction
-SRC_QSTR += $(SRC_C) $(DRIVERS_SRC_C) $(SRC_BOARD_MODULES)
+SRC_QSTR += $(SRC_C) $(DRIVERS_SRC_C) $(SRC_LIB) $(SRC_BOARD_MODULES)
 
 # Append any auto-generated sources that are needed by sources listed in
 # SRC_QSTR
 

User avatar
sebi
Posts: 48
Joined: Tue Mar 29, 2016 9:36 pm
Location: France

Re: [nRF52] Fix for buffered stdio

Post by sebi » Sun Sep 15, 2019 7:35 pm

Can you describe a bit more what buffered stdio is used for?
I am having difficulties copying files (e.g. using pyboard.py) onto a nRF board, and I assume this is due to not having the buffered stdio enabled in my current build. Do you confirm this could be a reason?
I have applied the content of your patch to the Makefile of the latest MicroPython nRF port. However when invoking `make` I still get errors:

Code: Select all

LINK build-pca10040/firmware.elf
/usr/lib/gcc/arm-none-eabi/8.3.1/../../../arm-none-eabi/bin/ld: /tmp/ccFGNuZx.ltrans3.ltrans.o: in function `stdio_ioctl.lto_priv.328':
/mnt/c/micropython/ports/nrf/../../lib/utils/sys_stdio_mphal.c:91: undefined reference to `mp_hal_stdio_poll'
collect2: error: ld returned 1 exit status
make: *** [Makefile:346: build-pca10040/firmware.elf] Error 1
Here is the content of Makefile from line 344 to line 350, line where a modification mentioned in your patch is applied:

Code: Select all

$(BUILD)/$(OUTPUT_FILENAME).elf: $(OBJ)
	$(ECHO) "LINK $@"
	$(Q)$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
	$(Q)$(SIZE) $@

# List of sources for qstr extraction
SRC_QSTR += $(SRC_C) $(DRIVERS_SRC_C) $(SRC_LIB) $(SRC_BOARD_MODULES)
Hence, the Makefile:346 error corresponds to `$(Q)$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)`. Do you know what this issue could be? Thanks in advance.

Post Reply