2021-12-12 03:37 AM
I noticed that some of the pins are configured in MX_GPIO_init() while others are not. They seem to have been configured somewhere else, so I'm not sure where to check if my pins were set properly.
Also, some of the pin configurations are not updated after manually changing the pin outs. For example, SPI2_NSS_Pin, which is "#define SPI2_NSS_Pin GPIO_PIN_11" in main.h, is still configured as "GPIO_PIN_11" in MX_GPIO_init() despite the fact that I changed it to another pin in STM32CUBEMX.
That said, I am quite confused on how the code generator works and how the pins are configured. Also, is it better to use stm32cubemx to generate code or would it be easier to manually configure everything from scratch? Thanks for the help
Solved! Go to Solution.
2021-12-12 09:40 AM
MX_GPIO_Init initializes non-peripheral pins, such as buttons or EXTI pins or LEDs, or other General Purpose Input Output pins.
2021-12-12 03:58 AM
Hmm.. to know if all the pins you configured are well... configured, go in debug mode and put a breakpoint at the main() loop (if bare metal), inspect HW registers GPIO ports and see once maually that all is well done. You also need to "regenerate code" to make sure the compiled and built code is updated down to the BIN file
2021-12-12 07:12 AM
SPI pins are configured in HAL_SPI_MspInit which is located in stm32xxx_hal_msp.c and is called from within HAL_SPI_Init. Other peripherals are similar.
> That said, I am quite confused on how the code generator works and how the pins are configured. Also, is it better to use stm32cubemx to generate code or would it be easier to manually configure everything from scratch? Thanks for the help
Up to you. Generally the code generator does a good job initializing everything and will be faster than doing it yourself. Opinions vary.
2021-12-12 09:21 AM
Interesting. I checked the stm32xxx_hal_msp.c file and the pins are configured correctly. So either it is intialised in main.c in MX_GPIO_Init() or stm32xxx_hal_msp.c (as I noticed that some of the pins are intialised there). Then, what does MX_GPIO_Init() do in main.c and how do I know if it is initialised in main.c or stm32xxx_hal_msp.c?
Thank you for your help!
2021-12-12 09:40 AM
MX_GPIO_Init initializes non-peripheral pins, such as buttons or EXTI pins or LEDs, or other General Purpose Input Output pins.
2021-12-12 09:05 PM
I see. Thank you for your help!