Compare commits
4 Commits
8576603e6d
...
4da8f59330
| Author | SHA1 | Date | |
|---|---|---|---|
| 4da8f59330 | |||
| c9f735acd9 | |||
| 30410f9b9e | |||
| e14a98eba4 |
+1
-1
@@ -46,7 +46,7 @@ extern "C" {
|
|||||||
/* Exported macro ------------------------------------------------------------*/
|
/* Exported macro ------------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN EM */
|
/* USER CODE BEGIN EM */
|
||||||
//#define DEBUG_ITM
|
//#define DEBUG_ITM
|
||||||
//#define DEBUG_DUMMY_FRAME
|
#define DEBUG_DUMMY_FRAME
|
||||||
|
|
||||||
#ifdef DEBUG_ITM
|
#ifdef DEBUG_ITM
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|||||||
+1
-4
@@ -93,10 +93,7 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
|
|||||||
led_task = xCAN2LedTask;
|
led_task = xCAN2LedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (osMessageQueuePut(queue, &message, 0U, 0U) == osOK)
|
if (osMessageQueuePut(queue, &message, 0U, 0U) == osOK) osThreadFlagsSet(led_task, 0x01);
|
||||||
{
|
|
||||||
osThreadFlagsSet(led_task, 0x01);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* END HAL_CAN_RxFifo0MsgPendingCallback */
|
/* END HAL_CAN_RxFifo0MsgPendingCallback */
|
||||||
|
|
||||||
|
|||||||
+34
-19
@@ -52,11 +52,14 @@ void uart_printf(const char *fmt, ...)
|
|||||||
{
|
{
|
||||||
if (osSemaphoreAcquire(xUARTDMASemaphore, osWaitForever) == osOK)
|
if (osSemaphoreAcquire(xUARTDMASemaphore, osWaitForever) == osOK)
|
||||||
{
|
{
|
||||||
if (HAL_UART_Transmit_DMA(&huart1, (uint8_t*)buf, len) != HAL_OK) osSemaphoreRelease(xUARTDMASemaphore);
|
HAL_UART_Transmit(&huart1, (uint8_t*)buf, len, HAL_MAX_DELAY);
|
||||||
else osSemaphoreAcquire(xUARTDMASemaphore, osWaitForever);
|
osSemaphoreRelease(xUARTDMASemaphore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else HAL_UART_Transmit(&huart1, (uint8_t*)buf, len, HAL_MAX_DELAY);
|
else
|
||||||
|
{
|
||||||
|
HAL_UART_Transmit(&huart1, (uint8_t*)buf, len, HAL_MAX_DELAY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* END uart_printf */
|
/* END uart_printf */
|
||||||
@@ -128,7 +131,19 @@ void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
|
|||||||
}
|
}
|
||||||
/* END HAL_UART_TxCpltCallback */
|
/* END HAL_UART_TxCpltCallback */
|
||||||
|
|
||||||
/* BEGIN vUARTLoggerListen */
|
/* BEGIN HAL_UART_ErrorCallback */
|
||||||
|
/**
|
||||||
|
* @brief Safely release UART semaphore inside ISR and yield task if possible.
|
||||||
|
* @param argument: UART handle
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
|
||||||
|
{
|
||||||
|
if (huart->Instance == USART1) osSemaphoreRelease(xUARTDMASemaphore);
|
||||||
|
}
|
||||||
|
/* END HAL_UART_ErrorCallback */
|
||||||
|
|
||||||
|
/* BEGIN vUARTLogger */
|
||||||
/**
|
/**
|
||||||
* @brief Send CAN bus traffic saved in FIFO buffer to USART1
|
* @brief Send CAN bus traffic saved in FIFO buffer to USART1
|
||||||
* @param argument: Not used
|
* @param argument: Not used
|
||||||
@@ -151,18 +166,15 @@ void vUARTLogger(void *argument)
|
|||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
DEBUG_PRINT("[D] Waiting for CAN traffic...\r\n");
|
uint32_t queue_timeout = 2500U;
|
||||||
|
|
||||||
#ifdef DEBUG_DUMMY_FRAME
|
//#ifdef DEBUG_DUMMY_FRAME
|
||||||
uint32_t queue_timeout = 1000U;
|
//uint32_t queue_timeout = 100U;
|
||||||
#else
|
//osMessageQueuePut(xUARTQueue, &dummy_frame, 0U, 0U);
|
||||||
uint32_t queue_timeout = osWaitForever;
|
//osDelay(500);
|
||||||
#endif
|
//#else
|
||||||
|
//uint32_t queue_timeout = osWaitForever;
|
||||||
#ifdef DEBUG_DUMMY_FRAME
|
// #endif
|
||||||
osMessageQueuePut(xUARTQueue, &dummy_frame, 0U, 0U);
|
|
||||||
osDelay(1000);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (osMessageQueueGet(xUARTQueue, &message, NULL, queue_timeout) == osOK)
|
if (osMessageQueueGet(xUARTQueue, &message, NULL, queue_timeout) == osOK)
|
||||||
{
|
{
|
||||||
@@ -170,12 +182,15 @@ void vUARTLogger(void *argument)
|
|||||||
{
|
{
|
||||||
int len = format_can_message(tx_buffer, message.source, &message);
|
int len = format_can_message(tx_buffer, message.source, &message);
|
||||||
|
|
||||||
if (HAL_UART_Transmit_DMA(&huart1, (uint8_t*)tx_buffer, len) != HAL_OK) Error_Handler();
|
if (HAL_UART_Transmit_DMA(&huart1, (uint8_t*)tx_buffer, len) != HAL_OK)
|
||||||
else DEBUG_PRINT("[E] HAL error, CAN frame NOT sent!\r\n");
|
{
|
||||||
osSemaphoreRelease(xUARTDMASemaphore);
|
osSemaphoreRelease(xUARTDMASemaphore);
|
||||||
|
DEBUG_PRINT("[E] HAL error, CAN frame NOT sent!\r\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else DEBUG_PRINT("[E] Semaphore timeout! UART might be stuck in BUSY state.\r\n");
|
else DEBUG_PRINT("[E] Semaphore timeout! UART might be stuck in BUSY state.\r\n");
|
||||||
}
|
}
|
||||||
|
else DEBUG_PRINT("[D] Waiting for CAN traffic...\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* END vUARTLoggerListen */
|
/* END vUARTLogger */
|
||||||
|
|||||||
+3
-1
@@ -76,6 +76,8 @@ static void MX_CAN2_Init(void);
|
|||||||
static void MX_SDIO_SD_Init(void);
|
static void MX_SDIO_SD_Init(void);
|
||||||
static void MX_USART1_UART_Init(void);
|
static void MX_USART1_UART_Init(void);
|
||||||
|
|
||||||
|
void uart_printf(const char *fmt, ...);
|
||||||
|
|
||||||
/* USER CODE BEGIN PFP */
|
/* USER CODE BEGIN PFP */
|
||||||
int _write(int file, char *ptr, int len)
|
int _write(int file, char *ptr, int len)
|
||||||
{
|
{
|
||||||
@@ -125,12 +127,12 @@ int main(void)
|
|||||||
/* USER CODE END SysInit */
|
/* USER CODE END SysInit */
|
||||||
|
|
||||||
/* Initialize all configured peripherals */
|
/* Initialize all configured peripherals */
|
||||||
|
MX_USART1_UART_Init();
|
||||||
MX_GPIO_Init();
|
MX_GPIO_Init();
|
||||||
MX_DMA_Init();
|
MX_DMA_Init();
|
||||||
MX_CAN1_Init();
|
MX_CAN1_Init();
|
||||||
MX_CAN2_Init();
|
MX_CAN2_Init();
|
||||||
MX_SDIO_SD_Init();
|
MX_SDIO_SD_Init();
|
||||||
MX_USART1_UART_Init();
|
|
||||||
/* USER CODE BEGIN 2 */
|
/* USER CODE BEGIN 2 */
|
||||||
DEBUG_PRINT("[L] Initializing CAN bus logger\r\n");
|
DEBUG_PRINT("[L] Initializing CAN bus logger\r\n");
|
||||||
CAN_Logger_Init(&hcan1, &hcan2);
|
CAN_Logger_Init(&hcan1, &hcan2);
|
||||||
|
|||||||
Reference in New Issue
Block a user