Senior
September 22, 2022
Solved
Missing alternate function on SPI-Pins in CubeMX-generated-code.
- September 22, 2022
- 5 replies
- 3227 views
uC: STM32H725AEIx
FW-Package: STM32Cube FW_H7 V1.10.0
CubeMX-Version: 6.6.1
IOC-File: Attached (SPI_bug.ioc)
I tried to generate code with CubeMX for my project. I set up SPI2 as Full-Duplex Master without hardware NSS with the follwing pin config:
- SCK: PB13
- MISO: PC2
- MOSI: PC3
The code generated in `void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)` looks like the following for MOSI and MISO:
GPIO_InitStruct.Pin = SPI_MISO_Pin|SPI_MOSI_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);Although it should look like that:
GPIO_InitStruct.Pin = SPI_MISO_Pin|SPI_MOSI_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);=> The configuration for `Alternate` is missing!
With the generated code, the MOSI and MISO lines do not work at all, while the SCK is doing its thing. After the fix they work like a charm.
