Hello,
I think I have found a bug in the code generation of the MSP TI Compiler v18.12.8.LTS.
I use a c++ clase for portpins and one for ports to access the hardware registers.
In this special case the SCL and SDA pins of the I2C bus.
scl_.selectIoFunction();
sda_.selectIoFunction();
Those two lines program the IOs as normal IOs, clearing one bit in the PnSEL register.
The compiler generates this code:
124 void clrPortFunktion(uint16_t selectedPins) {HWREG16(baseAddress_ + OFS_PASEL) &= ~selectedPins;}
017eb2: MOVA 0x0004(R12),R14
017eb6: MOVA @R14,R13
017eb8: MOV.W #0x000a,R15
017ebc: ADD.W 0x0004(R13),R15
017ec0: MOV.W R15,0x0000(SP)
017ec4: MOV.W 0x0004(R14),R13
017ec8: INV.W R13
017eca: MOVA 0x0000(SP),R15
017ece: AND.W R13,0x0000(R15)
124 void clrPortFunktion(uint16_t selectedPins) {HWREG16(baseAddress_ + OFS_PASEL) &= ~selectedPins;}
017ef0: MOVA 0x0008(R12),R15
017ef4: MOVA @R15,R14
017ef6: MOV.W #0x000a,R10
017efa: ADD.W 0x0004(R14),R10
017efe: BIC.W 0x0004(R15),0x0000(R10)
The strange thing is that the compiler generates totally different code for this two c++ lines, which are similar.
Both are instances of the same clase.
And the code generated for the first line is not working correctly. See the two red lines, the compiler stores the calculated address with 16 bit on the stack
and reloads it into a register with 20 bits, which leads to a random behavior, dependig on the old values on the stack.
I did not find an explanation for this in the errata sheets for the compiler. Is this a known problem ?
How can I avoid it ?
Thanks for your help