cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F446RE CubeMX HAL-SPI Problem

Sven1
Associate II
Posted on July 06, 2016 at 15:41

Hello,

I habe a two problems with the SPI-communication between a Nucleo64 and a X-Nucleo-IHM01A1 => STM32F446RE to L6474.

1. The CubeMx 4.15 creates following code in the

void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)

**SPI1 GPIO Configuration

PA5------> SPI1_SCK

PA6------> SPI1_MISO

PA7------> SPI1_MOSI */

GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;

GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

GPIO_InitStruct.Pull = GPIO_NOPULL;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

�.} Why GPIO_PIN_6 (= MISO) is defined as an output? I think it should be an input!?

(I tried this also with other F4xx, F3xx and F7xx => all the same. It's already shown in the

CubeMX->Configuration->SPI-Settings->GPIO-Settings

  and can&sharpt be changed.

Funny thing: Creating project for a STM32F103RBT6 => MISO is an input!!

 So I modified the void HAL_SPI_MspInit to:

GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_7;

GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

GPIO_InitStruct.Pull = GPIO_NOPULL;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

GPIO_InitStruct.Pin = GPIO_PIN_6;

GPIO_InitStruct.Mode = GPIO_MODE_INPUT;

GPIO_InitStruct.Pull = GPIO_PULLUP;  // (also tried NOPULL)

GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;  // should be obsolent

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

With this Init and HAL_SPI_Transmit I can send bytes to the L6474 (Stepper Controller).

With my analyzer I can see, that the L6474 sends the correct response-bytes.

I try to read it with:

if(HAL_SPI_TransmitReceive(&hspi1, (uint8_t*)aTxBuffer, (uint8_t *)aRxBuffer, 1, 1000) != HAL_OK)

{ Error_Handler();        }

The aTxBuffer is loaded with 0x00 for clocking the SCK

�but the aRxBuffer is always empty.(0x00).

Where is the (my?) mistake?

The input-hardware should be fine � I can read a signal if I define Pin6 as a simple GPIO-input.

Thanks for your ideas

Sven

#cubemx-stm32f446-hal_spi
1 REPLY 1
Amel NASRI
ST Employee
Posted on July 14, 2016 at 12:37

Hi Sven,

Please note that the GPIOs are not managed the same way for STM32F1 family and other ones.

You can refer to the reference manual of each family to know the differences.

If the pin is configured in AF mode, it will be driven by the peripheral depending on its usage.  So, there is no need to configure MISO pin in input mode for example with STM32F4.

If you have issues with your generated project and updates you made for it, I suggest you review one of the SPI examples available in the STM32Cube packages. Test the example, and if it is OK compare your code with the one of the example.

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.