4 Commits

3 changed files with 67 additions and 26 deletions
+21
View File
@@ -1,3 +1,24 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : canlog.h
* @brief : Header for canlog.c file.
* This file contains the defines related to SAE J1939 CAN.
******************************************************************************
* @attention
*
* Copyright (c) 2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef CANLOG_H
#define CANLOG_H
+33 -13
View File
@@ -1,7 +1,28 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : canlog.c
* @brief : SAE J1939 CAN Real Time listening and decoding
******************************************************************************
* @attention
*
* Copyright (c) 2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "canlog.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "cmsis_os.h"
#include <string.h>
/* USER CODE END Includes */
extern CAN_HandleTypeDef hcan1;
extern CAN_HandleTypeDef hcan2;
@@ -28,7 +49,7 @@ osThreadId_t vLED_CAN1_Heartbeat;
const osThreadAttr_t vLED_CAN1_Heartbeat_attributes = {
.name = "vLED_CAN1_HeartbeatTask",
.stack_size = 128 * 4,
.priority = (osPriority_t) osPriorityLow1,
.priority = (osPriority_t) osPriorityVeryLow1,
};
/* Definitions for CAN2 LED heartbeat */
@@ -36,15 +57,16 @@ osThreadId_t vLED_CAN2_Heartbeat;
const osThreadAttr_t vLED_CAN2_Heartbeat_attributes = {
.name = "vLED_CAN2_HeartbeatTask",
.stack_size = 128 * 4,
.priority = (osPriority_t) osPriorityLow,
.priority = (osPriority_t) osPriorityVeryLow,
};
/* USER END RTOS_TASKS */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */
/* BEGIN CAN_Logger_Init */
/**
* @brief Initialize CAN
* @brief Initialize CAN bus logger.
* @param argument: hcan1, hcan2
* @retval None
*/
@@ -71,15 +93,13 @@ void CAN_Logger_Init(CAN_HandleTypeDef *hcan1, CAN_HandleTypeDef *hcan2)
}
/* END CAN_Logger_Init */
static void CAN_Listen(void *argument){}
/* BEGIN vCAN_Get */
/* BEGIN vCAN_Logger_Listen */
/**
* @brief Log incoming CAN bus traffic in FIFO buffer
* @param argument: Not used
* @retval None
*/
void vCAN_Get(void *argument)
static void vCAN_Logger_Listen(void *argument)
{
/* CODE BEGIN */
/* Infinite loop */
@@ -89,16 +109,15 @@ void vCAN_Get(void *argument)
}
/* CODE END */
}
/* END vCAN_Get */
/* END vCAN_Logger_Listen */
/* BEGIN vLED_HeartbeatOnCanRx */
/* BEGIN vLED_Heartbeat */
/**
* @brief Blink a LED in heartbeat mode when there is CAN traffic detected
* @brief Blink a LED in heartbeat mode when CAN traffic is detected
* @param argument: LED GPIO (port and pin)
* @retval None
*/
void vLED_HeartbeatOnCanRx(void *argument)
void vLED_Heartbeat(void *argument)
{
/* CODE BEGIN */
LED_Config *led = (LED_Config*)argument;
@@ -117,3 +136,4 @@ void vLED_HeartbeatOnCanRx(void *argument)
/* CODE END */
}
/* END vLED_HeartbeatOnCanRx */
/* USER CODE END FunctionPrototypes */
+6 -6
View File
@@ -66,8 +66,8 @@ static void MX_CAN2_Init(void);
static void MX_SDIO_SD_Init(void);
/* USER CODE BEGIN PFP */
void vCAN_Get(void *argument);
void vLED_HeartbeatOnCanRx(void *argument);
void vCAN_Logger_Listen(void *argument);
void vLED_Heartbeat(void *argument);
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
@@ -134,10 +134,10 @@ int main(void)
/* USER CODE END RTOS_QUEUES */
/* USER CODE BEGIN RTOS_THREADS */
vCAN1_rx = osThreadNew(vCAN_Get, &hcan1, &vCAN1_rx_attributes);
vCAN2_rx = osThreadNew(vCAN_Get, &hcan2, &vCAN2_rx_attributes);
vLED_CAN1_Heartbeat = osThreadNew(vLED_HeartbeatOnCanRx, &led_can1, &vLED_CAN1_Heartbeat_attributes);
vLED_CAN2_Heartbeat = osThreadNew(vLED_HeartbeatOnCanRx, &led_can2, &vLED_CAN2_Heartbeat_attributes);
vCAN1_rx = osThreadNew(vCAN_Logger_Listen, &hcan1, &vCAN1_rx_attributes);
vCAN2_rx = osThreadNew(vCAN_Logger_Listen, &hcan2, &vCAN2_rx_attributes);
vLED_CAN1_Heartbeat = osThreadNew(vLED_Heartbeat, &led_can1, &vLED_CAN1_Heartbeat_attributes);
vLED_CAN2_Heartbeat = osThreadNew(vLED_Heartbeat, &led_can2, &vLED_CAN2_Heartbeat_attributes);
/* USER CODE END RTOS_THREADS */
/* USER CODE BEGIN RTOS_EVENTS */