-
Notifications
You must be signed in to change notification settings - Fork 68
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
Invalid memory access in all callback examples #42
Comments
OMG - I just wasted hours on this bug and rewired the board a bazillion times thinking I had the wiring wrong. Unfortunately as the crash is quite severe - as you would expect when you start executing code at a completely random address - there is no error logged - just silence - so you don't know what has happened. I ended up single stepping all the way to the "crash point" i.e. where the callback is performed and then came to the same conclusion you did. In the I2C sample I was using I simply moved the
from within the setup() method to just above it in global variable space so that the callbacks array stays valid and voila - everything works perfectly! (at last) BTW - all my testing is on STM32 - recently moved away from the 8bit world - just kept hitting memory constraints: both RAM and Flash way too small and the CPUs are underpowered. Perhaps the SerialTransfer examples somehow manage to work on the 328p due to some weird coincidence with memory arrangement but they definitely don't work in STM32 world until the callbacks array is allocated in global space (or malloc'd somewhere). |
Do you think it would be better to fix the examples or fix the code so that it makes a deep copy of the callback array? If it made a deep copy then users (and the existing examples) could safely create the array on the stack - and the example source code could remain unchanged. |
I'm not exactly sure how to do that - could you make a PR with all the changes you would like to see? |
It might even be more elegant to define a IPacketReceiver interface class and Packet calls that when a packet has been received. Hmmm, so many options. |
Hey guys, let me follow up on my comment :)
As it appears the "polish" effort (issue #35 and PR #37) will not finish in the immediate future, we should probably address this version. And I'd vote for just fixing the docs and examples for two reasons:
|
According to the code,
SerialTransfer
requires the passed callback array to stay allocated for its whole lifetime.Steps to reproduce: A modified
uart_rx_with_callbacks.ino
example is attached below - using LED blinking, as I have just one serial. I was able to reproduce it also by printing the memory addresses.Expected behavior:
Example of invalid memory access:
The text was updated successfully, but these errors were encountered: