Showing results for 
Search instead for 
Did you mean: 

Keil generating corrupted output files


I recently started working on a custom board project based on an STM32G070CBT and using the SWD interface through an ST-Link Debugger. The previous developer is no longer working, and all he left behind was the Keil uVision project. So, everything should have been easy. I downloaded the Keil uVision IDE, got the STM32G0XX license for Keil uVision, added the exact compiler that was used for the project (6.16), compiled the project with no errors as expected, and then loaded the code into the MCU's integrated Flash. The issue here is that once the code is loaded, the MCU does nothing. I opened a debug session just to see that after a few lines of code executed, the CPU would stay idle on a certain instruction.

Firstly, I thought it could be a problem related to the current code, so I decided to create a new, extremely simple project that toggles an LED. To my surprise, the issue remained, only that the CPU would stop at a different place.

Things I've done to rule out possible causes:
- Keil debug options: Run to main() and Load Application at Startup boxes checked. Inside "St-Link Debugger settings": connect under reset and HW reset (I've actually tried all the options though); download to Flash box checked; in the "Flash Download" window, the "Reset and Run" box is also checked.
- I've installed the ST-Link drivers from the KEIL_V5>ARM>STLink folder (but I've also tried to install the latest drivers from the official site).
- I've created the same project with the same simple code (literally it only uses the IOPENR, MODER, ODR registers, and a for loop as a delay) on the ST Cube IDE. Unexpectedly, the code runs perfectly here, and the LED is blinking. Furthermore, I've managed to send data to the serial console through UART2 without any problem.
-I've also used the ST Cube programmer to load the output (.bin, .hex, .elf) files into the flash, and they work from here. However, I can't perform any debugging, which is one of the most interesting features of Keil.

What is even more bizarre is that if I add the HAL libraries and call, for instance, the HAL_Delay() function, I face the same issue. However, if I use this function in the ST Cube IDE and compile, the .hex/.elf generated and loaded into the MCU will make the application work perfectly (toggle pin, correct delays, correct UART transmission).

I've been stuck with this problem for the last week, and I'm starting to get anxious since I can't make much progress with my work because I'm not able to debug. I'll attach the simple led toggle code.
I would greatly appreciate any help.