2021-03-21 04:58 PM
Can someone explain to me why CubeMX creates handles for objects within main but the GPIO configuration for that object (example an A/D or USART using DMA) is configured under the stm32l4xx_hal_msp.c instead of right within main as part of the object?
Solved! Go to Solution.
2021-03-24 07:59 AM
Hello @SWenn.1
Thank you for your post,
Actually, it's a kind of organization decided to be used for CubeMX code generation.
In fact, the stm32l4xx_hal_msp.c defines all initialization functions to configure the peripheral instances according to the user configuration such as the pin allocation, enabling of clock, use of DMA and Interrupts.
For the main.c, it is in charge of configuring and initializing the system clock and GPIOs that are not used by peripherals, in addition to that, the main.c define and call, for each configured peripheral, a peripheral initialization function that defines a handle structure that will be passed to the corresponding peripheral HAL init function which in turn will call the peripheral HAL MSP initialization function.
It's possible to gather the configuration generated in the two files by selecting the "Generate the peripheral Init as pair of '.c/.h'.." option as mentioned in the image below.
Hope my answer helped you :) when your question is answered, please close this topic by choosing Select as Best, it will help other user find that answer faster.
Thanks, Khouloud
2021-03-24 07:59 AM
Hello @SWenn.1
Thank you for your post,
Actually, it's a kind of organization decided to be used for CubeMX code generation.
In fact, the stm32l4xx_hal_msp.c defines all initialization functions to configure the peripheral instances according to the user configuration such as the pin allocation, enabling of clock, use of DMA and Interrupts.
For the main.c, it is in charge of configuring and initializing the system clock and GPIOs that are not used by peripherals, in addition to that, the main.c define and call, for each configured peripheral, a peripheral initialization function that defines a handle structure that will be passed to the corresponding peripheral HAL init function which in turn will call the peripheral HAL MSP initialization function.
It's possible to gather the configuration generated in the two files by selecting the "Generate the peripheral Init as pair of '.c/.h'.." option as mentioned in the image below.
Hope my answer helped you :) when your question is answered, please close this topic by choosing Select as Best, it will help other user find that answer faster.
Thanks, Khouloud