Compare commits
1 Commits
v0.0.4
..
8576603e6d
| Author | SHA1 | Date | |
|---|---|---|---|
| 8576603e6d |
@@ -22,7 +22,6 @@
|
||||
|
||||
#include "main.h"
|
||||
|
||||
void uart_printf(const char *fmt, ...);
|
||||
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart);
|
||||
void vUARTLogger(void *argument);
|
||||
|
||||
|
||||
+6
-4
@@ -18,7 +18,6 @@
|
||||
#include "main.h"
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "cansend.h"
|
||||
#include "cmsis_os.h"
|
||||
#include <string.h>
|
||||
/* USER CODE END Includes */
|
||||
@@ -94,7 +93,10 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
|
||||
led_task = xCAN2LedTask;
|
||||
}
|
||||
|
||||
if (osMessageQueuePut(queue, &message, 0U, 0U) == osOK) osThreadFlagsSet(led_task, 0x01);
|
||||
if (osMessageQueuePut(queue, &message, 0U, 0U) == osOK)
|
||||
{
|
||||
osThreadFlagsSet(led_task, 0x01);
|
||||
}
|
||||
}
|
||||
/* END HAL_CAN_RxFifo0MsgPendingCallback */
|
||||
|
||||
@@ -114,7 +116,7 @@ void vCANListener(void *argument)
|
||||
HAL_CAN_ActivateNotification(hcan, CAN_IT_RX_FIFO0_MSG_PENDING);
|
||||
|
||||
uint32_t irqn = (hcan->Instance == CAN1) ? CAN1_RX0_IRQn : CAN2_RX0_IRQn;
|
||||
HAL_NVIC_SetPriority(irqn, 5, 0);
|
||||
HAL_NVIC_SetPriority(irqn, 6, 0);
|
||||
HAL_NVIC_EnableIRQ(irqn);
|
||||
|
||||
for (;;)
|
||||
@@ -131,7 +133,7 @@ void vCANListener(void *argument)
|
||||
|
||||
/* BEGIN vLEDHeartbeat */
|
||||
/**
|
||||
* @brief Turn on LED when CAN traffic is detected
|
||||
* @brief Blink a LED in heartbeat mode when CAN traffic is detected
|
||||
* @param argument: LED GPIO (port and pin)
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
+15
-37
@@ -50,16 +50,13 @@ void uart_printf(const char *fmt, ...)
|
||||
{
|
||||
if (osKernelGetState() == osKernelRunning && __get_IPSR() == 0)
|
||||
{
|
||||
if (osSemaphoreAcquire(xUARTDMASemaphore, 100U) == osOK)
|
||||
if (osSemaphoreAcquire(xUARTDMASemaphore, osWaitForever) == osOK)
|
||||
{
|
||||
HAL_UART_Transmit(&huart1, (uint8_t*)buf, len, HAL_MAX_DELAY);
|
||||
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 */
|
||||
@@ -124,31 +121,22 @@ static int format_can_message(char *buf, uint8_t source, const CanMessage_t *mes
|
||||
*/
|
||||
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
|
||||
{
|
||||
if (huart->Instance == USART1) osSemaphoreRelease(xUARTDMASemaphore);
|
||||
if (huart->Instance == USART1)
|
||||
{
|
||||
osSemaphoreRelease(xUARTDMASemaphore);
|
||||
}
|
||||
}
|
||||
/* END HAL_UART_TxCpltCallback */
|
||||
|
||||
/* BEGIN HAL_UART_ErrorCallback */
|
||||
/**``MEN
|
||||
* @brief Handle UART errors
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
__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);
|
||||
}
|
||||
if (huart->Instance == USART1) osSemaphoreRelease(xUARTDMASemaphore);
|
||||
}
|
||||
/* END HAL_UART_ErrorCallback */
|
||||
|
||||
@@ -161,23 +149,15 @@ void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
|
||||
void vUARTLogger(void *argument)
|
||||
{
|
||||
CanMessage_t message;
|
||||
static char tx_buffer[45];
|
||||
|
||||
#ifdef DEBUG_DUMMY_FRAME
|
||||
CanMessage_t dummy_frame = {
|
||||
.id = 0x0CF00400, // J1939 EEC1 ID
|
||||
.dlc = 8, // 8 bytes of data
|
||||
.isExtended = 1, // 29-bit Extended ID
|
||||
.source = 1, // CAN1
|
||||
.payload = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x11, 0x22}
|
||||
};
|
||||
#endif
|
||||
char tx_buffer[45];
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (osMessageQueueGet(xUARTQueue, &message, NULL, 1000U) == osOK)
|
||||
DEBUG_PRINT("[D] Waiting for CAN traffic...\r\n");
|
||||
|
||||
if (osMessageQueueGet(xUARTQueue, &message, NULL, osWaitForever) == osOK)
|
||||
{
|
||||
if (osSemaphoreAcquire(xUARTDMASemaphore, 100U) == osOK)
|
||||
if (osSemaphoreAcquire(xUARTDMASemaphore, osWaitForever) == osOK)
|
||||
{
|
||||
int len = format_can_message(tx_buffer, message.source, &message);
|
||||
|
||||
@@ -187,9 +167,7 @@ void vUARTLogger(void *argument)
|
||||
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("[D] Waiting for CAN traffic...\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
/* END vUARTLogger */
|
||||
|
||||
+4
-20
@@ -127,12 +127,12 @@ int main(void)
|
||||
/* USER CODE END SysInit */
|
||||
|
||||
/* Initialize all configured peripherals */
|
||||
MX_DMA_Init();
|
||||
MX_GPIO_Init();
|
||||
MX_USART1_UART_Init();
|
||||
MX_DMA_Init();
|
||||
MX_CAN1_Init();
|
||||
MX_CAN2_Init();
|
||||
MX_SDIO_SD_Init();
|
||||
MX_USART1_UART_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
DEBUG_PRINT("[L] Initializing CAN bus logger\r\n");
|
||||
CAN_Logger_Init(&hcan1, &hcan2);
|
||||
@@ -498,22 +498,6 @@ static void MX_GPIO_Init(void)
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
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 */
|
||||
DEBUG_PRINT("[L] GPIO initialized\r\n");
|
||||
/* USER CODE END MX_GPIO_Init_2 */
|
||||
@@ -571,8 +555,8 @@ void Error_Handler(void)
|
||||
|
||||
while (1)
|
||||
{
|
||||
HAL_GPIO_TogglePin(led_error.port, led_error.pin);
|
||||
for(volatile uint32_t i = 0; i < 4000000; i++);
|
||||
HAL_GPIO_TogglePin(led_error.port, led_error.pin);
|
||||
HAL_Delay(250);
|
||||
}
|
||||
/* USER CODE END Error_Handler_Debug */
|
||||
}
|
||||
|
||||
+1
-18
@@ -41,8 +41,7 @@
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PV */
|
||||
extern CAN_HandleTypeDef hcan1;
|
||||
extern CAN_HandleTypeDef hcan2;
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
@@ -251,20 +250,4 @@ void DMA2_Stream7_IRQHandler(void)
|
||||
|
||||
/* 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 */
|
||||
|
||||
Reference in New Issue
Block a user