Re: Memory corruption (?) I don't understand
BERTRAND Joël <[email protected]> Tue, 22 Jun 2021 19:28:47 +0200
| Newsgroups | gmane.comp.hardware.avr.gcc |
|---|---|
| Message-ID | <[email protected]> |
BERTRAND Joël a écrit :
> Trampas Stern a écrit :
>> Does the code run if you comment out 'lora_send("coucou", 7);
>
> Yes. To be honnest, if I comment out LDL_MAC_otaa(&mac), it runs.
>
>> Does it still crash with simple main() { _delay_ms(1000);
>> stty_print("hello");}
>>
>> That is start removing code until it works, when you find the line in
>> main that causes a crash, go into that function and start removing code
>> until it works. Slowly you will find the problem.
>
> I have tried (and I continue...) but I'm not sure that this bug is in
> LoRaWAN library. Indeed, LDL_MAC_otaa(&mac) shows my bug but, sometimes,
> just with a debug trace in main(), LDL_MAC_otaa(&mac) doesn't crash.
In lorawan/ldl_mac.c, you have :
enum ldl_mac_status LDL_MAC_otaa(struct ldl_mac *self)
{
...
fillJoinBuffer(self, U16(self->devNonce));
self->devNonce++;
arg.dev_nonce_updated.nextDevNonce = self->devNonce;
self->handler(self->app, LDL_MAC_DEV_NONCE_UPDATED, &arg);
self->tx.power = 0;
self->op = LDL_OP_JOINING;
...
}
If I comment out :
self->handler(self->app, LDL_MAC_DEV_NONCE_UPDATED, &arg);
Firmware doesn't crash. This pointer is a pointer to app_handler() in
./lorawan.c.
Now, I suppose that this pointer is modified. Thus, I have add a debug
trace :
enum ldl_mac_status LDL_MAC_otaa(struct ldl_mac *self)
{
enum ldl_mac_status retval;
union ldl_mac_response_arg arg;
...
unsigned char t[80];
snprintf(t, 80, "self->handler=%p\r\n", self->handler);
stty_print(t);
self->handler(self->app, LDL_MAC_DEV_NONCE_UPDATED, &arg);
self->tx.power = 0;
self->op = LDL_OP_JOINING;
...
}
and with this simple debug trace, it doesn't crash anymore !...