RAM vs ROM, and JTAG init scripts
I’ve been working on porting a board running ST20 to a new processor. Ran into an absurd problem:
- We have two uart_init() functions
- Using uart_init #1, serial output works when the program is loaded into RAM via JTAG. It prints garbage when booting from flash.
- Using uart_init #2, serial output works when booting from flash. It prints garbage when debugging via JTAG.
It was a really easy problem that took a shamefully long time to debug. As it turns out, the two uart_init functions were written for different platforms… which ran at different clock speeds.
The clock speeds are set in #define macros, and hidden away in the depths of a massive ‘include’ directory, so the programmer in charge of porting (that’s me) is unlikely to ever notice.
The bootstrap code, the actual entry point that sets up memory timings and the such, is run when booting from ROM. It is not run when debugging; its job is performed, instead, by the debugger scripts.
And, of course, the debug scripts did not match the bootstrap code, so the board ran at two drastically different clock speeds depending on its boot method.