diff --git a/Core/Inc/sys_conf.h b/Core/Inc/sys_conf.h
index 1f15237..16d0145 100644
--- a/Core/Inc/sys_conf.h
+++ b/Core/Inc/sys_conf.h
@@ -47,12 +47,12 @@ extern "C" {
/**
* @brief Verbose level for all trace logs
*/
-#define VERBOSE_LEVEL VLEVEL_M
+#define VERBOSE_LEVEL VLEVEL_OFF
/**
* @brief Enable trace logs
*/
-#define APP_LOG_ENABLED 1
+#define APP_LOG_ENABLED 0
/**
* @brief Activate monitoring (probes) of some internal RF signals for debug purpose
diff --git a/Core/Inc/utilities_def.h b/Core/Inc/utilities_def.h
index bcf7700..f28e621 100644
--- a/Core/Inc/utilities_def.h
+++ b/Core/Inc/utilities_def.h
@@ -80,7 +80,7 @@ typedef enum
CFG_SEQ_Task_LoRaStoreContextEvent,
CFG_SEQ_Task_LoRaStopJoinEvent,
/* USER CODE BEGIN CFG_SEQ_Task_Id_t */
-
+ CFG_SEQ_Task_YunhornSTSP1CheckingEvent,
/* USER CODE END CFG_SEQ_Task_Id_t */
CFG_SEQ_Task_NBR
} CFG_SEQ_Task_Id_t;
diff --git a/Core/Src/gpio.c b/Core/Src/gpio.c
index 7cda6a6..f51ed30 100644
--- a/Core/Src/gpio.c
+++ b/Core/Src/gpio.c
@@ -49,6 +49,21 @@ void MX_GPIO_Init(void)
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
+ GPIO_InitStruct.Pin = GPIO_PIN_All;
+ GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+ HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
+ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+ __HAL_RCC_GPIOB_CLK_DISABLE();
+ __HAL_RCC_GPIOC_CLK_DISABLE();
+
+ GPIO_InitStruct.Pin = BUT1_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
+ GPIO_InitStruct.Pull = GPIO_PULLUP;
+ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+ __HAL_RCC_GPIOA_CLK_DISABLE();
+#if 0
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, LED1_Pin|LED2_Pin|PROB2_Pin|PROB1_Pin
|LED3_Pin, GPIO_PIN_RESET);
@@ -78,17 +93,17 @@ void MX_GPIO_Init(void)
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(BUT3_GPIO_Port, &GPIO_InitStruct);
-
+#endif
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI0_IRQn);
-
+#if 0
HAL_NVIC_SetPriority(EXTI1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI1_IRQn);
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
-
+#endif
}
/* USER CODE BEGIN 2 */
diff --git a/Core/Src/rtc.c b/Core/Src/rtc.c
index 04a8214..918ceaf 100644
--- a/Core/Src/rtc.c
+++ b/Core/Src/rtc.c
@@ -65,7 +65,7 @@ void MX_RTC_Init(void)
{
Error_Handler();
}
-
+#if 0
/** Enable the Alarm A
*/
sAlarm.BinaryAutoClr = RTC_ALARMSUBSECONDBIN_AUTOCLR_NO;
@@ -78,7 +78,7 @@ void MX_RTC_Init(void)
Error_Handler();
}
/* USER CODE BEGIN RTC_Init 2 */
-
+#endif
/* USER CODE END RTC_Init 2 */
}
diff --git a/Core/Src/stm32_lpm_if.c b/Core/Src/stm32_lpm_if.c
index 8b623ee..9d98b45 100644
--- a/Core/Src/stm32_lpm_if.c
+++ b/Core/Src/stm32_lpm_if.c
@@ -25,7 +25,7 @@
#include "usart_if.h"
/* USER CODE BEGIN Includes */
-
+#include "gpio.h"
/* USER CODE END Includes */
/* External variables ---------------------------------------------------------*/
@@ -78,14 +78,30 @@ const struct UTIL_LPM_Driver_s UTIL_PowerDriver =
void PWR_EnterOffMode(void)
{
/* USER CODE BEGIN EnterOffMode_1 */
+ /* Enable Power Clock */
+ HAL_SuspendTick();
+ /* Disable all used wakeup sources: Pin1(PA.0) */
+ HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1|PWR_WAKEUP_PIN2|PWR_WAKEUP_PIN3);
+
+ /* Clear all related wakeup flags */
+ __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
+
+ /* Re-enable all used wakeup sources: Pin1(PA.0) */
+ HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
+
+ /*## Enter Standby Mode ####################################################*/
+ /* Request to enter STANDBY mode */
+ HAL_PWR_EnterSTANDBYMode();
/* USER CODE END EnterOffMode_1 */
}
void PWR_ExitOffMode(void)
{
/* USER CODE BEGIN ExitOffMode_1 */
-
+ //HAL_ResumeTick();
+ __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
+ __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
/* USER CODE END ExitOffMode_1 */
}
@@ -94,6 +110,10 @@ void PWR_EnterStopMode(void)
/* USER CODE BEGIN EnterStopMode_1 */
/* USER CODE END EnterStopMode_1 */
+ HAL_GPIO_WritePin(GPIOB, GPIO_PIN_All, GPIO_PIN_RESET);
+ HAL_GPIO_WritePin(GPIOA, ~GPIO_PIN_0, GPIO_PIN_RESET);
+ vcom_DeInit();
+
HAL_SuspendTick();
/* Clear Status Flag before entering STOP/STANDBY Mode */
LL_PWR_ClearFlag_C1STOP_C1STB();
@@ -120,7 +140,8 @@ void PWR_ExitStopMode(void)
SRAM ctrls, DMAx, DMAMux, AES, RNG, HSEM */
/* Resume not retained USARTx and DMA */
- vcom_Resume();
+ //MX_GPIO_Init();
+ //vcom_Resume();
/* USER CODE BEGIN ExitStopMode_2 */
/* USER CODE END ExitStopMode_2 */
diff --git a/Core/Src/stm32wlxx_it.c b/Core/Src/stm32wlxx_it.c
index 66231ac..bfc2186 100644
--- a/Core/Src/stm32wlxx_it.c
+++ b/Core/Src/stm32wlxx_it.c
@@ -227,7 +227,7 @@ void EXTI0_IRQHandler(void)
/* USER CODE END EXTI0_IRQn 1 */
}
-
+#if 0
/**
* @brief This function handles EXTI Line 1 Interrupt.
*/
@@ -283,7 +283,7 @@ void USART2_IRQHandler(void)
/* USER CODE END USART2_IRQn 1 */
}
-
+#endif
/**
* @brief This function handles RTC Alarms (A and B) Interrupt.
*/
diff --git a/Core/Src/sys_app.c b/Core/Src/sys_app.c
index 705ba80..42d7e5d 100644
--- a/Core/Src/sys_app.c
+++ b/Core/Src/sys_app.c
@@ -100,7 +100,7 @@ void SystemApp_Init(void)
UTIL_TIMER_Init();
SYS_TimerInitialisedFlag = 1;
/* Initializes the SW probes pins and the monitor RF pins via Alternate Function */
- DBG_Init();
+ //DBG_Init();
/*Initialize the terminal */
UTIL_ADV_TRACE_Init();
@@ -122,7 +122,7 @@ void SystemApp_Init(void)
UTIL_LPM_Init();
/* Disable Stand-by mode */
UTIL_LPM_SetOffMode((1 << CFG_LPM_APPLI_Id), UTIL_LPM_DISABLE);
-
+ UTIL_LPM_SetOffMode((1 << CFG_LPM_UART_TX_Id), UTIL_LPM_ENABLE);
#if defined (LOW_POWER_DISABLE) && (LOW_POWER_DISABLE == 1)
/* Disable Stop Mode */
UTIL_LPM_SetStopMode((1 << CFG_LPM_APPLI_Id), UTIL_LPM_DISABLE);
diff --git a/Core/Src/usart.c b/Core/Src/usart.c
index bf9fd2b..62e4a98 100644
--- a/Core/Src/usart.c
+++ b/Core/Src/usart.c
@@ -100,13 +100,18 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
PA3 ------> USART2_RX
PA2 ------> USART2_TX
*/
- GPIO_InitStruct.Pin = USARTx_RX_Pin|USARTx_TX_Pin;
+ GPIO_InitStruct.Pin = USARTx_TX_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+ GPIO_InitStruct.Pin = USARTx_RX_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+
/* USART2 DMA Init */
/* USART2_TX Init */
hdma_usart2_tx.Instance = DMA1_Channel5;
diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c
index 0eabe19..43dc765 100644
--- a/LoRaWAN/App/lora_app.c
+++ b/LoRaWAN/App/lora_app.c
@@ -36,7 +36,7 @@
#include "flash_if.h"
/* USER CODE BEGIN Includes */
-
+#include "gpio.h"
/* USER CODE END Includes */
/* External variables ---------------------------------------------------------*/
@@ -215,6 +215,7 @@ static void OnPingSlotPeriodicityChanged(uint8_t pingSlotPeriodicity);
static void OnSystemReset(void);
/* USER CODE BEGIN PFP */
+static void OnYunhornSTSP1CheckingEvent(void);
/**
* @brief LED Tx timer callback function
@@ -300,7 +301,7 @@ static UTIL_TIMER_Object_t TxTimer;
/**
* @brief Tx Timer period
*/
-static UTIL_TIMER_Time_t TxPeriodicity = APP_TX_DUTYCYCLE;
+static UTIL_TIMER_Time_t TxPeriodicity = 1000;
/**
* @brief Join Timer period
@@ -342,7 +343,8 @@ static UTIL_TIMER_Object_t JoinLedTimer;
/* Exported functions ---------------------------------------------------------*/
/* USER CODE BEGIN EF */
-
+volatile uint8_t door_status=0, door_changed_flag=0, door_previous_status=0;
+volatile uint32_t checking_sn=0;
/* USER CODE END EF */
void LoRaWAN_Init(void)
@@ -404,7 +406,7 @@ void LoRaWAN_Init(void)
UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), UTIL_SEQ_RFU, SendTxData);
UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_LoRaStoreContextEvent), UTIL_SEQ_RFU, StoreContext);
UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_LoRaStopJoinEvent), UTIL_SEQ_RFU, StopJoin);
-
+ UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSP1CheckingEvent),UTIL_SEQ_RFU, OnYunhornSTSP1CheckingEvent);
/* Init Info table used by LmHandler*/
LoraInfo_Init();
@@ -423,7 +425,7 @@ void LoRaWAN_Init(void)
if (EventType == TX_ON_TIMER)
{
/* send every time timer elapses */
- UTIL_TIMER_Create(&TxTimer, TxPeriodicity, UTIL_TIMER_ONESHOT, OnTxTimerEvent, NULL);
+ UTIL_TIMER_Create(&TxTimer, TxPeriodicity, UTIL_TIMER_PERIODIC, OnTxTimerEvent, NULL);
UTIL_TIMER_Start(&TxTimer);
}
else
@@ -446,6 +448,9 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
case BUT1_Pin:
/* Note: when "EventType == TX_ON_TIMER" this GPIO is not initialized */
+ door_changed_flag = 1;
+ UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSP1CheckingEvent), CFG_SEQ_Prio_0);
+
if (EventType == TX_ON_EVENT)
{
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
@@ -466,7 +471,21 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
/* Private functions ---------------------------------------------------------*/
/* USER CODE BEGIN PrFD */
+static void OnYunhornSTSP1CheckingEvent(void)
+{
+
+ door_status = HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0);
+
+ if (door_status != door_previous_status)
+ {
+ door_previous_status = door_status;
+ door_changed_flag = 1;
+ APP_LOG(TS_OFF,VLEVEL_M,"\r\n----- Door Status Changed-------------\r\n");
+ }
+
+ //UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
+}
/* USER CODE END PrFD */
static void OnRxData(LmHandlerAppData_t *appData, LmHandlerRxParams_t *params)
@@ -572,10 +591,10 @@ static void SendTxData(void)
#endif /* CAYENNE_LPP */
EnvSensors_Read(&sensor_data);
-
+#if 0
APP_LOG(TS_ON, VLEVEL_M, "VDDA: %d\r\n", batteryLevel);
APP_LOG(TS_ON, VLEVEL_M, "temp: %d\r\n", (int16_t)(sensor_data.temperature));
-
+#endif
AppData.Port = LORAWAN_USER_APP_PORT;
#ifdef CAYENNE_LPP
@@ -610,8 +629,8 @@ static void SendTxData(void)
{
AppData.Buffer[i++] = 0;
AppData.Buffer[i++] = 0;
- AppData.Buffer[i++] = 0;
- AppData.Buffer[i++] = 0;
+ AppData.Buffer[i++] = (uint8_t)(99*GetBatteryLevel()/255); /* 1 (very low) to 254 (fully charged) */
+ AppData.Buffer[i++] = door_status;
}
else
{
@@ -666,12 +685,13 @@ static void SendTxData(void)
static void OnTxTimerEvent(void *context)
{
/* USER CODE BEGIN OnTxTimerEvent_1 */
-
- /* USER CODE END OnTxTimerEvent_1 */
- UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
-
- /*Wait for next tx slot*/
- UTIL_TIMER_Start(&TxTimer);
+ UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSP1CheckingEvent), CFG_SEQ_Prio_0);
+ if (door_changed_flag ==1)
+ {
+ door_changed_flag =0;
+ UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
+ //UTIL_TIMER_Start(&TxTimer);
+ }
/* USER CODE BEGIN OnTxTimerEvent_2 */
/* USER CODE END OnTxTimerEvent_2 */
diff --git a/STM32CubeIDE/.settings/language.settings.xml b/STM32CubeIDE/.settings/language.settings.xml
index 90666d3..879e516 100644
--- a/STM32CubeIDE/.settings/language.settings.xml
+++ b/STM32CubeIDE/.settings/language.settings.xml
@@ -5,7 +5,7 @@
-
+
@@ -16,10 +16,10 @@
-
+
-
\ No newline at end of file
+
diff --git a/STM32CubeIDE/.settings/stm32cubeide.project.prefs b/STM32CubeIDE/.settings/stm32cubeide.project.prefs
index 261dff3..66ab618 100644
--- a/STM32CubeIDE/.settings/stm32cubeide.project.prefs
+++ b/STM32CubeIDE/.settings/stm32cubeide.project.prefs
@@ -1,4 +1,2 @@
-2F62501ED4689FB349E356AB974DBE57=5C935C4C17B31F3FCDEC56E445F41B57
-8DF89ED150041C4CBC7CB9A9CAA90856=5C935C4C17B31F3FCDEC56E445F41B57
DC22A860405A8BF2F2C095E5B6529F12=74CD6EB106FB50B767E4FE71225C7638
eclipse.preferences.version=1
diff --git a/STM32CubeIDE/STM32WL55JCIX_FLASH.ld b/STM32CubeIDE/STM32WL55JCIX_FLASH.ld
index 43a7268..5a6bcc7 100644
--- a/STM32CubeIDE/STM32WL55JCIX_FLASH.ld
+++ b/STM32CubeIDE/STM32WL55JCIX_FLASH.ld
@@ -97,7 +97,7 @@ SECTIONS
. = ALIGN(8);
} >FLASH
- .ARM (READONLY): {
+ .ARM(READONLY) : {
. = ALIGN(8);
__exidx_start = .;
*(.ARM.exidx*)
@@ -105,6 +105,7 @@ SECTIONS
. = ALIGN(8);
} >FLASH
+
.preinit_array (READONLY) :
{
. = ALIGN(8);
@@ -114,6 +115,7 @@ SECTIONS
. = ALIGN(8);
} >FLASH
+
.init_array (READONLY):
{
. = ALIGN(8);
@@ -124,7 +126,7 @@ SECTIONS
. = ALIGN(8);
} >FLASH
- .fini_array (READONLY):
+ .fini_array(READONLY) :
{
. = ALIGN(8);
PROVIDE_HIDDEN (__fini_array_start = .);
diff --git a/STM32CubeIDE/WL55JC_AS923.launch b/STM32CubeIDE/WL55JC_AS923.launch
index 9c1e726..4ffa9b7 100644
--- a/STM32CubeIDE/WL55JC_AS923.launch
+++ b/STM32CubeIDE/WL55JC_AS923.launch
@@ -78,5 +78,6 @@
+