74 { .ModeDevice =
MODEDEVICE_SLEEP, .NfcTagged = 0, .Powering3v3 = 0, .NfcAfterTrigger = {} };
98 vsprintf(buf, format, argList);
100 if (len > 0 && buf[len - 1] !=
'\n' && buf[len - 2] !=
'\r')
108 va_start(argList, format);
117 HAL_StatusTypeDef res;
122 for (uint8_t addr = 1; addr < 127; addr++)
124 res = HAL_I2C_IsDeviceReady(hi2c, addr << 1, 2, 2);
127 writeLog(
"Found I2C device at 0x%02X", addr);
152 HAL_StatusTypeDef status;
156 writeLog(
"UART read: %d", (
int) status);
200 UTIL_TIMER_Stop(&
_.NfcAfterTrigger);
201 UTIL_TIMER_Start(&
_.NfcAfterTrigger);
209 HAL_StatusTypeDef status;
212 if (status == HAL_OK)
231 writeLog(
"checkResetRestart failed!, status:%d", (
int) status);
237 for (
int i = 0; i < count; i++)
252 if (
_.Powering3v3++ == 0)
264 if (
_.Powering3v3 > 0)
265 if (--
_.Powering3v3 == 0)
282 uint8_t countChanges, bootFromNFC;
283 uint8_t wasInStandby, wasSoftwareReset;
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);
300 bootFromNFC = wasSoftwareReset = 0;
302 __HAL_RCC_CLEAR_RESET_FLAGS();
303 __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF1);
304 __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
306 HAL_PWREx_SetRadioBusyTrigger(PWR_RADIO_IRQ_TRIGGER_WU_IT);
351 HAL_DBGMCU_DisableDBGStandbyMode();
370 writeLog(
"nfc tag: Init %s", (status == HAL_OK) ?
"OK" :
"failed");
379 writeLog(
"tick:%lu, batLevel:%d, batVoltage:%dmV boot from NFC:%d, wasInStandy:%d, wasSoftwareReset:%d",
389 if (bootFromNFC || wasSoftwareReset)
407 UTIL_TIMER_Create(&
_.NfcAfterTrigger, 5000, UTIL_TIMER_ONESHOT,
checkResetRestart, NULL);
494 SysTime_t sysTime = SysTimeGet();
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,
519 if (countChanges > 0)
522 writeLog(
"nfc_WriteSystemParams: changes:%d status:%s", (
int) countChanges, (status == HAL_OK) ?
"OK" :
"failed");
539 RCC_OscInitTypeDef RCC_OscInitStruct =
541 RCC_ClkInitTypeDef RCC_ClkInitStruct =
546 HAL_PWR_EnableBkUpAccess();
547 __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
551 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
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)
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;
575 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
601#ifdef USE_FULL_ASSERT
609void assert_failed(uint8_t *file, uint32_t line)
Header for ADC interface configuration.
uint16_t SYS_GetBatteryLevel(void)
Get the current battery level.
void MX_LoRaWAN_Process(void)
Entry Lora Process or scheduling.
void MX_LoRaWAN_Init(void)
Init Lora Application.
Header of application of the LRWAN Middleware.
This file contains all the function prototypes for the dma.c file.
This file contains all the function prototypes for the gpio.c file.
This file contains all the function prototypes for the i2c.c file.
void LoRaWAN_Init(void)
Init Lora Application.
void systemParams_SetLoRaWanParams()
set the lorawan parameters from _systemParams before start of loraWan
Header of application of the LRWAN Middleware.
void uart_Start()
start of UART reading
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
called from GPIO interrupt
void Error_Handler(void)
This function is executed in case of error occurrence.
void writeLog(const char *format,...)
Format and send a log message over UART (printf-style). Available only when WRITELOG is defined; comp...
UTIL_TIMER_Object_t NfcAfterTrigger
static void checkResetRestart()
void SystemClock_Config(void)
System Clock Configuration.
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 ...
void setModeDevice(modeDevice_t mod)
set new device mode
int main(void)
The application entry point.
void Power3v3_On()
The peripheries - flash, NFC & sensors are controlled by _3V3_Enb_GPIO_Port, _3V3_Enb_Pin Cumulative ...
static void ledBlink(int count, uint32_t ms)
void togle_LedOff(int off)
togle led
static struct @042147022327042232212126043022001043033342036075 _
void writeLogNL(const char *buf)
Send a pre-formatted C string to the UART log followed by a newline.
static void Uart_RxProcessing()
void Power3v3_Off()
Cumulative processing of peripheries to turn OFF.
volatile uint16_t NfcTagged
void I2C_Scan(I2C_HandleTypeDef *hi2c)
static void sensors_NFCInt()
The interrupt of NFC4 tag.
: Header for main.c file. This file contains the common defines of the application....
modeDevice_t
Device power/sleep mode selector.
#define Bat_Mon_Enb_GPIO_Port
#define NFC_LPD_Enb_GPIO_Port
#define USER_LED_GPIO_Port
#define _3V3_Enb_GPIO_Port
void myloraWan_Init(uint8_t myloraWanAppBit)
initialization of myloraWan process, sequencer
uint8_t mems_WriteToSystemParams()
write data from memory to systemParams
void mems_ReadFromSystemParams()
read data from NFC to mems block
void mems_Init()
Initialise NFC and external flash; load the main block and system parameters. Verifies the flash sign...
HAL_StatusTypeDef mems_Reset()
memory reset - remove sign from chip
void sensors_Init(I2C_HandleTypeDef *hi2c)
Initialization of all sensors, must be called before for store of hi2c handler.
void sensorsSeq_Init(uint32_t sensortAppBit, uint32_t mylorawanAppBit)
the sensors sequencer initialization and set the process in sequencer
void sensors_Retiming()
stop and start of sensor timer for next measure
void i2c_OnOff(uint8_t onOff)
possible to I2C turn on/off - cumulative
systemParams_t _systemParams
uint8_t systemParams_CorrectSystemTime()
setting/correction of the system time from _systemParams.MqttTime, if contains valid UNIX time(low ui...
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.
HAL_StatusTypeDef nfc_ReadSystemParams(I2C_HandleTypeDef *hi2c)
reading _systemParams from NFC - all data will be rewrite in _systemParams
HAL_StatusTypeDef nfc_FactoryReset(I2C_HandleTypeDef *hi2c)
reset NFC data to factory - default state
HAL_StatusTypeDef nfc_Init(I2C_HandleTypeDef *hi2c)
NFC initialization and read NFC tag systemParams from addr 0. If data there are not valid,...
This file contains all the function prototypes for the rtc.c file.
This file contains all the function prototypes for the spi.c file.
void HAL_Delay(__IO uint32_t Delay)
uint32_t HAL_GetTick(void)
Function prototypes for sys_app.c file.
void SystemApp_Init(void)
initialize the system (dbg pins, trace, mbmux, sys timer, LPM, ...)
uint8_t GetBatteryLevel(void)
callback to get the battery level in % of full charge (254 full charge, 0 no charge)
configuration of the timer_if.c instances
This file contains all the function prototypes for the usart.c file.
UART_HandleTypeDef huart1
void MX_USART1_UART_Init(void)
Header for USART interface configuration.
UTIL_ADV_TRACE_Status_t Uart_Info(const char *strInfo)
Write to UART1.
UTIL_ADV_TRACE_Status_t Uart_NextReceving()
continue with next reading if data arrived
UTIL_ADV_TRACE_Status_t Uart_StartReceving(UART_HandleTypeDef *uart)
start reading
void systemRestart()
the calling of system restart with disabling of interrupts