diff --git a/.cproject b/.cproject
index ee58f43..d158aa2 100644
--- a/.cproject
+++ b/.cproject
@@ -112,7 +112,7 @@
-
+
diff --git a/Core/Inc/FreeRTOSConfig.h b/Core/Inc/FreeRTOSConfig.h
index ab1a1d7..f67e663 100644
--- a/Core/Inc/FreeRTOSConfig.h
+++ b/Core/Inc/FreeRTOSConfig.h
@@ -67,10 +67,8 @@
#define configUSE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 8
#define configUSE_RECURSIVE_MUTEXES 1
-#define configUSE_APPLICATION_TASK_TAG 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
-#define configUSE_TICKLESS_IDLE 1
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
@@ -150,17 +148,4 @@ standard names. */
/* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */
/* USER CODE END Defines */
-#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
-void PreSleepProcessing(uint32_t *ulExpectedIdleTime);
-void PostSleepProcessing(uint32_t *ulExpectedIdleTime);
-#endif /* defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) */
-
-/* The configPRE_SLEEP_PROCESSING() and configPOST_SLEEP_PROCESSING() macros
-allow the application writer to add additional code before and after the MCU is
-placed into the low power state respectively. */
-#if configUSE_TICKLESS_IDLE == 1
-#define configPRE_SLEEP_PROCESSING PreSleepProcessing
-#define configPOST_SLEEP_PROCESSING PostSleepProcessing
-#endif /* configUSE_TICKLESS_IDLE == 1 */
-
#endif /* FREERTOS_CONFIG_H */
diff --git a/Core/Inc/gpio.h b/Core/Inc/gpio.h
index 4b739a2..54467d2 100644
--- a/Core/Inc/gpio.h
+++ b/Core/Inc/gpio.h
@@ -28,7 +28,8 @@
#include "main.h"
/* USER CODE BEGIN Includes */
-#include "gpio.h"
+#include "navikit.h"
+#include "stdbool.h"
/* USER CODE END Includes */
/* USER CODE BEGIN Private defines */
@@ -38,10 +39,8 @@
void MX_GPIO_Init(void);
/* USER CODE BEGIN Prototypes */
+void Beep(uint32_t time_ms);
-void demoEnumCtlInit();
-void demoLedInit();
-void demoLedBlink();
/* USER CODE END Prototypes */
#ifdef __cplusplus
diff --git a/Core/Inc/main.h b/Core/Inc/main.h
index e4d057e..f00e187 100644
--- a/Core/Inc/main.h
+++ b/Core/Inc/main.h
@@ -58,8 +58,9 @@ void Error_Handler(void);
/* USER CODE END EFP */
/* Private defines -----------------------------------------------------------*/
-#define POWER_BUTTON_Pin GPIO_PIN_2
-#define POWER_BUTTON_GPIO_Port GPIOE
+#define PWR_BUTTON_Pin GPIO_PIN_2
+#define PWR_BUTTON_GPIO_Port GPIOE
+#define PWR_BUTTON_EXTI_IRQn EXTI2_IRQn
#define LED_RUN_Pin GPIO_PIN_3
#define LED_RUN_GPIO_Port GPIOE
#define SYS_WKUP_Pin GPIO_PIN_0
diff --git a/Core/Inc/navikit.h b/Core/Inc/navikit.h
new file mode 100644
index 0000000..1590557
--- /dev/null
+++ b/Core/Inc/navikit.h
@@ -0,0 +1,19 @@
+/*
+ * navikit.h
+ *
+ * Created on: Apr 17, 2020
+ * Author: oarap
+ */
+
+#ifndef INC_NAVIKIT_H_
+#define INC_NAVIKIT_H_
+
+#include "stdbool.h"
+
+typedef struct
+{
+ bool pwr_button_status;
+}NaviKit_t;
+extern NaviKit_t NaviKit;
+
+#endif /* INC_NAVIKIT_H_ */
diff --git a/Core/Inc/stm32f1xx_it.h b/Core/Inc/stm32f1xx_it.h
index 2b19ed9..72a76bf 100644
--- a/Core/Inc/stm32f1xx_it.h
+++ b/Core/Inc/stm32f1xx_it.h
@@ -56,6 +56,7 @@ void DebugMon_Handler(void);
void PVD_IRQHandler(void);
void FLASH_IRQHandler(void);
void RCC_IRQHandler(void);
+void EXTI2_IRQHandler(void);
void TIM1_UP_IRQHandler(void);
void I2C1_EV_IRQHandler(void);
void I2C1_ER_IRQHandler(void);
diff --git a/Core/Src/freertos.c b/Core/Src/freertos.c
index c99c2c1..da538f5 100644
--- a/Core/Src/freertos.c
+++ b/Core/Src/freertos.c
@@ -30,6 +30,9 @@
#include "gpio.h"
#include "usart.h"
#include "stdio.h"
+#include "navikit.h"
+
+#include "stdbool.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
@@ -72,6 +75,13 @@ const osThreadAttr_t IWDGRefreshTask_attributes = {
.priority = (osPriority_t) osPriorityHigh,
.stack_size = 128 * 4
};
+/* Definitions for ButtonDetect */
+osThreadId_t ButtonDetectHandle;
+const osThreadAttr_t ButtonDetect_attributes = {
+ .name = "ButtonDetect",
+ .priority = (osPriority_t) osPriorityLow,
+ .stack_size = 128 * 4
+};
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */
@@ -80,26 +90,11 @@ const osThreadAttr_t IWDGRefreshTask_attributes = {
void StartDefaultTask(void *argument);
void StartLedBlinkTask(void *argument);
void StartIWDGRefreshTask(void *argument);
+void StartButtonDetect(void *argument);
extern void MX_USB_DEVICE_Init(void);
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
-/* Pre/Post sleep processing prototypes */
-void PreSleepProcessing(uint32_t *ulExpectedIdleTime);
-void PostSleepProcessing(uint32_t *ulExpectedIdleTime);
-
-/* USER CODE BEGIN PREPOSTSLEEP */
-__weak void PreSleepProcessing(uint32_t *ulExpectedIdleTime)
-{
-/* place for user code */
-}
-
-__weak void PostSleepProcessing(uint32_t *ulExpectedIdleTime)
-{
-/* place for user code */
-}
-/* USER CODE END PREPOSTSLEEP */
-
/**
* @brief FreeRTOS initialization
* @param None
@@ -136,6 +131,9 @@ void MX_FREERTOS_Init(void) {
/* creation of IWDGRefreshTask */
IWDGRefreshTaskHandle = osThreadNew(StartIWDGRefreshTask, NULL, &IWDGRefreshTask_attributes);
+ /* creation of ButtonDetect */
+ ButtonDetectHandle = osThreadNew(StartButtonDetect, NULL, &ButtonDetect_attributes);
+
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
@@ -155,7 +153,9 @@ void StartDefaultTask(void *argument)
/* init code for USB_DEVICE */
MX_USB_DEVICE_Init();
/* USER CODE BEGIN StartDefaultTask */
- demoEnumCtlInit();
+
+ HAL_GPIO_WritePin(ENUM_CTL_GPIO_Port,ENUM_CTL_Pin, GPIO_PIN_SET);
+// Beep(100);
/* Infinite loop */
for(;;)
{
@@ -176,12 +176,10 @@ void StartLedBlinkTask(void *argument)
{
/* USER CODE BEGIN StartLedBlinkTask */
/* Infinite loop */
- demoLedInit();
for(;;)
{
-// HAL_GPIO_TogglePin(LED_RUN_GPIO_Port,LED_RUN_Pin);
-
- demoLedBlink();
+ HAL_GPIO_TogglePin(LED_RUN_GPIO_Port,LED_RUN_Pin);
+// printf("1\n");
osDelay(500);
}
/* USER CODE END StartLedBlinkTask */
@@ -201,12 +199,41 @@ void StartIWDGRefreshTask(void *argument)
for(;;)
{
HAL_IWDG_Refresh(&hiwdg);
-// printf("iwdg refreshed\n");
+// printf("2\n");
osDelay(1000);
}
/* USER CODE END StartIWDGRefreshTask */
}
+/* USER CODE BEGIN Header_StartButtonDetect */
+/**
+* @brief Function implementing the ButtonDetect thread.
+* @param argument: Not used
+* @retval None
+*/
+/* USER CODE END Header_StartButtonDetect */
+void StartButtonDetect(void *argument)
+{
+ /* USER CODE BEGIN StartButtonDetect */
+ static bool last_pwr_button_status = false;
+ /* Infinite loop */
+ for(;;)
+ {
+ if(NaviKit.pwr_button_status != last_pwr_button_status)
+ {
+ last_pwr_button_status = NaviKit.pwr_button_status;
+ Beep(100);
+ }
+ else
+ {
+ last_pwr_button_status = NaviKit.pwr_button_status;
+ }
+// printf("3\n");
+ osDelay(10);
+ }
+ /* USER CODE END StartButtonDetect */
+}
+
/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */
diff --git a/Core/Src/gpio.c b/Core/Src/gpio.c
index f91e9f5..99bcd05 100644
--- a/Core/Src/gpio.c
+++ b/Core/Src/gpio.c
@@ -21,6 +21,7 @@
#include "gpio.h"
/* USER CODE BEGIN 0 */
+extern NaviKit_t NaviKit;
/* USER CODE END 0 */
/*----------------------------------------------------------------------------*/
@@ -63,11 +64,11 @@ void MX_GPIO_Init(void)
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(BUZZ_CTL_GPIO_Port, BUZZ_CTL_Pin, GPIO_PIN_RESET);
- /*Configure GPIO pins : PEPin PEPin */
- GPIO_InitStruct.Pin = POWER_BUTTON_Pin|COULOMB_ALCC_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
+ /*Configure GPIO pin : PtPin */
+ GPIO_InitStruct.Pin = PWR_BUTTON_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
+ GPIO_InitStruct.Pull = GPIO_PULLUP;
+ HAL_GPIO_Init(PWR_BUTTON_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : PEPin PEPin PEPin PEPin
PEPin PEPin */
@@ -107,32 +108,40 @@ void MX_GPIO_Init(void)
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(CHRG_STATUS_GPIO_Port, &GPIO_InitStruct);
+ /*Configure GPIO pin : PtPin */
+ GPIO_InitStruct.Pin = COULOMB_ALCC_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ HAL_GPIO_Init(COULOMB_ALCC_GPIO_Port, &GPIO_InitStruct);
+
+ /* EXTI interrupt init*/
+ HAL_NVIC_SetPriority(EXTI2_IRQn, 5, 0);
+ HAL_NVIC_EnableIRQ(EXTI2_IRQn);
+
}
/* USER CODE BEGIN 2 */
-void demoEnumCtlInit()
-{
- GPIO_InitTypeDef GPIO_InitStruct = {0};
- GPIO_InitStruct.Pin = GPIO_PIN_8;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
- HAL_GPIO_WritePin(GPIOC,GPIO_PIN_8, GPIO_PIN_SET);
-}
-void demoLedInit()
+void Beep(uint32_t time_ms)
{
- GPIO_InitTypeDef GPIO_InitStruct = {0};
- GPIO_InitStruct.Pin = POWER_BUTTON_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(POWER_BUTTON_GPIO_Port, &GPIO_InitStruct);
+ HAL_GPIO_WritePin(BUZZ_CTL_GPIO_Port,BUZZ_CTL_Pin, GPIO_PIN_SET);
+ osDelay(time_ms);
+ HAL_GPIO_WritePin(BUZZ_CTL_GPIO_Port,BUZZ_CTL_Pin, GPIO_PIN_RESET);
}
-void demoLedBlink()
+void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
- HAL_GPIO_TogglePin(POWER_BUTTON_GPIO_Port,POWER_BUTTON_Pin);
+ if(GPIO_Pin==PWR_BUTTON_Pin)
+ {
+ if(HAL_GPIO_ReadPin(PWR_BUTTON_GPIO_Port, PWR_BUTTON_Pin)==GPIO_PIN_SET)
+ {//Rising edge trigger
+ NaviKit.pwr_button_status = false;
+ }
+ if(HAL_GPIO_ReadPin(PWR_BUTTON_GPIO_Port, PWR_BUTTON_Pin)==GPIO_PIN_RESET)
+ {//falling edge trigger
+ NaviKit.pwr_button_status = true;
+ }
+ }
+
}
/* USER CODE END 2 */
diff --git a/Core/Src/main.c b/Core/Src/main.c
index 6ac9387..0abd7fa 100644
--- a/Core/Src/main.c
+++ b/Core/Src/main.c
@@ -49,7 +49,6 @@
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
-
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
@@ -96,7 +95,7 @@ int main(void)
MX_IWDG_Init();
MX_UART4_Init();
/* USER CODE BEGIN 2 */
- HAL_IWDG_Refresh(&hiwdg);
+ //HAL_IWDG_Refresh(&hiwdg);
printf("Core initial successfully\n");
/* USER CODE END 2 */
diff --git a/Core/Src/navikit.c b/Core/Src/navikit.c
new file mode 100644
index 0000000..759e4a4
--- /dev/null
+++ b/Core/Src/navikit.c
@@ -0,0 +1,10 @@
+/*
+ * navikit.c
+ *
+ * Created on: Apr 17, 2020
+ * Author: oarap
+ */
+
+
+#include "navikit.h"
+NaviKit_t NaviKit;
diff --git a/Core/Src/stm32f1xx_it.c b/Core/Src/stm32f1xx_it.c
index 6cd5ba3..2fb5aae 100644
--- a/Core/Src/stm32f1xx_it.c
+++ b/Core/Src/stm32f1xx_it.c
@@ -205,6 +205,20 @@ void RCC_IRQHandler(void)
/* USER CODE END RCC_IRQn 1 */
}
+/**
+ * @brief This function handles EXTI line2 interrupt.
+ */
+void EXTI2_IRQHandler(void)
+{
+ /* USER CODE BEGIN EXTI2_IRQn 0 */
+
+ /* USER CODE END EXTI2_IRQn 0 */
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_2);
+ /* USER CODE BEGIN EXTI2_IRQn 1 */
+
+ /* USER CODE END EXTI2_IRQn 1 */
+}
+
/**
* @brief This function handles TIM1 update interrupt.
*/
diff --git a/NaviKit_stm32 Debug.launch b/NaviKit_stm32 Debug.launch
index eadc6f3..49c28ef 100644
--- a/NaviKit_stm32 Debug.launch
+++ b/NaviKit_stm32 Debug.launch
@@ -37,15 +37,15 @@
-
+
-
+
-
+
-
+
@@ -76,6 +76,9 @@
+
+
+
diff --git a/NaviKit_stm32.ioc b/NaviKit_stm32.ioc
index 91b5e4e..0c70a2a 100644
--- a/NaviKit_stm32.ioc
+++ b/NaviKit_stm32.ioc
@@ -25,11 +25,17 @@ ARM.CMSIS.5.6.0_SwParameter=CMSISOoDriverJjUSARTJjCustom\:true;DeviceJjOSOoTickJ
FREERTOS.FootprintOK=true
FREERTOS.INCLUDE_xTaskGetCurrentTaskHandle=1
FREERTOS.INCLUDE_xTaskGetHandle=1
-FREERTOS.IPParameters=Tasks01,configMAX_TASK_NAME_LEN,configUSE_TICKLESS_IDLE,INCLUDE_xTaskGetCurrentTaskHandle,INCLUDE_xTaskGetHandle,configUSE_APPLICATION_TASK_TAG,FootprintOK
-FREERTOS.Tasks01=defaultTask,24,128,StartDefaultTask,Default,NULL,Dynamic,NULL,NULL;LedBlinkTask,8,128,StartLedBlinkTask,Default,NULL,Dynamic,NULL,NULL;IWDGRefreshTask,40,128,StartIWDGRefreshTask,Default,NULL,Dynamic,NULL,NULL
+FREERTOS.IPParameters=Tasks01,configMAX_TASK_NAME_LEN,configUSE_TICKLESS_IDLE,INCLUDE_xTaskGetCurrentTaskHandle,INCLUDE_xTaskGetHandle,configUSE_APPLICATION_TASK_TAG,FootprintOK,configUSE_IDLE_HOOK,configUSE_TICK_HOOK,configUSE_MALLOC_FAILED_HOOK,configGENERATE_RUN_TIME_STATS,configUSE_STATS_FORMATTING_FUNCTIONS,configUSE_TRACE_FACILITY
+FREERTOS.Tasks01=defaultTask,24,128,StartDefaultTask,Default,NULL,Dynamic,NULL,NULL;LedBlinkTask,8,128,StartLedBlinkTask,Default,NULL,Dynamic,NULL,NULL;IWDGRefreshTask,40,128,StartIWDGRefreshTask,Default,NULL,Dynamic,NULL,NULL;ButtonDetect,8,128,StartButtonDetect,Default,NULL,Dynamic,NULL,NULL
+FREERTOS.configGENERATE_RUN_TIME_STATS=0
FREERTOS.configMAX_TASK_NAME_LEN=32
-FREERTOS.configUSE_APPLICATION_TASK_TAG=1
-FREERTOS.configUSE_TICKLESS_IDLE=1
+FREERTOS.configUSE_APPLICATION_TASK_TAG=0
+FREERTOS.configUSE_IDLE_HOOK=0
+FREERTOS.configUSE_MALLOC_FAILED_HOOK=0
+FREERTOS.configUSE_STATS_FORMATTING_FUNCTIONS=0
+FREERTOS.configUSE_TICKLESS_IDLE=0
+FREERTOS.configUSE_TICK_HOOK=0
+FREERTOS.configUSE_TRACE_FACILITY=1
File.Version=6
GPIO.groupedBy=Group By Peripherals
IWDG.IPParameters=Prescaler,Reload
@@ -91,6 +97,7 @@ MxCube.Version=5.6.0
MxDb.Version=DB.5.0.60
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
+NVIC.EXTI2_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true
NVIC.FLASH_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true
NVIC.ForceEnableDMAVector=true
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
@@ -220,10 +227,12 @@ PE15.GPIOParameters=GPIO_Label
PE15.GPIO_Label=USB3_VBUS_CTL_4
PE15.Locked=true
PE15.Signal=GPIO_Output
-PE2.GPIOParameters=GPIO_Label
-PE2.GPIO_Label=POWER_BUTTON
+PE2.GPIOParameters=GPIO_PuPd,GPIO_Label,GPIO_ModeDefaultEXTI
+PE2.GPIO_Label=PWR_BUTTON
+PE2.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_RISING_FALLING
+PE2.GPIO_PuPd=GPIO_PULLUP
PE2.Locked=true
-PE2.Signal=GPIO_Input
+PE2.Signal=GPXTI2
PE3.GPIOParameters=GPIO_Label
PE3.GPIO_Label=LED_RUN
PE3.Locked=true
@@ -284,6 +293,8 @@ RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK
RCC.TimSysFreq_Value=72000000
RCC.USBFreq_Value=48000000
RCC.VCOOutput2Freq_Value=8000000
+SH.GPXTI2.0=GPIO_EXTI2
+SH.GPXTI2.ConfNb=1
UART4.IPParameters=VirtualMode
UART4.VirtualMode=Asynchronous
USB_DEVICE.CLASS_NAME_FS=CDC