2025-02-17 05:23 AM - edited 2025-02-17 05:26 AM
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
Solved! Go to Solution.
2025-02-17 06:25 AM
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.
2025-02-17 05:28 AM
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?
2025-02-17 05:44 AM
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?
2025-02-17 05:50 AM - edited 2025-02-17 05:51 AM
@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?
2025-02-17 05:52 AM
2025-02-17 06:25 AM
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.
2025-02-17 06:38 AM
I had a feeling I would kick myself after getting an answer...
Thank you