How do I make the GNSS Arduino library work with a stm32 board?

I have been working with the ZED-F9R module with an Arduino using the GNSS library from Sparkfun and it is working just fine, I wanted to set it up with an STM32 Nucleo-H7A3ZI-Q board. What changes do I have to make to the library to deploy it on the STM board using the cubeIDE?

Quite a few… To port an Arduino library to work with the STM32 Nucleo-H7A3ZI-Q board using CubeIDE, you need to make the following key changes:

  1. Replace Arduino-specific libraries with their STM32 HAL equivalents:
  • Replace Wire.h with stm32h7xx_hal_i2c.h for I2C

  • Replace SPI.h with stm32h7xx_hal_spi.h for SPI

  • Replace Serial.h with stm32h7xx_hal_uart.h for UART

  1. Modify the library code to use STM32 HAL APIs instead of Arduino APIs. For example:
  • digitalWrite() becomes HAL_GPIO_WritePin()

  • analogRead() becomes HAL_ADC_GetValue()

  • delay() becomes HAL_Delay()

  1. Configure the required peripherals (UART, I2C, SPI, etc.) in CubeIDE and initialize them in your code using the corresponding MX_<Peripheral>_Init() functions generated by CubeIDE

  2. Ensure the library’s timing and delay functions are compatible with the STM32 HAL by either:

  • Replacing them with HAL_Delay() or a timer-based delay function.

  • Adapting the existing delay functions to use a timer peripheral

  1. Adjust any pin mappings or configurations specific to the Arduino board to match the STM32 Nucleo-H7A3ZI-Q board’s pinout and peripheral mappings

  2. Build and link the modified library with your CubeIDE project, ensuring any required STM32 HAL libraries are also linked

The process can be time-consuming, as you may need to refactor significant portions of the library code to work with the STM32 HAL APIs and peripherals. Thoroughly testing the ported library is also crucial to ensure proper functionality