using LPUART to forward Bluetooth messages !
This commit is contained in:
@@ -43,11 +43,13 @@
|
||||
#include "BSP_GPIO.h"
|
||||
#include "BSP_ADC.h"
|
||||
#include "ram_loader.h"
|
||||
#include "AsyncComm.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PTD */
|
||||
uint8_t lp_buffer[2][1024] = {0};
|
||||
extern uart_desc_t uart_half;
|
||||
__attribute__((__section__(".dma_buffer"))) uint8_t lp_buffer[2][2048] = {0};
|
||||
uint8_t swap_index = 0;
|
||||
/* USER CODE END PTD */
|
||||
|
||||
@@ -142,13 +144,19 @@ int main(void)
|
||||
BSP_GPIO_PeriperalsOn();
|
||||
BSP_POWER_Init();
|
||||
ULOG_INIT();
|
||||
//ULOG_SUBSCRIBE(ULOG_SendLPUART,ULOG_DEBUG_LEVEL);
|
||||
ULOG_SUBSCRIBE(ULOG_SendLPUART,ULOG_DEBUG_LEVEL);
|
||||
ULOG_DEBUG("Setup Logger");
|
||||
gCLS_DEVICE_ADDRESS = 0x11; // Address is set to master
|
||||
ULOG_DEBUG("Setting Global CLS address to 0b10001");
|
||||
ULOG_DEBUG("Init Kernel and start schedule");
|
||||
|
||||
//HAL_UART_Receive(&hlpuart1, lp_buffer[swap_index], 10, 10000);
|
||||
|
||||
HAL_UART_Receive_DMA(&hlpuart1, lp_buffer[0], 1024);
|
||||
HAL_StatusTypeDef status = HAL_UARTEx_ReceiveToIdle_DMA(&hlpuart1, lp_buffer[swap_index], 2048);
|
||||
if(status != HAL_OK){
|
||||
ULOG_ERROR("Failed to start DMA");
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
@@ -172,6 +180,37 @@ int main(void)
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){
|
||||
if(huart->Instance ==LPUART1){
|
||||
uint8_t new_index = (swap_index + 1) % 2;
|
||||
HAL_UARTEx_ReceiveToIdle_DMA(&hlpuart1, lp_buffer[new_index], 2048);
|
||||
usart_send_data(&uart_half, lp_buffer[swap_index], 2048);
|
||||
swap_index = new_index;
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size){
|
||||
//restarts the DMA listening of the UART rx (next 247 bytes)
|
||||
if(huart->Instance ==LPUART1){
|
||||
|
||||
uint8_t new_index = (swap_index + 1) % 2;
|
||||
HAL_UARTEx_ReceiveToIdle_DMA(&hlpuart1, lp_buffer[new_index], 2048);
|
||||
usart_send_data(&uart_half, lp_buffer[swap_index], Size);
|
||||
swap_index = new_index;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
|
||||
{
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
if(huart->Instance ==LPUART1){
|
||||
swap_index = (swap_index + 1) % 2;
|
||||
HAL_UARTEx_ReceiveToIdle_DMA(&hlpuart1, lp_buffer[swap_index], 2048);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
|
||||
Reference in New Issue
Block a user