diff options
Diffstat (limited to 'Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_DataThroughput/Core/Src/hw_uart.c')
-rw-r--r-- | Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_DataThroughput/Core/Src/hw_uart.c | 496 |
1 files changed, 190 insertions, 306 deletions
diff --git a/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_DataThroughput/Core/Src/hw_uart.c b/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_DataThroughput/Core/Src/hw_uart.c index 775aa241d..f27523955 100644 --- a/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_DataThroughput/Core/Src/hw_uart.c +++ b/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_DataThroughput/Core/Src/hw_uart.c @@ -1,26 +1,31 @@ /** ****************************************************************************** - * @file hw_uart.c - * @author MCD Application Team - * @brief hardware access - ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ - + * File Name : Src/hw_uart.c + * Description : HW UART source file for STM32WPAN Middleware. + * + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under Ultimate Liberty license + * SLA0044, the "License"; You may not use this file except in compliance with + * the License. You may obtain a copy of the License at: + * www.st.com/SLA0044 + * + ****************************************************************************** + */ /* Includes ------------------------------------------------------------------*/ #include "app_common.h" #include "hw_conf.h" +#if (CFG_HW_LPUART1_ENABLED == 1) +extern UART_HandleTypeDef hlpuart1; +#endif +#if (CFG_HW_USART1_ENABLED == 1) +extern UART_HandleTypeDef huart1; +#endif /* Macros --------------------------------------------------------------------*/ #define HW_UART_INIT(__HANDLE__, __USART_BASE__) \ @@ -36,7 +41,7 @@ (__HANDLE__).AdvancedInit.AdvFeatureInit = CFG_HW_##__USART_BASE__##_ADVFEATUREINIT; \ HAL_UART_Init(&(__HANDLE__)); \ } while(0) - + #define HW_UART_RX_IT(__HANDLE__, __USART_BASE__) \ do{ \ HW_##__HANDLE__##RxCb = cb; \ @@ -57,82 +62,8 @@ hal_status = HAL_UART_Transmit(&(__HANDLE__), p_data, size, timeout); \ } while(0) -#define HW_UART_MSP_UART_INIT(__HANDLE__, __USART_BASE__) \ - do{ \ - \ - /* Configure Tx Pin */ \ - CFG_HW_##__USART_BASE__##_TX_PORT_CLK_ENABLE(); \ - \ - GPIO_InitStruct.Pin = CFG_HW_##__USART_BASE__##_TX_PIN ; \ - GPIO_InitStruct.Mode = CFG_HW_##__USART_BASE__##_TX_MODE; \ - GPIO_InitStruct.Pull = CFG_HW_##__USART_BASE__##_TX_PULL; \ - GPIO_InitStruct.Speed = CFG_HW_##__USART_BASE__##_TX_SPEED; \ - GPIO_InitStruct.Alternate = CFG_HW_##__USART_BASE__##_TX_ALTERNATE; \ - HAL_GPIO_Init(CFG_HW_##__USART_BASE__##_TX_PORT, &GPIO_InitStruct); \ - \ - \ - /* Configure Rx Pin */ \ - CFG_HW_##__USART_BASE__##_RX_PORT_CLK_ENABLE(); \ - \ - GPIO_InitStruct.Pin = CFG_HW_##__USART_BASE__##_RX_PIN; \ - GPIO_InitStruct.Mode = CFG_HW_##__USART_BASE__##_RX_MODE; \ - GPIO_InitStruct.Pull = CFG_HW_##__USART_BASE__##_RX_PULL; \ - GPIO_InitStruct.Speed = CFG_HW_##__USART_BASE__##_RX_SPEED; \ - GPIO_InitStruct.Alternate = CFG_HW_##__USART_BASE__##_RX_ALTERNATE; \ - HAL_GPIO_Init(CFG_HW_##__USART_BASE__##_RX_PORT, &GPIO_InitStruct); \ - \ - \ - /* Configure CTS Pin */ \ - CFG_HW_##__USART_BASE__##_CTS_PORT_CLK_ENABLE(); \ - \ - GPIO_InitStruct.Pin = CFG_HW_##__USART_BASE__##_CTS_PIN; \ - GPIO_InitStruct.Mode = CFG_HW_##__USART_BASE__##_CTS_MODE; \ - GPIO_InitStruct.Pull = CFG_HW_##__USART_BASE__##_CTS_PULL; \ - GPIO_InitStruct.Speed = CFG_HW_##__USART_BASE__##_CTS_SPEED; \ - GPIO_InitStruct.Alternate = CFG_HW_##__USART_BASE__##_CTS_ALTERNATE; \ - HAL_GPIO_Init(CFG_HW_##__USART_BASE__##_CTS_PORT, &GPIO_InitStruct); \ - \ - /* Set USART source clock */ \ - __HAL_RCC_##__USART_BASE__##_CONFIG(CFG_HW_##__USART_BASE__##_SOURCE_CLOCK); \ - \ - /* Enable USART clock */ \ - __HAL_RCC_##__USART_BASE__##_CLK_ENABLE(); \ - \ - HAL_NVIC_SetPriority(__USART_BASE__##_IRQn, CFG_HW_##__USART_BASE__##_PREEMPTPRIORITY, CFG_HW_##__USART_BASE__##_SUBPRIORITY); \ - HAL_NVIC_EnableIRQ(__USART_BASE__##_IRQn); \ - } while(0) - -#define HW_UART_MSP_TX_DMA_INIT(__HANDLE__, __USART_BASE__) \ - do{ \ - /* Configure the DMA handler for Transmission process */ \ - /* Enable DMA clock */ \ - CFG_HW_##__USART_BASE__##_DMA_CLK_ENABLE(); \ - /* Enable DMA MUX clock */ \ - CFG_HW_##__USART_BASE__##_DMAMUX_CLK_ENABLE(); \ - \ - HW_hdma_##__HANDLE__##_tx.Instance = CFG_HW_##__USART_BASE__##_TX_DMA_CHANNEL; \ - HW_hdma_##__HANDLE__##_tx.Init.Request = CFG_HW_##__USART_BASE__##_TX_DMA_REQ; \ - HW_hdma_##__HANDLE__##_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; \ - HW_hdma_##__HANDLE__##_tx.Init.PeriphInc = DMA_PINC_DISABLE; \ - HW_hdma_##__HANDLE__##_tx.Init.MemInc = DMA_MINC_ENABLE; \ - HW_hdma_##__HANDLE__##_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; \ - HW_hdma_##__HANDLE__##_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; \ - HW_hdma_##__HANDLE__##_tx.Init.Mode = DMA_NORMAL; \ - HW_hdma_##__HANDLE__##_tx.Init.Priority = DMA_PRIORITY_LOW; \ - \ - HAL_DMA_Init(&HW_hdma_##__HANDLE__##_tx); \ - \ - /* Associate the initialized DMA handle to the UART handle */ \ - __HAL_LINKDMA(huart, hdmatx, HW_hdma_##__HANDLE__##_tx); \ - \ - /* NVIC configuration for DMA transfer complete interrupt */ \ - HAL_NVIC_SetPriority(CFG_HW_##__USART_BASE__##_TX_DMA_IRQn, CFG_HW_##__USART_BASE__##_DMA_TX_PREEMPTPRIORITY, CFG_HW_##__USART_BASE__##_DMA_TX_SUBPRIORITY); \ - HAL_NVIC_EnableIRQ(CFG_HW_##__USART_BASE__##_TX_DMA_IRQn); \ - } while(0) - -/* Variables ------------------------------------------------------------------*/ +/* Variables -----------------------------------------------------------------*/ #if (CFG_HW_USART1_ENABLED == 1) - UART_HandleTypeDef huart1 = {0}; #if (CFG_HW_USART1_DMA_TX_SUPPORTED == 1) DMA_HandleTypeDef HW_hdma_huart1_tx ={0}; #endif @@ -141,12 +72,11 @@ #endif #if (CFG_HW_LPUART1_ENABLED == 1) - UART_HandleTypeDef lpuart1 = {0}; #if (CFG_HW_LPUART1_DMA_TX_SUPPORTED == 1) - DMA_HandleTypeDef HW_hdma_lpuart1_tx ={0}; + DMA_HandleTypeDef HW_hdma_hlpuart1_tx ={0}; #endif - void (*HW_lpuart1RxCb)(void); - void (*HW_lpuart1TxCb)(void); + void (*HW_hlpuart1RxCb)(void); + void (*HW_hlpuart1TxCb)(void); #endif void HW_UART_Init(hw_uart_id_t hw_uart_id) @@ -171,301 +101,255 @@ return; } - - void HW_UART_Receive_IT(hw_uart_id_t hw_uart_id, uint8_t *p_data, uint16_t size, void (*cb)(void)) + +void HW_UART_Receive_IT(hw_uart_id_t hw_uart_id, uint8_t *p_data, uint16_t size, void (*cb)(void)) +{ + switch (hw_uart_id) { - switch (hw_uart_id) - { #if (CFG_HW_USART1_ENABLED == 1) - case hw_uart1: - HW_UART_RX_IT(huart1, USART1); - break; + case hw_uart1: + HW_UART_RX_IT(huart1, USART1); + break; #endif #if (CFG_HW_LPUART1_ENABLED == 1) - case hw_lpuart1: - HW_UART_RX_IT(lpuart1, LPUART1); - break; + case hw_lpuart1: + HW_UART_RX_IT(hlpuart1, LPUART1); + break; #endif - default: - break; - } - - return; + default: + break; } - void HW_UART_Transmit_IT(hw_uart_id_t hw_uart_id, uint8_t *p_data, uint16_t size, void (*cb)(void)) + return; +} + +void HW_UART_Transmit_IT(hw_uart_id_t hw_uart_id, uint8_t *p_data, uint16_t size, void (*cb)(void)) +{ + switch (hw_uart_id) { - switch (hw_uart_id) - { #if (CFG_HW_USART1_ENABLED == 1) - case hw_uart1: - HW_UART_TX_IT(huart1, USART1); - break; + case hw_uart1: + HW_UART_TX_IT(huart1, USART1); + break; #endif #if (CFG_HW_LPUART1_ENABLED == 1) - case hw_lpuart1: - HW_UART_TX_IT(lpuart1, LPUART1); - break; + case hw_lpuart1: + HW_UART_TX_IT(hlpuart1, LPUART1); + break; #endif - default: - break; - } - - return; + default: + break; } - hw_status_t HW_UART_Transmit(hw_uart_id_t hw_uart_id, uint8_t *p_data, uint16_t size, uint32_t timeout) - { - HAL_StatusTypeDef hal_status = HAL_OK; - hw_status_t hw_status = hw_uart_ok; + return; +} - switch (hw_uart_id) - { +hw_status_t HW_UART_Transmit(hw_uart_id_t hw_uart_id, uint8_t *p_data, uint16_t size, uint32_t timeout) +{ + HAL_StatusTypeDef hal_status = HAL_OK; + hw_status_t hw_status = hw_uart_ok; + + switch (hw_uart_id) + { #if (CFG_HW_USART1_ENABLED == 1) - case hw_uart1: - HW_UART_TX(huart1, USART1); - break; + case hw_uart1: + HW_UART_TX(huart1, USART1); + break; #endif #if (CFG_HW_LPUART1_ENABLED == 1) - case hw_lpuart1: - HW_UART_TX(lpuart1, LPUART1); - break; + case hw_lpuart1: + HW_UART_TX(hlpuart1, LPUART1); + break; #endif - default: - break; - } - - switch (hal_status) - { - case HAL_OK: - hw_status = hw_uart_ok; - break; + default: + break; + } - case HAL_ERROR: - hw_status = hw_uart_error; - break; + switch (hal_status) + { + case HAL_OK: + hw_status = hw_uart_ok; + break; - case HAL_BUSY: - hw_status = hw_uart_busy; - break; + case HAL_ERROR: + hw_status = hw_uart_error; + break; - case HAL_TIMEOUT: - hw_status = hw_uart_to; - break; + case HAL_BUSY: + hw_status = hw_uart_busy; + break; - default: - break; - } + case HAL_TIMEOUT: + hw_status = hw_uart_to; + break; - return hw_status; + default: + break; } - hw_status_t HW_UART_Transmit_DMA(hw_uart_id_t hw_uart_id, uint8_t *p_data, uint16_t size, void (*cb)(void)) - { - HAL_StatusTypeDef hal_status = HAL_OK; - hw_status_t hw_status = hw_uart_ok; + return hw_status; +} - switch (hw_uart_id) - { -#if (CFG_HW_USART1_ENABLED == 1) - case hw_uart1: - HW_huart1TxCb = cb; - huart1.Instance = USART1; - hal_status = HAL_UART_Transmit_DMA(&huart1, p_data, size); - break; -#endif +hw_status_t HW_UART_Transmit_DMA(hw_uart_id_t hw_uart_id, uint8_t *p_data, uint16_t size, void (*cb)(void)) +{ + HAL_StatusTypeDef hal_status = HAL_OK; + hw_status_t hw_status = hw_uart_ok; -#if (CFG_HW_USART2_ENABLED == 1) - case hw_uart2: - HW_huart2TxCb = cb; - huart2.Instance = USART2; - hal_status = HAL_UART_Transmit_DMA(&huart2, p_data, size); - break; + switch (hw_uart_id) + { +#if (CFG_HW_USART1_ENABLED == 1) + case hw_uart1: + HW_huart1TxCb = cb; + huart1.Instance = USART1; + hal_status = HAL_UART_Transmit_DMA(&huart1, p_data, size); + break; #endif #if (CFG_HW_LPUART1_ENABLED == 1) - case hw_lpuart1: - HW_lpuart1TxCb = cb; - lpuart1.Instance = LPUART1; - hal_status = HAL_UART_Transmit_DMA(&lpuart1, p_data, size); - break; + case hw_lpuart1: + HW_hlpuart1TxCb = cb; + hlpuart1.Instance = LPUART1; + hal_status = HAL_UART_Transmit_DMA(&hlpuart1, p_data, size); + break; #endif - default: - break; - } - - switch (hal_status) - { - case HAL_OK: - hw_status = hw_uart_ok; - break; + default: + break; + } - case HAL_ERROR: - hw_status = hw_uart_error; - break; + switch (hal_status) + { + case HAL_OK: + hw_status = hw_uart_ok; + break; - case HAL_BUSY: - hw_status = hw_uart_busy; - break; + case HAL_ERROR: + hw_status = hw_uart_error; + break; - case HAL_TIMEOUT: - hw_status = hw_uart_to; - break; + case HAL_BUSY: + hw_status = hw_uart_busy; + break; - default: - break; - } + case HAL_TIMEOUT: + hw_status = hw_uart_to; + break; - return hw_status; + default: + break; } - void HW_UART_Interrupt_Handler(hw_uart_id_t hw_uart_id) + return hw_status; +} + +void HW_UART_Interrupt_Handler(hw_uart_id_t hw_uart_id) +{ + switch (hw_uart_id) { - switch (hw_uart_id) - { #if (CFG_HW_USART1_ENABLED == 1) - case hw_uart1: - HAL_UART_IRQHandler(&huart1); - break; + case hw_uart1: + HAL_UART_IRQHandler(&huart1); + break; #endif #if (CFG_HW_LPUART1_ENABLED == 1) - case hw_lpuart1: - HAL_UART_IRQHandler(&lpuart1); - break; + case hw_lpuart1: + HAL_UART_IRQHandler(&hlpuart1); + break; #endif - default: - break; - } - - return; + default: + break; } - void HW_UART_DMA_Interrupt_Handler(hw_uart_id_t hw_uart_id) - { - switch (hw_uart_id) - { -#if (CFG_HW_USART1_DMA_TX_SUPPORTED == 1) - case hw_uart1: - HAL_DMA_IRQHandler(huart1.hdmatx); - break; -#endif - -#if (CFG_HW_USART2_DMA_TX_SUPPORTED == 1) - case hw_uart2: - HAL_DMA_IRQHandler(huart2.hdmatx); - break; -#endif - -#if (CFG_HW_LPUART1_DMA_TX_SUPPORTED == 1) - case hw_lpuart1: - HAL_DMA_IRQHandler(lpuart1.hdmatx); - break; -#endif - - default: - break; - } + return; +} - return; - } - - void HAL_UART_MspInit(UART_HandleTypeDef *huart) +void HW_UART_DMA_Interrupt_Handler(hw_uart_id_t hw_uart_id) +{ + switch (hw_uart_id) { -#if ( (CFG_HW_USART1_ENABLED == 1) || (CFG_HW_LPUART1_ENABLED == 1) ) - GPIO_InitTypeDef GPIO_InitStruct = {0}; -#endif - switch ((uint32_t)huart->Instance) - { -#if (CFG_HW_USART1_ENABLED == 1) - case (uint32_t)USART1: - HW_UART_MSP_UART_INIT( huart1, USART1 ); #if (CFG_HW_USART1_DMA_TX_SUPPORTED == 1) - HW_UART_MSP_TX_DMA_INIT( huart1, USART1 ); -#endif + case hw_uart1: + HAL_DMA_IRQHandler(huart1.hdmatx); break; #endif -#if (CFG_HW_LPUART1_ENABLED == 1) - case (uint32_t)LPUART1: - HW_UART_MSP_UART_INIT( lpuart1, LPUART1 ); #if (CFG_HW_LPUART1_DMA_TX_SUPPORTED == 1) - HW_UART_MSP_TX_DMA_INIT( lpuart1, LPUART1 ); -#endif + case hw_lpuart1: + HAL_DMA_IRQHandler(hlpuart1.hdmatx); break; #endif - default: - break; - } - - return; + default: + break; } - void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) + return; +} + +void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) +{ + switch ((uint32_t)huart->Instance) { - switch ((uint32_t)huart->Instance) - { #if (CFG_HW_USART1_ENABLED == 1) - case (uint32_t)USART1: - if(HW_huart1RxCb) - { - HW_huart1RxCb(); - } + case (uint32_t)USART1: + if(HW_huart1RxCb) + { + HW_huart1RxCb(); + } break; #endif #if (CFG_HW_LPUART1_ENABLED == 1) - case (uint32_t)LPUART1: - if(HW_lpuart1RxCb) - { - HW_lpuart1RxCb(); - } + case (uint32_t)LPUART1: + if(HW_hlpuart1RxCb) + { + HW_hlpuart1RxCb(); + } break; #endif - default: - break; - } - - return; + default: + break; } - void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) + return; +} + +void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) +{ + switch ((uint32_t)huart->Instance) { - switch ((uint32_t)huart->Instance) - { #if (CFG_HW_USART1_ENABLED == 1) - case (uint32_t)USART1: - if(HW_huart1TxCb) - { - HW_huart1TxCb(); - } + case (uint32_t)USART1: + if(HW_huart1TxCb) + { + HW_huart1TxCb(); + } break; #endif #if (CFG_HW_LPUART1_ENABLED == 1) - case (uint32_t)LPUART1: - if(HW_lpuart1TxCb) - { - HW_lpuart1TxCb(); - } + case (uint32_t)LPUART1: + if(HW_hlpuart1TxCb) + { + HW_hlpuart1TxCb(); + } break; #endif - default: - break; - } - - return; + default: + break; } - /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ + return; +} + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |