2024-07-05 12:08:14 +00:00
2024-01-23 16:32:07 +01:00
2024-07-05 14:06:49 +02:00
2024-03-08 13:56:19 +01:00
2024-07-05 14:06:49 +02:00
2024-07-05 14:06:49 +02:00
2024-07-05 14:06:49 +02:00
2024-07-05 14:06:49 +02:00
2024-07-05 14:06:49 +02:00
2024-07-05 14:06:49 +02:00
2024-02-23 16:51:20 +01:00
2024-07-05 14:06:49 +02:00
2024-07-05 14:06:49 +02:00
2023-12-29 18:15:50 +01:00
2024-07-05 14:06:49 +02:00
2024-07-05 12:08:14 +00:00
2024-07-05 14:06:49 +02:00
2023-10-25 16:19:32 +02:00
2023-10-25 16:19:32 +02:00

STM32 CAN Demo

This Project is a simple CAN Demo for STM32F407. It uses sta-core, rtos2-utils and TACOS.

Explanation

In the startup.cpp we register threads in the onManagerInit() func, by calling the following:

// Register Spam Thread to only run in the first state
addThread<demo::CanSpam>({ALL_STATES}, 0x123);
// Register Receive Thread to run in states 0 and 2
addThread<demo::CanReceiver>({0,2}, 0x124);

The CanSpam thread sends a message every 1 second, while the CanReceiver thread receives messages and prints them to the console. Sending is done by calling the following:

CanSysMsg msg;

msg.paylod = ...;               // Set the payload
msg.header.sid = getCanID();    // Use the ID of the thread
msg.header.format = 0;          // Set the format to standard id

sta::tacos::queueCanBusMsg(msg, 0); // Send the message, 0 means no timeout

As we can see here every task has a unique ID, which is used to identify the task. Trough this ID (which is set at construction), messages are automagically forwarded to the correct task.

Receiving is done by calling the following:

CanSysMsg msg;
if (CAN_queue_.get(&msg, osWaitForever))
{
    // use msg.payload and msg.header to access the data
}

Setup

The only thing one must change outside of the App repository (and ofc the including of the Libs) is starting the ALPAKA stack in Core/freertos.c:

void StartDefaultTask(void *argument)
{
  /* USER CODE BEGIN StartDefaultTask */
  /* Infinite loop */

	extern void startALPAKA(void *);
	startALPAKA(argument);
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END StartDefaultTask */
}

Notes

We are using one of our own "ASEAG" modules which have a special define in the config.hpp to indicate the CAN bus and UART output. To replicate this for other hardware one must define STA_STM32_USART_HANDLE and STA_STM32_CAN_HANDLE in the config.hpp file.

Description
No description provided
Readme GPL-3.0 21 MiB
Languages
C 99.4%
Assembly 0.5%