-
Notifications
You must be signed in to change notification settings - Fork 0
SGF-7 Adding CAN Driver #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a comprehensive dual CAN/FDCAN driver for STM32 microcontrollers to support both bxCAN (STM32L4) and FDCAN (STM32U5) peripherals. The driver provides hardware filter configuration, callback-based message routing, and RTOS-based transmit/receive handling.
Key changes:
- Complete rewrite of the CAN driver with unified API for both CAN and FDCAN peripherals
- Addition of CANFrame class for message handling with mutex-based thread safety
- Implementation of hardware filtering and callback system for message routing
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.
Show a summary per file
File | Description |
---|---|
resources/Drivers/SG_Drivers/CAN/Src/CanDriver.cpp | Complete implementation of dual CAN/FDCAN driver with filtering, callbacks, and RTOS integration |
resources/Drivers/SG_Drivers/CAN/Include/CanDriverApi.hpp | API definitions and type aliases for CAN/FDCAN compatibility |
resources/Drivers/SG_Drivers/CAN/Include/CanDriver.hpp | Header with CANDevice and CANFrame class definitions |
firmware/CAN-DevBoard/user/src/user_threads.cpp | Example usage of the new CAN driver API |
firmware/NUCLEOL476RG-FreeRTOS-ExampleProject/CMakeLists.txt | Build system updates to include CAN driver |
Various header/source files | Code formatting and include order improvements |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
* @param msg | ||
* @return HAL_StatusTypeDef | ||
*/ | ||
HAL_StatusTypeDef Send(CANFrame* msg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HAL_StatusTypeDef Send(CANFrame* msg); | |
static HAL_StatusTypeDef Send(CANFrame* msg); |
Make this static
* @param id The CAN identifier to match against (11-bit or 29-bit depending on @p id_type). | ||
* @return const CanCallback* if found, nullptr if no connected callback | ||
*/ | ||
const CanCallback* find_by_range(uint32_t id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to private
* @param id The CAN identifier to match against (11-bit or 29-bit depending on @p id_type). | ||
* @return const CanCallback* if found, nullptr if no connected callback | ||
*/ | ||
const CanCallback* find_by_id(uint32_t id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to private
CanHandle_t* hcan_ = nullptr; | ||
|
||
std::vector<CanFilter_t> filters_; | ||
std::vector<IdEntry> idCallbacks_; | ||
std::vector<RangeEntry> rangeCallbacks_; | ||
CanCallback allCallback_ = nullptr; | ||
|
||
osMessageQueueId_t tx_queue_ = osMessageQueueNew(TX_QUEUE_SIZE, sizeof(CANFrame*), NULL); | ||
|
||
CANDevice(const CANDevice&) = delete; | ||
CANDevice& operator=(const CANDevice&) = delete; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean up formatting
#define THREAD_PRIORITY osPriorityAboveNormal /* Priority of Rx and Tx threads */ | ||
|
||
#define NUM_FILTER_BANKS 14 | ||
#define NUM_CAN_CALLBACKS 16 | ||
|
||
#define THREAD_STACK_SIZE_WORDS 512 | ||
|
||
#define TX_QUEUE_SIZE 3 /* Size of Tx message queue */ | ||
#define TX_TIMEOUT 10 /* Timeout for tx thread in ms */ | ||
|
||
#define MAX_CAN_ID 0x7FFu | ||
|
||
#ifndef CANDEVICE_MAX_BUSES | ||
#define CANDEVICE_MAX_BUSES 2 | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean up formatting and add more comments
Added dual CAN/FDCAN driver for stm32s.
Code marked as draft until tested on hardware.