F439_CPP_TX-RX_LoRa_Project

Loading...
Searching...
No Matches
Functions | Variables
main.c File Reference
Firmware Architecture » Hardware Abstraction Layer

: 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"`
Include dependency graph for main.c:

## Functions
void | SystemClock_Config (void)
| System Clock Configuration.
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)
| The 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

## Detailed Description

: Main program body

Attention

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.

## Function Documentation

## ◆ _Error_Handler()

void _Error_Handler | ( | const char * | file,
|  | int | line )

This function is executed in case of error occurrence.

Parameters

  file | The file name as string.
  line | The line in file as a number.

## ◆ _write()

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:

- 19200 baud, 8N1 ≈ 1.92 bytes/ms
- Approximate timeout = len / 2 ms
- Minimum timeout clamp: 10 ms
- Maximum timeout clamp: 300 ms

Parameters

  file | File descriptor (unused).
  ptr | Pointer to the buffer containing bytes to transmit.
  len | Number of bytes to transmit.

Returns
  Number of bytes successfully transmitted, or 0 on failure.

## ◆ delay_us()

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.

Parameters

  us | Number of microseconds to delay.

## ◆ HAL_GPIO_EXTI_Callback()

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.

Parameters

  pin | GPIO pin number that triggered the EXTI interrupt.

## ◆ main()

int main | ( | void |  | ) |

The application entry point.

Return values

  int |

## ◆ SystemClock_Config()

void SystemClock_Config | ( | void |  | ) |

System Clock Configuration.

Return values

  None |

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

## Variable Documentation

## ◆ hcryp

CRYP_HandleTypeDef hcryp

## ◆ hspi1

SPI_HandleTypeDef hspi1

## ◆ htim3

TIM_HandleTypeDef htim3

## ◆ huart1

UART_HandleTypeDef huart1

## ◆ sx

SX1262_Handle sx

## ◆ sx1262Role

SX1262_ROLE sx1262Role