L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1/* USER CODE BEGIN Header */
2/**
3 ******************************************************************************
4 * @file : main.c
5 * @brief : Main program body
6 ******************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2025 STMicroelectronics.
10 * All rights reserved.
11 *
12 * This software is licensed under terms that can be found in the LICENSE file
13 * in the root directory of this software component.
14 * If no LICENSE file comes with this software, it is provided AS-IS.
15 *
16 ******************************************************************************
17 */
18/* USER CODE END Header */
19/* Includes ------------------------------------------------------------------*/
20#include "main.h"
21#include "dma.h"
22#include "i2c.h"
23#include "app_lorawan.h"
24#include "rtc.h"
25#include "spi.h"
26#include "usart.h"
27#include "gpio.h"
28
29/* Private includes ----------------------------------------------------------*/
30/* USER CODE BEGIN Includes */
31#include <stdio.h>
32#include "mysensors.h"
33#include "mysensors_base.h"
34#include "mymems.h"
35#include "usart_if.h"
36#include "stm32_seq.h"
37#include "stm32_lpm.h"
38#include "mylora_process.h"
39#include "timer_if.h" // #define RTC_BKP_STANDBY RTC_BKP_DR3 // MT 25.1.2026 - restart register
40//#include "stm32_lpm_if.h"
41#include "nfc.h"
42#include "sys_app.h"
43#include "lora_app.h"
44#include "utils/utils.h"
45#include "adc_if.h"
46/* USER CODE END Includes */
47
48/* Private typedef -----------------------------------------------------------*/
49/* USER CODE BEGIN PTD */
50
51/* USER CODE END PTD */
52
53/* Private define ------------------------------------------------------------*/
54/* USER CODE BEGIN PD */
55
56/* USER CODE END PD */
57
58/* Private macro -------------------------------------------------------------*/
59/* USER CODE BEGIN PM */
60
61/* USER CODE END PM */
62
63/* Private variables ---------------------------------------------------------*/
64
65/* USER CODE BEGIN PV */
66
67static struct
68{
69 modeDevice_t ModeDevice; // = MODEDEVICE_SLEEP; // default state
70 volatile uint16_t NfcTagged; //counter of NFC tagged
71 UTIL_TIMER_Object_t NfcAfterTrigger; // after
72 uint16_t Powering3v3; // increment of powering 3V3 branch
73} _ =
74 { .ModeDevice = MODEDEVICE_SLEEP, .NfcTagged = 0, .Powering3v3 = 0, .NfcAfterTrigger = {} };
75
76/* USER CODE END PV */
77
78/* Private function prototypes -----------------------------------------------*/
79void SystemClock_Config(void);
80/* USER CODE BEGIN PFP */
81
82/* USER CODE END PFP */
83
84/* Private user code ---------------------------------------------------------*/
85/* USER CODE BEGIN 0 */
86
87#ifdef WRITELOG
88void writeLogNL(const char *buf)
89{
90 Uart_Info(buf);
91}
92
93void writeLogVA(const char *format, va_list argList)
94{
95 static char buf[200];
96 int len;
97
98 vsprintf(buf, format, argList);
99 len = strlen(buf);
100 if (len > 0 && buf[len - 1] != '\n' && buf[len - 2] != '\r')
101 strcat(buf, "\r\n");
102 writeLogNL(buf);
103}
104
105void writeLog(const char *format, ...) //
106{
107 va_list argList;
108 va_start(argList, format);
109 writeLogVA(format, argList);
110 va_end(argList);
111}
112
113#endif
114
115void I2C_Scan(I2C_HandleTypeDef *hi2c) //
116{
117 HAL_StatusTypeDef res;
118 int8_t found = 0;
119
120 HAL_Delay(1500);
121 writeLog("Scanning I2C bus...");
122 for (uint8_t addr = 1; addr < 127; addr++) //
123 {
124 res = HAL_I2C_IsDeviceReady(hi2c, addr << 1, 2, 2);
125 if (res == HAL_OK) //
126 {
127 writeLog("Found I2C device at 0x%02X", addr);
128 found++;
129 HAL_Delay(100);
130 }
131 }
132 if (!found)
133 writeLog("no I2C devices");
134 else
135 HAL_Delay(1500);
136}
137
138/**
139 * @brief called from GPIO interrupt
140 */
141void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
142{
143 // Check if the interrupt came from the GPO pin
144 if (GPIO_Pin == NFC_INT_Pin)
145 {
146 UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_NFC_INT), CFG_SEQ_Prio_0); // start of nfc4_INT
147 }
148}
149
151{
152 HAL_StatusTypeDef status;
153
154 writeLog("start UUART read");
155 status = Uart_StartReceving(&huart1);
156 writeLog("UART read: %d", (int) status);
157}
158
159void togle_LedOff(int off)
160{
161 if (off)
162 HAL_GPIO_WritePin(USER_LED_GPIO_Port, USER_LED_Pin, GPIO_PIN_RESET);
163 else
164 HAL_GPIO_TogglePin(USER_LED_GPIO_Port, USER_LED_Pin);
165}
166
168{
169 switch (mod)
170 {
171 case MODEDEVICE_SLEEP:
172 UTIL_LPM_SetStopMode((1 << CFG_LPM_APPLI_Id), UTIL_LPM_DISABLE);
173 UTIL_LPM_SetOffMode((1 << CFG_LPM_APPLI_Id), UTIL_LPM_DISABLE);
174 break;
175 case MODEDEVICE_STOP:
176 UTIL_LPM_SetStopMode((1 << CFG_LPM_APPLI_Id), UTIL_LPM_ENABLE);
177 UTIL_LPM_SetOffMode((1 << CFG_LPM_APPLI_Id), UTIL_LPM_DISABLE);
178 break;
179 case MODEDEVICE_OFF:
180 UTIL_LPM_SetStopMode((1 << CFG_LPM_APPLI_Id), UTIL_LPM_ENABLE);
181 UTIL_LPM_SetOffMode((1 << CFG_LPM_APPLI_Id), UTIL_LPM_ENABLE);
182 break;
183 }
184 _.ModeDevice = mod;
185}
186
187static void Uart_RxProcessing()
188{
189// writeLog("from:%s!", (const char*) uart_req_buf);
190 Uart_NextReceving(); // a pokracujeme v citani portu, data su nachystane v uart_req_buf
191}
192
193/**
194 * @brief The interrupt of NFC4 tag
195 */
196static void sensors_NFCInt()
197{
198 writeLog("nfc4 tag interrupt"); // don't know what to do with this.... and whether it makes sense
199 ++_.NfcTagged;
200 UTIL_TIMER_Stop(&_.NfcAfterTrigger); // restart timer
201 UTIL_TIMER_Start(&_.NfcAfterTrigger);
202}
203
204/**
205 * @bried check the data from NFC. Function is called from timer _nfcAfterTrigger or directly
206 */
207static void checkResetRestart()
208{
209 HAL_StatusTypeDef status;
210
211 status = nfc_ReadSystemParams(&hi2c2);
212 if (status == HAL_OK)
213 {
214 writeLog("checkResetRestart ok, reset:%d, restart:%d", (int) _systemParams.DevReset, (int) _systemParams.DevRestart);
215
216 if (_systemParams.DevReset)
217 {
219 mems_Reset();
221 }
222
223 if (_systemParams.DevRestart)
224 {
225 _systemParams.DevRestart = 0;
228 }
229 }
230 else
231 writeLog("checkResetRestart failed!, status:%d", (int) status);
232}
233
234static void ledBlink(int count, uint32_t ms)
235{
236 // pause after start within in 5s
237 for (int i = 0; i < count; i++)
238 {
239 HAL_GPIO_TogglePin(USER_LED_GPIO_Port, USER_LED_Pin);
240 HAL_Delay(ms);
241 }
242 HAL_GPIO_WritePin(USER_LED_GPIO_Port, USER_LED_Pin, GPIO_PIN_RESET);
243
244}
245
246/**
247 * @brief The peripheries - flash, NFC & sensors are controlled by _3V3_Enb_GPIO_Port, _3V3_Enb_Pin\n
248 * Cumulative processing
249 */
251{
252 if (_.Powering3v3++ == 0)
253 {
254 HAL_GPIO_WritePin(_3V3_Enb_GPIO_Port, _3V3_Enb_Pin, GPIO_PIN_SET); // turn ON peripheries
255 HAL_Delay(200); // because of flash chip
256 }
257}
258
259/**
260 * @brief Cumulative processing of peripheries to turn OFF
261 */
263{
264 if (_.Powering3v3 > 0)
265 if (--_.Powering3v3 == 0) // the last
266 {
267 HAL_GPIO_WritePin(_3V3_Enb_GPIO_Port, _3V3_Enb_Pin, GPIO_PIN_RESET); // turn OFF peripheries
268 }
269}
270
271/* USER CODE END 0 */
272
273/**
274 * @brief The application entry point.
275 * @retval int
276 */
277int main(void)
278{
279
280 /* USER CODE BEGIN 1 */
281 int8_t status;
282 uint8_t countChanges, bootFromNFC;
283 uint8_t wasInStandby, wasSoftwareReset;
284
285 /* USER CODE END 1 */
286
287 /* MCU Configuration--------------------------------------------------------*/
288
289 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
290 HAL_Init();
291
292 /* USER CODE BEGIN Init */
293 //PWR_WAKEUP_PIN1
294 bootFromNFC = (__HAL_PWR_GET_FLAG(PWR_FLAG_WUF1) != RESET);
295 wasInStandby = (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET);
296 wasSoftwareReset = (__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST) != RESET);
297
298#ifdef DEBUG
299 // because of missing reset button
300 bootFromNFC = wasSoftwareReset = 0;
301#endif
302 __HAL_RCC_CLEAR_RESET_FLAGS();
303 __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF1);
304 __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
305
306 HAL_PWREx_SetRadioBusyTrigger(PWR_RADIO_IRQ_TRIGGER_WU_IT);
307 UTIL_SEQ_Init();
308 /* USER CODE END Init */
309
310 /* Configure the system clock */
312
313 /* USER CODE BEGIN SysInit */
314
315// afterStandby = (getBackUpRegister(RTC_BKP_STANDBY) == RTC_BKP_STANDBY_SIGN);
316// if (afterStandby)
317// {
318// setBackUpRegister(RTC_BKP_STANDBY, 0);
319// }
320 /*
321 * The system_params contains all information about setting the program, included the LoRaWan settings as DEVEUI, APPKEY, APPEUI
322 * These values are set from system_params, which can be read from NFC tag - therefore must be suppressed default setting of MX_LoRaWAN_Init
323 * The MX_LoRaWAN_Init is below via SystemApp_Init and LoRaWAN_Init
324 */
325 // default setting of system_params
326 /* USER CODE END SysInit */
327
328 /* Initialize all configured peripherals */
329 MX_GPIO_Init();
330 MX_DMA_Init();
332 MX_I2C2_Init();
333 MX_SPI1_Init();
334 MX_RTC_Init();
336 /* USER CODE BEGIN 2 */
337
338 // MX_LoRaWan_Init() is disable above and is provide here, after NFC has been read - and the begining!!!
340
341 _batPercLevel = (uint8_t)(((float) GetBatteryLevel() / 254.0f) * 100.0f);
342
343 Power3v3_On(); // equal to HAL_GPIO_WritePin(_3V3_Enb_GPIO_Port, _3V3_Enb_Pin, GPIO_PIN_SET); // turn ON I2C - the _3V3_Enb_Pin is enabled by CubeMX
344 HAL_GPIO_WritePin(Bat_Mon_Enb_GPIO_Port, Bat_Mon_Enb_Pin, GPIO_PIN_SET);
345 HAL_GPIO_WritePin(NFC_LPD_Enb_GPIO_Port, NFC_LPD_Enb_Pin, GPIO_PIN_RESET); // reset - for normal work
346
347 ledBlink(2, 500); // must wait - becasue of initilization of memory due to 3V3 Power3v3_On
348
349#ifndef DEBUG
350 // !!! this is important !!!
351 HAL_DBGMCU_DisableDBGStandbyMode(); // no SWD in release
352#endif
353
354 // reading comport
355 uart_Start();
356 UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_Uart_RX), UTIL_SEQ_RFU, Uart_RxProcessing); // repeated v HAL_UART_RxCharMT
357 UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_NFC_INT), UTIL_SEQ_RFU, sensors_NFCInt); // repeated v HAL_GPIO_EXTI_Callback
358
359 //I2C_Scan(&hi2c2);
360
362 mems_Init();
363
364 // for debug - log system_params to log - default setting
365 //mems_WriteToSystemParams();
366 //systemParams_Log("(default)"); // default setting
367
369 status = nfc_Init(&hi2c2);
370 writeLog("nfc tag: Init %s", (status == HAL_OK) ? "OK" : "failed");
371
372 // for debug - log system_params to log - from NFC
373 systemParams_Log("(from NFC + mems)");
374 systemParams_CorrectSystemTime(); // the time correction
375
378
379 writeLog("tick:%lu, batLevel:%d, batVoltage:%dmV boot from NFC:%d, wasInStandy:%d, wasSoftwareReset:%d",
380 HAL_GetTick(), (int)_batPercLevel, (int)SYS_GetBatteryLevel(), (int) bootFromNFC, (int) wasInStandby, (int) wasSoftwareReset);
381
382 // 13.3.2026 - nothing, stop and go to sleep - NFC not present, always ON
383 if (_systemParams.DevOnOff || status != HAL_OK)
384 {
385 writeLog("...ON...");
386
387 _systemParams.DevOnOff = 1;
388
389 if (bootFromNFC || wasSoftwareReset)
390 sensors_Retiming(); // boot from NFC, only retiming of measure time, nothing else
391 else
392 {
394 // MX_LoRaWan_Init() is disable above and is provide here, after NFC has been read
395 LoRaWAN_Init();
396 // sequencer, added sequencer for sensors
399 }
400 }
401 else
402 writeLog("...OFF...");
403
404 checkResetRestart(); // check reset/restart
405
406 // create timer for NFC tag detection, 5sec after last
407 UTIL_TIMER_Create(&_.NfcAfterTrigger, 5000, UTIL_TIMER_ONESHOT, checkResetRestart, NULL);
408
409 i2c_OnOff(0);
410
411 /*
412 {
413 // memory test
414 int buf = 0, i, j, x;
415 char buf1[] = "mala lofasocka", buf2[] = "velka lofasocka", *bufW;
416 mems_SensorsDataBlock_t *data;
417
418 HAL_StatusTypeDef status;
419
420 writeLog("mem test start");
421
422 _memsMainBlock.Sens_CountMax = 19;
423 if (_memsMainBlock.Sens_CountCurrent > _memsMainBlock.Sens_CountMax)
424 _memsMainBlock.Sens_CountCurrent = _memsMainBlock.Sens_CountMax;
425
426 mems_WriteMainBlock();
427 mems_WriteMainBlock();
428
429 for (j = 0; j < 10; j++)
430 {
431 // precitam prazdny
432 // status = mems_SensorGetLastData(&data);
433 // if (status != HAL_OK && status != HAL_BUSY)
434 // Error_Handler();
435
436 // zapis....
437 for (i = 0; i < 50; i++)
438 {
439 bufW = ((buf) ? buf2 : buf1);
440 status = mems_SensorAddData(bufW, strlen(bufW)+1);
441 if (status != HAL_OK)
442 {
443 writeLog("err 1");
444 Error_Handler();
445 }
446 // kontrola na posledny
447 status = mems_SensorGetLastData(&data, 0); // chcem posledny
448 if (status != HAL_OK)
449 {
450 writeLog("err 2");
451 Error_Handler();
452 }
453 if (strcmp((const char*)data->Data, bufW) != 0)
454 {
455 Error_Handler();
456 writeLog("err 3");
457 }
458
459 x = _memsMainBlock.Sens_CountCurrent;
460 mems_SensorRemoveLastData(2); // remove last,beforelast,beforebeforelast - 3ps
461 mems_SensorCheck(0);
462
463 // kontrola
464 //if (x != _memsMainBlock.Sens_CountCurrent + 3)
465 //{
466 // writeLog("err 4");
467 // Error_Handler();
468 //}
469 }
470
471
472 mems_SensorCheck(0);
473
474 // citanie
475 // status = mems_SensorGetLastData(&data);
476 // if (status != HAL_OK && status != HAL_BUSY)
477 // Error_Handler();
478
479 buf = !buf;
480 writeLog("check:%d", j);
481 }
482 writeLog("mem test OK");
483 }
484 // */
485 /* USER CODE END 2 */
486
487 /* Infinite loop */
488 /* USER CODE BEGIN WHILE */
489
490 setModeDevice(MODEDEVICE_STOP); // default stop mode
491
492 {
493 struct tm localTime;
494 SysTime_t sysTime = SysTimeGet();
495
496 SysTimeLocalTime(sysTime.Seconds, &localTime);
497 writeLog("Current time: %04d-%02d-%02d %02d:%02d:%02d", localTime.tm_year + 1900, localTime.tm_mon + 1, localTime.tm_mday, localTime.tm_hour, localTime.tm_min,
498 localTime.tm_sec);
499 }
500
501 while (1) //
502 {
503 /* USER CODE END WHILE */
505
506 /* USER CODE BEGIN 3 */
507
508 if (_.ModeDevice == MODEDEVICE_OFF)
509 {
510 if (_.NfcTagged)
511 systemRestart(); // if was NFC tagged - the reset is followind
512 else
513 {
514 // write NFC if was not tagged
515 nfc_ReadSystemParams(&hi2c2); // 1st read from NFC, then write
516 countChanges = mems_WriteToSystemParams(); // the count of change
517 countChanges += (systemParams_CorrectSystemTime() == 2); // is necessary update of _systemParams.MqttTime ?
518
519 if (countChanges > 0) // update NFC, before going to OFF mode - if is NFC tagged never write my...
520 {
521 status = nfc_WriteSystemParams(&hi2c2);
522 writeLog("nfc_WriteSystemParams: changes:%d status:%s", (int) countChanges, (status == HAL_OK) ? "OK" : "failed");
523 }
524 }
525 HAL_GPIO_WritePin(NFC_LPD_Enb_GPIO_Port, NFC_LPD_Enb_Pin, GPIO_PIN_SET);
526 HAL_GPIO_WritePin(Bat_Mon_Enb_GPIO_Port, Bat_Mon_Enb_Pin, GPIO_PIN_RESET);
527 ledBlink(10, 50);
528 }
529 }
530 /* USER CODE END 3 */
531}
532
533/**
534 * @brief System Clock Configuration
535 * @retval None
536 */
538{
539 RCC_OscInitTypeDef RCC_OscInitStruct =
540 { 0 };
541 RCC_ClkInitTypeDef RCC_ClkInitStruct =
542 { 0 };
543
544 /** Configure LSE Drive Capability
545 */
546 HAL_PWR_EnableBkUpAccess();
547 __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
548
549 /** Configure the main internal regulator output voltage
550 */
551 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
552
553 /** Initializes the CPU, AHB and APB buses clocks
554 */
555 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE | RCC_OSCILLATORTYPE_MSI;
556 RCC_OscInitStruct.LSEState = RCC_LSE_ON;
557 RCC_OscInitStruct.MSIState = RCC_MSI_ON;
558 RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
559 RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_8;
560 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
561 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
562 {
564 }
565
566 /** Configure the SYSCLKSource, HCLK, PCLK1 and PCLK2 clocks dividers
567 */
568 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK3 | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
569 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
570 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
571 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
572 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
573 RCC_ClkInitStruct.AHBCLK3Divider = RCC_SYSCLK_DIV1;
574
575 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
576 {
578 }
579}
580
581/* USER CODE BEGIN 4 */
582
583/* USER CODE END 4 */
584
585/**
586 * @brief This function is executed in case of error occurrence.
587 * @retval None
588 */
590{
591 /* USER CODE BEGIN Error_Handler_Debug */
592 /* User can add his own implementation to report the HAL error return state */
593 //__disable_irq();
594 while (1)
595 {
596 HAL_GPIO_TogglePin(USER_LED_GPIO_Port, USER_LED_Pin);
597 HAL_Delay(100);
598 }
599 /* USER CODE END Error_Handler_Debug */
600}
601#ifdef USE_FULL_ASSERT
602/**
603 * @brief Reports the name of the source file and the source line number
604 * where the assert_param error has occurred.
605 * @param file: pointer to the source file name
606 * @param line: assert_param error line source number
607 * @retval None
608 */
609void assert_failed(uint8_t *file, uint32_t line)
610{
611 /* USER CODE BEGIN 6 */
612 /* User can add his own implementation to report the file name and line number,
613 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
614 /* USER CODE END 6 */
615}
616#endif /* USE_FULL_ASSERT */
Header for ADC interface configuration.
uint16_t SYS_GetBatteryLevel(void)
Get the current battery level.
Definition adc_if.c:139
void MX_LoRaWAN_Process(void)
Entry Lora Process or scheduling.
Definition app_lorawan.c:81
void MX_LoRaWAN_Init(void)
Init Lora Application.
Definition app_lorawan.c:65
Header of application of the LRWAN Middleware.
This file contains all the function prototypes for the dma.c file.
void MX_DMA_Init(void)
Definition dma.c:39
This file contains all the function prototypes for the gpio.c file.
void MX_GPIO_Init(void)
Definition gpio.c:42
This file contains all the function prototypes for the i2c.c file.
void MX_I2C2_Init(void)
Definition i2c.c:30
I2C_HandleTypeDef hi2c2
Definition i2c.c:27
void LoRaWAN_Init(void)
Init Lora Application.
Definition lora_app.c:310
void systemParams_SetLoRaWanParams()
set the lorawan parameters from _systemParams before start of loraWan
Definition lora_app.c:300
Header of application of the LRWAN Middleware.
void uart_Start()
start of UART reading
Definition main.c:150
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
called from GPIO interrupt
Definition main.c:141
void Error_Handler(void)
This function is executed in case of error occurrence.
Definition main.c:589
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
uint16_t Powering3v3
Definition main.c:72
UTIL_TIMER_Object_t NfcAfterTrigger
Definition main.c:71
static void checkResetRestart()
Definition main.c:207
void SystemClock_Config(void)
System Clock Configuration.
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
int main(void)
The application entry point.
Definition main.c:277
void Power3v3_On()
The peripheries - flash, NFC & sensors are controlled by _3V3_Enb_GPIO_Port, _3V3_Enb_Pin Cumulative ...
Definition main.c:250
static void ledBlink(int count, uint32_t ms)
Definition main.c:234
void togle_LedOff(int off)
togle led
Definition main.c:159
static struct @042147022327042232212126043022001043033342036075 _
modeDevice_t ModeDevice
Definition main.c:69
void writeLogNL(const char *buf)
Send a pre-formatted C string to the UART log followed by a newline.
Definition main.c:88
static void Uart_RxProcessing()
Definition main.c:187
void Power3v3_Off()
Cumulative processing of peripheries to turn OFF.
Definition main.c:262
volatile uint16_t NfcTagged
Definition main.c:70
void I2C_Scan(I2C_HandleTypeDef *hi2c)
Definition main.c:115
static void sensors_NFCInt()
The interrupt of NFC4 tag.
Definition main.c:196
: Header for main.c file. This file contains the common defines of the application....
#define _3V3_Enb_Pin
Definition main.h:153
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
#define NFC_INT_Pin
Definition main.h:146
#define Bat_Mon_Enb_GPIO_Port
Definition main.h:156
#define NFC_LPD_Enb_GPIO_Port
Definition main.h:158
#define NFC_LPD_Enb_Pin
Definition main.h:157
#define USER_LED_Pin
Definition main.h:151
#define USER_LED_GPIO_Port
Definition main.h:152
#define _3V3_Enb_GPIO_Port
Definition main.h:154
#define Bat_Mon_Enb_Pin
Definition main.h:155
void myloraWan_Init(uint8_t myloraWanAppBit)
initialization of myloraWan process, sequencer
uint8_t mems_WriteToSystemParams()
write data from memory to systemParams
Definition mymems.c:295
void mems_ReadFromSystemParams()
read data from NFC to mems block
Definition mymems.c:331
void mems_Init()
Initialise NFC and external flash; load the main block and system parameters. Verifies the flash sign...
Definition mymems.c:66
HAL_StatusTypeDef mems_Reset()
memory reset - remove sign from chip
Definition mymems.c:152
void sensors_Init(I2C_HandleTypeDef *hi2c)
Initialization of all sensors, must be called before for store of hi2c handler.
Definition mysensors.c:413
void sensorsSeq_Init(uint32_t sensortAppBit, uint32_t mylorawanAppBit)
the sensors sequencer initialization and set the process in sequencer
Definition mysensors.c:454
void sensors_Retiming()
stop and start of sensor timer for next measure
Definition mysensors.c:438
void i2c_OnOff(uint8_t onOff)
possible to I2C turn on/off - cumulative
Definition mysensors.c:190
systemParams_t _systemParams
uint8_t systemParams_CorrectSystemTime()
setting/correction of the system time from _systemParams.MqttTime, if contains valid UNIX time(low ui...
uint8_t _batPercLevel
void systemParams_Log(const char *info)
Log the current _systemParams fields to the UART debug output.
void sensorsBase_Init()
Initialization of base sensor data structure.
HAL_StatusTypeDef nfc_WriteSystemParams(I2C_HandleTypeDef *hi2c)
Write system params to NFC.
Definition nfc.c:149
HAL_StatusTypeDef nfc_ReadSystemParams(I2C_HandleTypeDef *hi2c)
reading _systemParams from NFC - all data will be rewrite in _systemParams
Definition nfc.c:189
HAL_StatusTypeDef nfc_FactoryReset(I2C_HandleTypeDef *hi2c)
reset NFC data to factory - default state
Definition nfc.c:169
HAL_StatusTypeDef nfc_Init(I2C_HandleTypeDef *hi2c)
NFC initialization and read NFC tag systemParams from addr 0. If data there are not valid,...
Definition nfc.c:109
This file contains all the function prototypes for the rtc.c file.
void MX_RTC_Init(void)
Definition rtc.c:30
This file contains all the function prototypes for the spi.c file.
void MX_SPI1_Init(void)
Definition spi.c:30
void HAL_Delay(__IO uint32_t Delay)
Definition sys_app.c:369
uint32_t HAL_GetTick(void)
Definition sys_app.c:337
Function prototypes for sys_app.c file.
void SystemApp_Init(void)
initialize the system (dbg pins, trace, mbmux, sys timer, LPM, ...)
Definition sys_app.c:90
uint8_t GetBatteryLevel(void)
callback to get the battery level in % of full charge (254 full charge, 0 no charge)
Definition sys_app.c:152
configuration of the timer_if.c instances
This file contains all the function prototypes for the usart.c file.
UART_HandleTypeDef huart1
Definition usart.c:30
void MX_USART1_UART_Init(void)
Definition usart.c:35
Header for USART interface configuration.
UTIL_ADV_TRACE_Status_t Uart_Info(const char *strInfo)
Write to UART1.
Definition usart_if.c:299
UTIL_ADV_TRACE_Status_t Uart_NextReceving()
continue with next reading if data arrived
Definition usart_if.c:306
UTIL_ADV_TRACE_Status_t Uart_StartReceving(UART_HandleTypeDef *uart)
start reading
Definition usart_if.c:313
@ CFG_SEQ_Prio_0
@ CFG_SEQ_Task_NFC_INT
@ CFG_SEQ_Task_Uart_RX
@ CFG_SEQ_Task_Sensors
@ CFG_SEQ_Task_MyLora
@ CFG_LPM_APPLI_Id
void systemRestart()
the calling of system restart with disabling of interrupts
Definition utils.c:135