6 Commits

Author SHA1 Message Date
eeeck 7dcdbbadf1 Implement print for UART logging 2026-06-24 17:10:37 +02:00
eeeck 334295e1cd Disable UARTrx 2026-06-24 17:03:22 +02:00
eeeck 89cd1e00d0 Remove whitespace 2026-06-24 08:11:11 +02:00
eeeck 591a96cf6d Increase CAN task size 2026-06-24 08:10:59 +02:00
eeeck 2be0f0370e Use larger baudrate 2026-06-24 08:10:49 +02:00
eeeck 58c4b66f34 Try different prescalers 2026-06-24 08:10:41 +02:00
3 changed files with 42 additions and 8 deletions
+1 -1
View File
@@ -52,7 +52,7 @@ extern "C" {
#include <stdio.h> #include <stdio.h>
#define DEBUG_PRINT(...) printf(__VA_ARGS__) #define DEBUG_PRINT(...) printf(__VA_ARGS__)
#else #else
#define DEBUG_PRINT(...) #define DEBUG_PRINT(...) uart_printf(__VA_ARGS__)
#endif #endif
/* USER CODE END EM */ /* USER CODE END EM */
+35
View File
@@ -20,11 +20,46 @@
#include "main.h" #include "main.h"
#include "cmsis_os.h" #include "cmsis_os.h"
#include "canlog.h" #include "canlog.h"
#include <stdio.h>
#include <stdarg.h>
#include "cmsis_os.h"
#include "stm32f4xx.h"
/* USER CODE END Includes */ /* USER CODE END Includes */
extern UART_HandleTypeDef huart1; extern UART_HandleTypeDef huart1;
extern osSemaphoreId_t xUARTDMASemaphore; extern osSemaphoreId_t xUARTDMASemaphore;
extern osMessageQueueId_t xUARTQueue; extern osMessageQueueId_t xUARTQueue;
extern UART_HandleTypeDef huart1;
extern osSemaphoreId_t xUARTDMASemaphore;
/* BEGIN uart_printf */
/**
* @brief Implementation of a simple print to UART.
* @param arguments: strings to print
* @retval None
*/
void uart_printf(const char *fmt, ...)
{
static char buf[128];
va_list args;
va_start(args, fmt);
int len = vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
if (len > 0)
{
if (osKernelGetState() == osKernelRunning && __get_IPSR() == 0)
{
if (osSemaphoreAcquire(xUARTDMASemaphore, osWaitForever) == osOK)
{
if (HAL_UART_Transmit_DMA(&huart1, (uint8_t*)buf, len) != HAL_OK) osSemaphoreRelease(xUARTDMASemaphore);
else osSemaphoreAcquire(xUARTDMASemaphore, osWaitForever);
}
}
else HAL_UART_Transmit(&huart1, (uint8_t*)buf, len, HAL_MAX_DELAY);
}
}
/* END uart_printf */
/* BEGIN format_can_message */ /* BEGIN format_can_message */
/** /**
+6 -7
View File
@@ -95,7 +95,6 @@ int _write(int file, char *ptr, int len)
*/ */
int main(void) int main(void)
{ {
/* USER CODE BEGIN 1 */ /* USER CODE BEGIN 1 */
if (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) if (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk)
{ {
@@ -145,12 +144,12 @@ int main(void)
/* USER CODE BEGIN RTOS_TASKS */ /* USER CODE BEGIN RTOS_TASKS */
const osThreadAttr_t CAN1rxAttributes = { const osThreadAttr_t CAN1rxAttributes = {
.name = "CAN1rx", .name = "CAN1rx",
.stack_size = 128 * 4, .stack_size = 512 * 4,
.priority = (osPriority_t) osPriorityRealtime1, .priority = (osPriority_t) osPriorityRealtime1,
}; };
const osThreadAttr_t CAN2rxAttributes = { const osThreadAttr_t CAN2rxAttributes = {
.name = "CAN2rx", .name = "CAN2rx",
.stack_size = 128 * 4, .stack_size = 512 * 4,
.priority = (osPriority_t) osPriorityRealtime, .priority = (osPriority_t) osPriorityRealtime,
}; };
const osThreadAttr_t UartLoggerAttributes = { const osThreadAttr_t UartLoggerAttributes = {
@@ -280,7 +279,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 = 8; hcan1.Init.Prescaler = 4;
hcan1.Init.Mode = CAN_MODE_SILENT; hcan1.Init.Mode = CAN_MODE_SILENT;
hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ; hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
hcan1.Init.TimeSeg1 = CAN_BS1_16TQ; hcan1.Init.TimeSeg1 = CAN_BS1_16TQ;
@@ -317,7 +316,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 = 16; hcan2.Init.Prescaler = 8;
hcan2.Init.Mode = CAN_MODE_SILENT; hcan2.Init.Mode = CAN_MODE_SILENT;
hcan2.Init.SyncJumpWidth = CAN_SJW_1TQ; hcan2.Init.SyncJumpWidth = CAN_SJW_1TQ;
hcan2.Init.TimeSeg1 = CAN_BS1_16TQ; hcan2.Init.TimeSeg1 = CAN_BS1_16TQ;
@@ -390,11 +389,11 @@ 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 = 115200; huart1.Init.BaudRate = 1152000;
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;
huart1.Init.Mode = UART_MODE_TX_RX; huart1.Init.Mode = UART_MODE_TX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16; huart1.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart1) != HAL_OK) if (HAL_UART_Init(&huart1) != HAL_OK)