Skip to main content
Visitor II
November 28, 2025
Solved

Nucleo-L4R5ZI-P: Modifying Code without ioc file

  • November 28, 2025
  • 2 replies
  • 168 views

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?

    This topic has been closed for replies.
    Best answer by Gyessine

    hello @_godsonthomas 
    You can check the STM32L4xx_hal_msp.c file under the Core/Src folder.

    Gyessine_0-1764322681258.png

    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

    2 replies

    GyessineAnswer
    Technical Moderator
    November 28, 2025

    hello @_godsonthomas 
    You can check the STM32L4xx_hal_msp.c file under the Core/Src folder.

    Gyessine_0-1764322681258.png

    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

    Super User
    November 28, 2025

    @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 ?

    Super User
    November 28, 2025

    @_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_1

    Then it's simply a matter of changing those definitions!

    Visitor II
    December 2, 2025

    Hi @Andrew Neil,

    My codebase is using HAL. The PA5 pin has been defined as a macro.