2021-07-06 06:16 AM
Hello everyone,
I am trying to replace a simple code in C inside a STM32H7 that goes like this:
function(0, &array[0]);
function(1, &array[1]);
function(2, &array[2]);
function(3, &array[3]);
function(4, &array[4]);
with
enum_variable_t index ;
for(index = FIRST_ENUM ; index < LAST_ENUM; index ++)
{
function((uint16_t)index , &array[index]);
}
However, some data is corrupted due to this simple change, I thought it might be an optimization problem but I can't solve it by including the (-O) flag. Any advice would be of great help.
Regards
Alan
Solved! Go to Solution.
2021-07-09 05:30 AM
Quick update
I have changed all global variables to volatile and now everything works as intended.
Regards!
2021-07-06 06:29 AM
Hello,
Does your SPI is master in transmission ?
Br,
2021-07-06 06:30 AM
Yes it is
2021-07-06 06:35 AM
What data is corrupted? There's nothing wrong with the code you posted, assuming FIRST_ENUM=0 and LAST_ENUM=5.
2021-07-06 06:36 AM
And when you say data is corrupted, it means that all the next data are wrong or are they any recovery ? Is data shifted by some bits ?
2021-07-06 06:47 AM
Hi @CPINA ,
When I read the values in array[0] without the for loop, I get these values (which are correct)
But when I replace the code with the for loop (nothing else changes) I get this data.
2021-07-06 06:48 AM
The blue line represent array[0]
2021-07-06 06:49 AM
Hi @TDK
I explained in the topic avode what I mean with corrupted data.
Regards
Alan
2021-07-06 07:22 AM
Not sure to understand, for both blue line is your array[0) ? I was thinking it was the yellow one. what is supposed to be the data linked to array[0].
If the data line is supposed to be the blue one, it seems it is even not a data, looks like noise. Did you check that the SPI is well configured in debug just before writing the data into the data register ? Please confirm to me, you are master transmitter in such case ? If yes can you see the SPI going out after writing the Data register of the SPI ?
2021-07-06 11:09 PM
Hello @CPINA
After restarting my computer today morning it seems that the problem solves itself and now works without the error, some kind of magic I guess.
Regards
Alan