cancel
Showing results for 
Search instead for 
Did you mean: 

Missing alternate function on SPI-Pins in CubeMX-generated-code.

Florian Moser
Senior

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Ghofrane GSOURI
ST Employee

Hello @Florian Moser​ 

I am glad to inform you that the Internal ticket number: 135607 is fixed and integrated in the latest CubeMX version 6.8.0 .

This is the LINK for downloading it .

Thanks again for your contributions .

Ghofrane.

View solution in original post

8 REPLIES 8
Ghofrane GSOURI
ST Employee

Hi @Florian Moser​ 

uC: STM32H725AEIx

FW-Package: STM32Cube FW_H7 V1.10.0

CubeMX-Version: 6.6.1

I created a project where i activated the SPI2 only (same configuration as you ) to make sure of the existence of the issue that you mentioned before ; i checked the function "HAL_SPI_MspInit" and i found The configuration for `Alternate`

0693W00000SwGQrQAN.png 

Kind regards

Ghofrane

Thanks for your response!

It generated it for PD3 and PC1, but not for PC2 in your case.

Please try using the same GPIO as me and you will more likely run into that bug:

  • SCK: PB13
  • MISO: PC2
  • MOSI: PC3

Ghofrane GSOURI
ST Employee

Hi @Florian Moser​ 

I reproduced the configuration using the same  GPIO as you said

  • SCK: PB13
  • MISO: PC2
  • MOSI: PC3

0693W00000SwKRtQAN.pngI found this :

0693W00000SwKUEQA3.pngPlease have a look .

Kind regards

Ghofrane

Thank you for reproducing!

That's exactly the bug I am describing.

For PC2 and PC3 following line is missing in the CubeMX-generated code:

GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;

(Should be between lines 116 and 117 in your screenshot code)

Without that line, the MOSI pin isn't working, it just stays low.

Hope this bug get's fixed soon!

Ghofrane GSOURI
ST Employee

Hi @Florian Moser​ 

Thank you for your contributions and for your detailed explanations,

I confirm the issue on my side, it has been reported to STM32CubeMX development team .

Internal ticket number: 135607(This is an internal tracking number and is not accessible or usable by customers).

I will keep you posted with updates.

Regards,

Ghofrane

Thank you very much!

Ghofrane GSOURI
ST Employee

Hello @Florian Moser​ 

I am glad to inform you that the Internal ticket number: 135607 is fixed and integrated in the latest CubeMX version 6.8.0 .

This is the LINK for downloading it .

Thanks again for your contributions .

Ghofrane.

Florian Moser
Senior

Nice, thank you!