Skip to content
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

TTN strcpy_P and pgmstrcmp start to fail after including more code elsewhere in the application #274

Open
bsc-itcl opened this issue Feb 24, 2021 · 2 comments

Comments

@bsc-itcl
Copy link

Hello,

I am using this library on a custom board based on Arduino Zero (same SAMD microcontroller) with the RN2483 LoRa transceiver. TTN was working perfectly until, at some point after adding extra code in other files, LoRa initialization started to fail. The symptoms were that the buffers were corrupt since the beginning (reset function), checked with the debug Serial and the oscilloscope.

At the beginning I could work around it commenting out some parts of my other code (floats, Serial.prints, etc) but in the end this was the bottleneck.

Finally after a lot of debugging with the oscilloscope I found out the problem was in the strcpy_P function: I replaced all strcpy_P for strcpy and e.g. pgmstrcmp(buffer, CMP_ACCEPTED) for strcmp(buffer, compare_table[CMP_ACCEPTED]).
I guess this is not optimal, but for now it's working. I can try to give more information if anyone cares, I just post this to let everyone know my solution and because I'm curious about the root cause and eager to learn.

Regards

@jpmeijers
Copy link
Collaborator

It sounds like you are running out of memory (RAM) during runtime, corrupting your buffers.

Because this library fits and works correctly on AVR (Arduino Leonardo and Uno), and the SAMD your are using has much more memory that the AVR, I doubt that the issue is in this library. Most likely you are defining a buffer in your code that is very big (512 bytes or more), which eats up all the memory, corrupting this library's buffers.

There could be other causes too, but this is the most likely one.

@bsc-itcl
Copy link
Author

bsc-itcl commented Feb 25, 2021

Hi @jpmeijers thanks for your reply.

You are right, it looks like an out-of-RAM problem. I don't have any big buffer or array, however I am using several other libraries for the different sensors which may sum up more variables.

However, the solution I got (and that is working well so far) confuses me. I followed strcpy_P definition in SAMD pgmspace.h, and it's just #define strcpy_P(dest, src) strcpy((dest), (src)). How can my patch (changing strcpy_P for strcpy) make it work?

EDIT> well, I also changed for example:

  • strcpy_P(command, (char *)pgm_read_word(&(mac_table[index])));
  • strcpy(command, mac_table[index]);

The problem could lie here: #define pgm_read_word(addr) (*(const unsigned short *)(addr))
I access directly to mac_table instead of through pgm_read_word.
<EDIT

It's frustrating not being able to use debug tools, I tried to import the sketch to Atmel Studio but there are a lot of compilation errors in the solution - some very weird.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants