2025-11-27 11:24 PM
Hi,
I already have a codebase that uses the STM32L4R5ZI microcontroller. The codebase does not include an .ioc file, which we normally use to configure the pins and other related parameters. But the codebase seems to be compiling fine. I am working with a development board for our customer project (Nucleo-L4R5ZI-P).
We are trying to establish SPI communication with an external chip via SPI1. The codebase currently configures the SPI1 interface, but the SPI_CLK function is assigned to PA1. I need to change this to PA5. Since I don’t have an .ioc file, how can I make this modification?
Solved! Go to Solution.
2025-11-28 1:38 AM
hello @_godsonthomas
You can check the STM32L4xx_hal_msp.c file under the Core/Src folder.
You can make changes to the SPI configuration.
Here is an example of an SPI configuration that you should find in that file:
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_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);
/* SPI1 interrupt Init */
HAL_NVIC_SetPriority(SPI1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(SPI1_IRQn);
/* USER CODE BEGIN SPI1_MspInit 1 */
/* USER CODE END SPI1_MspInit 1 */
}
}
Hope that helps
Gyessine
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.
2025-11-28 1:38 AM
hello @_godsonthomas
You can check the STM32L4xx_hal_msp.c file under the Core/Src folder.
You can make changes to the SPI configuration.
Here is an example of an SPI configuration that you should find in that file:
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_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);
/* SPI1 interrupt Init */
HAL_NVIC_SetPriority(SPI1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(SPI1_IRQn);
/* USER CODE BEGIN SPI1_MspInit 1 */
/* USER CODE END SPI1_MspInit 1 */
}
}
Hope that helps
Gyessine
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.
2025-11-28 2:11 AM
@_godsonthomas wrote:The codebase currently configures the SPI1 interface,
So find the place in your code where this happens, and change it from using PA1 to use PA5 instead.
Is your codebase using HAL ?
This is an example of why it's always a good idea to abstract stuff like this:
Instead of directly using "PA5" like a "magic number" in your code, have some symbolic definitions; eg,
#define MY_SPI_PERIPHERAL SPI1
#define MY_SPI_CLK_PORT GPIOA
#define MY_SPI_CLK_PIN GPIO_PIN_1Then it's simply a matter of changing those definitions!
2025-11-28 2:15 AM
@Gyessine wrote:You can check the STM32L4xx_hal_msp.c file
But that file is generated by CubeMX.
@_godsonthomas says the project doesn't have a .ioc file - so it's not using CubeMX code generation ?
2025-12-01 9:17 PM
Hi @Gyessine ,
I will do this modification. Thanks for the input.
2025-12-01 9:18 PM
Hi @Andrew Neil,
My codebase is using HAL. The PA5 pin has been defined as a macro.