|
F439_CPP_TX-RX_LoRa_Project
|
: Main program body More...
#include "main.h"#include "sx1262.h"#include "radio_app.h"#include <sys/unistd.h>#include <stdio.h>#include <string.h>#include "ada1897_mb85rs64b.h"#include "qa_app.h"
Functions | |
| void | SystemClock_Config (void) |
| Configure the MCU system clock. | |
| int | _write (int file, char *ptr, int len) |
| Retargets the C library write() function to UART1. | |
| void | HAL_GPIO_EXTI_Callback (uint16_t pin) |
| GPIO EXTI interrupt callback handler. | |
| void | delay_us (uint16_t us) |
| Busy-wait microsecond delay using TIM3. | |
| int | main (void) |
| Application entry point. | |
| void | _Error_Handler (const char *file, int line) |
| This function is executed in case of error occurrence. | |
Variables | |
| CRYP_HandleTypeDef | hcryp |
| SPI_HandleTypeDef | hspi1 |
| TIM_HandleTypeDef | htim3 |
| UART_HandleTypeDef | huart1 |
| SX1262_Handle | sx |
| SX1262_ROLE | sx1262Role |
: Main program body
Copyright (c) 2026 STMicroelectronics. All rights reserved.
This software is licensed under terms that can be found in the LICENSE file in the root directory of this software component. If no LICENSE file comes with this software, it is provided AS-IS.
| void _Error_Handler | ( | const char * | file, |
| int | line ) |
This function is executed in case of error occurrence.
| file | The file name as string. |
| line | The line in file as a number. |
| int _write | ( | int | file, |
| char * | ptr, | ||
| int | len ) |
Retargets the C library write() function to UART1.
This function allows standard library output functions such as printf() to transmit data over USART1. It is used by the newlib or nano-libc retargeting mechanism when stdout/stderr are mapped to this implementation.
The function calculates a bounded transmit timeout based on the number of bytes being written. This prevents large printf() calls from blocking the main loop for excessive periods of time.
Timeout estimation:
| file | File descriptor (unused). |
| ptr | Pointer to the buffer containing bytes to transmit. |
| len | Number of bytes to transmit. |
| void delay_us | ( | uint16_t | us | ) |
Busy-wait microsecond delay using TIM3.
This function provides a simple blocking delay with microsecond resolution by polling the TIM3 hardware counter. The timer must be configured so that its counter increments at 1 MHz (1 count per microsecond).
The function resets the TIM3 counter to zero and then spins until the counter reaches the requested delay value.
This delay mechanism is intended for short timing gaps required by hardware drivers (for example SPI peripherals, radio devices, or other timing-sensitive interfaces). Because it is a busy-wait loop, it will block the CPU for the duration of the delay and should not be used for long delays inside time-critical execution paths.
| us | Number of microseconds to delay. |
| void HAL_GPIO_EXTI_Callback | ( | uint16_t | pin | ) |
GPIO EXTI interrupt callback handler.
This function is invoked by the STM32 HAL whenever a GPIO external interrupt (EXTI) occurs. It serves as a bridge between the HAL interrupt infrastructure and the RadioApp layer.
For this project the callback is used to forward SX1262 DIO1 events to the radio application logic, allowing the RadioApp layer to process radio interrupts without embedding radio logic inside CubeMX-generated code.
| pin | GPIO pin number that triggered the EXTI interrupt. |
| int main | ( | void | ) |
Application entry point.
Initializes the HAL, configures the system clock, initializes all CubeMX-generated peripherals, and then performs application specific initialization for the LoRa radio stack and FRAM persistence layer.
After initialization completes the firmware enters the main service loop where RadioApp_Loop() drives the radio state machine.
| int | Should never return. |
| void SystemClock_Config | ( | void | ) |
Configure the MCU system clock.
Configures PLL and bus clocks generated by STM32CubeMX. This function is generated by CubeMX and should not be modified outside USER CODE blocks.
Any failure in clock configuration results in Error_Handler().
Configure the main internal regulator output voltage
Initializes the RCC Oscillators according to the specified parameters in the RCC_OscInitTypeDef structure.
Activate the Over-Drive mode
Initializes the CPU, AHB and APB buses clocks
| CRYP_HandleTypeDef hcryp |
| SPI_HandleTypeDef hspi1 |
| TIM_HandleTypeDef htim3 |
| UART_HandleTypeDef huart1 |
| SX1262_ROLE sx1262Role |