Compare commits
32 Commits
9ea83fcbcd
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| d2d9d21f3d | |||
| f53f49a94e | |||
| dce176cc1e | |||
| e351c762d3 | |||
| 89b5fe349c | |||
| 2b445aac84 | |||
| 8b8c97316b | |||
| 714051c66d | |||
| 89b3b6b876 | |||
| e57188a51e | |||
| 3780497e8d | |||
| 3e1bcd6195 | |||
| fcf36e4513 | |||
| fe2a3e075f | |||
| 21a64d66fd | |||
| cef7e5e445 | |||
| 263b699662 | |||
| da0211ebd5 | |||
| d5fd649325 | |||
| 79ef4c5fdb | |||
| e32f501285 | |||
| 85c8cd4eed | |||
| 9a58e41d55 | |||
| 48aaaf7fb8 | |||
| 4236c204a6 | |||
| 2d7e7f514a | |||
| 600a4e24d8 | |||
| 6954fc5497 | |||
| 03fec5ff34 | |||
| 76f6526036 | |||
| ff1335b0dc | |||
| 397711e9fb |
@@ -1,15 +1,15 @@
|
|||||||
# Third-Party Notices
|
# Copyright Notices
|
||||||
|
|
||||||
This project is built with open source components and includes third-party software:
|
This project is built with open source components and includes third-party software:
|
||||||
|
|
||||||
## 1. Original Application Code
|
## 1. Original Application Code
|
||||||
- **Copyright (c) 2026 Erick Ahmed**
|
- **Copyright (c) 2026 Erick Ahmed**
|
||||||
- **License:** [GNU General Public License v3.0](https://git.erickahmed.com/erickahmed/bxcan-logger/src/branch/main/LICENSE.txt)
|
- **License:** [GNU General Public License v3.0 or later](https://git.erickahmed.com/erickahmed/CANdigger/src/branch/main/LICENSE)
|
||||||
|
|
||||||
## 2. STM32F4 HAL Drivers
|
## 2. STM32F4 HAL Drivers
|
||||||
- **Copyright (c) 2016 STMicroelectronics**
|
- **Copyright (c) 2016 STMicroelectronics**
|
||||||
- **License:** [BSD 3-Clause License](https://git.erickahmed.com/erickahmed/bxcan-logger/src/branch/main/Drivers/STM32F4xx_HAL_Driver/LICENSE.txt)
|
- **License:** [BSD 3-Clause License](https://git.erickahmed.com/erickahmed/CANdigger/src/branch/main/Drivers/STM32F4xx_HAL_Driver/LICENSE.txt)
|
||||||
|
|
||||||
## 3. STM32 CMSIS
|
## 3. STM32 CMSIS
|
||||||
- **Copyright (c) 2017 STMicroelectronics**
|
- **Copyright (c) 2017 STMicroelectronics**
|
||||||
- **License:** [Apache License 2.0](https://git.erickahmed.com/erickahmed/bxcan-logger/src/branch/main/Drivers/CMSIS/LICENSE.txt)
|
- **License:** [Apache License 2.0](https://git.erickahmed.com/erickahmed/CANdigger/src/branch/main/Drivers/CMSIS/LICENSE.txt)
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
|
void uart_printf(const char *fmt, ...);
|
||||||
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart);
|
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart);
|
||||||
void vUARTLogger(void *argument);
|
void vUARTLogger(void *argument);
|
||||||
|
|
||||||
|
|||||||
+9
-9
@@ -18,6 +18,7 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
/* Private includes ----------------------------------------------------------*/
|
/* Private includes ----------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN Includes */
|
/* USER CODE BEGIN Includes */
|
||||||
|
#include "cansend.h"
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
@@ -72,11 +73,15 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
|
|||||||
osMessageQueueId_t queue;
|
osMessageQueueId_t queue;
|
||||||
osThreadId_t led_task;
|
osThreadId_t led_task;
|
||||||
|
|
||||||
// TODO: manage the case of FIFO overflow
|
if (__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_FOV0) != RESET) __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_FOV0);
|
||||||
|
|
||||||
if (HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &rxHeader, data) != HAL_OK) return;
|
if (HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &rxHeader, data) != HAL_OK) return;
|
||||||
|
|
||||||
|
if (rxHeader.DLC > 8) return;
|
||||||
|
|
||||||
if (rxHeader.IDE == CAN_ID_EXT) message.id = rxHeader.ExtId;
|
if (rxHeader.IDE == CAN_ID_EXT) message.id = rxHeader.ExtId;
|
||||||
else message.id = rxHeader.StdId;
|
else message.id = rxHeader.StdId;
|
||||||
|
|
||||||
message.dlc = rxHeader.DLC;
|
message.dlc = rxHeader.DLC;
|
||||||
message.isExtended = (rxHeader.IDE == CAN_ID_EXT);
|
message.isExtended = (rxHeader.IDE == CAN_ID_EXT);
|
||||||
message.source = (hcan->Instance == CAN1) ? 1 : 2;
|
message.source = (hcan->Instance == CAN1) ? 1 : 2;
|
||||||
@@ -113,24 +118,19 @@ void vCANListener(void *argument)
|
|||||||
HAL_CAN_ActivateNotification(hcan, CAN_IT_RX_FIFO0_MSG_PENDING);
|
HAL_CAN_ActivateNotification(hcan, CAN_IT_RX_FIFO0_MSG_PENDING);
|
||||||
|
|
||||||
uint32_t irqn = (hcan->Instance == CAN1) ? CAN1_RX0_IRQn : CAN2_RX0_IRQn;
|
uint32_t irqn = (hcan->Instance == CAN1) ? CAN1_RX0_IRQn : CAN2_RX0_IRQn;
|
||||||
HAL_NVIC_SetPriority(irqn, 6, 0);
|
HAL_NVIC_SetPriority(irqn, 5, 0);
|
||||||
HAL_NVIC_EnableIRQ(irqn);
|
HAL_NVIC_EnableIRQ(irqn);
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if (osMessageQueueGet(queue, &message, NULL, 1000) == osOK)
|
if (osMessageQueueGet(queue, &message, NULL, 1000) == osOK) osMessageQueuePut(xUARTQueue, &message, 0U, 0U);
|
||||||
{
|
|
||||||
// J1939 decoding
|
|
||||||
|
|
||||||
osMessageQueuePut(xUARTQueue, &message, 0U, 0U);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* END vCANListener */
|
/* END vCANListener */
|
||||||
|
|
||||||
/* BEGIN vLEDHeartbeat */
|
/* BEGIN vLEDHeartbeat */
|
||||||
/**
|
/**
|
||||||
* @brief Blink a LED in heartbeat mode when CAN traffic is detected
|
* @brief Turn on LED when CAN traffic is detected
|
||||||
* @param argument: LED GPIO (port and pin)
|
* @param argument: LED GPIO (port and pin)
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
|
|||||||
+56
-55
@@ -40,26 +40,28 @@ extern osSemaphoreId_t xUARTDMASemaphore;
|
|||||||
*/
|
*/
|
||||||
void uart_printf(const char *fmt, ...)
|
void uart_printf(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
static char buf[128];
|
if (__get_IPSR() != 0) return;
|
||||||
|
|
||||||
|
char buffer[128];
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
int len = vsnprintf(buf, sizeof(buf), fmt, args);
|
|
||||||
|
int len = vsnprintf(buffer, sizeof(buffer), fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
{
|
{
|
||||||
if (osKernelGetState() == osKernelRunning && __get_IPSR() == 0)
|
if (len >= sizeof(buffer)) len = sizeof(buffer) - 1;
|
||||||
|
|
||||||
|
if (osKernelGetState() == osKernelRunning)
|
||||||
{
|
{
|
||||||
if (osSemaphoreAcquire(xUARTDMASemaphore, osWaitForever) == osOK)
|
if (osSemaphoreAcquire(xUARTDMASemaphore, osWaitForever) == osOK)
|
||||||
{
|
{
|
||||||
HAL_UART_Transmit(&huart1, (uint8_t*)buf, len, HAL_MAX_DELAY);
|
HAL_UART_Transmit(&huart1, (uint8_t*)buffer, len, HAL_MAX_DELAY);
|
||||||
osSemaphoreRelease(xUARTDMASemaphore);
|
osSemaphoreRelease(xUARTDMASemaphore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else HAL_UART_Transmit(&huart1, (uint8_t*)buffer, len, HAL_MAX_DELAY);
|
||||||
{
|
|
||||||
HAL_UART_Transmit(&huart1, (uint8_t*)buf, len, HAL_MAX_DELAY);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* END uart_printf */
|
/* END uart_printf */
|
||||||
@@ -70,49 +72,49 @@ void uart_printf(const char *fmt, ...)
|
|||||||
* @param arguments: buffer, source, message
|
* @param arguments: buffer, source, message
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static int format_can_message(char *buf, uint8_t source, const CanMessage_t *message)
|
static int format_can_message(char *buffer, uint8_t source, const CanMessage_t *message)
|
||||||
{
|
{
|
||||||
const char hex[] = "0123456789ABCDEF";
|
const char hex[] = "0123456789ABCDEF";
|
||||||
|
|
||||||
buf[0] = 'C';
|
buffer[0] = 'C';
|
||||||
buf[1] = (source == 1) ? '1' : '2';
|
buffer[1] = (source == 1) ? '1' : '2';
|
||||||
buf[2] = ':';
|
buffer[2] = ':';
|
||||||
|
|
||||||
buf[3] = hex[(message->id >> 28) & 0x0F];
|
buffer[3] = hex[(message->id >> 28) & 0x0F];
|
||||||
buf[4] = hex[(message->id >> 24) & 0x0F];
|
buffer[4] = hex[(message->id >> 24) & 0x0F];
|
||||||
buf[5] = hex[(message->id >> 20) & 0x0F];
|
buffer[5] = hex[(message->id >> 20) & 0x0F];
|
||||||
buf[6] = hex[(message->id >> 16) & 0x0F];
|
buffer[6] = hex[(message->id >> 16) & 0x0F];
|
||||||
buf[7] = hex[(message->id >> 12) & 0x0F];
|
buffer[7] = hex[(message->id >> 12) & 0x0F];
|
||||||
buf[8] = hex[(message->id >> 8) & 0x0F];
|
buffer[8] = hex[(message->id >> 8) & 0x0F];
|
||||||
buf[9] = hex[(message->id >> 4) & 0x0F];
|
buffer[9] = hex[(message->id >> 4) & 0x0F];
|
||||||
buf[10] = hex[message->id & 0x0F];
|
buffer[10] = hex[message->id & 0x0F];
|
||||||
|
|
||||||
buf[11] = ' ';
|
buffer[11] = ' ';
|
||||||
buf[12] = hex[(message->dlc >> 4) & 0x0F];
|
buffer[12] = hex[(message->dlc >> 4) & 0x0F];
|
||||||
buf[13] = hex[message->dlc & 0x0F];
|
buffer[13] = hex[message->dlc & 0x0F];
|
||||||
buf[14] = ' ';
|
buffer[14] = ' ';
|
||||||
|
|
||||||
int idx = 15;
|
int index = 15;
|
||||||
for (int i = 0; i < 8; i++)
|
for (int i = 0; i < 8; i++)
|
||||||
{
|
{
|
||||||
if (i < message->dlc)
|
if (i < message->dlc)
|
||||||
{
|
{
|
||||||
buf[idx++] = hex[(message->payload[i] >> 4) & 0x0F];
|
buffer[index++] = hex[(message->payload[i] >> 4) & 0x0F];
|
||||||
buf[idx++] = hex[message->payload[i] & 0x0F];
|
buffer[index++] = hex[message->payload[i] & 0x0F];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
buf[idx++] = ' ';
|
buffer[index++] = ' ';
|
||||||
buf[idx++] = ' ';
|
buffer[index++] = ' ';
|
||||||
}
|
}
|
||||||
if (i < 7) buf[idx++] = ' ';
|
if (i < 7) buffer[index++] = ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
buf[idx++] = '\r';
|
buffer[index++] = '\r';
|
||||||
buf[idx++] = '\n';
|
buffer[index++] = '\n';
|
||||||
buf[idx] = '\0';
|
buffer[index] = '\0';
|
||||||
|
|
||||||
return idx;
|
return index;
|
||||||
}
|
}
|
||||||
/* END format_can_message */
|
/* END format_can_message */
|
||||||
|
|
||||||
@@ -124,22 +126,31 @@ static int format_can_message(char *buf, uint8_t source, const CanMessage_t *mes
|
|||||||
*/
|
*/
|
||||||
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
|
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
|
||||||
{
|
{
|
||||||
if (huart->Instance == USART1)
|
if (huart->Instance == USART1) osSemaphoreRelease(xUARTDMASemaphore);
|
||||||
{
|
|
||||||
osSemaphoreRelease(xUARTDMASemaphore);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* END HAL_UART_TxCpltCallback */
|
/* END HAL_UART_TxCpltCallback */
|
||||||
|
|
||||||
/* BEGIN HAL_UART_ErrorCallback */
|
/* BEGIN HAL_UART_ErrorCallback */
|
||||||
/**
|
/**``MEN
|
||||||
* @brief Safely release UART semaphore inside ISR and yield task if possible.
|
* @brief Handle UART errors
|
||||||
* @param argument: UART handle
|
* @param argument: UART handle
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
|
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
|
||||||
{
|
{
|
||||||
if (huart->Instance == USART1) osSemaphoreRelease(xUARTDMASemaphore);
|
if (huart->Instance == USART1)
|
||||||
|
{
|
||||||
|
__HAL_UART_CLEAR_OREFLAG(huart);
|
||||||
|
__HAL_UART_CLEAR_FEFLAG(huart);
|
||||||
|
__HAL_UART_CLEAR_NEFLAG(huart);
|
||||||
|
__HAL_UART_CLEAR_PEFLAG(huart);
|
||||||
|
|
||||||
|
HAL_UART_DMAStop(huart);
|
||||||
|
|
||||||
|
huart->gState = HAL_UART_STATE_READY;
|
||||||
|
|
||||||
|
osSemaphoreRelease(xUARTDMASemaphore);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* END HAL_UART_ErrorCallback */
|
/* END HAL_UART_ErrorCallback */
|
||||||
|
|
||||||
@@ -152,7 +163,7 @@ void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
|
|||||||
void vUARTLogger(void *argument)
|
void vUARTLogger(void *argument)
|
||||||
{
|
{
|
||||||
CanMessage_t message;
|
CanMessage_t message;
|
||||||
char tx_buffer[45];
|
static char tx_buffer[45];
|
||||||
|
|
||||||
#ifdef DEBUG_DUMMY_FRAME
|
#ifdef DEBUG_DUMMY_FRAME
|
||||||
CanMessage_t dummy_frame = {
|
CanMessage_t dummy_frame = {
|
||||||
@@ -166,19 +177,9 @@ void vUARTLogger(void *argument)
|
|||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
uint32_t queue_timeout = 2500U;
|
if (osMessageQueueGet(xUARTQueue, &message, NULL, osWaitForever) == osOK)
|
||||||
|
{
|
||||||
//#ifdef DEBUG_DUMMY_FRAME
|
if (osSemaphoreAcquire(xUARTDMASemaphore, 100U) == osOK)
|
||||||
//uint32_t queue_timeout = 100U;
|
|
||||||
//osMessageQueuePut(xUARTQueue, &dummy_frame, 0U, 0U);
|
|
||||||
//osDelay(500);
|
|
||||||
//#else
|
|
||||||
//uint32_t queue_timeout = osWaitForever;
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
if (osMessageQueueGet(xUARTQueue, &message, NULL, queue_timeout) == osOK)
|
|
||||||
{
|
|
||||||
if (osSemaphoreAcquire(xUARTDMASemaphore, queue_timeout) == osOK)
|
|
||||||
{
|
{
|
||||||
int len = format_can_message(tx_buffer, message.source, &message);
|
int len = format_can_message(tx_buffer, message.source, &message);
|
||||||
|
|
||||||
|
|||||||
+42
-20
@@ -127,9 +127,9 @@ 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_DMA_Init();
|
MX_DMA_Init();
|
||||||
|
MX_GPIO_Init();
|
||||||
|
MX_USART1_UART_Init();
|
||||||
MX_CAN1_Init();
|
MX_CAN1_Init();
|
||||||
MX_CAN2_Init();
|
MX_CAN2_Init();
|
||||||
MX_SDIO_SD_Init();
|
MX_SDIO_SD_Init();
|
||||||
@@ -183,9 +183,9 @@ int main(void)
|
|||||||
/* USER CODE END RTOS_TIMERS */
|
/* USER CODE END RTOS_TIMERS */
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_QUEUES */
|
/* USER CODE BEGIN RTOS_QUEUES */
|
||||||
xCAN1RxQueue = osMessageQueueNew(64, sizeof(CanMessage_t), NULL);
|
xCAN1RxQueue = osMessageQueueNew(2048, sizeof(CanMessage_t), NULL);
|
||||||
xCAN2RxQueue = osMessageQueueNew(64, sizeof(CanMessage_t), NULL);
|
xCAN2RxQueue = osMessageQueueNew(2048, sizeof(CanMessage_t), NULL);
|
||||||
xUARTQueue = osMessageQueueNew(128, sizeof(CanMessage_t), NULL);
|
xUARTQueue = osMessageQueueNew(4096, sizeof(CanMessage_t), NULL);
|
||||||
|
|
||||||
if (xCAN1RxQueue == NULL || xCAN2RxQueue == NULL || xUARTQueue == NULL) Error_Handler();
|
if (xCAN1RxQueue == NULL || xCAN2RxQueue == NULL || xUARTQueue == NULL) Error_Handler();
|
||||||
/* USER CODE END RTOS_QUEUES */
|
/* USER CODE END RTOS_QUEUES */
|
||||||
@@ -196,6 +196,9 @@ int main(void)
|
|||||||
xUartTask = osThreadNew(vUARTLogger, NULL, &UartLoggerAttributes);
|
xUartTask = osThreadNew(vUARTLogger, NULL, &UartLoggerAttributes);
|
||||||
xCAN1LedTask = osThreadNew(vLEDHeartbeat, &led_can1, &LEDHeartbeatCAN1Attributes);
|
xCAN1LedTask = osThreadNew(vLEDHeartbeat, &led_can1, &LEDHeartbeatCAN1Attributes);
|
||||||
xCAN2LedTask = osThreadNew(vLEDHeartbeat, &led_can2, &LEDHeartbeatCAN2Attributes);
|
xCAN2LedTask = osThreadNew(vLEDHeartbeat, &led_can2, &LEDHeartbeatCAN2Attributes);
|
||||||
|
|
||||||
|
if (xCAN1rxTask == NULL || xCAN2rxTask == NULL || xUartTask == NULL ||
|
||||||
|
xCAN1LedTask == NULL || xCAN2LedTask == NULL) Error_Handler();
|
||||||
/* USER CODE END RTOS_THREADS */
|
/* USER CODE END RTOS_THREADS */
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_EVENTS */
|
/* USER CODE BEGIN RTOS_EVENTS */
|
||||||
@@ -282,7 +285,7 @@ static void MX_CAN1_Init(void)
|
|||||||
/* USER CODE END CAN1_Init 1 */
|
/* USER CODE END CAN1_Init 1 */
|
||||||
hcan1.Instance = CAN1;
|
hcan1.Instance = CAN1;
|
||||||
hcan1.Init.Prescaler = 4;
|
hcan1.Init.Prescaler = 4;
|
||||||
hcan1.Init.Mode = CAN_MODE_SILENT;
|
hcan1.Init.Mode = CAN_MODE_NORMAL;
|
||||||
hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
|
hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
|
||||||
hcan1.Init.TimeSeg1 = CAN_BS1_16TQ;
|
hcan1.Init.TimeSeg1 = CAN_BS1_16TQ;
|
||||||
hcan1.Init.TimeSeg2 = CAN_BS2_4TQ;
|
hcan1.Init.TimeSeg2 = CAN_BS2_4TQ;
|
||||||
@@ -319,7 +322,7 @@ static void MX_CAN2_Init(void)
|
|||||||
/* USER CODE END CAN2_Init 1 */
|
/* USER CODE END CAN2_Init 1 */
|
||||||
hcan2.Instance = CAN2;
|
hcan2.Instance = CAN2;
|
||||||
hcan2.Init.Prescaler = 8;
|
hcan2.Init.Prescaler = 8;
|
||||||
hcan2.Init.Mode = CAN_MODE_SILENT;
|
hcan2.Init.Mode = CAN_MODE_NORMAL;
|
||||||
hcan2.Init.SyncJumpWidth = CAN_SJW_1TQ;
|
hcan2.Init.SyncJumpWidth = CAN_SJW_1TQ;
|
||||||
hcan2.Init.TimeSeg1 = CAN_BS1_16TQ;
|
hcan2.Init.TimeSeg1 = CAN_BS1_16TQ;
|
||||||
hcan2.Init.TimeSeg2 = CAN_BS2_4TQ;
|
hcan2.Init.TimeSeg2 = CAN_BS2_4TQ;
|
||||||
@@ -391,7 +394,7 @@ static void MX_USART1_UART_Init(void)
|
|||||||
|
|
||||||
/* USER CODE END USART1_Init 1 */
|
/* USER CODE END USART1_Init 1 */
|
||||||
huart1.Instance = USART1;
|
huart1.Instance = USART1;
|
||||||
huart1.Init.BaudRate = 1152000;
|
huart1.Init.BaudRate = 1000000;
|
||||||
huart1.Init.WordLength = UART_WORDLENGTH_8B;
|
huart1.Init.WordLength = UART_WORDLENGTH_8B;
|
||||||
huart1.Init.StopBits = UART_STOPBITS_1;
|
huart1.Init.StopBits = UART_STOPBITS_1;
|
||||||
huart1.Init.Parity = UART_PARITY_NONE;
|
huart1.Init.Parity = UART_PARITY_NONE;
|
||||||
@@ -498,6 +501,22 @@ static void MX_GPIO_Init(void)
|
|||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
//*Configure CAN1 pins : PB8, PB9 */
|
||||||
|
GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||||
|
GPIO_InitStruct.Alternate = GPIO_AF9_CAN1;
|
||||||
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
//*Configure CAN2 pins : PB12, PB13 */
|
||||||
|
GPIO_InitStruct.Pin = GPIO_PIN_12 | GPIO_PIN_13;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||||
|
GPIO_InitStruct.Alternate = GPIO_AF9_CAN2;
|
||||||
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||||
|
|
||||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
DEBUG_PRINT("[L] GPIO initialized\r\n");
|
DEBUG_PRINT("[L] GPIO initialized\r\n");
|
||||||
/* USER CODE END MX_GPIO_Init_2 */
|
/* USER CODE END MX_GPIO_Init_2 */
|
||||||
@@ -538,25 +557,28 @@ void Error_Handler(void)
|
|||||||
|
|
||||||
/* USER CODE BEGIN Error_Handler_Debug */
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
/* User can add his own implementation to report the HAL error return state */
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
if (HAL_CAN_GetState(&hcan1) != HAL_CAN_STATE_READY)
|
||||||
|
{
|
||||||
|
DEBUG_PRINT("[E] CAN1 error code: 0x%08lX\r\n", (unsigned long)HAL_CAN_GetError(&hcan1));
|
||||||
|
}
|
||||||
|
if (HAL_CAN_GetState(&hcan2) != HAL_CAN_STATE_READY)
|
||||||
|
{
|
||||||
|
DEBUG_PRINT("[E] CAN2 error code: 0x%08lX\r\n", (unsigned long)HAL_CAN_GetError(&hcan2));
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: write error to SD
|
||||||
|
|
||||||
|
/* Disabling interrupts here (after reporting above) freezes the FreeRTOS
|
||||||
|
scheduler for good, since it relies on SysTick/PendSV. */
|
||||||
__disable_irq();
|
__disable_irq();
|
||||||
|
|
||||||
//TODO: check if it is necessary to stop FreeRTOS
|
|
||||||
|
|
||||||
uint32_t error_code_can1;
|
|
||||||
uint32_t error_code_can2;
|
|
||||||
|
|
||||||
if (HAL_CAN_GetState(&hcan1) != HAL_CAN_STATE_READY) error_code_can1 = HAL_CAN_GetError(&hcan1);
|
|
||||||
if (HAL_CAN_GetState(&hcan2) != HAL_CAN_STATE_READY) error_code_can2 = HAL_CAN_GetError(&hcan2);
|
|
||||||
|
|
||||||
// TODO: write error to SD and/or serial
|
|
||||||
|
|
||||||
HAL_GPIO_WritePin(led_can1.port, led_can1.pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(led_can1.port, led_can1.pin, GPIO_PIN_RESET);
|
||||||
HAL_GPIO_WritePin(led_can2.port, led_can2.pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(led_can2.port, led_can2.pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
HAL_GPIO_TogglePin(led_error.port, led_error.pin);
|
HAL_GPIO_TogglePin(led_error.port, led_error.pin);
|
||||||
HAL_Delay(250);
|
for(volatile uint32_t i = 0; i < 4000000; i++);
|
||||||
}
|
}
|
||||||
/* USER CODE END Error_Handler_Debug */
|
/* USER CODE END Error_Handler_Debug */
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-1
@@ -41,7 +41,8 @@
|
|||||||
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
/* Private variables ---------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN PV */
|
/* USER CODE BEGIN PV */
|
||||||
|
extern CAN_HandleTypeDef hcan1;
|
||||||
|
extern CAN_HandleTypeDef hcan2;
|
||||||
/* USER CODE END PV */
|
/* USER CODE END PV */
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
@@ -250,4 +251,20 @@ void DMA2_Stream7_IRQHandler(void)
|
|||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function handles CAN1 RX0 interrupt.
|
||||||
|
*/
|
||||||
|
void CAN1_RX0_IRQHandler(void)
|
||||||
|
{
|
||||||
|
HAL_CAN_IRQHandler(&hcan1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function handles CAN2 RX0 interrupt.
|
||||||
|
*/
|
||||||
|
void CAN2_RX0_IRQHandler(void)
|
||||||
|
{
|
||||||
|
HAL_CAN_IRQHandler(&hcan2);
|
||||||
|
}
|
||||||
|
|
||||||
/* USER CODE END 1 */
|
/* USER CODE END 1 */
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.ip_address_local" value="localhost"/>
|
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.ip_address_local" value="localhost"/>
|
||||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.limit_swo_clock.enabled" value="false"/>
|
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.limit_swo_clock.enabled" value="false"/>
|
||||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.limit_swo_clock.value" value=""/>
|
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.limit_swo_clock.value" value=""/>
|
||||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.loadList" value="{"fItems":[{"fIsFromMainTab":true,"fPath":"Debug/can-logger.elf","fProjectName":"can-logger","fPerformBuild":true,"fDownload":true,"fLoadSymbols":true}]}"/>
|
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.loadList" value="{"fItems":[{"fIsFromMainTab":true,"fPath":"/Users/erickahmed/TESI/j1939-can-logger_NEW/can-logger/can-logger/Debug/can-logger.elf","fProjectName":"can-logger","fPerformBuild":true,"fDownload":true,"fLoadSymbols":true}]}"/>
|
||||||
<intAttribute key="com.st.stm32cube.ide.mcu.debug.launch.mode" value="0"/>
|
<intAttribute key="com.st.stm32cube.ide.mcu.debug.launch.mode" value="0"/>
|
||||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.multi_drop_enabled" value="false"/>
|
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.multi_drop_enabled" value="false"/>
|
||||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.override_start_address_mode" value="default"/>
|
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.override_start_address_mode" value="default"/>
|
||||||
@@ -74,9 +74,9 @@
|
|||||||
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_START_MODE" value="remote"/>
|
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_START_MODE" value="remote"/>
|
||||||
<booleanAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN" value="true"/>
|
<booleanAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN" value="true"/>
|
||||||
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN_SYMBOL" value="main"/>
|
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN_SYMBOL" value="main"/>
|
||||||
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="Debug/can-logger.elf"/>
|
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="/Users/erickahmed/TESI/j1939-can-logger_NEW/can-logger/can-logger/Debug/can-logger.elf"/>
|
||||||
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="can-logger"/>
|
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="can-logger"/>
|
||||||
<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="true"/>
|
<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/>
|
||||||
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.642969664"/>
|
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.642969664"/>
|
||||||
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/>
|
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/>
|
||||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
|
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
|
||||||
|
|||||||
Reference in New Issue
Block a user