2021-11-30 03:17 PM
I have a strange issue. I use printf function in a uart port for print some variables that I use in my code. This works perfectly in cortex m4, but now in cortex m0, the variable printed show me 0, in the next code:
uint8_t flash_ext_init(void){
uint8_t wr_word[4];
uint8_t rd_word[4];
printf("Loading flash memory BY25Q32...\n");
// w25q_FirstFallingCS();
memset(wr_word, 0, 4);
memset(rd_word, 0, 4);
wr_word[0] = W25Q_CMD_JEDEC_ID;
_flash_ext_spi_write_read_data(rd_word, wr_word, 4);
printf("Flash_stat: %02xh, %02xh, %02xh, %02xh\n", rd_word[0], rd_word[1], rd_word[2], rd_word[3]);
printf("BY25Q32 flash loaded...\n");
// printf("Flash_stat_reg1: %02xh, flash_stat_reg2: %02xh, flash_stat_reg3: %02xh...\n", w25qxx.StatusRegister1, w25qxx.StatusRegister2, w25qxx.StatusRegister3);
return 1;
}
I am using -O2 optimization, and when I make a debugging process in stm32cube ide i can see that variables has the correct value, however when the variables are printed, this print a 0 value. I have test disabling "strict aliasing" in optimization settings. And the issue is solved. However, I think is better enable this optimization flag.
2021-12-02 02:24 PM
I solve the problem, I incorrectly call the header. The name is "flash_ext.h" and I typed "flash_Ext.h". Curious is that compiler did not report any error or even warning. How is that possible. Sometimes I think that compiler is not working well with warnings or detecting errors, or maybe is my configuration.
2021-12-02 02:43 PM
Is this on Windows or lInux/MacOS? On Windows, file names are NOT case sensitive, so "flash_ext.h", "flash_Ext.h" and "FLASH_EXT.H" should all work. So if you are on Windows, I don't think that change is what fixed your problem.
2021-12-02 03:03 PM
So, I don't know how the problem was solved, btw I disable the flag optimization strict aliasing also.