Having had problems in the past trying to debug FastGPIO, I recently tried again.
I've just spent a considerable amount of time isolating what I believe to be another interesting (and frustrating) bug in the uVision debugger. I hope this may save someone else some time...
I'm using MDK v3.20 targetting an NXP LPC2142. When I try to initialise FastGPIO, the debugger shows some very odd behaviour. Basically, the FIO0DIR register appears to change its contents following execution of an instruction that does not reference it. I say appears because I am convinced this is a debugger bug rather than a hardware problem.
A fragment of my c source looks like this :-
// Enable FastGPIO on both I/O ports SCS |= (GPIO0M | GPIO1M); // Set masks FIO0MASK = ~CPLD_P0_OUTPUTS; FIO1MASK = DATA_BUS_MASK; // Set Port 0 designated bit directions FIO0DIR = CPLD_P0_OUTPUTS;
With optimisation set to Level 3, this results in the following generated code :-
97: SCS |= (GPIO0M | GPIO1M); 98: 99: // Set masks 0x00004FF4 4935 LDR R1,[PC,#0x00D4] 0x00004FF6 6A08 LDR R0,[R1,#0x20] 0x00004FF8 2203 MOV R2,#0x03 0x00004FFA 4310 ORR R0,R2 0x00004FFC 6208 STR R0,[R1,#0x20] 100: FIO0MASK = ~CPLD_P0_OUTPUTS; 0x00004FFE 4934 LDR R1,[PC,#0x00D0] 0x00005000 4834 LDR R0,[PC,#0x00D0] 0x00005002 6101 STR R1,[R0,#0x10] 101: FIO1MASK = DATA_BUS_MASK; 102: 103: // Set Port 0 designated bit directions 0x00005004 4934 LDR R1,[PC,#0x00D0] 0x00005006 6301 STR R1,[R0,#0x30] 104: FIO0DIR = CPLD_P0_OUTPUTS; 105: 0x00005008 4931 LDR R1,[PC,#0x00C4] 0x0000500A 43C9 MVN R1,R1 0x0000500C 6001 STR R1,[R0,#0x00]
Following single-stepping of the line at 0x00005000, which loads into R0 the base address for the Port 0 FastGPIO registers (0x3FFFC000), the FIO0DIR register (as shown in the peripheral dialog) changes to this same value (0x3FFFC000) !
When I subsequently single-step the line at 0x0000500C which should change the value in the FIO0DIR register, it is not shown to change. I can change it directly by editing it in the peripheral dialog.
This does not happen with optimisation set to Level 0.
Needless to say, when you can't depend on the debugger, debugging is made somewhat more difficult :-)
Can anyone else (Keil ?) confirm, refute or explain this behaviour ?
Regards,
David