L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
Loading...
Searching...
No Matches
main.h
Go to the documentation of this file.
1/* USER CODE BEGIN Header */
2/**
3 ******************************************************************************
4 * @file : main.h
5 * @brief : Header for main.c file.
6 * This file contains the common defines of the application.
7 ******************************************************************************
8 * @attention
9 *
10 * Copyright (c) 2025 STMicroelectronics.
11 * All rights reserved.
12 *
13 * This software is licensed under terms that can be found in the LICENSE file
14 * in the root directory of this software component.
15 * If no LICENSE file comes with this software, it is provided AS-IS.
16 *
17 ******************************************************************************
18 */
19/* USER CODE END Header */
20
21/* Define to prevent recursive inclusion -------------------------------------*/
22#ifndef __MAIN_H
23#define __MAIN_H
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29/* Includes ------------------------------------------------------------------*/
30#include "stm32wlxx_hal.h"
31
32/* Private includes ----------------------------------------------------------*/
33/* USER CODE BEGIN Includes */
34#include "LmHandler.h"
35#include "mysensors_def.h"
36
37/* USER CODE END Includes */
38
39/* Exported types ------------------------------------------------------------*/
40/* USER CODE BEGIN ET */
41
42// HAL_RTC_AlarmIRQHandler, RTC_Alarm_IRQHandler
43
44/* USER CODE END ET */
45
46/* Exported constants --------------------------------------------------------*/
47/* USER CODE BEGIN EC */
48/**
49 * @brief Device power/sleep mode selector.
50 *
51 * Passed to setModeDevice() to request a specific power state transition.
52 * The sequencer ensures in-flight LoRaWAN transmissions complete before
53 * the mode switch is executed.
54 */
55typedef enum
56{
57 MODEDEVICE_SLEEP, /**< CPU sleep only – clocks running, fastest wake-up (rarely used) */
58 MODEDEVICE_STOP, /**< STOP2 mode – most peripherals off, RTC running, ~1 µA; wake via RTC or interrupt */
59 MODEDEVICE_OFF, /**< Standby (OFF) mode – deepest sleep, restarts via RTC wakeup timer */
61/* USER CODE END EC */
62
63/* Exported macro ------------------------------------------------------------*/
64/* USER CODE BEGIN EM */
65
66
67#ifdef WRITELOG
68#include <stdarg.h>
69/**
70 * @brief Send a pre-formatted C string to the UART log followed by a newline.
71 * @param buf Null-terminated string to transmit.
72 */
73void writeLogNL(const char *buf);
74
75/**
76 * @brief Format and send a log message using a va_list argument list.
77 * Used internally by writeLog(); can also be called from wrapper
78 * functions that accept a variadic argument list.
79 * @param format printf-compatible format string.
80 * @param argList Initialised va_list of format arguments.
81 */
82void writeLogVA(const char *format, va_list argList);
83
84/**
85 * @brief Format and send a log message over UART (printf-style).
86 * Available only when WRITELOG is defined; compiles to nothing otherwise.
87 * @param format printf-compatible format string followed by optional arguments.
88 */
89void writeLog(const char *format, ...);
90#else
91#define writeLogNL(...)
92#define writeLogVA(...)
93#define writeLog(...)
94#endif
95
96
97/* USER CODE END EM */
98
99/* Exported functions prototypes ---------------------------------------------*/
100/**
101 * @brief Default error handler called by HAL on unrecoverable errors.
102 * Disables interrupts and enters an infinite loop; attach a debugger
103 * or add custom recovery logic inside the USER CODE section in main.c.
104 */
105void Error_Handler(void);
106
107/* USER CODE BEGIN EFP */
108
109/**
110 * @brief Re-configure all system clocks after waking from STOP or OFF mode.
111 * Called automatically during the startup/reset sequence; may also be
112 * called after exiting low-power modes to restore the full clock tree.
113 */
114void SystemClock_Config(void);
115
116/**
117 * @brief start of UART reading
118 */
119void uart_Start();
120
121/**
122 * @brief togle led
123 * @param off - 0 - led is toggled, 1 - led is OFF
124 */
125void togle_LedOff(int off);
126
127/**
128 * @brief set new device mode
129 */
131
132
133/* USER CODE END EFP */
134
135/* Private defines -----------------------------------------------------------*/
136#define RTC_N_PREDIV_S 10
137#define RTC_PREDIV_S ((1<<RTC_N_PREDIV_S)-1)
138#define RTC_PREDIV_A ((1<<(15-RTC_N_PREDIV_S))-1)
139#define NFC_INT_Pin GPIO_PIN_0
140#define NFC_INT_GPIO_Port GPIOA
141#define NFC_INT_EXTI_IRQn EXTI0_IRQn
142#define SPI1_CS_Pin GPIO_PIN_4
143#define SPI1_CS_GPIO_Port GPIOA
144#define USER_LED_Pin GPIO_PIN_8
145#define USER_LED_GPIO_Port GPIOA
146
147/* USER CODE BEGIN Private defines */
148
149/**
150 * @brief Control variable for entering stop mode.
151 *
152 * Set this variable to 1 to request the device to enter stop mode.
153 * The device will:
154 * - Check if LoRaWAN stack is ready (not busy)
155 * - Turn off sensors
156 * - Deinitialize I2C, SPI, and UART peripherals
157 * - Enter STOP mode with low power regulator
158 * - Wake up after the configured SensorTimeoutMeasure interval via RTC wakeup timer
159 * - Reinitialize all peripherals and resume operation
160 *
161 * Set to 0 for normal operation (default).
162 *
163 * Example usage:
164 * @code
165 * extern volatile int8_t _GoToStop;
166 * _GoToStop = 1; // Request stop mode entry
167 * @endcode
168 */
169
170/* USER CODE END Private defines */
171
172#ifdef __cplusplus
173}
174#endif
175
176#endif /* __MAIN_H */
void uart_Start()
start of UART reading
Definition main.c:142
void Error_Handler(void)
Default error handler called by HAL on unrecoverable errors. Disables interrupts and enters an infini...
Definition main.c:505
modeDevice_t
Device power/sleep mode selector.
Definition main.h:56
@ MODEDEVICE_SLEEP
Definition main.h:57
@ MODEDEVICE_OFF
Definition main.h:59
@ MODEDEVICE_STOP
Definition main.h:58
void writeLog(const char *format,...)
Format and send a log message over UART (printf-style). Available only when WRITELOG is defined; comp...
Definition main.c:97
void SystemClock_Config(void)
Re-configure all system clocks after waking from STOP or OFF mode. Called automatically during the st...
Definition main.c:453
void writeLogVA(const char *format, va_list argList)
Format and send a log message using a va_list argument list. Used internally by writeLog(); can also ...
Definition main.c:85
void setModeDevice(modeDevice_t mod)
set new device mode
Definition main.c:159
void togle_LedOff(int off)
togle led
Definition main.c:151
void writeLogNL(const char *buf)
Send a pre-formatted C string to the UART log followed by a newline.
Definition main.c:80