cancel
Showing results for 
Search instead for 
Did you mean: 

Use alternate function STM32F405

SBaro.11
Associate III

 

Hi,

I'm a little lost, I would like to use the alternative6 (AF6) function on my stm32f405. I tried to do it via cube mx by configuring the pins but the generated code seems strange to me :

So for me I'd like to use SPI3 with PB3/4/5 so AF6 in datasheet. But if I configured that on cubemx I got this:

 

 

static void MX_SPI3_Init(void)

{


/* USER CODE BEGIN SPI3_Init 0 */


/* USER CODE END SPI3_Init 0 */


/* USER CODE BEGIN SPI3_Init 1 */


/* USER CODE END SPI3_Init 1 */

/* SPI3 parameter configuration*/

hspi3.Instance = SPI3;

hspi3.Init.Mode = SPI_MODE_MASTER;

hspi3.Init.Direction = SPI_DIRECTION_2LINES;

hspi3.Init.DataSize = SPI_DATASIZE_8BIT;

hspi3.Init.CLKPolarity = SPI_POLARITY_LOW;

hspi3.Init.CLKPhase = SPI_PHASE_1EDGE;

hspi3.Init.NSS = SPI_NSS_SOFT;

hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;

hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;

hspi3.Init.TIMode = SPI_TIMODE_DISABLE;

hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;

hspi3.Init.CRCPolynomial = 10;

if (HAL_SPI_Init(&hspi3) != HAL_OK)

{

Error_Handler();

}

/* USER CODE BEGIN SPI3_Init 2 */


/* USER CODE END SPI3_Init 2 */


}

 

 

 

And for GPIO init

 

 

 

static void MX_GPIO_Init(void)

{

GPIO_InitTypeDef GPIO_InitStruct = {0};

/* USER CODE BEGIN MX_GPIO_Init_1 */

/* USER CODE END MX_GPIO_Init_1 */


/* GPIO Ports Clock Enable */

__HAL_RCC_GPIOC_CLK_ENABLE();

__HAL_RCC_GPIOH_CLK_ENABLE();

__HAL_RCC_GPIOA_CLK_ENABLE();

__HAL_RCC_GPIOB_CLK_ENABLE();


/*Configure GPIO pin Output Level */

HAL_GPIO_WritePin(GPIOC, LED_R_Pin|LED_G_Pin|LED_B_Pin, GPIO_PIN_SET);


/*Configure GPIO pins : LED_R_Pin LED_G_Pin LED_B_Pin */

GPIO_InitStruct.Pin = LED_R_Pin|LED_G_Pin|LED_B_Pin;

GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

GPIO_InitStruct.Pull = GPIO_NOPULL;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);


/* USER CODE BEGIN MX_GPIO_Init_2 */

/* USER CODE END MX_GPIO_Init_2 */

}

 

 

So for me thuis function is strange why I don't see somewhere Alternate_function use ?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SofLit
ST Employee

Hello,

Check the stm32f4xx_hal_msp.c file.

All the AFs which are configured with CubeMx are located in the msp file.

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.

View solution in original post

2 REPLIES 2
SofLit
ST Employee

Hello,

Check the stm32f4xx_hal_msp.c file.

All the AFs which are configured with CubeMx are located in the msp file.

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.

nice thanks everything is clear now :beaming_face_with_smiling_eyes: