cancel
Showing results for 
Search instead for 
Did you mean: 

Strange logic problem after compilation in CUBE IDE 1.14.1

kevinKang
Associate II

Hi all,

    basic info:

    stm32 CUBE IDE v1.14.1

    PC: Win10 64bit

    MCU:STM32G0B1CC

 

    In my code, there are two functions to control the battery to enter charge mode from init mode, when the battery receive a command. Check_AuthCmdToCHG()will set CANOpenStruct.flag_authCmdGotoCHG to STD_TRUE and set CANOpenStruct.sendTPDOInfo STD_TRUE. 

   normally,after CANOpenStruct.flag_authCmdGotoCHG be set to  STD_TRUE , CheckFlag_InitGotoCHG() will make state machine FSM goes to charge mode.

   But it's very strange, i send a command to MCU, then I receive TPDO info from CAN bus, this means CANOpenStruct.sendTPDOInfo already be set to STD_TRUE. however  CANOpenStruct.flag_authCmdGotoCHG and CheckFlag_InitGotoCHG() are not work!

   When I examined the code, I couldn't find the cause. Therefore, I wrote a test function Test_CANCmd() ready to read CANOpenStruct.flag_authCmdGotoCHG and CANOpenStruct.sendTPDOInfo out, the other did not modify any code!  I compile the code and burn it like before. Then something amazing happened. Everything worked!

   is there anyone can explain this? The Test_CANCmd()function just uses the value of CANOpenStruct.flag_authCmdGotoCHG, FSMStruct.flag_initGotoCHG and does not change it, why does it have such an effect? 

   

void Check_AuthCmdToCHG(void) { if(sysInfoStruct.statusCharger == STD_FALSE) { if(pinStatus_present == STD_ON) { if(sysInfoStruct.chargerOnline == 0x1234) { sysInfoStruct.statusCharger = STD_TRUE; CANOpenStruct.flag_authCmdGotoCHG = STD_TRUE; CANOpenStruct.sendTPDOInfo= STD_TRUE; //if true,it will enable CAN TPDO } } else { sysInfoStruct.chargerOnline = 0; } } }
void CheckFlag_InitGotoCHG(void) { if(pinStatus_present == STD_ON) { if(CANOpenStruct.flag_authCmdGotoCHG == STD_TRUE) { CANOpenStruct.flag_authCmdGotoCHG = STD_FALSE; FSMStruct.flag_initGotoCHG = STD_TRUE; } } }
uint32 Test_CANCmd(union_64bits cmd) { //.......... switch(cmd.byte[2]) { case 0xF1: //...... break; case 0xF5: //ESD Pres pin onoff times test if(cmd.byte[3] == 0xFF) { errCode = CANOpenStruct.flag_authCmdGotoCHG; } else if(cmd.byte[3] == 0xFE) { errCode = FSMStruct.flag_initGotoCHG; } else { errCode = TEC_cmdParaErr; } break; //.......... } return errCode; }

 

1 ACCEPTED SOLUTION

Accepted Solutions

My problem has been solved!
Root cause: STM32G0B1CC is based on Arm Cortex -M0+ core, it no support unaligned accesses, pay attention to the large structure in your code.

View solution in original post

3 REPLIES 3
liaifat85
Senior III

If you have debugging enabled, print the values of flag_authCmdGotoCHG, sendTPDOInfo, and FSMStruct.flag_initGotoCHG right after setting and reading them to observe any anomalies.

Hi liaifat85,

  Thanks for your feedback!

  My current APP code is address offset because the system comes with a bootloader. I have tried to modify the offset address and directly run online simulation, and the program works normally.

  I have tried the following 2 situations:

  S1:  

  Comment out the code for CANOpenStruct.flag_authCmdGotoCHG and FSMStruct.flag_initGotoCHG , without changing anything else, and the program works abnormally.

uint32 Test_CANCmd(union_64bits cmd) { //.......... switch(cmd.byte[2]) { case 0xF1: //...... break; case 0xF5: //ESD Pres pin onoff times test /* if(cmd.byte[3] == 0xFF) { errCode = CANOpenStruct.flag_authCmdGotoCHG; } else if(cmd.byte[3] == 0xFE) { errCode = FSMStruct.flag_initGotoCHG; } else { errCode = TEC_cmdParaErr; } */ break; //.......... } return errCode; }

 S2:

  Keep CANOpenStruct.flag_authCmdGotoCHG and FSMStruct.flag_initGotoCHG code, do not change other codes, the program works fine.

My problem has been solved!
Root cause: STM32G0B1CC is based on Arm Cortex -M0+ core, it no support unaligned accesses, pay attention to the large structure in your code.