This project demonstrates how to use the STM32 NUCLEO-H7A3ZI-Q with the Adafruit Ultimate GPS HAT to read and process GPS data via UART. The code leverages the leech001/gps repository as a foundation for GPS data parsing and communication.
This repository now serves as documentation of how I configured the GPS module with the microcontroller. I hope it can help others who are starting with GPS and STM32 development.
- Launch STM32CubeIDE and open the
.iocfile for the project.
- Navigate to Pinout & Configuration.
- Under the peripherals list (A → Z), search for USART1.
- Enable USART1 in Mode as Asynchronous.
- Go to NVIC Settings and check the box for USART1 global interrupt (as shown in the image below).
- In Parameter Settings, set the Baud Rate to 9600 Bits/s (as shown in the image below).
- Adjust GPIO Settings for USART1 as shown in the image below.
- Go to Project Manager → Code Generator.
- Uncheck the box for Generate peripheral initialization as a pair of
.c/.hfiles per peripheral.
- Press
Ctrl + Sto save the.iocfile, which will regenerate the code with the updated configuration.
To enable floating-point support in printf and scanf, follow these steps:
- Go to Project → Properties in STM32CubeIDE.
- Navigate to C/C++ Build → Settings.
- Under the Tool Settings tab, find Miscellaneous (under MCU GCC Linker).
- In the Other Flags field, add the following flags:
-u _printf_float-u _scanf_float
- Click Apply and Close to save the changes.
This step ensures that floating-point values can be properly handled in formatted input/output functions like printf and scanf.
Add these files to your project:
- Place
gps.cin the Core/Src folder. - Place
gps.hin the Core/Inc folder.
- Open
main.cin STM32CubeIDE. - Add the following includes inside the
/* USER CODE BEGIN Includes */section:
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <stdio.h>
#include "string.h"
#include "gps.h"
/* USER CODE END Includes */- In the
/_ USER CODE BEGIN 2 _/section ofmain.c, add the following setup code to initialize the BNO055 IMU sensor:
/* USER CODE BEGIN 2 */
GPS_Init();
/* USER CODE END 2 */- Inside the
/_ USER CODE BEGIN 0 _/section ofmain.c, add the following function:
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if(huart == GPS_USART) GPS_UART_CallBack();
}
void send_gps_data() {
char buffer[200];
// GPS data
snprintf(buffer, sizeof(buffer),
"[GPS Data] Time: %02d:%02d:%02d, Latitude: %.6f %c, Longitude: %.6f %c, Speed: %.2f knots, Status: %c\r\n",
GPS.hours, GPS.minutes, GPS.seconds, // Use pre-converted time
GPS.dec_latitude, // Decimal latitude
GPS.ns, // N/S indicator
GPS.dec_longitude, // Decimal longitude
GPS.ew, // E/W indicator
GPS.speed_k, // Speed in knots
GPS.rmc_status // RMC status ('A' = active, 'V' = void)
);
HAL_UART_Transmit(&huart3, (uint8_t*) buffer, strlen(buffer), HAL_MAX_DELAY);
HAL_Delay(100); // 10 Hz
}
/* USER CODE END 0 */- Call the function inside the main loop to continuously fetch and transmit data:
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
send_gps_data();
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */To connect the Adafruit Ultimate GPS HAT to the STM32 NUCLEO-H7A3ZI-Q, use the following wiring:
| GPS HAT Pin | NUCLEO Pin |
|---|---|
| 3.3V | 3V3 |
| GND | GND |
| TX | TX (PB6) |
| RX | RX (PB15) |
Ensure the connections are secure to avoid communication issues. The image below illustrates the wiring:
For more detailed information about the external header connections of the NUCLEO-H7A3ZI-Q, refer to the image below:
For more detailed information about the external header connections of the Adafruit Ultimate GPS HAT, refer to the image below:
- IDE: STM32CubeIDE (1.16.1)
- Microcontroller: STM32 NUCLEO-H7A3ZI-Q
- GPS Module: Adafruit Ultimate GPS HAT for Raspberry Pi A+/B+/Pi 2/3/4/Pi 5 - Mini Kit
This project includes code from the gps.c and gps.h files by Bulanov Konstantin, originally sourced from the leech001/gps repository. The code is licensed under the GNU General Public License (GPL) v3.
For the full terms of the GPL, see the LICENSE file included in this repository.
- Extended the GPS parsing logic to include additional NMEA messages:
$GNGGA: Position and satellite data$GNRMC: Position, speed, and time data
- Added helper functions:
GPS_ConvertTime: Converts raw UTC time to hours, minutes, and seconds.GPS_ConvertDate: Converts raw date to day, month, and year.





