I'm exploring a TM4C123GLX Launchpad, using CCS v6 with the TivaWare C driver library.
I'm baffled at the seemingly liberal amount of instruction reordering that the C compiler is doing in the generated assembly, even at the Debug level. My setup is as follows:
- I have added the Examples directory of TivaWare to the TI Resource Explorer
- I cloned an example project from the Examples/Boards/ek-tm4c123gxl directory
- I'm using the default "Debug" build configuration
- I'm using the function-style of the peripheral driver library of TivaWare
- An example of the code is as follows:
uint32_t pad, strength;
MAP_GPIOPinTypeSSI(GPIO_PORTB_BASE,
GPIO_PIN_4 | GPIO_PIN_6 | GPIO_PIN_7);
// The FSS pin (CS) we handle by software
MAP_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_5);
spi_cs_clear();
// Set weak pull downs on the output
MAP_GPIOPadConfigGet(GPIO_PORTB_BASE, GPIO_PIN_7,
&strength, &pad);
MAP_GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_7,
strength,
GPIO_PIN_TYPE_STD_WPU);
However, in the debugger view the annotated generated assembly is:
194 MAP_GPIOPinTypeSSI(GPIO_PORTB_BASE, 000006ca: 6A20 LDR R0, [R4, #32] 203 MAP_GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_7, 000006cc: 4D21 LDR R5, $C$CON12 194 MAP_GPIOPinTypeSSI(GPIO_PORTB_BASE, 000006ce: 6CC0 LDR R0, [R0, #76] ... 000006d6: 4790 BLX R2 197 MAP_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_5); 000006d8: 6A20 LDR R0, [R4, #32] ... 000006e2: 4790 BLX R2 198 spi_cs_clear(); 000006e4: 6A20 LDR R0, [R4, #32] ... 000006f0: 4798 BLX R3 201 MAP_GPIOPadConfigGet(GPIO_PORTB_BASE, GPIO_PIN_7, 000006f2: 6A20 LDR R0, [R4, #32] ... 00000700: 47B0 BLX R6 203 MAP_GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_7, 00000702: 6A20 LDR R0, [R4, #32] .. 00000710: 47B0 BLX R6
Do you notice how MAP_GPIOPadConfigGet is absurdly executed after MAP_GPIOPadConfigSet, when it is clearly otherwise in the code? And this is not the only instance of this situation. So, is there some preprocesor directive or something that wll force the compiler to generate the assembly following the exact same order I wrote in my C source?
Thanks in advance!
