Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ports/nrf: Consolidate stdio functions.#15158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
dpgeorge merged 4 commits intomicropython:masterfromandrewleech:nrf_updated_stdio
Jul 26, 2024

Conversation

andrewleech
Copy link
Contributor

Consolidate CDC, UART and NUS stdio interfaces into the one handler.
Allows any/all of them to be enabled separately.

Note there are some conflicts between UART and CDC REPL handling, particularly if hwfc is enabled on the UART.
This can block for long enough to cause the CDC connection to be broken. This is not a new bug as such, the current release of nrf port is restricted to not allow both CDC and UART to be enabled at the same time at all.

Updates UART REPL to use similar define to other platforms:
MICROPY_HW_ENABLE_UART_REPL

Uses shared/tinyusb cdc implementation.

Thie PR builds upon (and therefore include commits from)#14462 and#14485

It has currently only been tested on a nrf52840 dongle, however uart, cdc and nus support have individually all worked on this board.

@github-actionsGitHub Actions
Copy link

github-actionsbot commentedMay 29, 2024
edited
Loading

Code size report:

   bare-arm:    +0 +0.000% minimal x86:    +0 +0.000%    unix x64:    +0 +0.000% standard      stm32:    +0 +0.000% PYBV10     mimxrt:  +168 +0.046% TEENSY40        rp2:  +204 +0.023% RPI_PICO_W       samd:  +156 +0.059% ADAFRUIT_ITSYBITSY_M4_EXPRESS[incl +4(bss)]

@codecovCodecov
Copy link

codecovbot commentedMay 29, 2024
edited
Loading

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.39%. Comparing base(3c8089d) to head(d126e2a).
Report is 37 commits behind head on master.

Current headd126e2a differs from pull request most recent head139fcd1

Pleaseupload reports for the commit139fcd1 to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@##           master   #15158      +/-   ##==========================================- Coverage   98.42%   98.39%   -0.03%==========================================  Files         161      161                Lines       21204    21204              ==========================================- Hits        20870    20864       -6- Misses        334      340       +6

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report?Share it here.

@robert-hh
Copy link
Contributor

This PR does not even build for a Arduino BLE 33 Sense or a SEEED XIAO NRF52 or NRF52840_MDK_USB_DONGLE. Compile errors:

rivers/usb/usb_cdc.c: In function 'mp_usbd_port_get_serial_number':
drivers/usb/usb_cdc.c:108:46: error: 'MICROPY_HW_USB_DESC_STR_MAX' undeclared (first use in this function)
108 | MP_STATIC_ASSERT(sizeof(deviceid) * 2 <= MICROPY_HW_USB_DESC_STR_MAX);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
../../py/misc.h:54:61: note: in definition of macro 'MP_STATIC_ASSERT'
54 | #define MP_STATIC_ASSERT(cond) ((void)sizeof(char[1 - 2 * !(cond)]))
| ^~~~
drivers/usb/usb_cdc.c:108:46: note: each undeclared identifier is reported only once for each function it appears in
108 | MP_STATIC_ASSERT(sizeof(deviceid) * 2 <= MICROPY_HW_USB_DESC_STR_MAX);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
../../py/misc.h:54:61: note: in definition of macro 'MP_STATIC_ASSERT'
54 | #define MP_STATIC_ASSERT(cond) ((void)sizeof(char[1 - 2 * !(cond)]))
| ^~~~
CC ../../lib/tinyusb/src/portable/nordic/nrf5x/dcd_nrf5x.c
drivers/usb/usb_cdc.c:109:5: error: implicit declaration of function 'mp_usbd_hex_str'; did you mean 'mp_obj_new_str'? [-Werror=implicit-function-declaration]
109 | mp_usbd_hex_str(serial_buf, (uint8_t *)deviceid, sizeof(deviceid));
| ^~~~~~~~~~~~~~~
| mp_obj_new_str
drivers/usb/usb_cdc.c: In function 'usb_cdc_init':
drivers/usb/usb_cdc.c:124:5: error: implicit declaration of function 'mp_usbd_init'; did you mean 'mp_set_init'? [-Werror=implicit-function-declaration]
124 | mp_usbd_init();
| ^~~~~~~~~~~~
| mp_set_init
CC device/startup_nrf52840.c
drivers/usb/usb_cdc.c: In function 'USBD_IRQHandler':
drivers/usb/usb_cdc.c:143:5: error: implicit declaration of function 'tud_int_handler' [-Werror=implicit-function-declaration]
143 | tud_int_handler(0);
| ^~~~~~~~~~~~~~~

Rebasing to the current master branch fails as well due to conflicts in the make files of the other ports. Nothings difficult, just duplicating references to files, but it breaks rebase.

If you look at the CI of this PR, you see that it fails as well in building the firmware.

@andrewleech
Copy link
ContributorAuthor

Ah yes it seems I rushed ahead with this, it was building previously before I went and consolidated some more settings to make UART and ble repl all work the same way.
A little more work to do to get it cleaned up!

@robert-hh
Copy link
Contributor

robert-hh commentedJun 2, 2024
edited
Loading

The mpconfigboard.h file for the SEEED and Arduino board miss enabling of MICROPY_HW_ENABLE_USBDEV and MICROPY_HW_USB_CDC.
Edit: And in the master branch.tud_sof_cb_enable does not exist at all.

andrewleech reacted with thumbs up emoji

@andrewleech
Copy link
ContributorAuthor

Ah thanks for looking into that. I should make that define enabled by default if USB is enabled.

@andrewleechandrewleechforce-pushed thenrf_updated_stdio branch 4 times, most recently frombc97045 to32fbb18CompareJune 4, 2024 02:34
@robert-hh
Copy link
Contributor

Adding#define MICROPY_HW_ENABLE_USBDEV (1) makes both the Seeed NRF52 board and the Arduino Nano 33 BLE Sense compile & build properly, given that the old version of lib/tinyusb is used and the branch isnot rebased to master. The boards boot and works fine.
When building with the actual master branch, the Seeed board refuses to work. The USB device does not register.

@andrewleech
Copy link
ContributorAuthor

This has been rebased on master (still on top / including the startup buffer PR). I haven't yet re-tested it however.

@robert-hh
Copy link
Contributor

Both SEEED NRF52 and Arduino Nanon 33 BLE build and run. Only I had to define MICROPY_HW_ENABLE_USBDEV as 1.

@andrewleech
Copy link
ContributorAuthor

andrewleech commentedJun 5, 2024
edited
Loading

Ah, I see now, those boards had justMICROPY_HW_USB_CDC defined, notMICROPY_HW_ENABLE_USBDEV.

I think it makes sense more broadly to haveMICROPY_HW_ENABLE_USBDEV as the "main" define to enable usb, so I've added it to those two boards. All other nrf boards with USB seemed to have both defines already.

For reference, the tinyusb update came in for#14485 and is needed for those features. I don't think it should matter for just this PR though, I really would have thought the previous tinyusb commit would be fine for the changes just made here.

@andrewleech
Copy link
ContributorAuthor

andrewleech commentedJun 5, 2024
edited
Loading

Ok that build failure:

LINK build-PCA10056-s140/firmware.elf/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /tmp/firmware.elf.6R2Ffu.ltrans0.ltrans.o: in function `__wrap_dcd_event_handler':<artificial>:(.text+0x3f3c): undefined reference to `dcd_event_handler'

Is caused by binutils:

Bug 24406 - -Wl,--wrap= incompatible with -flto

Which was apparently fixed in binutils 2.33
The CI build is on ubuntu focal, which hasbinutils-arm-none-eabi amd64 2.34-4ubuntu1+13ubuntu1 so should have had that particular fix, though there's a few linked tickets from that bug report.

Of note I don't have the issue at home with gcc 12.x so it's been fixed since then, but it's hard to tell exactly when.

@andrewleech
Copy link
ContributorAuthor

Also thanks@robert-hh your reports made it clear there were a number of build failures on nrf52840 whenMICROPY_HW_USB_CDC = 1 butMICROPY_HW_ENABLE_USBDEV = 0
I've cleaned them up too, as there's definitely cases where you might want that chip without USB being used.

@robert-hh
Copy link
Contributor

Building with that PR works fine for the SEEED and Arduino boards, linking is now almost instantly. Both run. However rebasing on top of the current master branch causes conflicts in shared/tinyusb/mp_usbd_cdc.c and differences in lib/tinyusb.

P.S:: I'm using GCC 12.2 as the standard version of the OS.

@andrewleech
Copy link
ContributorAuthor

Thanks I've rebased again onto master now my previous PR has been merged!

@robert-hh
Copy link
Contributor

I compiled and ran this PR on two NRF52 boards. They build fine and work most of the times. But sometimes the boards do not register as USB devices any more, even when I do a full power cycle. The boards are connected to an external hub. Unplugging the hub from the PC and re-plugging helps most of the time. Connection the boards directly to the PC does not work. There are similar reports in the MIMXRT section on Discord/micropython. So it may be a generic problem of TinyUSB. Note to@projectgus.
Can you suggest something to trace the state more, now that it happens here?

@robert-hh
Copy link
Contributor

@andrewleech SO I see a strange behavior on the RP2040 port. If in main.py a script is started which enables a Pin IRQ (and disables), then after a hard reset or power up USB is blocked like detailed above. I have to disconnect the USB hub and reconnect it to get USB working again, and then I see at the next boot fragments of the messages created by scripts started from main.py. If I do not add this test script, everything is fine. Once booted, soft reset works without problems.
The trigger does not have to occur. I can tie that input pin to GND and still the problem shows up.
Since I noticed the same behavior at the NRF52 board with this PR, the reason may be identical. People also mentioned problems with the MIMXRT port. I have to check.
Test script:

from machine import Pinfrom time import sleep_ms, sleep_uspin7 = Pin(7, Pin.OUT)def callback(_, p=pin7):    p(1)  # Trigger    p(0)pin3 = Pin(3, Pin.IN)pin3.irq(callback, trigger=Pin.IRQ_FALLING)sleep_ms(100)pin3.irq(handler=None)

@robert-hh
Copy link
Contributor

robert-hh commentedJun 14, 2024
edited
Loading

The issue starts with the following commit:
8809ae716 shared/tinyusb: Buffer startup CDC data to send to host on connection.

And actually the device is registered, as I shows up in lsusb, but REPL is locked.

@andrewleech
Copy link
ContributorAuthor

Thanks for the report and testing@robert-hh
That's a shame, I thought I'd tested that change pretty thoroughly, looks like I missed some use cases though.
I'll try to make the to replicate your test and hopefully see where the problem occurs, might be related to how the tiny USB tx buffer switches from overwrite to blocking mode

@robert-hh
Copy link
Contributor

Some information about my test case: The above script is imported in main.py after having imported another python script. Sometimes it locks up, sometimes strange error messages pop up, like the one below, where importing the script should raise an error message. It was iperf3.py, which is not working at a plain RPI Pico. That all looks like having a uninitialized symbol.

ror: unexpected indent>>> TrTraceback (most recent call last):  File "<stdin>", line 1, in <module>NameError: name 'Tr' isn't defined>>> >>> TrTraceback (most recent call last):  File "<stdin>", line 1, in <module>NameError: name 'Tr' isn't defined>>> >>>  >>> Trac  acrTracTraceback (most recent call last):  File "<stdin>", line 1SyntaxError: invalid syntax

@robert-hh
Copy link
Contributor

robert-hh commentedJun 14, 2024
edited
Loading

It seems that it does not have to be that specific script. It often happens if the imported script raises an exception. Then, the output it want to create plus the usual boot banner get lengthy, like 674 bytes.
Edit: But just creating a lengthy output in main.py does not cause the lock-up.

@robert-hh
Copy link
Contributor

Another strange observation:
I nuked the board which showed most of the phenomenon and copied back a small main,py and the sample file. Then, the problem was gone!
Then, I copied back like 40 more files to the board, and the issue as back again.

andrewleech and projectgus reacted with eyes emoji

@robert-hh
Copy link
Contributor

With mprmote I get a REPL prompt, but with a part of the main.py being in the REPL input buffer, like:

Connected to MicroPython at /dev/ttyACM0Use Ctrl-] or Ctrl-x to exit this shellysh import *Traceback (most recent call last):  File "<stdin>", line 1SyntaxError: invalid syntax

The main.py I'm using now for tests is:

from upysh import *from pye import pyefrom machine import Pinimport cs1237power=Pin(13, Pin.OUT, value=1)cs=cs1237.CS1237(Pin(15), Pin(14))

With upysh.py being from mircopython-lib, pye.py is my on-board editor, both being frozen in the firmware, and cs1237.py being the driver for a cs1237 ADC, at which I noticed the problem. attached. When starting it you must NOT attach the sensor. Without the sensor an error is raised. With the sensor, all is fine. Maybe a timing issue. In some tests, instead of importing that file a simpletime.sleep_ms(500) was sufficient to cause that misbehavior. The cs1237 driver waits for ~500ms to get a response from the ADC on instantiation.

cs1237.zip

So it''s still kind of spooky. The problem may as well be somewhere in the file system or timing dependent.

@andrewleech
Copy link
ContributorAuthor

The "correct" behaviour of that new buffering changeis to to keep the most recent "full stdout" buffer worth of data from before a terminal is connected for display on-connection.

So a failure in main that drops to repl should show the tail of the error message along with the repl prompt when you open a terminal.

So yeah I'd expect that snippet of traceback, though probably not the content from main itself.... It would be interesting to increase the size of the buffer and see what else is shown then. This is defined in micropython/shared/tinyusb/tusb_config.h

The lockups seen on picocom are definitely an issue that warrants deeper investigation also.

@robert-hh
Copy link
Contributor

robert-hh commentedJun 16, 2024
edited
Loading

I see indeed the tail of output made during execution of main.py. But text from main.py should not be there, and the REPL history buffer must be empty. With Picocom, the REPL history buffer contains e.g.:

from upysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fiberoupysh impo Fibe

That looks very strange!

@andrewleech
Copy link
ContributorAuthor

Really strange! Was that after a soft reset or a hard boot? I'm wondering if there's some static buffers / memory pointers being reused without appropriate clearing on soft reset? I'm really not sure how the buffer change could do this either unless it's a buffer (mis) allocation issue that the explicit clear in tinyusb was hiding previously.
Though maybe my disabling the buffer clear in tinyusb is also relating to initial reboot, it might be missing a reset on the tx ringbuffer head and tail pointers on a cold boot now too.

Repl history buffer though seems like a separate issue to me, though might be a similar root cause. I don't think there should be any direct relation between repl history buffer and tinyusb tx buffer though.

@robert-hh
Copy link
Contributor

That all happens only after hard reset resp power cycle. Once it's working, soft reset behaves fine. It seems to be the initial set-up, which fails. And only if the start-up is delayed and/or an exception is raised by the code executed in main.py. May it be that some initialization only happens when input is requested from REPL? Or the opposite? It could be a timing effect.

andrewleech reacted with thumbs up emoji

@projectgus
Copy link
Contributor

I think the root cause is in the linked issue above (found by debugging@robert-hh's case above and then refining it.)

if (!nrfx_is_in_ram(buf_in)) {
// EasyDMA requires that transfer buffers are placed in DataRAM,
// NRFX_ERROR_INVALID_ADDR if the are not.
buf = alloca(size);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This seems pretty dangerous, the stack may overflow if the buffer is large.

Maybe limit it to 256 bytes alloca, and do a loop over the buffer to break it up and send it in chunks?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Good catch! I had been thinking this was really just stuff like exception messages where it's sending const strings from the firmware. But looking forward, certainly when RomFS comes in there will be plenty of opportunity to send data directly from flash.
I've reworked this in a chunked send loop which was tested on a nrf52840 dev board (repl on uart).

@@ -259,6 +261,11 @@ SRC_C += $(addprefix lib/tinyusb/src/,\
portable/nordic/nrf5x/dcd_nrf5x.c \
)

CFLAGS += \
-DCFG_TUSB_MCU=OPT_MCU_NRF5X \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Instead of defining this at this level I suggest (this may not work but worth a try):

  • don't add theINC += -I../../shared/tinyusb line above (this will prevent the defaulttusb_config.h from being included)
  • addINC += -I./drivers/usb
  • reuse the existingdrivers/usb/tusb_config.h file and define thisCFG_TUSB_MCU option there, and then do#include "shared/tinyusb/tusb_config.h" to get the remaining config from the common file

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks, I had thought it was confusing to have two levels of this same header - but having the port one explicitely import the shared one does make it clearer for sure. It's certainly better to have this define in the header it belongs in rather than a global cflag.

I've made this change and yes it does work!

@@ -2,6 +2,8 @@ MCU_SERIES = m4
MCU_VARIANT = nrf52
MCU_SUB_VARIANT = nrf52840
SOFTDEV_VERSION = 6.1.1
FLASHER ?= jlink
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Is this line needed, since jlink is the default flasher?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Ah, not anymore that's true.

#endif
#endif

#if MICROPY_HW_ENABLE_USBDEV
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Any reason why this extra #if is needed here, can't the config below be part of the block just above with theMICROPY_HW_USB_CDC config?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Oh thanks, yes I'd moved the block above to that spot to consolidate the two, then forget the final cleanup.

#endif

#ifndef MICROPY_HW_USB_CDC_TX_TIMEOUT
#define MICROPY_HW_USB_CDC_TX_TIMEOUT (500)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is the default so I'd say just leave this define out.

andrewleech reacted with thumbs up emoji
@@ -43,6 +44,9 @@ typedef enum

extern const unsigned char mp_hal_status_to_errno_table[4];

extern int mp_interrupt_char;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Please includeshared/runtime/interrupt_char.h instead of declaring this variable.

andrewleech reacted with thumbs up emoji
@@ -50,6 +54,14 @@
#include "soc/nrfx_coredep.h"
#endif

#ifndef MICROPY_HW_STDIN_BUFFER_LEN
#define MICROPY_HW_STDIN_BUFFER_LEN 1024
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This seems large, especially since nrf parts don't usually have that much RAM.

Can we drop it down to 512 like rp2?

I know it's currently 1024 in master, but the new code in this PR usesringbuf_free(&stdin_ringbuf) to never overflow this buffer, and also the CFG_TUD_CDC_RX_BUFSIZE/CFG_TUD_CDC_TX_BUFSIZE values are now 256 (in this PR) vs 64 (in master), so there's already more buffering.

andrewleech reacted with thumbs up emoji
@dpgeorge
Copy link
Member

@andrewleech I see you made changes. Is this ready for re-review?

@andrewleech
Copy link
ContributorAuthor

Not quite sorry@dpgeorge I need to test them still.

@andrewleechandrewleechforce-pushed thenrf_updated_stdio branch 3 times, most recently fromffe7814 to9614d45CompareJuly 24, 2024 02:17
@andrewleech
Copy link
ContributorAuthor

@dpgeorge I've addressed your review feedback thanks and re-tested on the nrf52840 dongle and dev board.

I also tested USB without the poll after adding theLDFLAGS += -Wl,--wrap=dcd_event_handler and it appears to work correctly with just the interrupt (like on other ports) which is great!

Consolidate CDC, UART and NUS stdio interfaces into the one handler.Allows any/all of them to be enabled separately.Updates UART REPL to use similar define to other platforms:`MICROPY_HW_ENABLE_UART_REPL`.USB now uses the shared/tinyusb CDC implementation.Signed-off-by: Andrew Leech <andrew@alelec.net>
Signed-off-by: Andrew Leech <andrew@alelec.net>
Older gcc/binutils linker does not support lto with wrap.Signed-off-by: Andrew Leech <andrew@alelec.net>
Signed-off-by: Andrew Leech <andrew@alelec.net>
@dpgeorge
Copy link
Member

Thanks for updating, the changes now look good.

I tested this on anARDUINO_NANO_33_BLE_SENSE and it works well. Tested:

  • CDC upload and download speed and integrity
  • mpremote cp files to and from the device over USB CDC
  • run the test suite

@dpgeorgedpgeorge merged commit5e80416 intomicropython:masterJul 26, 2024
7 checks passed
# linker wrap does not work with lto on older gcc/binutils: https://sourceware.org/bugzilla/show_bug.cgi?id=24406
GCC_VERSION = $(shell arm-none-eabi-gcc --version | sed -n -E 's:^arm.*([0-9]+\.[0-9]+\.[0-9]+).*$$:\1:p')
GCC_MAJOR_VERS = $(word 1,$(subst ., ,$(GCC_VERSION)))
ifeq ($(shell test $(GCC_MAJOR_VERS) -ge 10; echo $$?),0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@andrewleech this looks a bit funny to me. On my Arch system I have:

arm-none-eabi-gcc (Arch Repository) 14.1.0

ButGCC_VERSION here evaluates to4.1.0.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Ah drats, it worked on a few systems I'd tested on but yes my arch server is also at 14.1.0 and I get the same thing. Silly greedy regex. Easy fix...
arm-none-eabi-gcc --version | sed -n -E 's:^arm.*([0-9]+\.[0-9]+\.[0-9]+).*$$:\1:p' ->
arm-none-eabi-gcc --version | sed -n -E 's:^arm.* ([0-9]+\.[0-9]+\.[0-9]+).*$$:\1:p'

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

#15553

I wish there was a way to do this in a proper programatic way, but I couldn't find one.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@dpgeorgedpgeorgedpgeorge left review comments

Assignees
No one assigned
Labels
Projects
None yet
Milestone
release-1.24.0
Development

Successfully merging this pull request may close these issues.

5 participants
@andrewleech@robert-hh@projectgus@dpgeorge@pi-anl

[8]ページ先頭

©2009-2025 Movatter.jp