Hi,
lately I did some tests with arm embedded, compiling for the microcontroller STM32F103C8 (Cortex M3). Building the cross compiler worked fine, I got LEDs flashing toggled by a timer interrupt, the serial port is sending data and a 1602 text display also works.
The first error, where I blame the compiler: After some code changes (I ported my first program version using the firmware lib [from here:
http://www.j-software.dk/stm32f103.php] to direct register calls) in the ISR of the timer interrupt the program crashed when the timer interrupt was enabled the first time. Even having an empty ISR resulted in a crash. But including a random procedure call (e.g. serial port or delay) helped to prevent the crash. Probably the whole ISR was optimized away by the compiler. Changing the optimization level from -O3 to -O0 helped to solve that problem.
The second error: I tried to port some c-code using an I2C interface to connect to a sensor. In the initialisation phase I call an init procedure of the sensor unit. After including this procedure call the program seems to crash directly at startup. Means only having this procedure call corrupts the complete code, even if its never reached. If I comment out the init call, then the programm starts normally with flashing LED, some delays and status messages via the serial port, everything before the code reaches the position of the init call. But if the init call is there, then no LED will light up and no single byte of a status is transfered through the serial port, that means the code is corrupted from the very beginning. Again when I add a random procedure call within the I2C-init-procedure, for example sending a status message through the serial port, then the program will start corectly and reach the initialisation code. Removing such call than the programm again won't startup at all. Changing compiler optimisation settings didn't help in this case.
My question is now, how can I identify such problems so that I can report them. Obviously its a very target specific problem and it arises in the larger context of the program.
I have a debugger connected to the microcontroller, so I could check on which address the programm got stuck, but with the bare address I have no idea in which pascal line this is. For the first issue I'd like to know if the ISR-Procedure is even linked by the linker (it exists as assembler code), but there is no hint in the binary about the procedures or anything. Debug symbols or procedure names are always stripped away, no matter if I change the compiler settings (e.g. -Xs).
Sure I can provide the code to anyone who could try to help, but I don't want to publish it here because the code is still a bit messy. Attached the timer unit for the timer interrupt as reference / example.
Thanks for any suggestions!