-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
ports/renesas: Replace MICROPY_EVENT_POLL_HOOK with mp_event_wait. #15929
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
ports/renesas: Replace MICROPY_EVENT_POLL_HOOK with mp_event_wait. #15929
Conversation
Thanks. We need to eventually do this for all ports. |
1cf893a
to
956e6a1
Compare
@iabdalkader I had to also make a similar change in I will endevour to get something set up to test esphosted as I'm keen to use it in the near future, but not sure when I'll have it running. |
@dpgeorge I've now done some basic testing and switched to |
ac1c916
to
acecb0f
Compare
@@ -126,7 +126,7 @@ int mp_bluetooth_hci_controller_init(void) { | |||
if (mp_bluetooth_hci_uart_any()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bit off topic, but @iabdalkader does this just block for 2.5 seconds at boot every time? Does the esp chip take that long to boot, or is it just extra timeout in case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, because the firmware is configured to output debug messages on boot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you meant to comment on this line:
while ((mp_hal_ticks_ms() - start) < 2500) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I did, but github only seems to let me start a comment on a line x rows from an actual change... this was as close as I could get!
That feels like a long time to block, but if that's needed / intended I won't worry about it too much until I have hw and time to actually work on it myself :-D
I can test it next week and let you know. |
I tested this, sorry for the delay. I ran multitests and they pass just as before. Unrelated, but most of the sslcontext tests are skipped not sure why (this was the case before this change). |
Thanks @iabdalkader for the testing! No apologies necessary, this was just a bit of opportunistic cleanup for me and not in a rush for any reason. |
Although this PR has correct behaviour I think it will increase power consumption at an idle REPL (and other idle locations) because it's now doing a busy loop rather than executing WFI. To fix that you'll need to define MICROPY_INTERNAL_WFE. Since renesas-ra is not tickless (unlike rp2 which is tickless) this macro probably needs to be: #define MICROPY_INTERNAL_WFE(TIMEOUT_MS) __WFI() And please put that in |
ed8555c
to
0f1c2c1
Compare
Thanks for the review @dpgeorge |
ports/renesas-ra/mphalport.h
Outdated
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) \ | ||
do { \ | ||
if ((TIMEOUT_MS) < 0) { \ | ||
__WFE(); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure WFE is correct to use on this port. It doesn't do SEV anywhere, and SCB_SCR_SEVONPEND is not enabled (as far as I can tell), so it's unlikely that the WFE will ever wake up.
Eg this WFE will be run each time mp_hal_stdin_rx_chr()
loops around, and so it's supposed to wake whenever a new character is available, ie an "event" occurs. But I can't see how that would work in the current code (would need to add SEV's in the right locations).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh interesting, I don't know much about these internals.
I had done some minimal testing at repl (over uart) which I just repeated:
anl@STEP:~/micropython/ports/renesas-ra$ mpremote u0
Connected to MicroPython at /dev/ttyUSB0
Use Ctrl-] or Ctrl-x to exit this shell
>>>
MPY: sync filesystems
MPY: soft reboot
MicroPython v1.26.0-preview.25.g0f1c2c1f25.dirty on 2025-04-24; EK-RA4W1 with RA4W1
Type "help()" for more information.
>>>
>>> import time
>>> time.sleep(1)
>>> while True:
... time.sleep(1)
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
KeyboardInterrupt:
>>>
>>> while True:
... pass
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
KeyboardInterrupt:
>>>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be that interrupts automatically set the event flag on these MCUs. In that case, WFI and WFE are equivalent, in which case this macro should just unconditionally use one of them.
We need to get this right because it's tricky and can have lots of impacts on the system if not done the right way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went hunting on their website for a reference manual that covers the core in this way, found nothing.
Looking at the source, these do just both go to cmsis that implements them as the two wfi
/wfe
assembly commands which doesn't really help.
Based on the lack of data I'm certainly inclined to take the route of simple / safe and just use the one-liner WFI command instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think just a simple WFI would be best here.
Signed-off-by: Andrew Leech <andrew@alelec.net>
Signed-off-by: Andrew Leech <andrew@alelec.net>
0f1c2c1
to
57e605b
Compare
Summary
Basic update to the renesas to replace the traditional
MICROPY_EVENT_POLL_HOOK
with the newermp_event_wait_indefinite()
/mp_event_wait_ms()
as appropriate.Testing
Renesas imxrt1010 EVK
python3 test_serial.py
from #15909 has been run on both usb and uart and works without any failures.~/micropython/tests$ ./run-tests.py --target renesas-ra --device /dev/ttyACM0
has been run before and after MR with no changes (fails onbuiltin_pow3_intbig machine_spi_rate
in both cases).