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