cancel
Showing results for 
Search instead for 
Did you mean: 

Facing strange issue with STM32 IDE

HBavi.1
Associate III

I am facing strange issue with STM32 IDE (Code Generated by Assembly code)

C Code:

case SET_TIMER:  Gst_FlashMemoryData.u8_SetTimerMode = (uint8_t)u16_Display2Info - (uint8_t)START_TIMER_MODE_OFFSET; // START_TIMER_MODE_OFFSET is equal to 8
				break;

Assembly Code Generated by the Compiler:

281       		case SET_TIMER: Gst_FlashMemoryData.u8_SetTimerMode = (uint8_t)u16_Display2Info - (uint8_t)START_TIMER_MODE_OFFSET;
08000c58:   ldr     r3, [pc, #40]   ; (0x8000c84 <EnterKeyHandler+168>)
08000c5a:   ldr     r2, [pc, #44]   ; (0x8000c88 <EnterKeyHandler+172>)
08000c5c:   ldrh    r3, [r3, #0]
08000c5e:   adds    r3, #2
08000c60:   strb    r3, [r2, #12]
282       						break;
08000c62:   b.n     0x8000c00 <EnterKeyHandler+36>

Register Values:

General Registers General Purpose and FPU Register Group

r0 8

r1 16

r2 0x2000007c (Hex)

r3 9

r4 536871118

r5 0

r6 -1

r7 -1

r8 -1

r9 536871388

r10 -1

r11 -1

r12 0

sp 0x20001f70

lr 134221013

pc 0x8000c5e <EnterKeyHandler+130>

xpsr 16777234

PRIMASK 0

BASEPRI 0

FAULTMASK 0

CONTROL 0

MSP 536878960

PSP -4

What I observed is

08000c5c:  ldrh  r3, [r3, #0] // It reads the value from Global Variable -> r3 (9)

08000c5e:  adds  r3, #2 // Instead of subtracting by 8, it adds and stores it back.

08000c60:  strb  r3, [r2, #12]

I am unable to understand what really went wrong in my code. Any clue in this regard would be appreciated.

0 REPLIES 0