Hi, my name is Alessandro and I'm new in this community. I have a very strange issue in the development of a 21371 firmware for a CNC machine. Recently I made an apparently innocuous change in a C source file by adding a new "case" in a switch statement. The debug through ICE-1000 went good both in debug and release configurations so I moved to the LDR generation and the final programming of the firmware in flash memory (SPI flash). After the chip reset, the firmware loads correctly but the program image in memory is corrupted from a certain address. In particular the "main" function is corrupted as well so the machine do not starts.
I did a lot of tests to find the cause of the issue:
- The DXE file seems good as the program runs ok if loaded by the emulator
- I checked the content of the flash memory: it is correct and corresponds with the loaded LDR
- I found the address in program memory where the corruption starts and the corresponding position in the LDR file and in DXE.
Memory dump of working program
(DXE loaded from emulator)
Memory dump of corrupt program
(booted from flash)
It seems to me some sort of misalingment of the instruction codes as highlighted with colors.
Last but not the least, I found that the address where this starts is part of the "switch-case" statement code
I dont't know where to start to look for the issue. If I change the "case" value (for example from "case 215:" to "case 216:") the DXE content changes significantly (and also the position of routines in memory) and the problem disappears.