This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I am trying to use logic shift left for MSP430F2274 using CCS v5 in following way. This crashes when it tries to do shift. I suspect it is because of arithmetic overflow. If so how can I work around ? If not what is the issue? Logic shift right appears to work fine. Only left has issue
unsigned char shift_len;
unsigned long int outdata;
shift_len = 24;
outdata = outdata << shift_len;
thanks
Thank you for the response. Watchdog is turn off and interrupts are not enabled.
After spending hours on it, I discovered that single stepping the code is the problem. If logic shift left is done in nested function calls (3 levels inside), program crash most of the time and it restarts if I step through the code. Note that I have turned off code optimisation too.
If I use same bit of code in IAR, it steps through fine. It appears that single stepping in CCS v5 (in my case using MSP-FET430UIF and MSP430F2274 hardware) can not be trusted.
The MSP does not have a "<<n" instruction (well, the X2 core has one for n<=4).
So the compiler generates a mixture of byte swap, byte move and shift operations. To not waste too much space on this, the MSPGCC compiler (where I once analyzed this) uses an instruction stack where it jumps into the stack depending on the number of shifts and at the end the function returns with the result of the shift. A clever but puzzling construct.
What instruciton chain does your compiler generate?
In case of a (fixed) <<24 on a long int, I would do a move from low byte to high word, then a byte swap and clear of the lower 16 bit.
Assuming the value in R14 (bit 0-15) and R15 (bit 16-32), a <<24 would be
MOV.B R14,R15
SWAPB R15
CLR R14
Independent of the code, there may be some errata on your specific MSP related to signle stepping and CPU instructions. See teh EMM and CPU errata in the device errata sheet.
The debugger generally cannot be trusted at all. Usually, it works fine for abstract code. But as soon as 'real world effects' are part of the problem, the debugger may become useless or even turn into a bugger. unfortunately, real-world effects are what you usually have to deal with on a microcontroller.Pramod Aryal said:It appears that single stepping in CCS v5 can not be trusted.
Personally, I never (!) used a debugger on an MSP. Not a single debug session ever in all these years. I use logic analyzers and port pins, LEDs and UART messages for debugging.
**Attention** This is a public forum