diff --git a/firmware/iot-risk-logger-stm32l4/Core/Inc/main.h b/firmware/iot-risk-logger-stm32l4/Core/Inc/main.h index 1d82044d..3eb6a7e1 100644 --- a/firmware/iot-risk-logger-stm32l4/Core/Inc/main.h +++ b/firmware/iot-risk-logger-stm32l4/Core/Inc/main.h @@ -37,6 +37,7 @@ extern "C" { #include "actor.h" #include "event_manager.h" #include "power_mode_manager.h" +#include "gpio_ext_interrupts.h" #include "nfc.h" #include "memory.h" #include "temperature_humidity_sensor.h" diff --git a/firmware/iot-risk-logger-stm32l4/Makefile b/firmware/iot-risk-logger-stm32l4/Makefile index b6daf551..a32b1b55 100644 --- a/firmware/iot-risk-logger-stm32l4/Makefile +++ b/firmware/iot-risk-logger-stm32l4/Makefile @@ -25,8 +25,9 @@ DEBUG = 1 OPT = -Og # NOR Flash: erase & write FAT12 filesystem boot header -ERASE_CHIP_AND_FLASH_FAT12_BOOT_SECTOR = 0 - +FLASH_ERASE_CHIP_AND_WRITE_FAT12_BOOT_SECTOR = 0 +# NOR Flash: actual writing is enabled +FLASH_WRITE_ENABLED = 0 ####################################### @@ -114,14 +115,15 @@ libraries/SystemView/SYSVIEW/SEGGER_SYSVIEW.c \ libraries/SystemView/Sample/FreeRTOSV10/SEGGER_SYSVIEW_FreeRTOS.c \ app/core/trace/SEGGER_SYSVIEW_Config_FreeRTOS.c \ app/core/actor/actor.c \ +app/core/gpio_ext_interrupts/gpio_ext_interrupts.c \ +app/core/power_mode_manager/power_mode_manager.c \ +app/core/cron/cron.c \ +app/core/fs_static/fs_static.c \ +app/core/info_led/info_led.c \ app/config/actors_list/actors_list.c \ app/config/events_list/events_list.c \ app/config/bsp_bus/bsp_bus.c \ -app/core/power_mode_manager/power_mode_manager.c \ app/tasks/event_manager/event_manager.c \ -app/core/cron/cron.c \ -app/core/info_led/info_led.c \ -app/core/fs_static/fs_static.c \ app/drivers/opt3001/opt3001.c \ app/drivers/sht3x/sht3x.c \ app/drivers/w25q/w25q.c \ @@ -215,19 +217,20 @@ C_INCLUDES = \ -Ilibraries/SystemView/SYSVIEW \ -Ilibraries/SystemView/Sample/FreeRTOSV10 \ -Iapp/core/actor \ --Iapp/config/actors_list/actors_list \ --Iapp/config/events_list/events_list \ --Iapp/config/bsp_bus \ -Iapp/core/trace \ --Iapp/core/power_mode_manager \ +-Iapp/config/bsp_bus \ -Iapp/core/fs_static \ +-Iapp/core/power_mode_manager \ +-Iapp/core/cron \ +-Iapp/core/info_led \ +-Iapp/core/gpio_ext_interrupts \ +-Iapp/config/actors_list/actors_list \ +-Iapp/config/events_list/events_list \ -Iapp/tasks/event_manager \ -Iapp/drivers/opt3001 \ -Iapp/drivers/sht3x \ -Iapp/drivers/w25q \ -Iapp/middlewares/usb_msc_storage \ --Iapp/core/cron \ --Iapp/core/info_led \ -Iapp/tasks/memory \ -Iapp/tasks/temperature_humidity_sensor \ -Iapp/tasks/light_sensor \ @@ -242,10 +245,14 @@ ifeq ($(DEBUG), 1) CFLAGS += -g -gdwarf-2 -DDEBUG endif -ifeq ($(ERASE_CHIP_AND_FLASH_FAT12_BOOT_SECTOR), 1) +ifeq ($(FLASH_ERASE_CHIP_AND_WRITE_FAT12_BOOT_SECTOR), 1) CFLAGS += -DERASE_CHIP_AND_FLASH_FAT12_BOOT_SECTOR endif +ifeq ($(FLASH_WRITE_ENABLED), 1) +CFLAGS += -FLASH_WRITE_ENABLED +endif + # Generate dependency information CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" diff --git a/firmware/iot-risk-logger-stm32l4/app/core/gpio_ext_interrupts/gpio_ext_interrupts.c b/firmware/iot-risk-logger-stm32l4/app/core/gpio_ext_interrupts/gpio_ext_interrupts.c new file mode 100644 index 00000000..8cd4039f --- /dev/null +++ b/firmware/iot-risk-logger-stm32l4/app/core/gpio_ext_interrupts/gpio_ext_interrupts.c @@ -0,0 +1,40 @@ +/*! + * @file gpio_ext_interrupts.c + * @brief implementation of gpio_ext_interrupts + * + * Detailed description of the implementation file. + * + * @date 07/10/2024 + * @author artempolisskyi + */ + +#include "gpio_ext_interrupts.h" + +extern actor_t* ACTORS_LIST_SystemRegistry[MAX_ACTORS]; + +void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { + if (GPIO_Pin == USB_VBUS_SENSE_Pin) { + GPIO_PinState usbVBusPin = HAL_GPIO_ReadPin(USB_VBUS_SENSE_GPIO_Port, USB_VBUS_SENSE_Pin); + osMessageQueueId_t evManagerQueue = ACTORS_LIST_SystemRegistry[EV_MANAGER_ACTOR_ID]->osMessageQueueId; + + if (usbVBusPin == GPIO_PIN_SET) { + osMessageQueuePut(evManagerQueue, &(message_t) {USB_CONNECTED}, 0, 0); +#if DEBUG + fprintf(stdout, "USB connected\n"); +#endif + } else { + osMessageQueuePut(evManagerQueue, &(message_t) {USB_DISCONNECTED}, 0, 0); +#if DEBUG + fprintf(stdout, "USB disconnected\n"); +#endif + } + } + + // TODO maybe check only falling edge (configure in CubeMX) + if (GPIO_Pin == _NFC_INT_Pin) { +#ifdef DEBUG + fprintf(stdout, "NFC GPO Interrupt\n"); +#endif + osMessageQueuePut(NFC_Actor.super.osMessageQueueId, &(message_t){NFC_GPO_INTERRUPT}, 0, 0); + } +} \ No newline at end of file diff --git a/firmware/iot-risk-logger-stm32l4/app/core/gpio_ext_interrupts/gpio_ext_interrupts.h b/firmware/iot-risk-logger-stm32l4/app/core/gpio_ext_interrupts/gpio_ext_interrupts.h new file mode 100644 index 00000000..f2d3eab6 --- /dev/null +++ b/firmware/iot-risk-logger-stm32l4/app/core/gpio_ext_interrupts/gpio_ext_interrupts.h @@ -0,0 +1,27 @@ +/*! + * @file gpio_ext_interrupts.h + * @brief Brief description of the file. + * + * Detailed description of the file. + * + * @date 07/10/2024 + * @author artempolisskyi + */ + +#ifndef GPIO_EXT_INTERRUPTS_H +#define GPIO_EXT_INTERRUPTS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include "main.h" + + +#ifdef __cplusplus +} +#endif + +#endif //GPIO_EXT_INTERRUPTS_H \ No newline at end of file diff --git a/firmware/iot-risk-logger-stm32l4/app/tasks/memory/memory.c b/firmware/iot-risk-logger-stm32l4/app/tasks/memory/memory.c index 8ea334e3..b01c3d6e 100644 --- a/firmware/iot-risk-logger-stm32l4/app/tasks/memory/memory.c +++ b/firmware/iot-risk-logger-stm32l4/app/tasks/memory/memory.c @@ -156,32 +156,6 @@ uint32_t MEMORY_SeekFreeSpaceAddress(void) { return addr; } -// TODO move to more suitable place -void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { - if (GPIO_Pin == USB_VBUS_SENSE_Pin) { - GPIO_PinState usbVBusPin = HAL_GPIO_ReadPin(USB_VBUS_SENSE_GPIO_Port, USB_VBUS_SENSE_Pin); - osMessageQueueId_t evManagerQueue = ACTORS_LIST_SystemRegistry[EV_MANAGER_ACTOR_ID]->osMessageQueueId; - - if (usbVBusPin == GPIO_PIN_SET) { - osMessageQueuePut(evManagerQueue, &(message_t) {USB_CONNECTED}, 0, 0); - #if DEBUG - fprintf(stdout, "USB connected\n"); - #endif - } else { - osMessageQueuePut(evManagerQueue, &(message_t) {USB_DISCONNECTED}, 0, 0); - #if DEBUG - fprintf(stdout, "USB disconnected\n"); - #endif - } - } - - if (GPIO_Pin == _NFC_INT_Pin) { - #ifdef DEBUG - fprintf(stdout, "NFC GPO Interrupt\n"); - #endif - osMessageQueuePut(NFC_Actor.super.osMessageQueueId, &(message_t){NFC_GPO_INTERRUPT}, 0, 0); - } -} /** * @brief Writes FAT12 boot sector to the NOR Flash @@ -229,7 +203,7 @@ static osStatus_t handleInit(MEMORY_Actor_t *this, message_t *message) { fprintf(stdout, "W25Q NOR MF ID: 0x%x, Device ID: 0x%x\n", norFlashID[0], norFlashID[1]); #endif - #ifdef ERASE_CHIP_AND_FLASH_FAT12_BOOT_SECTOR + #ifdef FLASH_ERASE_CHIP_AND_WRITE_FAT12_BOOT_SECTOR writeFAT12BootSector(&MEMORY_Actor); #endif @@ -324,6 +298,8 @@ static void publishMemoryWriteOnMeasurementsReady(MEMORY_Actor_t *this) { } static osStatus_t appendMeasurementsToNORFlashLogTail(MEMORY_Actor_t *this) { + osStatus_t ioStatus = osOK; + // sensors actors pointers from the system registry TH_SENS_Actor_t *thSensActor = (TH_SENS_Actor_t *)ACTORS_LIST_SystemRegistry[TEMPERATURE_HUMIDITY_SENSOR_ACTOR_ID]; LIGHT_SENS_Actor_t *lightSensorActor = (LIGHT_SENS_Actor_t *)ACTORS_LIST_SystemRegistry[LIGHT_SENSOR_ACTOR_ID]; @@ -350,7 +326,9 @@ static osStatus_t appendMeasurementsToNORFlashLogTail(MEMORY_Actor_t *this) { #endif // write measurements to the memory - osStatus_t ioStatus = osOK; //W25Q_WriteData(&MEMORY_W25QHandle, (uint8_t *) &sensorsMeasurementEntry, this->logFileTailAddress, MEMORY_LOG_ENTRY_SIZE); + #ifdef FLASH_WRITE_ENABLED + ioStatus = W25Q_WriteData(&MEMORY_W25QHandle, (uint8_t *) &sensorsMeasurementEntry, this->logFileTailAddress, MEMORY_LOG_ENTRY_SIZE); + #endif // increment tail free space address for the next entry this->logFileTailAddress += MEMORY_LOG_ENTRY_SIZE; diff --git a/firmware/iot-risk-logger-stm32l4/app/tasks/nfc/README.md b/firmware/iot-risk-logger-stm32l4/app/tasks/nfc/README.md index e55cff98..f52e7cad 100644 --- a/firmware/iot-risk-logger-stm32l4/app/tasks/nfc/README.md +++ b/firmware/iot-risk-logger-stm32l4/app/tasks/nfc/README.md @@ -11,8 +11,13 @@ @startuml title NFC FSM hide empty description + STANDBY: RF free\nI2C free -[*] --> STANDBY : INITIALIZE +MAILBOX_TRANSMISSION: Mailbox data exchange +ERROR: Error state\n\nGLOBAL_ERROR: Error message + +[*] --> STANDBY : GLOBAL_CMD_INITIALIZE +STANDBY --> MAILBOX_TRANSMISSION : NFC_GPO_INTERRUPT STANDBY --> ERROR : ERROR @enduml ``` diff --git a/firmware/iot-risk-logger-stm32l4/app/tasks/nfc/nfc.c b/firmware/iot-risk-logger-stm32l4/app/tasks/nfc/nfc.c index 96e438a5..01b8aef0 100644 --- a/firmware/iot-risk-logger-stm32l4/app/tasks/nfc/nfc.c +++ b/firmware/iot-risk-logger-stm32l4/app/tasks/nfc/nfc.c @@ -12,6 +12,8 @@ static osStatus_t handleNFCFSM(NFC_Actor_t *this, message_t *message); static osStatus_t handleInit(NFC_Actor_t *this, message_t *message); +extern actor_t* ACTORS_LIST_SystemRegistry[MAX_ACTORS]; + NFC_Actor_t NFC_Actor = { .super = { .actorId = NFC_ACTOR_ID, @@ -53,24 +55,16 @@ void NFC_Task(void *argument) { // Wait for messages from the queue if (osMessageQueueGet(NFC_Actor.super.osMessageQueueId, &msg, NULL, osWaitForever) == osOK) { osStatus_t status = NFC_Actor.super.messageHandler((actor_t *) &NFC_Actor, &msg); + if (status != osOK) { - // TODO Handle error, emit common error event and reinitialize module - NFC_Actor.state = NFC_STATE_ERROR; + osMessageQueueId_t evManagerQueue = ACTORS_LIST_SystemRegistry[EV_MANAGER_ACTOR_ID]->osMessageQueueId; + osMessageQueuePut(evManagerQueue, &(message_t){GLOBAL_ERROR, .payload.value = NFC_ACTOR_ID}, 0, 0); + TO_STATE(&NFC_Actor, NFC_STATE_ERROR); } } } } -/** Handle GPO interrupt */ -//void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { -// if (GPIO_Pin == _NFC_INT_Pin) { -// #ifdef DEBUG -// fprintf(stdout, "NFC GPO Interrupt\n"); -// #endif -// osMessageQueuePut(NFC_Actor.super.osMessageQueueId, &(message_t){NFC_GPO_INTERRUPT}, 0, 0); -// } -//} - static osStatus_t handleNFCFSM(NFC_Actor_t *this, message_t *message) { switch (this->state) { case NFC_NO_STATE: diff --git a/firmware/iot-risk-logger-stm32l4/app/tasks/nfc/nfc_handlers.c b/firmware/iot-risk-logger-stm32l4/app/tasks/nfc/nfc_handlers.c index 0f18c4f0..0bfc9d20 100644 --- a/firmware/iot-risk-logger-stm32l4/app/tasks/nfc/nfc_handlers.c +++ b/firmware/iot-risk-logger-stm32l4/app/tasks/nfc/nfc_handlers.c @@ -31,11 +31,6 @@ int32_t NFC_ST25DVInit(ST25DV_Object_t *pObj) { return NFCTAG_OK; } -int32_t NFC_LowPowerMode(ST25DV_Object_t *pObj) { - - return NFCTAG_OK; -} - void NFC_HandleGPOInterrupt(ST25DV_Object_t *pObj) { uint8_t ITStatus; ST25DV_ReadITSTStatus_Dyn(pObj, &ITStatus); diff --git a/hardware-debug/iot-risk-logger-stm32l4.ozone.jdebug.user b/hardware-debug/iot-risk-logger-stm32l4.ozone.jdebug.user index 6c8ac85f..2693fdce 100644 --- a/hardware-debug/iot-risk-logger-stm32l4.ozone.jdebug.user +++ b/hardware-debug/iot-risk-logger-stm32l4.ozone.jdebug.user @@ -1,26 +1,28 @@ -Breakpoint=/Users/artempolisskyi/projects/iot-risk-logger-stm32l4/firmware/iot-risk-logger-stm32l4/app/tasks/memory/memory.c:132:5, State=BP_STATE_DISABLED -Breakpoint=/Users/artempolisskyi/projects/iot-risk-logger-stm32l4/firmware/iot-risk-logger-stm32l4/app/tasks/memory/memory.c:251:9, State=BP_STATE_DISABLED -OpenDocument="memory.c", FilePath="/Users/artempolisskyi/projects/iot-risk-logger-stm32l4/firmware/iot-risk-logger-stm32l4/app/tasks/memory/memory.c", Line=286 -OpenDocument="tasks.c", FilePath="/Users/artempolisskyi/projects/iot-risk-logger-stm32l4/firmware/iot-risk-logger-stm32l4/Middlewares/Third_Party/FreeRTOS/Source/tasks.c", Line=3402 -OpenDocument="main.c", FilePath="/Users/artempolisskyi/projects/iot-risk-logger-stm32l4/firmware/iot-risk-logger-stm32l4/Core/Src/main.c", Line=55 +Breakpoint=/Users/artempolisskyi/projects/iot-risk-logger-stm32l4/firmware/iot-risk-logger-stm32l4/app/tasks/memory/memory.c:111:5, State=BP_STATE_DISABLED +Breakpoint=/Users/artempolisskyi/projects/iot-risk-logger-stm32l4/firmware/iot-risk-logger-stm32l4/app/tasks/memory/memory.c:140:5, State=BP_STATE_DISABLED +Breakpoint=/Users/artempolisskyi/projects/iot-risk-logger-stm32l4/firmware/iot-risk-logger-stm32l4/app/tasks/memory/memory.c:253:5, State=BP_STATE_DISABLED +OpenDocument="stm32l4xx_it.c", FilePath="/Users/artempolisskyi/projects/iot-risk-logger-stm32l4/firmware/iot-risk-logger-stm32l4/Core/Src/stm32l4xx_it.c", Line=79 +OpenDocument="memory.c", FilePath="/Users/artempolisskyi/projects/iot-risk-logger-stm32l4/firmware/iot-risk-logger-stm32l4/app/tasks/memory/memory.c", Line=88 +OpenDocument="tasks.c", FilePath="/Users/artempolisskyi/projects/iot-risk-logger-stm32l4/firmware/iot-risk-logger-stm32l4/Middlewares/Third_Party/FreeRTOS/Source/tasks.c", Line=3652 +OpenDocument="main.c", FilePath="/Users/artempolisskyi/projects/iot-risk-logger-stm32l4/firmware/iot-risk-logger-stm32l4/Core/Src/main.c", Line=64 OpenToolbar="Debug", Floating=0, x=0, y=0 -OpenWindow="Call Stack", DockArea=RIGHT, x=0, y=2, w=361, h=91, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0 +OpenWindow="Call Stack", DockArea=RIGHT, x=0, y=2, w=361, h=92, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0 OpenWindow="Registers 1", DockArea=RIGHT, x=0, y=4, w=361, h=91, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0, FilteredItems=[], RefreshRate=1 -OpenWindow="Source Files", DockArea=LEFT, x=0, y=2, w=323, h=187, TabPos=1, TopOfStack=1, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0 -OpenWindow="Disassembly", DockArea=RIGHT, x=0, y=3, w=361, h=91, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0 -OpenWindow="Break & Tracepoints", DockArea=LEFT, x=0, y=1, w=323, h=172, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0, VectorCatchIndexMask=255 -OpenWindow="Global Data", DockArea=RIGHT, x=0, y=0, w=361, h=100, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0 -OpenWindow="Local Data", DockArea=RIGHT, x=0, y=1, w=361, h=91, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0 -OpenWindow="Watched Data 1", DockArea=LEFT, x=0, y=0, w=323, h=91, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0 -OpenWindow="Functions", DockArea=LEFT, x=0, y=2, w=323, h=187, TabPos=0, TopOfStack=0, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0 -OpenWindow="Terminal", DockArea=BOTTOM, x=0, y=0, w=544, h=315, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0 -OpenWindow="Console", DockArea=BOTTOM, x=1, y=0, w=735, h=315, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0 +OpenWindow="Source Files", DockArea=LEFT, x=0, y=2, w=323, h=175, TabPos=1, TopOfStack=1, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0 +OpenWindow="Disassembly", DockArea=RIGHT, x=0, y=3, w=361, h=92, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0 +OpenWindow="Break & Tracepoints", DockArea=LEFT, x=0, y=1, w=323, h=168, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0, VectorCatchIndexMask=255 +OpenWindow="Global Data", DockArea=RIGHT, x=0, y=0, w=361, h=97, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0 +OpenWindow="Local Data", DockArea=RIGHT, x=0, y=1, w=361, h=92, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0 +OpenWindow="Watched Data 1", DockArea=LEFT, x=0, y=0, w=323, h=107, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0 +OpenWindow="Functions", DockArea=LEFT, x=0, y=2, w=323, h=175, TabPos=0, TopOfStack=0, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0 +OpenWindow="Terminal", DockArea=BOTTOM, x=0, y=0, w=302, h=315, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0 +OpenWindow="Console", DockArea=BOTTOM, x=1, y=0, w=959, h=315, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0 SmartViewPlugin="", Page="", Toolbar="Hidden", Window="SmartView 1" TableHeader="Source Files", SortCol="File", SortOrder="ASCENDING", VisibleCols=["File";"Status";"Size";"#Insts";"Path"], ColWidths=[197;100;100;100;980] TableHeader="Functions", SortCol="Name", SortOrder="ASCENDING", VisibleCols=["Name";"Address";"Size";"#Insts";"Source"], ColWidths=[1236;100;100;100;100] -TableHeader="Global Data", SortCol="Name", SortOrder="ASCENDING", VisibleCols=["Name";"Value";"Location";"Size";"Type";"Scope"], ColWidths=[183;269;100;100;100;100] +TableHeader="Global Data", SortCol="Name", SortOrder="ASCENDING", VisibleCols=["Name";"Value";"Location";"Size";"Type";"Scope"], ColWidths=[183;269;100;100;100;272] TableHeader="Vector Catches", SortCol="", SortOrder="ASCENDING", VisibleCols=["";"Vector Catch";"Description"], ColWidths=[50;300;500] TableHeader="Break & Tracepoints", SortCol="", SortOrder="ASCENDING", VisibleCols=["";"Type";"Location";"Extras"], ColWidths=[100;100;350;224] TableHeader="Local Data", SortCol="Name", SortOrder="ASCENDING", VisibleCols=["Name";"Value";"Location";"Size";"Type";"Scope"], ColWidths=[152;206;100;100;100;100]