Skip to content
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

Guard STM peripheral files #345

Open
BlakeFreer opened this issue Nov 30, 2024 · 0 comments
Open

Guard STM peripheral files #345

BlakeFreer opened this issue Nov 30, 2024 · 0 comments
Assignees

Comments

@BlakeFreer
Copy link
Contributor

BlakeFreer commented Nov 30, 2024

The stm mcal files rely on files which are generated per-project by CubeMX. Thus if a project does not use a peripheral (say ADC), then the mcal/stm/periph/adc.hpp file will have a ton of errors since the file does not exist.

We can use #ifdef guards to detect if the current project uses each peripheral and enable / disable the whole file accordingly. CubeMX generates an stm32f7xx_hal.h file which includes ...hal_conf.h which has #define statements to indicate which peripherals are enabled.

For an example, see mcal/stm32f767/periph/can.hpp and can.cc in the dev/can branch. https://github.com/macformula/racecar/blob/dev/can/firmware/mcal/stm32f767/periph/can.hpp

//// can.hpp ////
#include "stm32f7xx_hal.h"
#ifdef HAL_CAN_MODULE_ENABLED // this disables the code if #define HAL_CAN is commented out below


//// stm32f7xx_hal.h ////
#include "stm32f7xx_hal_conf.h"


//// stm32f7xx_hal_conf.h ////
/* #define HAL_CRYP_MODULE_ENABLED */
#define HAL_ADC_MODULE_ENABLED
#define HAL_CAN_MODULE_ENABLED
/* #define HAL_CEC_MODULE_ENABLED */
/* #define HAL_CRC_MODULE_ENABLED */

Task

  1. Create a branch off of dev/can

  2. Guard all of the other peripheral files

  3. Make a PR. Select dev/can as the base branch

@Micnasr Micnasr self-assigned this Mar 2, 2025
@saadatq saadatq self-assigned this Mar 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants