cancel
Showing results for 
Search instead for 
Did you mean: 

Ununderstandable HAL enum behaviour

astree
Associate II
Posted on July 11, 2015 at 07:41

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 #ifelse

1 REPLY 1
astree
Associate II
Posted on August 20, 2015 at 13:42

Actually It was not a real issue, the visual wired behaviour was just because of the compiler optimisation which was maximal