Mercurial > public > ostc4
diff Discovery/Src/ostc.c @ 1036:5865f0aeb438 Puls_Integration
Radio data integration:
Added functionality for displaying radio data as debug message. The USART3 has been configurated for receiption and a function for the visualization of the data has been added to the demo unit (draft implementation). For activation the radio as well as the logger functionality needs to be activated via compile switch. Note that at the moment bluetooth and radio DMA may not be operated in parallel.
| author | Ideenmodellierer |
|---|---|
| date | Sun, 10 Aug 2025 15:28:59 +0200 |
| parents | 33b91584d827 |
| children | 1d7c7a36df15 |
line wrap: on
line diff
--- a/Discovery/Src/ostc.c Sat Aug 09 16:55:20 2025 +0200 +++ b/Discovery/Src/ostc.c Sun Aug 10 15:28:59 2025 +0200 @@ -47,6 +47,10 @@ #endif UART_HandleTypeDef UartIR_HUD_Handle; +#ifdef ENABLE_USART_RADIO +UART_HandleTypeDef UartRadio_Handle; +#endif + __IO ITStatus UartReady = RESET; __IO ITStatus UartReadyHUD = RESET; @@ -57,6 +61,14 @@ /* Private variables with external access via get_xxx() function -------------*/ static uint8_t hardwareDisplay = 0; //< either OSTC4 LCD (=0) or new Screen (=1) +#ifdef ENABLE_PULSE_SENSOR_BT +static DMA_HandleTypeDef hdma_uart_BT_rx; +#endif + +#ifdef ENABLE_USART_RADIO +static DMA_HandleTypeDef hdma_uart_radio_rx; +#endif + static uint16_t rxBufRead = 0; static uint16_t rxBufWrite = 0; static uint8_t rxBufferUart[CHUNK_SIZE * CHUNKS_PER_BUFFER]; /* The complete buffer has a X * chunk size to allow variations in buffer read time */ @@ -385,10 +397,22 @@ HAL_UART_Init(&UartIR_HUD_Handle); #endif + +#ifdef ENABLE_USART_RADIO + UartRadio_Handle.Instance = USART_RADIO; + UartRadio_Handle.Init.BaudRate = 9600; + UartRadio_Handle.Init.WordLength = UART_WORDLENGTH_8B; + UartRadio_Handle.Init.StopBits = UART_STOPBITS_1; + UartRadio_Handle.Init.Parity = UART_PARITY_NONE; + UartRadio_Handle.Init.HwFlowCtl = UART_HWCONTROL_NONE; + UartRadio_Handle.Init.Mode = UART_MODE_RX; + + HAL_UART_Init(&UartRadio_Handle); +#endif + } -static DMA_HandleTypeDef hdma_uart_BT_rx; - +#ifdef ENABLE_PULSE_SENSOR_BT void MX_UART_BT_Init_DMA() { @@ -412,6 +436,33 @@ HAL_NVIC_SetPriority(DMA2_Stream2_IRQn, 0, 0); HAL_NVIC_EnableIRQ(DMA2_Stream2_IRQn); } +#endif + +#ifdef ENABLE_USART_RADIO +void MX_UART_RADIO_Init_DMA() +{ + + __DMA2_CLK_ENABLE(); + __HAL_RCC_DMA2_CLK_ENABLE(); + + hdma_uart_radio_rx.Instance = DMA2_Stream1; + hdma_uart_radio_rx.Init.Channel = DMA_CHANNEL_4; + hdma_uart_radio_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; + hdma_uart_radio_rx.Init.PeriphInc = DMA_PINC_DISABLE; + hdma_uart_radio_rx.Init.MemInc = DMA_MINC_ENABLE; + hdma_uart_radio_rx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE; + hdma_uart_radio_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; + hdma_uart_radio_rx.Init.Mode = DMA_NORMAL; + hdma_uart_radio_rx.Init.Priority = DMA_PRIORITY_LOW; + hdma_uart_radio_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; + HAL_DMA_Init(&hdma_uart_radio_rx); + + __HAL_LINKDMA(&UartRadio_Handle, hdmarx, hdma_uart_radio_rx); + + HAL_NVIC_SetPriority(DMA2_Stream1_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(DMA2_Stream1_IRQn); +} +#endif uint8_t UART_getChar() @@ -429,7 +480,7 @@ } return retChar; } - +#ifdef ENABLE_PULSE_SENSOR_BT void UART_StartDMARx() { HAL_UART_Receive_DMA (&UartHandle, &rxBufferUart[rxBufWrite], CHUNK_SIZE); @@ -439,11 +490,28 @@ rxBufWrite = 0; } } - void DMA2_Stream2_IRQHandler(void) { HAL_DMA_IRQHandler(&hdma_uart_BT_rx); } +#endif + +#ifdef ENABLE_USART_RADIO +void UART_StartDMARxRadio() +{ + HAL_UART_Receive_DMA (&UartRadio_Handle, &rxBufferUart[rxBufWrite], CHUNK_SIZE); + rxBufWrite += CHUNK_SIZE; + if(rxBufWrite >= CHUNK_SIZE * CHUNKS_PER_BUFFER) + { + rxBufWrite = 0; + } +} + +void DMA2_Stream2_IRQHandler(void) +{ + HAL_DMA_IRQHandler(&hdma_uart_radio_rx); +} +#endif void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) {
