10 Commits

Author SHA1 Message Date
eeeck 30b7538e26 Use HAL WritePin func instead of TogglePin
- Better reliability in blinking LED
- Slightly more efficiency (fewer CPU clocks)
2026-06-09 10:05:25 +02:00
eeeck c891681b94 Minor comment clarifications 2026-06-09 09:51:10 +02:00
eeeck 770e97ccd9 Move include declaration to private includes 2026-06-09 09:50:00 +02:00
eeeck 5d3c8c0ec0 Refactor task function name 2026-06-09 09:12:11 +02:00
eeeck 495c9cb377 Enable auto wake up on CAN traffic for future sleep mode 2026-06-09 00:33:14 +02:00
eeeck c274be6907 Minor clarification on existing comment 2026-06-09 00:27:17 +02:00
eeeck b92b26b026 Remove trailing newlines 2026-06-09 00:24:41 +02:00
eeeck bbdb278338 Minor changes on comments
- Clarifications on existing comments
- Add TODO
2026-06-09 00:17:06 +02:00
eeeck a236377784 Add simple GPIO toggling in RT 2026-06-09 00:08:24 +02:00
eeeck 9f3d681134 Remove explicit cast 2026-06-09 00:00:42 +02:00
3 changed files with 486 additions and 486 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ extern const osThreadAttr_t vLED_CAN2_Heartbeat_attributes;
* @param hcan2 Pointer to the CAN2 handle
*/
void CAN_Logger_Init(CAN_HandleTypeDef *hcan1, CAN_HandleTypeDef *hcan2);
void vCAN_log(void *argument);
void vCAN_Get(void *argument);
void vLED_HeartbeatOnCanRx(void *argument);
#endif /* CANLOG_H */
+21 -11
View File
@@ -1,3 +1,4 @@
#include "canlog.h"
#include "cmsis_os.h"
#include <string.h>
@@ -5,8 +6,7 @@
extern CAN_HandleTypeDef hcan1;
extern CAN_HandleTypeDef hcan2;
/* FreeRTOS task definitions */
/* USER CODE BEGIN RTOS_TASKS */
/* Definitions for CAN1rx incoming */
osThreadId_t vCAN1_rx;
const osThreadAttr_t vCAN1_rx_attributes = {
@@ -38,18 +38,20 @@ const osThreadAttr_t vLED_CAN2_Heartbeat_attributes = {
.stack_size = 128 * 4,
.priority = (osPriority_t) osPriorityLow,
};
/* USER END RTOS_TASKS */
/* Private function prototypes -----------------------------------------------*/
void CAN_Logger_Init(CAN_HandleTypeDef *hcan1, CAN_HandleTypeDef *hcan2){}
static void CAN_Listen(void *argument){}
/* BEGIN vCAN_log */
/* BEGIN vCAN_Get */
/**
* @brief Log incoming CAN bus traffic.
* @brief Log incoming CAN bus traffic in FIFO buffer
* @param argument: Not used
* @retval None
*/
void vCAN_log(void *argument)
void vCAN_Get(void *argument)
{
/* CODE BEGIN */
/* Infinite loop */
@@ -59,23 +61,31 @@ void vCAN_log(void *argument)
}
/* CODE END */
}
/* END vCAN_log */
/* END vCAN_Get */
/* BEGIN vLED_HeartbeatOnCanRx */
/**
* @brief Blink a LED in heartbeat mode when there is CAN traffic detected.
* @param argument: Not used
* @brief Blink a LED in heartbeat mode when there is CAN traffic detected
* @param argument: LED GPIO (port and pin)
* @retval None
*/
void vLED_HeartbeatOnCanRx(void *argument)
{
/* CODE BEGIN */
/* Infinite loop */
LED_Config *led = (LED_Config*)argument;
for(;;)
{
osDelay(1);
//HAL_GPIO_WritePin(led->port, led->pin, GPIO_PIN_RESET);
// if semaphore for canrx, do the rest
HAL_GPIO_WritePin(led->port, led->pin, GPIO_PIN_SET);
vTaskDelay(pdMS_TO_TICKS(100));
HAL_GPIO_WritePin(led->port, led->pin, GPIO_PIN_RESET);
vTaskDelay(pdMS_TO_TICKS(100));
}
/* CODE END */
}
/* vLED_HeartbeatOnCanRx */
/* END vLED_HeartbeatOnCanRx */
+8 -18
View File
@@ -19,21 +19,18 @@
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "cmsis_os.h"
#include "canlog.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "canlog.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
typedef struct {
GPIO_TypeDef* port;
uint16_t pin;
} LED_Config;
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
@@ -55,10 +52,8 @@ DMA_HandleTypeDef hdma_sdio_rx;
DMA_HandleTypeDef hdma_sdio_tx;
/* USER CODE BEGIN PV */
LED_Config led_can1 = {GPIOB, GPIO_PIN_2};
LED_Config led_can2 = {GPIOB, GPIO_PIN_5};
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
@@ -70,10 +65,8 @@ static void MX_CAN2_Init(void);
static void MX_SDIO_SD_Init(void);
/* USER CODE BEGIN PFP */
void vCAN_log(void *argument);
void vCAN_Get(void *argument);
void vLED_HeartbeatOnCanRx(void *argument);
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
@@ -114,11 +107,10 @@ int main(void)
MX_CAN1_Init();
MX_CAN2_Init();
MX_SDIO_SD_Init();
/* USER CODE BEGIN 2 */
// Initialize CAN1 and CAN2
/* Initialize CAN1 and CAN2 */
CAN_Logger_Init(&hcan1, &hcan2);
/* USER CODE END 2 */
/* Init scheduler */
@@ -141,12 +133,10 @@ int main(void)
/* USER CODE END RTOS_QUEUES */
/* USER CODE BEGIN RTOS_THREADS */
vCAN1_rx = osThreadNew(vCAN_log, (void*)&hcan1, &vCAN1_rx_attributes);
vCAN2_rx = osThreadNew(vCAN_log, (void*)&hcan2, &vCAN2_rx_attributes);
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);
/* USER CODE END RTOS_THREADS */
/* USER CODE BEGIN RTOS_EVENTS */
@@ -238,7 +228,7 @@ static void MX_CAN1_Init(void)
hcan1.Init.TimeSeg2 = CAN_BS2_4TQ;
hcan1.Init.TimeTriggeredMode = DISABLE;
hcan1.Init.AutoBusOff = DISABLE;
hcan1.Init.AutoWakeUp = DISABLE;
hcan1.Init.AutoWakeUp = ENABLE;
hcan1.Init.AutoRetransmission = DISABLE;
hcan1.Init.ReceiveFifoLocked = DISABLE;
hcan1.Init.TransmitFifoPriority = DISABLE;
@@ -275,7 +265,7 @@ static void MX_CAN2_Init(void)
hcan2.Init.TimeSeg2 = CAN_BS2_4TQ;
hcan2.Init.TimeTriggeredMode = DISABLE;
hcan2.Init.AutoBusOff = DISABLE;
hcan2.Init.AutoWakeUp = DISABLE;
hcan2.Init.AutoWakeUp = ENABLE;
hcan2.Init.AutoRetransmission = DISABLE;
hcan2.Init.ReceiveFifoLocked = DISABLE;
hcan2.Init.TransmitFifoPriority = DISABLE;