Skip to main content
SirapK
Visitor II
December 28, 2019
Question

How to initialize LPUART1 in STM32CubeIDE on b-l072z-lrwan1 ?

Hello.

I was having a problem about initializing the LPUART1 on b-l072z-lrwan1 using the built-in CubeMX code generation in STM32CubeIDE.

The problem was when I started debugging the code seems to run fine until the execution reaches MX_LPUART1_UART_Init(); The debugger keep prompting

"Target is not responding, retrying...

Error! Failed to read target status "

and then shut down.

My question is how to properly initialize the LPUART1? Does it require any extra work to do in order to use this peripheral?

--

Anyway here's my LPUART1 peripheral configuration

static void MX_LPUART1_UART_Init(void)
{
 
 /* USER CODE BEGIN LPUART1_Init 0 */
 
 /* USER CODE END LPUART1_Init 0 */
 
 /* USER CODE BEGIN LPUART1_Init 1 */
 
 /* USER CODE END LPUART1_Init 1 */
 hlpuart1.Instance = LPUART1;
 hlpuart1.Init.BaudRate = 9600;
 hlpuart1.Init.WordLength = UART_WORDLENGTH_8B;
 hlpuart1.Init.StopBits = UART_STOPBITS_1;
 hlpuart1.Init.Parity = UART_PARITY_NONE;
 hlpuart1.Init.Mode = UART_MODE_TX_RX;
 hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
 hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
 hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
 if (HAL_UART_Init(&hlpuart1) != HAL_OK)
 {
 Error_Handler();
 }
 /* USER CODE BEGIN LPUART1_Init 2 */
 
 /* USER CODE END LPUART1_Init 2 */
 
}

The MspInit function

void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{
 GPIO_InitTypeDef GPIO_InitStruct = {0};
 if(huart->Instance==LPUART1)
 {
 /* USER CODE BEGIN LPUART1_MspInit 0 */
 
 /* USER CODE END LPUART1_MspInit 0 */
 /* Peripheral clock enable */
 __HAL_RCC_LPUART1_CLK_ENABLE();
 
 __HAL_RCC_GPIOA_CLK_ENABLE();
 /**LPUART1 GPIO Configuration 
 PA14 ------> LPUART1_TX
 PA13 ------> LPUART1_RX 
 */
 GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_13;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
 GPIO_InitStruct.Alternate = GPIO_AF6_LPUART1;
 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
 /* USER CODE BEGIN LPUART1_MspInit 1 */
 
 /* USER CODE END LPUART1_MspInit 1 */
 }
 else if(huart->Instance==USART2)
 {
 /* USER CODE BEGIN USART2_MspInit 0 */
 
 /* USER CODE END USART2_MspInit 0 */
 /* Peripheral clock enable */
 __HAL_RCC_USART2_CLK_ENABLE();
 
 __HAL_RCC_GPIOA_CLK_ENABLE();
 /**USART2 GPIO Configuration 
 PA2 ------> USART2_TX
 PA3 ------> USART2_RX 
 */
 GPIO_InitStruct.Pin = STLINK_RX_Pin|STLINK_TX_Pin;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
 GPIO_InitStruct.Alternate = GPIO_AF4_USART2;
 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
 /* USART2 interrupt Init */
 HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
 HAL_NVIC_EnableIRQ(USART2_IRQn);
 /* USER CODE BEGIN USART2_MspInit 1 */
 
 /* USER CODE END USART2_MspInit 1 */
 }
 
}

This topic has been closed for replies.