2024-12-04 06:43 AM - edited 2024-12-04 06:47 AM
Hi All,
I need some help ,I am pulling my hair out ,
I declare a buffer of 40 Bytes
uint8_t myBuffer[40]= {0};
I then read a nunber of bytes from an EEPROM over SPI ,I have a logic analyser connected and can see the for example if I read 10 buytes at address x the 10 bytes are in the correct order clocked out and the byte information is also as I have written then to these bytes ;
However the Byffer data always gets mixed up, bytes mssing and also in wrong array elements and some times on occasion they are correct. The read function that I am using has been tested and been used in many other projets with other compilers ,
I suspect it there is smeting in declaring and configuring the buffer in the RAM compler that I do not know about or not do ,Can you people please think and explain how to handle buffers(arrays ) in the ARM complilers.
Posting some code is a bit of a problem as it is a high security and special project ,I am affraid I will get huge problems .
a general hint and guide will help Please!!
Regards
Pje
Solved! Go to Solution.
2024-12-04 10:50 AM
Ok, but mixed up how exactly? Bit / Byte shifted, reversed, consistent/inconsistent?
Check SPI configuration, sizes, phase, direction
Make sure to explictly clear auto/local variables/structures as these typically contain random stack junk.
Enable asserts() to do some more bounds/range scanning of parameters at the library level.
Check settings in the Peripheral registers vs those sent, expected or desired.
Make something that illustrates the issue minimally and doesn't violate top-secret expectations, I think this can be done without specific disclosure. But then you likely have staff who can assist you directly, or contractors with NDA's
2024-12-04 06:48 AM
@Pje wrote:the ARM complilers.
What "ARM compilers" - Keil? IAR? GCC?
@Pje wrote:I suspect it there is smeting in declaring and configuring the buffer in the RAM compler that I do not know about or not do ,
Nope. What you've shown should be fine.
You need to show a minimum but complete example which illustrates the problem.
2024-12-04 06:51 AM - edited 2024-12-04 07:00 AM
Hello,
@Pje wrote:
Posting some code is a bit of a problem as it is a high security and special project ,I am affraid I will get huge problems .
As you can't post the code, the only thing we can do is to advice you to simplify your code as much as possible. Maybe try to create a very simple project to just read the EEPROM and fill the buffer. Do you get the same behavior?
+ you set the product TAG to STM32F1 are you sure? and isn't a Cortex M7 product. I mean data coherency issues while using DMA!
2024-12-04 06:53 AM
>>Posting some code is a bit of a problem as it is a high security and special project
Then presumably you have more senior developers/coders who can help you directly? To debug your code and analyze the problem.
Probably got nothing to do with the buffer allocation. Look elsewhere. Does data get filled via IRQ or DMA? Does it need to be volatile?
Add instrumentation and output so you understand what's happening, as it happens. The code can be commented out for production, but you need to better understand the failure, and this is probably simpler than single stepping your own code.
2024-12-04 07:35 AM
Dear All ,
Thanks for the comments,
It is only a simple project with the SPI configuration an the EEPROM connected the Code reads the EEPROM(by SPI) the SPI directly put the data bytes into the buffer , I have an logic analyser connected and I am writing the buffer out on the UART I can cearly see the buffer is mixed up, it is totaly out of sync with the MISO line shown by the LA ,
Any case I understand it difficult to judge by the little information ,I will try to show the the code in a way that does not violate my commitments.
It is Keil and STM Micro 32F103
again thans for all the replies it is appreciated
Pje
2024-12-04 10:50 AM
Ok, but mixed up how exactly? Bit / Byte shifted, reversed, consistent/inconsistent?
Check SPI configuration, sizes, phase, direction
Make sure to explictly clear auto/local variables/structures as these typically contain random stack junk.
Enable asserts() to do some more bounds/range scanning of parameters at the library level.
Check settings in the Peripheral registers vs those sent, expected or desired.
Make something that illustrates the issue minimally and doesn't violate top-secret expectations, I think this can be done without specific disclosure. But then you likely have staff who can assist you directly, or contractors with NDA's
2024-12-05 06:30 AM
Hi All,
Thank you once again for all the indicators and sugestions!
I solved the issue today and are now ok,
In short the problem seenms to me (I am new to STM32 and ARM cores in general) the code has an function that checks the RNE and RDY Status flags (not sure if this is an earlier programmers code or a HAL function) in anaycase
this code for some reason miss the flags and read the DR register in wrong times ,what I did for now is I monitor these flags directly by accessing the Status register and read when the flags indicate the data is ready , now all is aligned and I can read up to a EEPROM page ( 64 bytes) and all the data is in the correct positions in the databuffer and can be placed in their data structures, even applying offsets and read a number of bytes is all ok,
this needs more refinement but I can progress now Thanks once again
@Tesla DeLorean yout indicator to the SPI config and so on made me look away from the buffer back into the SPI and there I found my problem Thank you so much
Regards
Pje