AnsweredAssumed Answered

USART1 Receive Problem with STM32L072CZ

Question asked by Emanuele Zampieri on Nov 23, 2017
Latest reply on Dec 4, 2017 by Clive One


I'm trying to read via USART1 the bytes generated by the GNSS module.

I'm developing on the discovery kit B-L072Z-LRWAN1 board (Discovery kit LoRa), where the TX and RX pins of the GNSS module are connected respectively to PA9 and PA10 of the STM32.


In my code, I read the bytes (one by one) sent by the GNSS module via HAL_UART_Receive function, as shown below. The problem occurs when the mcu executes the third call to HAL_UART_Receive(). In this case the STM32 remains blocked and does not respect the timeout set as parameter.

The GNSS module works properly, with a UART-USB converter I can correctly read the bytes generated by the module.


This is my code:

#define UART                                   USART1

#define UART_TX_PIN                     GPIO_PIN_9

#define UART_RX_PIN                     GPIO_PIN_10

#define UART_GPIO_PORT             GPIOA 

#define UART_AF                             GPIO_AF4_USART1

#define UART_CLK_ENABLE()        __USART1_CLK_ENABLE();


//Uart Handle

static UART_HandleTypeDef uartHandle;

void GNSS_Uart_IoInit(void);



 * @brief Initializes the UART interface

 * @param None

 * @retval None


UART_HandleTypeDef GNSS_Init(void)


   //Enable clock






   uartHandle.Instance = UART;

   uartHandle.Init.BaudRate = 9600;

   uartHandle.Init.WordLength = UART_WORDLENGTH_8B;

   uartHandle.Init.StopBits = UART_STOPBITS_1;

   uartHandle.Init.Parity = UART_PARITY_NONE;

   uartHandle.Init.Mode = UART_MODE_TX_RX;

   uartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;


   if(HAL_UART_Init(&uartHandle) != HAL_OK)


       /* Initialization Error */




   if(HAL_UART_GetState(&uartHandle) != HAL_UART_STATE_READY)



   return uartHandle;




 * @brief Initializes the GPIO for UART interface

 * @param None

 * @retval None


void GNSS_Uart_IoInit(void)




/**UART GPIO Configuration    

    PA9     ------> UART1_TX

    PA10    ------> UART1_RX 


   GPIO_InitTypeDef GPIO_InitStruct = {0};


   //Set pin


   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

   GPIO_InitStruct.Pull = GPIO_PULLUP;

   GPIO_InitStruct.Speed = GPIO_SPEED_LOW;

   GPIO_InitStruct.Alternate = UART_AF;





void readData(void)


   uint8_t buff[2];


   if(HAL_UART_GetState(&uartHandle) == HAL_UART_STATE_READY)


      HAL_UART_Receive(&uartHandle, buff, 1, 200);


      PRINTF("R: %c \n\r", buff[0]);








This is the main:

int main( void )


  //STM32 HAL library initialization



  //Configure the system clock




   //Configure the debug mode



  //Configure the hardware




  //Configure the Lora Stack

  lora_Init(&LoRaMainCallbacks, &LoRaParamInit);


  //Main loop




       //Run the LoRa class A state machine







The PRINTF function allows the communication with the pc through the st-link.