Interrupt based LPUART with BLE application.
Hi
I'm working with STM32WB5MMG-dk. The purpose is to develop BLE Gateway.
The module has a custom GATT svc with 4 GATT char svc which sends and receive bytes, this data is been provided by MSP430 to STM32WB5 vice versa. So MSP430 acts as master whenever it wanna send some data to air it adds the data with few more bytes(4byte string) and the send it to STM32WB5 via UART the STM receives them and decode the the received data(by added 4byte string) and extracts the data bytes and send it via a appropriate GATT char svc to air. It happens the same way around STM receives data from air, depends on the GATT char svc the data is added with more bytes(4byte string) and sent to MSP via UART.
***Keeping in Mind for Developing a LOW POWER Application***
The UART need to work with Interrupts thus the STM remains in low power mode mostly with its usual RF ops.
To start Working with LPUART, created a dummy GAP, GATT svc with single GATT char(R,N,WOR) and thought of checking LPUART as bellow.
BLE Services works fine as intended. but no response from UART.
Note: GFG_HW_LPUART is disabled, SMPS Enable, CFG_LPM_SUPPORT Enable, disabled Debug traces**no debugging**. LPUART is running with HSI clk.
//Init Rx Call Back
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
{
HAL_UART_Receive_IT(&hlpuart1, UART_Buffer, 10);
if(HAL_UART_Transmit_IT(&hlpuart1, UART_Buffer, 10)!= HAL_OK)
{
Error_Handler();
}
}
/**
* @brief LPUART1 Initialization Function
* @param None
* @retval None
*/
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 = 38400;
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.Init.ClockPrescaler = UART_PRESCALER_DIV1;
hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
hlpuart1.FifoMode = UART_FIFOMODE_DISABLE;
if (HAL_UART_Init(&hlpuart1) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN LPUART1_Init 2 */
/* make sure that no LPUART transfer is on-going */
while (__HAL_UART_GET_FLAG(&hlpuart1, USART_ISR_BUSY) == SET);
/* make sure that LPUART is ready to receive
* (test carried out again later in HAL_UARTEx_StopModeWakeUpSourceConfig) */
while (__HAL_UART_GET_FLAG(&hlpuart1, USART_ISR_REACK) == RESET);
/* set the wake-up event:
* specify wake-up on start-bit detection */
WakeUpSelection.WakeUpEvent = UART_WAKEUP_ON_STARTBIT;
if (HAL_UARTEx_StopModeWakeUpSourceConfig(&hlpuart1, WakeUpSelection) != HAL_OK)
{
Error_Handler();
}
/* Enable the LPUART Wake UP from STOP mode Interrupt */
__HAL_UART_ENABLE_IT(&hlpuart1, UART_IT_WUF);
HAL_UART_Receive_IT(&hlpuart1, UART_Buffer, 10);
/* USER CODE END LPUART1_Init 2 */
}
So The LPUART is not walking up. For BLE application the LPM states(sleep/Stop-x/standby ) are not the same at any given time. when i was working around simple LPUART with STOP mode with all the above MX_LPUART1_UART_Init() just had
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
/* enable MCU wake-up by LPUART */
HAL_UARTEx_EnableStopMode(&hlpuart1);
/* enter STOP mode */
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
SystemClock_Config();
/* Wake Up on start bit detection successful */
HAL_UARTEx_DisableStopMode(&hlpuart1);
/* wait for some delay */
HAL_Delay(5);
}
The UART was working fine. But with BLE not sure where the HAL_UARTEx_EnableStopMode/HAL_UARTEx_DisableStopMode to be defined. I tried defining them in stm32_lpm_if.c PWR_EnterStopMode/PWR_ExitStopMode but no luck.