Re: Of course, I have a memory corruption, but I'm not able to fix it...

2021-05-22 Thread BERTRAND Joël
Paweł Si a écrit :
> 
> sob., 22 maj 2021 o 09:49 BERTRAND Joël  > napisał(a):
> 
>         I'm not sure. In main() you will find :
> 
>         rfid_tag_t  tag;
>         iso14443a_anticol(0, );
> 
> 
> I would remove this line (file iso14443a.c:244): 
> memset(, 0, sizeof(tag));

Runs better with :

memset(tag, 0, sizeof(tag));

I have used a library without verifications. And I have found another
error in header file :

ISO14443A_AC_SEL_CODE_CL2 should be equal to 0x95 !

Thanks a lot,

JB



Re: Of course, I have a memory corruption, but I'm not able to fix it...

2021-05-22 Thread Paweł Si
sob., 22 maj 2021 o 09:49 BERTRAND Joël 
napisał(a):

> I'm not sure. In main() you will find :
>
> rfid_tag_t  tag;
> iso14443a_anticol(0, );
>

I would remove this line (file iso14443a.c:244):
memset(, 0, sizeof(tag));

Best regards
Paweł


Re: Of course, I have a memory corruption, but I'm not able to fix it...

2021-05-22 Thread BERTRAND Joël
Paweł Si a écrit :
> 
> 
> pt., 21 maj 2021 o 12:09 BERTRAND Joël  > napisał(a):
> 
> Trampas Stern a écrit :
> > You also  need to send the rest of the code. 
> 
> 
> This was actually a good advice, most likely the bug is in your code, so
> seeing the rest would be helpful 

Firmware is downloadable at
https://hilbert.systella.fr/public/20210122.tar.gz

> uint8_t
> iso14443a_anticol(uint8_t wup, rfid_tag_t *tag)
> 
> 
> I'm guessing  the pointer 'tag' is pointing to a random memory address,
> but without rest of your code it is hard to tell.

I'm not sure. In main() you will find :

rfid_tag_t  tag;
iso14443a_anticol(0, );

Best regards,

JB



Re: Of course, I have a memory corruption, but I'm not able to fix it...

2021-05-21 Thread Paweł Si
pt., 21 maj 2021 o 12:09 BERTRAND Joël 
napisał(a):

> Trampas Stern a écrit :
> > You also  need to send the rest of the code.
>

This was actually a good advice, most likely the bug is in your code, so
seeing the rest would be helpful


> uint8_t
> iso14443a_anticol(uint8_t wup, rfid_tag_t *tag)
>

I'm guessing  the pointer 'tag' is pointing to a random memory address, but
without rest of your code it is hard to tell.


Re: Of course, I have a memory corruption, but I'm not able to fix it...

2021-05-21 Thread BERTRAND Joël
Trampas Stern a écrit :
> You also  need to send the rest of the code. 
> 
> For example it could be that rx_len is where memory overflow is happening
> 
> cascade:
> *    rx_len = sizeof(sak);*
> snprintf(t, 3, "%d", (*tag).level);
> 
> On Thu, May 20, 2021 at 11:07 AM Trampas Stern  > wrote:
> 
> Try  changing this:
> unsigned char           t[3];
> 
> to this
> unsigned char           t[4];
> 
> Then see if your problem goes away. 

I have tried to replace t[3] by t[8] before my first post, same result.
I have tried also to add a delay after each stty_print() and I obtain
the same corruption.

> So snprintf() is not well documented...  is the size parameter
> including null terminator or not?  

snprintf always contains null terminator.

> Even worse is when you get to
> multiple threads (ISR handlers) is snprintf() reentrant? 
> 
> Generally I write my own snprintf() so that I know what it does and
> make sure it is reentrant. This is not as optimized but I know what
> the results are.  
> 
> You also have lots of other things to consider for example the AVR
> is Harvard machine so code like this:
> stty_print("Anticol ACF\r\n");
> actually will copy string from flash to RAM and thus use more RAM.  

I have found a very strange bug.

uint8_t
iso14443a_anticol(uint8_t wup, rfid_tag_t *tag)
{
...

(*tag).state = ISO14443A_STATE_ANTICOL_RUNNING;
(*tag).level = ISO14443A_LEVEL_CL1;

snprintf(t, 3, "%02X", (*tag).level);
snprintf(t, 3, "%02X", (*tag).level);
snprintf(t, 3, "%02X", (*tag).level);
snprintf(t, 3, "%02X", (*tag).level);
snprintf(t, 3, "%02X", (*tag).level);
snprintf(t, 3, "%02X", (*tag).level);
snprintf(t, 3, "%02X", (*tag).level);
vfd_print(t); vfd_print(" (0)\r\n");
//vfd_print("1"); vfd_print(" (0)\r\n");
snprintf(t, 3, "%02X", (*tag).level); stty_print(t); stty_print(" (0)\r\n");
snprintf(t, 3, "%02X", (*tag).level); stty_print(t); stty_print("
(0.0)\r\n");
cascade:
rx_len = sizeof(sak);
snprintf(t, 3, "%02X", (*tag).level); stty_print(t); stty_print("
(0.1)\r\n");
...

This code runs as expected (please note vfd_print(t); vfd_print("
(0)\r\n");).

On VFD screen, I obtain "01 (0)".

If I replace this line by vfd_print("01 (0)\r\n"); I can see my memory
corruption again.

If I deplace this line after snprintf(t, 3, "%02X", (*tag).level);
stty_print(t); stty_print(" (0.0)\r\n"); program runs as expected.

If I remove this line, memory corruption again.

My avr-gcc is an old release (5.4 given by debian). I will try a recent
gcc.

JB