Some notes on using the Keil Debugger
- Local Variables in the Watch window
- Constants in the Watch window
- Breakpoint opportunities do not align with code
- Doubt everything
- Keil SAVE command utility
Local Variables in the Watch window
The breakpoint is clearly within the function "ProcessData()", the variables 'section', 'input', 'wn' and 'yn' are clearly in scope. Neither the "Call Stack + Locals" window nor the "Watch" window seem to be able to list their values. Note that these two forum posts [1] & [2] suggest turning off any optimisations to remedy this problem, i.e. "-O0". In order to make this work, you must recompile everything, i.e. "Rebuild" not "Build". If you find that initially the remedy did not work, recheck the "-O0" switch and rebuild again. It does work when done carefully (including 'fully'). There were plenty of replies saying this did not work, and indeed it didn't for me immediately even when I thought I had turned off optimisation. The easiest solution I found was to make the variable you wished to watch a global one, if only briefly. This saved the need to flip the optimisation switch and recompile all code.
Constants in the Watch window
Okay, so you would think this was unimportant. Clearly we know the value of a constant, its assigned at compile time and never changes. Its in the source code, why would anyone want to verify its value? Well simply, when you are doubting everything, hunting down the unexpected mathematical result, it is useful to know what value the compiler thinks it is using. Also when the value is off the screen and you just want to be reminded of it. Anyway, bad luck. Constants appear to display their address instead of their value.
The IEEE-754 Floating Point Converter confirms the float32 representation of 0x1ffd0ae0 is the value 1.0716766E-19 shown in the watch window. The answer we wanted was 8000.0. It looks like the Keil debugger is listing the address the constant is read from, based upon the address given for the y[] array of float32.

Breakpoint opportunities do not align with code
A simple one this. If it appears that the places you can set a breakpoint do not align with the code as you would expect, save and recompile. You only need to be distracted mid-thought to see this. A previous breakpoint that can no longer be used is shown greyed out here on line 33.

Doubt everything
Its easy to code up a beautifully presented formula. Chances are it won't work first time. There's very little help in terms of compiler warnings about misuse of types, and implied casting from float to int. Set the compiler to "all warnings" and change a variable from float32 to int. It all compiles without warnings. My C is a little rusty having more recently written software in more strongly typed languages. This means I found that each multiplication and assignment needed to be suspected when working out why the code was not working. It all feels a little fast and loose.
Keil SAVE command utility
I found the creation of a command to save values from the memory window fiddly and annoying. The simple solution was a small spreadsheet to calculate the maximum address from the given start address and size, and then concatenate a string to copy & paste. Here it is for your own personal use, but it is trivial. Here's an Excel Spreadsheet for download.
