2015-07-10 10:41 PM
Hello,
I have a very simple issue but ununderstandable for me. Hopping someone could explain me what's happening. I have made the code simple in order to point out the issue:#include ''main.h''
int main(void) { HARD_Mcu_Init(); GSM_config(); while (1) { GSM_State_Machine(); } }In GSM.c: #include ''stm32f0xx_hal_uart.h'' #include ''GSM.h'' void GSM_State_Machine(){ GSM_Fixed_Baude (Term_huart, ATData, GSM_BAUD, GSM_BUFFERSIZE, &Conf1, aGSM_BAUD_RXBuffer, GSM_BAUD_RX_BUFFERSIZE); } int GSM_Fixed_Baude(UART_HandleTypeDef GSM_UART, char * const pbyDst, uint8_t* aTxBuffer, int iMaxSize, M66_ConfData * psConfData,uint8_t* aRxBuffer, int iMaxSizeRx){ if(HAL_UART_Receive(&GSM_UART,(uint8_t*) aRxBuffer, iMaxSizeRx, 1000) != HAL_OK) { return 0; } else { return 1; } } So I intentionally don't write anything on UART so in debug I can see that HAL_UART_Receive returns HAL_TIMEOUT.Now, If I check for HAL_OK I get the opposite than checking for HAL_TIMEOUT without changing anything else. if(HAL_UART_Receive(&M66_UART,(uint8_t*) aRxBuffer, iMaxSizeRx, 1000) == HAL_OK) -> return 0;if(HAL_UART_Receive(&M66_UART,(uint8_t*) aRxBuffer, iMaxSizeRx, 1000) ==HAL_TIMEOUT) -> return 0;if(HAL_UART_Receive(&M66_UART,(uint8_t*) aRxBuffer, iMaxSizeRx, 1000) !=HAL_OK) -> return 1;if(HAL_UART_Receive(&M66_UART,(uint8_t*) aRxBuffer, iMaxSizeRx, 1000) !=HAL_TIMEOUT) ?? -> return 1;I have got other behaviour like both else and if executed , I have checked in debug mode as well but it's not doing this anymore and I can't tell what I have changed... Does that could come from IAR or bad #include or? It is a big mystery I am very curious to understand why it is doing this.Thank you ; #hal #enum #ifelse2015-08-20 04:42 AM
Actually It was not a real issue, the visual wired behaviour was just because of the compiler optimisation which was maximal