getchar() fails after 1.19 hours (Problem with time_reached / at_the_end_of_time) #132
Labels
No labels
bazel
bluetooth
board settings
boot_stage2
bug
build
c++
can't reproduce
clang
clib-interface
cmsis
code cleanliness
code size
compiler version issues
cyw43_driver
debug
discussion
documentation
duplicate
dynamic_clock
elf2uf2
enhancement
errata
filesystem
flash layout
floating point
FreeRTOS
hardware_adc
hardware_claim
hardware_clocks
hardware_dma
hardware_exception
hardware_flash
hardware_gpio
hardware_i2c
hardware_irq
hardware_pio
hardware_pwm
hardware_rcp
hardware_rtc
hardware_spi
hardware_sync
hardware_uart
hardware_vreg
hardware_watchdog
hardware_xosc
help wanted
host
IAR
installation
invalid
linker scripts
lto
lwip
mbedtls
missing API
needs reporter detail
networking
newlib
newlib-multicore
non-c
non-cmake
non-gcc
openocd
orphan PR
OS integration
pico_async_context
pico_base
pico_binary_info
pico_flash
picolibc
pico_lwip
pico_malloc
pico_multicore
pico_printf
pico_runtime
pico_stdio
pico_stdio_usb
pico_sync
pico_time
pico_util
pioasm
port
question
review
review2
rtos interop
runtime init
static library
svd
test
tinyusb
vscode
wifi integration
wontfix
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-raspberrypi/pico-sdk#132
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I haven't reproduced this for myself, but user on the Adafruit Discord a user reported:
and showed this loop, citing https://github.com/wa1tnr/camelforth-rp2040-aU/blob/main/17-camelforth-a.d/pico-examples/camelforth-a/forth/rp2040_pico_getkey_usb.inc:
I noticed that
getchar()uses a wait untilat_the_end_of_time. However, at least superficially it looks like "the end of time" is just 1.19 hours after boot!absolute_time_tis a 64-bit quantity, butat_the_end_of_timeis initialized toULONG_MAX, a 32-bit quantity (0xfffffffu):Instead, it seems it should be initialized to another value, possibly UINT64_MAX from stdint.h.
A second problem is likely to arise when waiting for absolute times after 1.19 hours:
The
ifline should possibly readif (target == at_the_end_of_time) return false;and similarly for other sites.Following. Thanks jepler.
Note the only place you'll hit this right now is with explicit use of at_the_end_of_time by code - likely the getchar_with_timeout method you mention; the second file (with the PICO_WEAK_FUNCTION_DEF) is for host compilation.
I'm not quite following you - by code are you referring to end-user code? Because the issue's exposed by the implementation of getchar in stdio.c where the end-user isn't attempting to use any timeout.
yes it is a bug; i was saying it really for practical purposes only affects getchar unless you use at_the_end_of_time yourself
multicore.c may also have some weird behavior once the pico's been running for more than a ULONG_MAX. I haven't dug into it far enough to determine if it's expecting to be using an absolute or relative "until".
that was the "for all practical purposes" bit... it will obviously be fixed in passing, but there is no reason to sit in that method for a long time
I just want to clarify for others reading that this does break the use of
getchar()(which does not take a time as an argument, instead usingat_the_end_of_timeinternally). Usinggetchar_timeout_uswill be OK if you use a finite timeout. However, the SDK documentation suggests usinggetchar()in 2.7.1 (the documentation/examples for reading characters is in general pretty sparse...see raspberrypi/pico-examples#51). I've also seen similar problems withfgetcandfgetswhen reading from stdin. Pretty much anything other than the pico specificgetchar_timeout_uswith a finite timeout will eventually cause the pico to crash.I realise there is a PR to fix this already (which I will test shortly). I mainly wanted to document this so it's easy for other people to find via search terms because I've been bashing my head against a wall for several weekends wondering why my serial communication locks up after 1.19 hours when almost identical code on other microcontrollers does not. I'm pretty sure this is why. I'll add a comment in a few hours to the PR should I verify it fixes my issue.
https://github.com/wa1tnr/camelforth-rp2040-aU/blob/main/17-camelforth-a.d/pico-examples/camelforth-a/forth/rp2040_pico_getkey_usb.inc#L3
I've re-titled the issue to mention
getchar().merged into develop
I seem to be having an issue with the fix in #145 where serial communication using
getchar()is blocked in core 0 while core 1 is busy. It's fine when core 1 is blocked on reading from the multicore fifo, but while core 1 is doing something it seems like serial communication in core 0 is buffered until core 1 stops/blocks (at which pointgetchar()works as normal again). This issue does not appear in SDK v1.0.1, but does appear from the first commit onwards in #145.I haven't had time to create a minimal working example (probably won't until next weekend) so I was wondering if anyone else had seen something like this while using #145?