Compare commits
12 Commits
4da8f59330
...
v0.0.4
| Author | SHA1 | Date | |
|---|---|---|---|
| e32f501285 | |||
| 85c8cd4eed | |||
| 9a58e41d55 | |||
| 48aaaf7fb8 | |||
| 4236c204a6 | |||
| 2d7e7f514a | |||
| 600a4e24d8 | |||
| 6954fc5497 | |||
| 03fec5ff34 | |||
| 76f6526036 | |||
| ff1335b0dc | |||
| 397711e9fb |
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "main.h"
|
||||
|
||||
void uart_printf(const char *fmt, ...);
|
||||
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart);
|
||||
void vUARTLogger(void *argument);
|
||||
|
||||
|
||||
+3
-2
@@ -18,6 +18,7 @@
|
||||
#include "main.h"
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "cansend.h"
|
||||
#include "cmsis_os.h"
|
||||
#include <string.h>
|
||||
/* USER CODE END Includes */
|
||||
@@ -113,7 +114,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, 6, 0);
|
||||
HAL_NVIC_SetPriority(irqn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(irqn);
|
||||
|
||||
for (;;)
|
||||
@@ -130,7 +131,7 @@ void vCANListener(void *argument)
|
||||
|
||||
/* 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)
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
+21
-22
@@ -50,7 +50,7 @@ void uart_printf(const char *fmt, ...)
|
||||
{
|
||||
if (osKernelGetState() == osKernelRunning && __get_IPSR() == 0)
|
||||
{
|
||||
if (osSemaphoreAcquire(xUARTDMASemaphore, osWaitForever) == osOK)
|
||||
if (osSemaphoreAcquire(xUARTDMASemaphore, 100U) == osOK)
|
||||
{
|
||||
HAL_UART_Transmit(&huart1, (uint8_t*)buf, len, HAL_MAX_DELAY);
|
||||
osSemaphoreRelease(xUARTDMASemaphore);
|
||||
@@ -124,22 +124,31 @@ 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 */
|
||||
/**
|
||||
* @brief Safely release UART semaphore inside ISR and yield task if possible.
|
||||
/**``MEN
|
||||
* @brief Handle UART errors
|
||||
* @param argument: UART handle
|
||||
* @retval None
|
||||
*/
|
||||
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 */
|
||||
|
||||
@@ -152,7 +161,7 @@ void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
|
||||
void vUARTLogger(void *argument)
|
||||
{
|
||||
CanMessage_t message;
|
||||
char tx_buffer[45];
|
||||
static char tx_buffer[45];
|
||||
|
||||
#ifdef DEBUG_DUMMY_FRAME
|
||||
CanMessage_t dummy_frame = {
|
||||
@@ -166,19 +175,9 @@ void vUARTLogger(void *argument)
|
||||
|
||||
for (;;)
|
||||
{
|
||||
uint32_t queue_timeout = 2500U;
|
||||
|
||||
//#ifdef DEBUG_DUMMY_FRAME
|
||||
//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)
|
||||
if (osMessageQueueGet(xUARTQueue, &message, NULL, 1000U) == osOK)
|
||||
{
|
||||
if (osSemaphoreAcquire(xUARTDMASemaphore, 100U) == osOK)
|
||||
{
|
||||
int len = format_can_message(tx_buffer, message.source, &message);
|
||||
|
||||
|
||||
+20
-4
@@ -127,9 +127,9 @@ int main(void)
|
||||
/* USER CODE END SysInit */
|
||||
|
||||
/* Initialize all configured peripherals */
|
||||
MX_USART1_UART_Init();
|
||||
MX_GPIO_Init();
|
||||
MX_DMA_Init();
|
||||
MX_GPIO_Init();
|
||||
MX_USART1_UART_Init();
|
||||
MX_CAN1_Init();
|
||||
MX_CAN2_Init();
|
||||
MX_SDIO_SD_Init();
|
||||
@@ -498,6 +498,22 @@ 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 */
|
||||
@@ -555,8 +571,8 @@ void Error_Handler(void)
|
||||
|
||||
while (1)
|
||||
{
|
||||
HAL_GPIO_TogglePin(led_error.port, led_error.pin);
|
||||
HAL_Delay(250);
|
||||
HAL_GPIO_TogglePin(led_error.port, led_error.pin);
|
||||
for(volatile uint32_t i = 0; i < 4000000; i++);
|
||||
}
|
||||
/* USER CODE END Error_Handler_Debug */
|
||||
}
|
||||
|
||||
+18
-1
@@ -41,7 +41,8 @@
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
extern CAN_HandleTypeDef hcan1;
|
||||
extern CAN_HandleTypeDef hcan2;
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
@@ -250,4 +251,20 @@ 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