Skip to main content
Associate II
February 17, 2025
Solved

STM32F103: Option to assign pins to core M3 in CubeMX

  • February 17, 2025
  • 3 replies
  • 778 views

Hello,
When generating code via CubeMX, the main code does not contain the configuration for the GPIO pins I need to be using.

I have checked other solutions and seen that the pins need to be assigned to the core (in this case it would be the M3). The option to do this doesn't seem to be available; is there any hidden menus I need to be looking for? 


Thanks

Best answer by TDK

SPI pins are initialized in HAL_SPI_MspInit within the stm32f1xx_hal_msp.c file.

/**
* @brief SPI MSP Initialization
* This function configures the hardware resources used in this example
* @PAram hspi: SPI handle pointer
* @retval None
*/
void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
{
 GPIO_InitTypeDef GPIO_InitStruct = {0};
 if(hspi->Instance==SPI1)
 {
 /* USER CODE BEGIN SPI1_MspInit 0 */

 /* USER CODE END SPI1_MspInit 0 */
 /* Peripheral clock enable */
 __HAL_RCC_SPI1_CLK_ENABLE();

 __HAL_RCC_GPIOA_CLK_ENABLE();
 /**SPI1 GPIO Configuration
 PA5 ------> SPI1_SCK
 PA6 ------> SPI1_MISO
 PA7 ------> SPI1_MOSI
 */
 GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_7;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

 GPIO_InitStruct.Pin = GPIO_PIN_6;
 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

 /* USER CODE BEGIN SPI1_MspInit 1 */

 /* USER CODE END SPI1_MspInit 1 */

 }

}

 This gets called through HAL_SPI_Init. 

3 replies

mƎALLEm
Technical Moderator
February 17, 2025

Hello,

I don't see what do you mean by "assigning a pin to core"? STM32F103 is a single core product.

Could you please elaborate so we can understand what do you want to do?

"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."
XPChiAuthor
Associate II
February 17, 2025

Thanks for your reply SofLit.

At the moment, the generated code is not initialising the GPIO pins that I've selected in the .ioc file. All it does is enable the clock access to the GPIO.
I saw someone else in the ST Community had this issue (but yes the board had multiple cores). Solved: STM32CubeIDE doesn't seem to be initialising GPIO ... - STMicroelectronics Community
Is there anything I'm missing? 

mƎALLEm
Technical Moderator
February 17, 2025

@XPChi wrote:

I saw someone else in the ST Community had this issue (but yes the board had multiple cores). Solved: STM32CubeIDE doesn't seem to be initialising GPIO ... - STMicroelectronics Community
Is there anything I'm missing? 


Indeed this is for dual core product that doesn't apply to STM32F103 products.

Could you please share your ioc file so I can have a look at and check?

"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."
XPChiAuthor
Associate II
February 17, 2025
TDK
TDKBest answer
Super User
February 17, 2025

SPI pins are initialized in HAL_SPI_MspInit within the stm32f1xx_hal_msp.c file.

/**
* @brief SPI MSP Initialization
* This function configures the hardware resources used in this example
* @PAram hspi: SPI handle pointer
* @retval None
*/
void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
{
 GPIO_InitTypeDef GPIO_InitStruct = {0};
 if(hspi->Instance==SPI1)
 {
 /* USER CODE BEGIN SPI1_MspInit 0 */

 /* USER CODE END SPI1_MspInit 0 */
 /* Peripheral clock enable */
 __HAL_RCC_SPI1_CLK_ENABLE();

 __HAL_RCC_GPIOA_CLK_ENABLE();
 /**SPI1 GPIO Configuration
 PA5 ------> SPI1_SCK
 PA6 ------> SPI1_MISO
 PA7 ------> SPI1_MOSI
 */
 GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_7;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

 GPIO_InitStruct.Pin = GPIO_PIN_6;
 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

 /* USER CODE BEGIN SPI1_MspInit 1 */

 /* USER CODE END SPI1_MspInit 1 */

 }

}

 This gets called through HAL_SPI_Init. 

"If you feel a post has answered your question, please click ""Accept as Solution""."
XPChiAuthor
Associate II
February 17, 2025

I had a feeling I would kick myself after getting an answer...
Thank you