diff --git a/firmware/targets/api-hal-include/api-hal-power.h b/firmware/targets/api-hal-include/api-hal-power.h
index 8454a2c6..1c7a3b63 100644
--- a/firmware/targets/api-hal-include/api-hal-power.h
+++ b/firmware/targets/api-hal-include/api-hal-power.h
@@ -38,8 +38,8 @@ void api_hal_power_insomnia_exit();
/* Check if deep sleep availble */
bool api_hal_power_deep_available();
-/* Go to deep sleep */
-void api_hal_power_deep_sleep();
+/* Go to sleep */
+void api_hal_power_sleep();
/* Get predicted remaining battery capacity in percents */
uint8_t api_hal_power_get_pct();
diff --git a/firmware/targets/f4/Src/gpio.c b/firmware/targets/f4/Src/gpio.c
index 6418ba09..81f6146f 100644
--- a/firmware/targets/f4/Src/gpio.c
+++ b/firmware/targets/f4/Src/gpio.c
@@ -1,191 +1,144 @@
-/**
- ******************************************************************************
- * @file gpio.c
- * @brief This file provides code for the configuration
- * of all used GPIO pins.
- ******************************************************************************
- * @attention
- *
- *
© Copyright (c) 2021 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- * www.st.com/SLA0044
- *
- ******************************************************************************
- */
-
-/* Includes ------------------------------------------------------------------*/
#include "gpio.h"
-/* USER CODE BEGIN 0 */
+void MX_GPIO_Init(void) {
+ GPIO_InitTypeDef GPIO_InitStruct = {0};
-/* USER CODE END 0 */
+ /* GPIO Ports Clock Enable */
+ __HAL_RCC_GPIOC_CLK_ENABLE();
+ __HAL_RCC_GPIOH_CLK_ENABLE();
+ __HAL_RCC_GPIOB_CLK_ENABLE();
+ __HAL_RCC_GPIOA_CLK_ENABLE();
+ __HAL_RCC_GPIOE_CLK_ENABLE();
+ __HAL_RCC_GPIOD_CLK_ENABLE();
-/*----------------------------------------------------------------------------*/
-/* Configure GPIO */
-/*----------------------------------------------------------------------------*/
-/* USER CODE BEGIN 1 */
+ /*Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(GPIOA, LED_RED_Pin|LED_GREEN_Pin|LED_BLUE_Pin, GPIO_PIN_SET);
-/* USER CODE END 1 */
+ /*Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(DISPLAY_RST_GPIO_Port, DISPLAY_RST_Pin, GPIO_PIN_RESET);
-/** Configure pins as
- * Analog
- * Input
- * Output
- * EVENT_OUT
- * EXTI
-*/
-void MX_GPIO_Init(void)
-{
+ /*Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(NFC_CS_GPIO_Port, NFC_CS_Pin, GPIO_PIN_SET);
- GPIO_InitTypeDef GPIO_InitStruct = {0};
+ /*Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(DISPLAY_DI_GPIO_Port, DISPLAY_DI_Pin, GPIO_PIN_RESET);
- /* GPIO Ports Clock Enable */
- __HAL_RCC_GPIOC_CLK_ENABLE();
- __HAL_RCC_GPIOH_CLK_ENABLE();
- __HAL_RCC_GPIOB_CLK_ENABLE();
- __HAL_RCC_GPIOA_CLK_ENABLE();
- __HAL_RCC_GPIOE_CLK_ENABLE();
- __HAL_RCC_GPIOD_CLK_ENABLE();
+ /*Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(DISPLAY_BACKLIGHT_GPIO_Port, DISPLAY_BACKLIGHT_Pin, GPIO_PIN_RESET);
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(GPIOA, LED_RED_Pin|LED_GREEN_Pin|LED_BLUE_Pin, GPIO_PIN_SET);
+ /*Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(GPIOC, DISPLAY_CS_Pin|SD_CS_Pin, GPIO_PIN_SET);
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(DISPLAY_RST_GPIO_Port, DISPLAY_RST_Pin, GPIO_PIN_RESET);
+ /*Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(CC1101_CS_GPIO_Port, CC1101_CS_Pin, GPIO_PIN_SET);
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(NFC_CS_GPIO_Port, NFC_CS_Pin, GPIO_PIN_SET);
+ /*Configure GPIO pin : PtPin */
+ GPIO_InitStruct.Pin = BUTTON_BACK_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
+ GPIO_InitStruct.Pull = GPIO_PULLUP;
+ HAL_GPIO_Init(BUTTON_BACK_GPIO_Port, &GPIO_InitStruct);
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(DISPLAY_DI_GPIO_Port, DISPLAY_DI_Pin, GPIO_PIN_RESET);
+ /*Configure GPIO pin : PtPin */
+ GPIO_InitStruct.Pin = BUTTON_OK_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ HAL_GPIO_Init(BUTTON_OK_GPIO_Port, &GPIO_InitStruct);
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(DISPLAY_BACKLIGHT_GPIO_Port, DISPLAY_BACKLIGHT_Pin, GPIO_PIN_RESET);
+ /*Configure GPIO pins : PCPin PCPin PCPin PCPin */
+ GPIO_InitStruct.Pin = PC0_Pin|PC1_Pin|PC3_Pin|PC10_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(GPIOC, DISPLAY_CS_Pin|SD_CS_Pin, GPIO_PIN_SET);
+ /*Configure GPIO pins : PAPin PAPin PAPin */
+ GPIO_InitStruct.Pin = LED_RED_Pin|LED_GREEN_Pin|LED_BLUE_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(CC1101_CS_GPIO_Port, CC1101_CS_Pin, GPIO_PIN_SET);
+ /*Configure GPIO pins : PAPin PAPin PAPin */
+ GPIO_InitStruct.Pin = PA4_Pin|PA6_Pin|PA7_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
- /*Configure GPIO pin : PtPin */
- GPIO_InitStruct.Pin = BUTTON_BACK_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
- GPIO_InitStruct.Pull = GPIO_PULLUP;
- HAL_GPIO_Init(BUTTON_BACK_GPIO_Port, &GPIO_InitStruct);
+ /*Configure GPIO pin : PtPin */
+ GPIO_InitStruct.Pin = RFID_PULL_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ HAL_GPIO_Init(RFID_PULL_GPIO_Port, &GPIO_InitStruct);
- /*Configure GPIO pin : PtPin */
- GPIO_InitStruct.Pin = BUTTON_OK_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(BUTTON_OK_GPIO_Port, &GPIO_InitStruct);
+ /*Configure GPIO pin : PtPin */
+ GPIO_InitStruct.Pin = CC1101_G0_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
+ GPIO_InitStruct.Pull = GPIO_PULLDOWN;
+ // HAL_GPIO_Init(CC1101_G0_GPIO_Port, &GPIO_InitStruct);
- /*Configure GPIO pins : PCPin PCPin PCPin PCPin */
- GPIO_InitStruct.Pin = PC0_Pin|PC1_Pin|PC3_Pin|PC10_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
+ /*Configure GPIO pins : PBPin PBPin PBPin */
+ GPIO_InitStruct.Pin = PB2_Pin|iBTN_Pin|PB3_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
- /*Configure GPIO pins : PAPin PAPin PAPin */
- GPIO_InitStruct.Pin = LED_RED_Pin|LED_GREEN_Pin|LED_BLUE_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+ /*Configure GPIO pins : PBPin PBPin PBPin PBPin */
+ GPIO_InitStruct.Pin = BUTTON_UP_Pin|BUTTON_LEFT_Pin|BUTTON_DOWN_Pin|BUTTON_RIGHT_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
+ GPIO_InitStruct.Pull = GPIO_PULLUP;
+ HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
- /*Configure GPIO pins : PAPin PAPin PAPin */
- GPIO_InitStruct.Pin = PA4_Pin|PA6_Pin|PA7_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+ /*Configure GPIO pin : PtPin */
+ GPIO_InitStruct.Pin = DISPLAY_RST_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+ HAL_GPIO_Init(DISPLAY_RST_GPIO_Port, &GPIO_InitStruct);
- /*Configure GPIO pin : PtPin */
- GPIO_InitStruct.Pin = RFID_PULL_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(RFID_PULL_GPIO_Port, &GPIO_InitStruct);
+ /*Configure GPIO pin : PtPin */
+ GPIO_InitStruct.Pin = NFC_CS_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
+ HAL_GPIO_Init(NFC_CS_GPIO_Port, &GPIO_InitStruct);
- /*Configure GPIO pin : PtPin */
- GPIO_InitStruct.Pin = CC1101_G0_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
- GPIO_InitStruct.Pull = GPIO_PULLDOWN;
- HAL_GPIO_Init(CC1101_G0_GPIO_Port, &GPIO_InitStruct);
+ /*Configure GPIO pins : PCPin PCPin */
+ GPIO_InitStruct.Pin = DISPLAY_DI_Pin|DISPLAY_CS_Pin;
+ 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);
- /*Configure GPIO pins : PBPin PBPin PBPin */
- GPIO_InitStruct.Pin = PB2_Pin|iBTN_Pin|PB3_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+ /*Configure GPIO pin : PtPin */
+ GPIO_InitStruct.Pin = DISPLAY_BACKLIGHT_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+ GPIO_InitStruct.Pull = GPIO_PULLDOWN;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+ HAL_GPIO_Init(DISPLAY_BACKLIGHT_GPIO_Port, &GPIO_InitStruct);
- /*Configure GPIO pins : PBPin PBPin PBPin PBPin */
- GPIO_InitStruct.Pin = BUTTON_UP_Pin|BUTTON_LEFT_Pin|BUTTON_DOWN_Pin|BUTTON_RIGHT_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
- GPIO_InitStruct.Pull = GPIO_PULLUP;
- HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+ /*Configure GPIO pin : PtPin */
+ GPIO_InitStruct.Pin = SD_CS_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
+ HAL_GPIO_Init(SD_CS_GPIO_Port, &GPIO_InitStruct);
- /*Configure GPIO pin : PtPin */
- GPIO_InitStruct.Pin = DISPLAY_RST_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(DISPLAY_RST_GPIO_Port, &GPIO_InitStruct);
+ /*Configure GPIO pin : PtPin */
+ GPIO_InitStruct.Pin = CC1101_CS_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
+ HAL_GPIO_Init(CC1101_CS_GPIO_Port, &GPIO_InitStruct);
- /*Configure GPIO pin : PtPin */
- GPIO_InitStruct.Pin = NFC_CS_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- HAL_GPIO_Init(NFC_CS_GPIO_Port, &GPIO_InitStruct);
+ /* EXTI interrupt init*/
+ HAL_NVIC_SetPriority(EXTI1_IRQn, 5, 0);
+ HAL_NVIC_EnableIRQ(EXTI1_IRQn);
- /*Configure GPIO pins : PCPin PCPin */
- GPIO_InitStruct.Pin = DISPLAY_DI_Pin|DISPLAY_CS_Pin;
- 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_NVIC_SetPriority(EXTI3_IRQn, 5, 0);
+ HAL_NVIC_EnableIRQ(EXTI3_IRQn);
- /*Configure GPIO pin : PtPin */
- GPIO_InitStruct.Pin = DISPLAY_BACKLIGHT_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_PULLDOWN;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(DISPLAY_BACKLIGHT_GPIO_Port, &GPIO_InitStruct);
-
- /*Configure GPIO pin : PtPin */
- GPIO_InitStruct.Pin = SD_CS_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- HAL_GPIO_Init(SD_CS_GPIO_Port, &GPIO_InitStruct);
-
- /*Configure GPIO pin : PtPin */
- GPIO_InitStruct.Pin = CC1101_CS_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- HAL_GPIO_Init(CC1101_CS_GPIO_Port, &GPIO_InitStruct);
-
- /* EXTI interrupt init*/
- HAL_NVIC_SetPriority(EXTI1_IRQn, 5, 0);
- HAL_NVIC_EnableIRQ(EXTI1_IRQn);
-
- HAL_NVIC_SetPriority(EXTI3_IRQn, 5, 0);
- HAL_NVIC_EnableIRQ(EXTI3_IRQn);
-
- HAL_NVIC_SetPriority(EXTI9_5_IRQn, 5, 0);
- HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
-
- HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0);
- HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
+ HAL_NVIC_SetPriority(EXTI9_5_IRQn, 5, 0);
+ HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
+ HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0);
+ HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
}
-
-/* USER CODE BEGIN 2 */
-
-/* USER CODE END 2 */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/firmware/targets/f4/Src/stm32wbxx_it.c b/firmware/targets/f4/Src/stm32wbxx_it.c
index 14d93ede..c1a82cfb 100644
--- a/firmware/targets/f4/Src/stm32wbxx_it.c
+++ b/firmware/targets/f4/Src/stm32wbxx_it.c
@@ -1,63 +1,8 @@
-/* USER CODE BEGIN Header */
-/**
- ******************************************************************************
- * @file stm32wbxx_it.c
- * @brief Interrupt Service Routines.
- ******************************************************************************
- * @attention
- *
- * © Copyright (c) 2020 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- * www.st.com/SLA0044
- *
- ******************************************************************************
- */
-/* USER CODE END Header */
-
-/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32wbxx_it.h"
#include "FreeRTOS.h"
#include "task.h"
-/* Private includes ----------------------------------------------------------*/
-/* USER CODE BEGIN Includes */
-/* USER CODE END Includes */
-/* Private typedef -----------------------------------------------------------*/
-/* USER CODE BEGIN TD */
-
-/* USER CODE END TD */
-
-/* Private define ------------------------------------------------------------*/
-/* USER CODE BEGIN PD */
-
-/* USER CODE END PD */
-
-/* Private macro -------------------------------------------------------------*/
-/* USER CODE BEGIN PM */
-
-/* USER CODE END PM */
-
-/* Private variables ---------------------------------------------------------*/
-/* USER CODE BEGIN PV */
-
-/* USER CODE END PV */
-
-/* Private function prototypes -----------------------------------------------*/
-/* USER CODE BEGIN PFP */
-
-/* USER CODE END PFP */
-
-/* Private user code ---------------------------------------------------------*/
-/* USER CODE BEGIN 0 */
-
-/* USER CODE END 0 */
-
-/* External variables --------------------------------------------------------*/
extern PCD_HandleTypeDef hpcd_USB_FS;
extern ADC_HandleTypeDef hadc1;
extern COMP_HandleTypeDef hcomp1;
@@ -67,349 +12,132 @@ extern TIM_HandleTypeDef htim2;
extern TIM_HandleTypeDef htim16;
extern TIM_HandleTypeDef htim17;
-/* USER CODE BEGIN EV */
-
-/* USER CODE END EV */
-
-/******************************************************************************/
-/* Cortex Processor Interruption and Exception Handlers */
-/******************************************************************************/
-/**
- * @brief This function handles Non maskable interrupt.
- */
-void NMI_Handler(void)
-{
- /* USER CODE BEGIN NonMaskableInt_IRQn 0 */
-
- /* USER CODE END NonMaskableInt_IRQn 0 */
- HAL_RCC_NMI_IRQHandler();
- /* USER CODE BEGIN NonMaskableInt_IRQn 1 */
-
- /* USER CODE END NonMaskableInt_IRQn 1 */
-}
-
-/**
- * @brief This function handles Hard fault interrupt.
- */
-void HardFault_Handler(void)
-{
- /* USER CODE BEGIN HardFault_IRQn 0 */
- if ((*(volatile uint32_t *)CoreDebug_BASE) & (1 << 0)) {
- __asm("bkpt 1");
- }
- /* USER CODE END HardFault_IRQn 0 */
- while (1)
- {
- /* USER CODE BEGIN W1_HardFault_IRQn 0 */
- /* USER CODE END W1_HardFault_IRQn 0 */
- }
-}
-
-/**
- * @brief This function handles Memory management fault.
- */
-void MemManage_Handler(void)
-{
- /* USER CODE BEGIN MemoryManagement_IRQn 0 */
- __asm("bkpt 1");
- /* USER CODE END MemoryManagement_IRQn 0 */
- while (1)
- {
- /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
- /* USER CODE END W1_MemoryManagement_IRQn 0 */
- }
-}
-
-/**
- * @brief This function handles Prefetch fault, memory access fault.
- */
-void BusFault_Handler(void)
-{
- /* USER CODE BEGIN BusFault_IRQn 0 */
- __asm("bkpt 1");
- /* USER CODE END BusFault_IRQn 0 */
- while (1)
- {
- /* USER CODE BEGIN W1_BusFault_IRQn 0 */
- /* USER CODE END W1_BusFault_IRQn 0 */
- }
-}
-
-/**
- * @brief This function handles Undefined instruction or illegal state.
- */
-void UsageFault_Handler(void)
-{
- /* USER CODE BEGIN UsageFault_IRQn 0 */
- __asm("bkpt 1");
- /* USER CODE END UsageFault_IRQn 0 */
- while (1)
- {
- /* USER CODE BEGIN W1_UsageFault_IRQn 0 */
- /* USER CODE END W1_UsageFault_IRQn 0 */
- }
-}
-
-/**
- * @brief This function handles Debug monitor.
- */
-void DebugMon_Handler(void)
-{
- /* USER CODE BEGIN DebugMonitor_IRQn 0 */
-
- /* USER CODE END DebugMonitor_IRQn 0 */
- /* USER CODE BEGIN DebugMonitor_IRQn 1 */
-
- /* USER CODE END DebugMonitor_IRQn 1 */
-}
-
-/**
- * @brief This function handles System tick timer.
- */
-void SysTick_Handler(void)
-{
- /* USER CODE BEGIN SysTick_IRQn 0 */
-
- /* USER CODE END SysTick_IRQn 0 */
- /* USER CODE BEGIN SysTick_IRQn 1 */
- HAL_IncTick();
- /* USER CODE END SysTick_IRQn 1 */
-}
-
-/******************************************************************************/
-/* STM32WBxx Peripheral Interrupt Handlers */
-/* Add here the Interrupt Handlers for the used peripherals. */
-/* For the available peripheral interrupt handler names, */
-/* please refer to the startup file (startup_stm32wbxx.s). */
-/******************************************************************************/
-
-/**
- * @brief This function handles RTC tamper and time stamp, CSS on LSE interrupts through EXTI line 18.
- */
-void TAMP_STAMP_LSECSS_IRQHandler(void)
-{
- if (!LL_RCC_LSE_IsReady()) {
- // TODO: notify user about issue with LSE
- LL_RCC_ForceBackupDomainReset();
- LL_RCC_ReleaseBackupDomainReset();
- NVIC_SystemReset();
- }
-}
-
-/**
- * @brief This function handles RCC global interrupt.
- */
-void RCC_IRQHandler(void)
-{
- /* USER CODE BEGIN RCC_IRQn 0 */
- /* USER CODE END RCC_IRQn 0 */
- /* USER CODE BEGIN RCC_IRQn 1 */
-
- /* USER CODE END RCC_IRQn 1 */
-}
-
-/**
- * @brief This function handles EXTI line1 interrupt.
- */
-void EXTI1_IRQHandler(void)
-{
- /* USER CODE BEGIN EXTI1_IRQn 0 */
-
- /* USER CODE END EXTI1_IRQn 0 */
- HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_1);
- /* USER CODE BEGIN EXTI1_IRQn 1 */
-
- /* USER CODE END EXTI1_IRQn 1 */
-}
-
-/**
- * @brief This function handles EXTI line3 interrupt.
- */
-void EXTI3_IRQHandler(void)
-{
- /* USER CODE BEGIN EXTI3_IRQn 0 */
-
- /* USER CODE END EXTI3_IRQn 0 */
- HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_3);
- /* USER CODE BEGIN EXTI3_IRQn 1 */
-
- /* USER CODE END EXTI3_IRQn 1 */
-}
-
-/**
- * @brief This function handles ADC1 global interrupt.
- */
-void ADC1_IRQHandler(void)
-{
- /* USER CODE BEGIN ADC1_IRQn 0 */
-
- /* USER CODE END ADC1_IRQn 0 */
- HAL_ADC_IRQHandler(&hadc1);
- /* USER CODE BEGIN ADC1_IRQn 1 */
-
- /* USER CODE END ADC1_IRQn 1 */
-}
-
-/**
- * @brief This function handles USB low priority interrupt, USB wake-up interrupt through EXTI line 28.
- */
-void USB_LP_IRQHandler(void)
-{
- /* USER CODE BEGIN USB_LP_IRQn 0 */
-
- /* USER CODE END USB_LP_IRQn 0 */
- HAL_PCD_IRQHandler(&hpcd_USB_FS);
- /* USER CODE BEGIN USB_LP_IRQn 1 */
-
- /* USER CODE END USB_LP_IRQn 1 */
-}
-
-/**
- * @brief This function handles COMP1 and COMP2 interrupts through EXTI lines 20 and 21.
- */
-void COMP_IRQHandler(void)
-{
- /* USER CODE BEGIN COMP_IRQn 0 */
-
- /* USER CODE END COMP_IRQn 0 */
- HAL_COMP_IRQHandler(&hcomp1);
- /* USER CODE BEGIN COMP_IRQn 1 */
-
- /* USER CODE END COMP_IRQn 1 */
-}
-
-/**
- * @brief This function handles EXTI line[9:5] interrupts.
- */
-void EXTI9_5_IRQHandler(void)
-{
- /* USER CODE BEGIN EXTI9_5_IRQn 0 */
-
- /* USER CODE END EXTI9_5_IRQn 0 */
- HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_8);
- /* USER CODE BEGIN EXTI9_5_IRQn 1 */
-
- /* USER CODE END EXTI9_5_IRQn 1 */
-}
-
-/**
- * @brief This function handles TIM1 update interrupt and TIM16 global interrupt.
- */
-void TIM1_UP_TIM16_IRQHandler(void)
-{
- /* USER CODE BEGIN TIM1_UP_TIM16_IRQn 0 */
-
- /* USER CODE END TIM1_UP_TIM16_IRQn 0 */
- HAL_TIM_IRQHandler(&htim1);
- HAL_TIM_IRQHandler(&htim16);
- /* USER CODE BEGIN TIM1_UP_TIM16_IRQn 1 */
-
- /* USER CODE END TIM1_UP_TIM16_IRQn 1 */
-}
-
-/**
- * @brief This function handles TIM1 trigger and commutation interrupts and TIM17 global interrupt.
- */
-void TIM1_TRG_COM_TIM17_IRQHandler(void)
-{
- /* USER CODE BEGIN TIM1_TRG_COM_TIM17_IRQn 0 */
-
- /* USER CODE END TIM1_TRG_COM_TIM17_IRQn 0 */
- HAL_TIM_IRQHandler(&htim1);
- /* USER CODE BEGIN TIM1_TRG_COM_TIM17_IRQn 1 */
-
- /* USER CODE END TIM1_TRG_COM_TIM17_IRQn 1 */
-}
-
-/**
- * @brief This function handles TIM1 capture compare interrupt.
- */
-void TIM1_CC_IRQHandler(void)
-{
- /* USER CODE BEGIN TIM1_CC_IRQn 0 */
-
- /* USER CODE END TIM1_CC_IRQn 0 */
- HAL_TIM_IRQHandler(&htim1);
- /* USER CODE BEGIN TIM1_CC_IRQn 1 */
-
- /* USER CODE END TIM1_CC_IRQn 1 */
-}
-
-/**
- * @brief This function handles TIM2 global interrupt.
- */
-void TIM2_IRQHandler(void)
-{
- /* USER CODE BEGIN TIM2_IRQn 0 */
-
- /* USER CODE END TIM2_IRQn 0 */
- HAL_TIM_IRQHandler(&htim2);
- /* USER CODE BEGIN TIM2_IRQn 1 */
-
- /* USER CODE END TIM2_IRQn 1 */
-}
-
-/**
- * @brief This function handles EXTI line[15:10] interrupts.
- */
-void EXTI15_10_IRQHandler(void)
-{
- /* USER CODE BEGIN EXTI15_10_IRQn 0 */
-
- /* USER CODE END EXTI15_10_IRQn 0 */
- HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_10);
- HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_11);
- HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_12);
- HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);
- /* USER CODE BEGIN EXTI15_10_IRQn 1 */
- HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_14);
- /* USER CODE END EXTI15_10_IRQn 1 */
-}
-
-/**
- * @brief This function handles HSEM global interrupt.
- */
-void HSEM_IRQHandler(void)
-{
- /* USER CODE BEGIN HSEM_IRQn 0 */
-
- /* USER CODE END HSEM_IRQn 0 */
- HAL_HSEM_IRQHandler();
- /* USER CODE BEGIN HSEM_IRQn 1 */
-
- /* USER CODE END HSEM_IRQn 1 */
-}
-
-/* USER CODE BEGIN 1 */
-void EXTI4_IRQHandler(void)
-{
- /* USER CODE BEGIN EXTI4_IRQn 0 */
-
- /* USER CODE END EXTI4_IRQn 0 */
- HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4);
- /* USER CODE BEGIN EXTI4_IRQn 1 */
-
- /* USER CODE END EXTI4_IRQn 1 */
-}
-
extern void HW_TS_RTC_Wakeup_Handler();
extern void HW_IPCC_Tx_Handler();
extern void HW_IPCC_Rx_Handler();
-void RTC_WKUP_IRQHandler(void)
-{
- HW_TS_RTC_Wakeup_Handler();
+void NMI_Handler(void) {
+ HAL_RCC_NMI_IRQHandler();
}
-void IPCC_C1_TX_IRQHandler(void)
-{
- HW_IPCC_Tx_Handler();
+void HardFault_Handler(void) {
+ if ((*(volatile uint32_t *)CoreDebug_BASE) & (1 << 0)) {
+ __asm("bkpt 1");
+ }
+ while (1) {}
}
-void IPCC_C1_RX_IRQHandler(void)
-{
- HW_IPCC_Rx_Handler();
+void MemManage_Handler(void) {
+ __asm("bkpt 1");
+ while (1) {}
}
-/* USER CODE END 1 */
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+void BusFault_Handler(void) {
+ __asm("bkpt 1");
+ while (1) {}
+}
+
+void UsageFault_Handler(void) {
+ __asm("bkpt 1");
+ while (1) {}
+}
+
+void DebugMon_Handler(void) {
+}
+
+void SysTick_Handler(void) {
+ HAL_IncTick();
+}
+
+void TAMP_STAMP_LSECSS_IRQHandler(void) {
+ if (!LL_RCC_LSE_IsReady()) {
+ // TODO: notify user about issue with LSE
+ LL_RCC_ForceBackupDomainReset();
+ LL_RCC_ReleaseBackupDomainReset();
+ NVIC_SystemReset();
+ }
+}
+
+void RCC_IRQHandler(void) {
+}
+
+void EXTI0_IRQHandler(void) {
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
+}
+
+void EXTI1_IRQHandler(void) {
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_1);
+}
+
+void EXTI2_IRQHandler(void) {
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_2);
+}
+
+void EXTI3_IRQHandler(void) {
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_3);
+}
+
+void EXTI4_IRQHandler(void) {
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4);
+}
+
+void EXTI9_5_IRQHandler(void) {
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_5);
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_6);
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_7);
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_8);
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_9);
+}
+
+void EXTI15_10_IRQHandler(void) {
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_10);
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_11);
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_12);
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_14);
+}
+
+void ADC1_IRQHandler(void) {
+ HAL_ADC_IRQHandler(&hadc1);
+}
+
+void USB_LP_IRQHandler(void) {
+ HAL_PCD_IRQHandler(&hpcd_USB_FS);
+}
+
+void COMP_IRQHandler(void) {
+ HAL_COMP_IRQHandler(&hcomp1);
+}
+
+void TIM1_UP_TIM16_IRQHandler(void) {
+ HAL_TIM_IRQHandler(&htim1);
+ HAL_TIM_IRQHandler(&htim16);
+}
+
+void TIM1_TRG_COM_TIM17_IRQHandler(void) {
+ HAL_TIM_IRQHandler(&htim1);
+}
+
+void TIM1_CC_IRQHandler(void) {
+ HAL_TIM_IRQHandler(&htim1);
+}
+
+void TIM2_IRQHandler(void) {
+ HAL_TIM_IRQHandler(&htim2);
+}
+
+void HSEM_IRQHandler(void) {
+ HAL_HSEM_IRQHandler();
+}
+
+void RTC_WKUP_IRQHandler(void){
+ HW_TS_RTC_Wakeup_Handler();
+}
+
+void IPCC_C1_TX_IRQHandler(void){
+ HW_IPCC_Tx_Handler();
+}
+
+void IPCC_C1_RX_IRQHandler(void){
+ HW_IPCC_Rx_Handler();
+}
diff --git a/firmware/targets/f4/api-hal/api-hal-os.c b/firmware/targets/f4/api-hal/api-hal-os.c
index f6b01e0e..7d9dc259 100644
--- a/firmware/targets/f4/api-hal/api-hal-os.c
+++ b/firmware/targets/f4/api-hal/api-hal-os.c
@@ -1,6 +1,7 @@
#include
#include
#include
+#include
#include
#include
@@ -13,10 +14,17 @@
#ifdef API_HAL_OS_DEBUG
#include
+
#define LED_SLEEP_PORT GPIOA
#define LED_SLEEP_PIN LL_GPIO_PIN_7
#define LED_TICK_PORT GPIOA
#define LED_TICK_PIN LL_GPIO_PIN_6
+#define LED_SECOND_PORT GPIOA
+#define LED_SECOND_PIN LL_GPIO_PIN_4
+
+void api_hal_os_timer_callback() {
+ LL_GPIO_TogglePin(LED_SECOND_PORT, LED_SECOND_PIN);
+}
#endif
volatile uint32_t api_hal_os_skew = 0;
@@ -30,6 +38,9 @@ void api_hal_os_init() {
#ifdef API_HAL_OS_DEBUG
LL_GPIO_SetPinMode(LED_SLEEP_PORT, LED_SLEEP_PIN, LL_GPIO_MODE_OUTPUT);
LL_GPIO_SetPinMode(LED_TICK_PORT, LED_TICK_PIN, LL_GPIO_MODE_OUTPUT);
+ LL_GPIO_SetPinMode(LED_SECOND_PORT, LED_SECOND_PIN, LL_GPIO_MODE_OUTPUT);
+ osTimerId_t second_timer = osTimerNew(api_hal_os_timer_callback, osTimerPeriodic, NULL, NULL);
+ osTimerStart(second_timer, 1024);
#endif
}
@@ -52,20 +63,20 @@ void LPTIM2_IRQHandler(void) {
static inline uint32_t api_hal_os_sleep(TickType_t expected_idle_ticks) {
// Stop ticks
api_hal_os_timer_reset();
- HAL_SuspendTick();
+ LL_SYSTICK_DisableIT();
// Start wakeup timer
api_hal_os_timer_single(expected_idle_ticks * API_HAL_OS_CLK_PER_TICK);
#ifdef API_HAL_OS_DEBUG
- LL_GPIO_SetOutputPin(LED_SLEEP_PORT, LED_SLEEP_PIN);
+ LL_GPIO_ResetOutputPin(LED_SLEEP_PORT, LED_SLEEP_PIN);
#endif
- // Go to stop2 mode
- api_hal_power_deep_sleep();
+ // Go to sleep mode
+ api_hal_power_sleep();
#ifdef API_HAL_OS_DEBUG
- LL_GPIO_ResetOutputPin(LED_SLEEP_PORT, LED_SLEEP_PIN);
+ LL_GPIO_SetOutputPin(LED_SLEEP_PORT, LED_SLEEP_PIN);
#endif
// Calculate how much time we spent in the sleep
@@ -73,22 +84,21 @@ static inline uint32_t api_hal_os_sleep(TickType_t expected_idle_ticks) {
uint32_t after_tick = after_cnt / API_HAL_OS_CLK_PER_TICK;
api_hal_os_skew = after_cnt % API_HAL_OS_CLK_PER_TICK;
+ bool cmpm = LL_LPTIM_IsActiveFlag_CMPM(API_HAL_OS_TIMER);
+ bool arrm = LL_LPTIM_IsActiveFlag_ARRM(API_HAL_OS_TIMER);
+ if (cmpm && arrm) after_tick += expected_idle_ticks;
+
// Prepare tick timer for new round
api_hal_os_timer_reset();
// Resume ticks
- HAL_ResumeTick();
+ LL_SYSTICK_EnableIT();
api_hal_os_timer_continuous(API_HAL_OS_CLK_PER_TICK);
return after_tick;
}
void vPortSuppressTicksAndSleep(TickType_t expected_idle_ticks) {
- // Check if sleep is available now
- if (!api_hal_power_deep_available()) {
- return;
- }
-
// Limit mount of ticks to maximum that timer can count
if (expected_idle_ticks > API_HAL_OS_MAX_SLEEP) {
expected_idle_ticks = API_HAL_OS_MAX_SLEEP;
@@ -98,8 +108,6 @@ void vPortSuppressTicksAndSleep(TickType_t expected_idle_ticks) {
__disable_irq();
// Confirm OS that sleep is still possible
- // And check if timer is in safe zone
- // (8 clocks till any IRQ event or ongoing synchronization)
if (eTaskConfirmSleepModeStatus() == eAbortSleep) {
__enable_irq();
return;
diff --git a/firmware/targets/f4/api-hal/api-hal-power.c b/firmware/targets/f4/api-hal/api-hal-power.c
index d0060d55..5d682cc5 100644
--- a/firmware/targets/f4/api-hal/api-hal-power.c
+++ b/firmware/targets/f4/api-hal/api-hal-power.c
@@ -41,6 +41,10 @@ bool api_hal_power_deep_available() {
return api_hal_bt_is_alive() && api_hal_power_insomnia == 0;
}
+void api_hal_power_light_sleep() {
+ __WFI();
+}
+
void api_hal_power_deep_sleep() {
while( LL_HSEM_1StepLock(HSEM, CFG_HW_RCC_SEMID));
@@ -85,6 +89,15 @@ void api_hal_power_deep_sleep() {
LL_HSEM_ReleaseLock(HSEM, CFG_HW_RCC_SEMID, 0);
}
+void api_hal_power_sleep() {
+ if(api_hal_power_deep_available()) {
+ api_hal_power_deep_sleep();
+ } else {
+ api_hal_power_light_sleep();
+ }
+}
+
+
uint8_t api_hal_power_get_pct() {
return bq27220_get_state_of_charge();
}
@@ -197,9 +210,7 @@ void api_hal_power_dump_state(string_t buffer) {
}
void api_hal_power_enable_external_3_3v(){
- // nothing to do
}
void api_hal_power_disable_external_3_3v(){
- // nothing to do
-}
\ No newline at end of file
+}
diff --git a/firmware/targets/f5/Src/gpio.c b/firmware/targets/f5/Src/gpio.c
index d682b18b..2b09ca83 100644
--- a/firmware/targets/f5/Src/gpio.c
+++ b/firmware/targets/f5/Src/gpio.c
@@ -1,197 +1,150 @@
-/**
- ******************************************************************************
- * @file gpio.c
- * @brief This file provides code for the configuration
- * of all used GPIO pins.
- ******************************************************************************
- * @attention
- *
- * © Copyright (c) 2021 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- * www.st.com/SLA0044
- *
- ******************************************************************************
- */
-
-/* Includes ------------------------------------------------------------------*/
#include "gpio.h"
-/* USER CODE BEGIN 0 */
+void MX_GPIO_Init(void) {
+ GPIO_InitTypeDef GPIO_InitStruct = {0};
-/* USER CODE END 0 */
+ /* GPIO Ports Clock Enable */
+ __HAL_RCC_GPIOC_CLK_ENABLE();
+ __HAL_RCC_GPIOH_CLK_ENABLE();
+ __HAL_RCC_GPIOB_CLK_ENABLE();
+ __HAL_RCC_GPIOA_CLK_ENABLE();
+ __HAL_RCC_GPIOE_CLK_ENABLE();
+ __HAL_RCC_GPIOD_CLK_ENABLE();
-/*----------------------------------------------------------------------------*/
-/* Configure GPIO */
-/*----------------------------------------------------------------------------*/
-/* USER CODE BEGIN 1 */
+ /*Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(GPIOA, RF_SW_0_Pin|RF_SW_1_Pin, GPIO_PIN_RESET);
-/* USER CODE END 1 */
+ /*Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(PERIPH_POWER_GPIO_Port, PERIPH_POWER_Pin, GPIO_PIN_SET);
-/** Configure pins as
- * Analog
- * Input
- * Output
- * EVENT_OUT
- * EXTI
-*/
-void MX_GPIO_Init(void)
-{
+ /*Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(DISPLAY_RST_GPIO_Port, DISPLAY_RST_Pin, GPIO_PIN_RESET);
- GPIO_InitTypeDef GPIO_InitStruct = {0};
+ /*Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(NFC_CS_GPIO_Port, NFC_CS_Pin, GPIO_PIN_SET);
- /* GPIO Ports Clock Enable */
- __HAL_RCC_GPIOC_CLK_ENABLE();
- __HAL_RCC_GPIOH_CLK_ENABLE();
- __HAL_RCC_GPIOB_CLK_ENABLE();
- __HAL_RCC_GPIOA_CLK_ENABLE();
- __HAL_RCC_GPIOE_CLK_ENABLE();
- __HAL_RCC_GPIOD_CLK_ENABLE();
+ /*Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(DISPLAY_DI_GPIO_Port, DISPLAY_DI_Pin, GPIO_PIN_RESET);
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(GPIOA, RF_SW_0_Pin|RF_SW_1_Pin, GPIO_PIN_RESET);
+ /*Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(GPIOC, DISPLAY_CS_Pin, GPIO_PIN_SET);
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(PERIPH_POWER_GPIO_Port, PERIPH_POWER_Pin, GPIO_PIN_SET);
+ /*Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(CC1101_CS_GPIO_Port, CC1101_CS_Pin, GPIO_PIN_SET);
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(DISPLAY_RST_GPIO_Port, DISPLAY_RST_Pin, GPIO_PIN_RESET);
+ /*Configure GPIO pin : PtPin */
+ GPIO_InitStruct.Pin = BUTTON_BACK_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
+ GPIO_InitStruct.Pull = GPIO_PULLUP;
+ HAL_GPIO_Init(BUTTON_BACK_GPIO_Port, &GPIO_InitStruct);
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(NFC_CS_GPIO_Port, NFC_CS_Pin, GPIO_PIN_SET);
+ /*Configure GPIO pin : PtPin */
+ GPIO_InitStruct.Pin = BUTTON_OK_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ HAL_GPIO_Init(BUTTON_OK_GPIO_Port, &GPIO_InitStruct);
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(DISPLAY_DI_GPIO_Port, DISPLAY_DI_Pin, GPIO_PIN_RESET);
+ /*Configure GPIO pins : PCPin PCPin PCPin PCPin */
+ GPIO_InitStruct.Pin = PC0_Pin|PC1_Pin|PC3_Pin|VIBRO_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(GPIOC, DISPLAY_CS_Pin, GPIO_PIN_SET);
+ /*Configure GPIO pins : PAPin PAPin */
+ GPIO_InitStruct.Pin = RF_SW_0_Pin|RF_SW_1_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(CC1101_CS_GPIO_Port, CC1101_CS_Pin, GPIO_PIN_SET);
+ /*Configure GPIO pin : PtPin */
+ GPIO_InitStruct.Pin = PERIPH_POWER_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+ HAL_GPIO_Init(PERIPH_POWER_GPIO_Port, &GPIO_InitStruct);
- /*Configure GPIO pin : PtPin */
- GPIO_InitStruct.Pin = BUTTON_BACK_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
- GPIO_InitStruct.Pull = GPIO_PULLUP;
- HAL_GPIO_Init(BUTTON_BACK_GPIO_Port, &GPIO_InitStruct);
+ /*Configure GPIO pins : PAPin PAPin PAPin */
+ GPIO_InitStruct.Pin = PA4_Pin|PA6_Pin|PA7_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
- /*Configure GPIO pin : PtPin */
- GPIO_InitStruct.Pin = BUTTON_OK_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(BUTTON_OK_GPIO_Port, &GPIO_InitStruct);
+ /*Configure GPIO pin : PtPin */
+ GPIO_InitStruct.Pin = RFID_PULL_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ HAL_GPIO_Init(RFID_PULL_GPIO_Port, &GPIO_InitStruct);
- /*Configure GPIO pins : PCPin PCPin PCPin PCPin */
- GPIO_InitStruct.Pin = PC0_Pin|PC1_Pin|PC3_Pin|VIBRO_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
+ /*Configure GPIO pin : PtPin */
+ GPIO_InitStruct.Pin = CC1101_G0_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
+ GPIO_InitStruct.Pull = GPIO_PULLDOWN;
+ // HAL_GPIO_Init(CC1101_G0_GPIO_Port, &GPIO_InitStruct);
- /*Configure GPIO pins : PAPin PAPin */
- GPIO_InitStruct.Pin = RF_SW_0_Pin|RF_SW_1_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+ /*Configure GPIO pins : PBPin PBPin PBPin */
+ GPIO_InitStruct.Pin = PB2_Pin|iBTN_Pin|PB3_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
- /*Configure GPIO pin : PtPin */
- GPIO_InitStruct.Pin = PERIPH_POWER_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(PERIPH_POWER_GPIO_Port, &GPIO_InitStruct);
+ /*Configure GPIO pins : PBPin PBPin PBPin PBPin */
+ GPIO_InitStruct.Pin = BUTTON_UP_Pin|BUTTON_LEFT_Pin|BUTTON_DOWN_Pin|BUTTON_RIGHT_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
+ GPIO_InitStruct.Pull = GPIO_PULLUP;
+ HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
- /*Configure GPIO pins : PAPin PAPin PAPin */
- GPIO_InitStruct.Pin = PA4_Pin|PA6_Pin|PA7_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+ /*Configure GPIO pin : PtPin */
+ GPIO_InitStruct.Pin = DISPLAY_RST_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+ HAL_GPIO_Init(DISPLAY_RST_GPIO_Port, &GPIO_InitStruct);
- /*Configure GPIO pin : PtPin */
- GPIO_InitStruct.Pin = RFID_PULL_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(RFID_PULL_GPIO_Port, &GPIO_InitStruct);
+ /*Configure GPIO pin : PtPin */
+ GPIO_InitStruct.Pin = NFC_CS_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
+ HAL_GPIO_Init(NFC_CS_GPIO_Port, &GPIO_InitStruct);
- /*Configure GPIO pin : PtPin */
- GPIO_InitStruct.Pin = CC1101_G0_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
- GPIO_InitStruct.Pull = GPIO_PULLDOWN;
- HAL_GPIO_Init(CC1101_G0_GPIO_Port, &GPIO_InitStruct);
+ /*Configure GPIO pins : PCPin PCPin */
+ GPIO_InitStruct.Pin = DISPLAY_DI_Pin|DISPLAY_CS_Pin;
+ 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);
- /*Configure GPIO pins : PBPin PBPin PBPin */
- GPIO_InitStruct.Pin = PB2_Pin|iBTN_Pin|PB3_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+ /*Configure GPIO pin : PtPin */
+ GPIO_InitStruct.Pin = SD_CD_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ HAL_GPIO_Init(SD_CD_GPIO_Port, &GPIO_InitStruct);
- /*Configure GPIO pins : PBPin PBPin PBPin PBPin */
- GPIO_InitStruct.Pin = BUTTON_UP_Pin|BUTTON_LEFT_Pin|BUTTON_DOWN_Pin|BUTTON_RIGHT_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
- GPIO_InitStruct.Pull = GPIO_PULLUP;
- HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+ /*Configure GPIO pin : PtPin */
+ GPIO_InitStruct.Pin = SD_CS_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
+ HAL_GPIO_Init(SD_CS_GPIO_Port, &GPIO_InitStruct);
- /*Configure GPIO pin : PtPin */
- GPIO_InitStruct.Pin = DISPLAY_RST_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(DISPLAY_RST_GPIO_Port, &GPIO_InitStruct);
+ /*Configure GPIO pin : PtPin */
+ GPIO_InitStruct.Pin = CC1101_CS_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
+ HAL_GPIO_Init(CC1101_CS_GPIO_Port, &GPIO_InitStruct);
- /*Configure GPIO pin : PtPin */
- GPIO_InitStruct.Pin = NFC_CS_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- HAL_GPIO_Init(NFC_CS_GPIO_Port, &GPIO_InitStruct);
+ /* EXTI interrupt init*/
+ HAL_NVIC_SetPriority(EXTI1_IRQn, 5, 0);
+ HAL_NVIC_EnableIRQ(EXTI1_IRQn);
- /*Configure GPIO pins : PCPin PCPin */
- GPIO_InitStruct.Pin = DISPLAY_DI_Pin|DISPLAY_CS_Pin;
- 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_NVIC_SetPriority(EXTI3_IRQn, 5, 0);
+ HAL_NVIC_EnableIRQ(EXTI3_IRQn);
- /*Configure GPIO pin : PtPin */
- GPIO_InitStruct.Pin = SD_CD_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(SD_CD_GPIO_Port, &GPIO_InitStruct);
-
- /*Configure GPIO pin : PtPin */
- GPIO_InitStruct.Pin = SD_CS_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- HAL_GPIO_Init(SD_CS_GPIO_Port, &GPIO_InitStruct);
-
- /*Configure GPIO pin : PtPin */
- GPIO_InitStruct.Pin = CC1101_CS_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- HAL_GPIO_Init(CC1101_CS_GPIO_Port, &GPIO_InitStruct);
-
- /* EXTI interrupt init*/
- HAL_NVIC_SetPriority(EXTI1_IRQn, 5, 0);
- HAL_NVIC_EnableIRQ(EXTI1_IRQn);
-
- HAL_NVIC_SetPriority(EXTI3_IRQn, 5, 0);
- HAL_NVIC_EnableIRQ(EXTI3_IRQn);
-
- HAL_NVIC_SetPriority(EXTI9_5_IRQn, 5, 0);
- HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
-
- HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0);
- HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
+ HAL_NVIC_SetPriority(EXTI9_5_IRQn, 5, 0);
+ HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
+ HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0);
+ HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
}
-
-/* USER CODE BEGIN 2 */
-
-/* USER CODE END 2 */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/firmware/targets/f5/Src/stm32wbxx_it.c b/firmware/targets/f5/Src/stm32wbxx_it.c
index 14d93ede..c1a82cfb 100644
--- a/firmware/targets/f5/Src/stm32wbxx_it.c
+++ b/firmware/targets/f5/Src/stm32wbxx_it.c
@@ -1,63 +1,8 @@
-/* USER CODE BEGIN Header */
-/**
- ******************************************************************************
- * @file stm32wbxx_it.c
- * @brief Interrupt Service Routines.
- ******************************************************************************
- * @attention
- *
- * © Copyright (c) 2020 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- * www.st.com/SLA0044
- *
- ******************************************************************************
- */
-/* USER CODE END Header */
-
-/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32wbxx_it.h"
#include "FreeRTOS.h"
#include "task.h"
-/* Private includes ----------------------------------------------------------*/
-/* USER CODE BEGIN Includes */
-/* USER CODE END Includes */
-/* Private typedef -----------------------------------------------------------*/
-/* USER CODE BEGIN TD */
-
-/* USER CODE END TD */
-
-/* Private define ------------------------------------------------------------*/
-/* USER CODE BEGIN PD */
-
-/* USER CODE END PD */
-
-/* Private macro -------------------------------------------------------------*/
-/* USER CODE BEGIN PM */
-
-/* USER CODE END PM */
-
-/* Private variables ---------------------------------------------------------*/
-/* USER CODE BEGIN PV */
-
-/* USER CODE END PV */
-
-/* Private function prototypes -----------------------------------------------*/
-/* USER CODE BEGIN PFP */
-
-/* USER CODE END PFP */
-
-/* Private user code ---------------------------------------------------------*/
-/* USER CODE BEGIN 0 */
-
-/* USER CODE END 0 */
-
-/* External variables --------------------------------------------------------*/
extern PCD_HandleTypeDef hpcd_USB_FS;
extern ADC_HandleTypeDef hadc1;
extern COMP_HandleTypeDef hcomp1;
@@ -67,349 +12,132 @@ extern TIM_HandleTypeDef htim2;
extern TIM_HandleTypeDef htim16;
extern TIM_HandleTypeDef htim17;
-/* USER CODE BEGIN EV */
-
-/* USER CODE END EV */
-
-/******************************************************************************/
-/* Cortex Processor Interruption and Exception Handlers */
-/******************************************************************************/
-/**
- * @brief This function handles Non maskable interrupt.
- */
-void NMI_Handler(void)
-{
- /* USER CODE BEGIN NonMaskableInt_IRQn 0 */
-
- /* USER CODE END NonMaskableInt_IRQn 0 */
- HAL_RCC_NMI_IRQHandler();
- /* USER CODE BEGIN NonMaskableInt_IRQn 1 */
-
- /* USER CODE END NonMaskableInt_IRQn 1 */
-}
-
-/**
- * @brief This function handles Hard fault interrupt.
- */
-void HardFault_Handler(void)
-{
- /* USER CODE BEGIN HardFault_IRQn 0 */
- if ((*(volatile uint32_t *)CoreDebug_BASE) & (1 << 0)) {
- __asm("bkpt 1");
- }
- /* USER CODE END HardFault_IRQn 0 */
- while (1)
- {
- /* USER CODE BEGIN W1_HardFault_IRQn 0 */
- /* USER CODE END W1_HardFault_IRQn 0 */
- }
-}
-
-/**
- * @brief This function handles Memory management fault.
- */
-void MemManage_Handler(void)
-{
- /* USER CODE BEGIN MemoryManagement_IRQn 0 */
- __asm("bkpt 1");
- /* USER CODE END MemoryManagement_IRQn 0 */
- while (1)
- {
- /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
- /* USER CODE END W1_MemoryManagement_IRQn 0 */
- }
-}
-
-/**
- * @brief This function handles Prefetch fault, memory access fault.
- */
-void BusFault_Handler(void)
-{
- /* USER CODE BEGIN BusFault_IRQn 0 */
- __asm("bkpt 1");
- /* USER CODE END BusFault_IRQn 0 */
- while (1)
- {
- /* USER CODE BEGIN W1_BusFault_IRQn 0 */
- /* USER CODE END W1_BusFault_IRQn 0 */
- }
-}
-
-/**
- * @brief This function handles Undefined instruction or illegal state.
- */
-void UsageFault_Handler(void)
-{
- /* USER CODE BEGIN UsageFault_IRQn 0 */
- __asm("bkpt 1");
- /* USER CODE END UsageFault_IRQn 0 */
- while (1)
- {
- /* USER CODE BEGIN W1_UsageFault_IRQn 0 */
- /* USER CODE END W1_UsageFault_IRQn 0 */
- }
-}
-
-/**
- * @brief This function handles Debug monitor.
- */
-void DebugMon_Handler(void)
-{
- /* USER CODE BEGIN DebugMonitor_IRQn 0 */
-
- /* USER CODE END DebugMonitor_IRQn 0 */
- /* USER CODE BEGIN DebugMonitor_IRQn 1 */
-
- /* USER CODE END DebugMonitor_IRQn 1 */
-}
-
-/**
- * @brief This function handles System tick timer.
- */
-void SysTick_Handler(void)
-{
- /* USER CODE BEGIN SysTick_IRQn 0 */
-
- /* USER CODE END SysTick_IRQn 0 */
- /* USER CODE BEGIN SysTick_IRQn 1 */
- HAL_IncTick();
- /* USER CODE END SysTick_IRQn 1 */
-}
-
-/******************************************************************************/
-/* STM32WBxx Peripheral Interrupt Handlers */
-/* Add here the Interrupt Handlers for the used peripherals. */
-/* For the available peripheral interrupt handler names, */
-/* please refer to the startup file (startup_stm32wbxx.s). */
-/******************************************************************************/
-
-/**
- * @brief This function handles RTC tamper and time stamp, CSS on LSE interrupts through EXTI line 18.
- */
-void TAMP_STAMP_LSECSS_IRQHandler(void)
-{
- if (!LL_RCC_LSE_IsReady()) {
- // TODO: notify user about issue with LSE
- LL_RCC_ForceBackupDomainReset();
- LL_RCC_ReleaseBackupDomainReset();
- NVIC_SystemReset();
- }
-}
-
-/**
- * @brief This function handles RCC global interrupt.
- */
-void RCC_IRQHandler(void)
-{
- /* USER CODE BEGIN RCC_IRQn 0 */
- /* USER CODE END RCC_IRQn 0 */
- /* USER CODE BEGIN RCC_IRQn 1 */
-
- /* USER CODE END RCC_IRQn 1 */
-}
-
-/**
- * @brief This function handles EXTI line1 interrupt.
- */
-void EXTI1_IRQHandler(void)
-{
- /* USER CODE BEGIN EXTI1_IRQn 0 */
-
- /* USER CODE END EXTI1_IRQn 0 */
- HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_1);
- /* USER CODE BEGIN EXTI1_IRQn 1 */
-
- /* USER CODE END EXTI1_IRQn 1 */
-}
-
-/**
- * @brief This function handles EXTI line3 interrupt.
- */
-void EXTI3_IRQHandler(void)
-{
- /* USER CODE BEGIN EXTI3_IRQn 0 */
-
- /* USER CODE END EXTI3_IRQn 0 */
- HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_3);
- /* USER CODE BEGIN EXTI3_IRQn 1 */
-
- /* USER CODE END EXTI3_IRQn 1 */
-}
-
-/**
- * @brief This function handles ADC1 global interrupt.
- */
-void ADC1_IRQHandler(void)
-{
- /* USER CODE BEGIN ADC1_IRQn 0 */
-
- /* USER CODE END ADC1_IRQn 0 */
- HAL_ADC_IRQHandler(&hadc1);
- /* USER CODE BEGIN ADC1_IRQn 1 */
-
- /* USER CODE END ADC1_IRQn 1 */
-}
-
-/**
- * @brief This function handles USB low priority interrupt, USB wake-up interrupt through EXTI line 28.
- */
-void USB_LP_IRQHandler(void)
-{
- /* USER CODE BEGIN USB_LP_IRQn 0 */
-
- /* USER CODE END USB_LP_IRQn 0 */
- HAL_PCD_IRQHandler(&hpcd_USB_FS);
- /* USER CODE BEGIN USB_LP_IRQn 1 */
-
- /* USER CODE END USB_LP_IRQn 1 */
-}
-
-/**
- * @brief This function handles COMP1 and COMP2 interrupts through EXTI lines 20 and 21.
- */
-void COMP_IRQHandler(void)
-{
- /* USER CODE BEGIN COMP_IRQn 0 */
-
- /* USER CODE END COMP_IRQn 0 */
- HAL_COMP_IRQHandler(&hcomp1);
- /* USER CODE BEGIN COMP_IRQn 1 */
-
- /* USER CODE END COMP_IRQn 1 */
-}
-
-/**
- * @brief This function handles EXTI line[9:5] interrupts.
- */
-void EXTI9_5_IRQHandler(void)
-{
- /* USER CODE BEGIN EXTI9_5_IRQn 0 */
-
- /* USER CODE END EXTI9_5_IRQn 0 */
- HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_8);
- /* USER CODE BEGIN EXTI9_5_IRQn 1 */
-
- /* USER CODE END EXTI9_5_IRQn 1 */
-}
-
-/**
- * @brief This function handles TIM1 update interrupt and TIM16 global interrupt.
- */
-void TIM1_UP_TIM16_IRQHandler(void)
-{
- /* USER CODE BEGIN TIM1_UP_TIM16_IRQn 0 */
-
- /* USER CODE END TIM1_UP_TIM16_IRQn 0 */
- HAL_TIM_IRQHandler(&htim1);
- HAL_TIM_IRQHandler(&htim16);
- /* USER CODE BEGIN TIM1_UP_TIM16_IRQn 1 */
-
- /* USER CODE END TIM1_UP_TIM16_IRQn 1 */
-}
-
-/**
- * @brief This function handles TIM1 trigger and commutation interrupts and TIM17 global interrupt.
- */
-void TIM1_TRG_COM_TIM17_IRQHandler(void)
-{
- /* USER CODE BEGIN TIM1_TRG_COM_TIM17_IRQn 0 */
-
- /* USER CODE END TIM1_TRG_COM_TIM17_IRQn 0 */
- HAL_TIM_IRQHandler(&htim1);
- /* USER CODE BEGIN TIM1_TRG_COM_TIM17_IRQn 1 */
-
- /* USER CODE END TIM1_TRG_COM_TIM17_IRQn 1 */
-}
-
-/**
- * @brief This function handles TIM1 capture compare interrupt.
- */
-void TIM1_CC_IRQHandler(void)
-{
- /* USER CODE BEGIN TIM1_CC_IRQn 0 */
-
- /* USER CODE END TIM1_CC_IRQn 0 */
- HAL_TIM_IRQHandler(&htim1);
- /* USER CODE BEGIN TIM1_CC_IRQn 1 */
-
- /* USER CODE END TIM1_CC_IRQn 1 */
-}
-
-/**
- * @brief This function handles TIM2 global interrupt.
- */
-void TIM2_IRQHandler(void)
-{
- /* USER CODE BEGIN TIM2_IRQn 0 */
-
- /* USER CODE END TIM2_IRQn 0 */
- HAL_TIM_IRQHandler(&htim2);
- /* USER CODE BEGIN TIM2_IRQn 1 */
-
- /* USER CODE END TIM2_IRQn 1 */
-}
-
-/**
- * @brief This function handles EXTI line[15:10] interrupts.
- */
-void EXTI15_10_IRQHandler(void)
-{
- /* USER CODE BEGIN EXTI15_10_IRQn 0 */
-
- /* USER CODE END EXTI15_10_IRQn 0 */
- HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_10);
- HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_11);
- HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_12);
- HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);
- /* USER CODE BEGIN EXTI15_10_IRQn 1 */
- HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_14);
- /* USER CODE END EXTI15_10_IRQn 1 */
-}
-
-/**
- * @brief This function handles HSEM global interrupt.
- */
-void HSEM_IRQHandler(void)
-{
- /* USER CODE BEGIN HSEM_IRQn 0 */
-
- /* USER CODE END HSEM_IRQn 0 */
- HAL_HSEM_IRQHandler();
- /* USER CODE BEGIN HSEM_IRQn 1 */
-
- /* USER CODE END HSEM_IRQn 1 */
-}
-
-/* USER CODE BEGIN 1 */
-void EXTI4_IRQHandler(void)
-{
- /* USER CODE BEGIN EXTI4_IRQn 0 */
-
- /* USER CODE END EXTI4_IRQn 0 */
- HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4);
- /* USER CODE BEGIN EXTI4_IRQn 1 */
-
- /* USER CODE END EXTI4_IRQn 1 */
-}
-
extern void HW_TS_RTC_Wakeup_Handler();
extern void HW_IPCC_Tx_Handler();
extern void HW_IPCC_Rx_Handler();
-void RTC_WKUP_IRQHandler(void)
-{
- HW_TS_RTC_Wakeup_Handler();
+void NMI_Handler(void) {
+ HAL_RCC_NMI_IRQHandler();
}
-void IPCC_C1_TX_IRQHandler(void)
-{
- HW_IPCC_Tx_Handler();
+void HardFault_Handler(void) {
+ if ((*(volatile uint32_t *)CoreDebug_BASE) & (1 << 0)) {
+ __asm("bkpt 1");
+ }
+ while (1) {}
}
-void IPCC_C1_RX_IRQHandler(void)
-{
- HW_IPCC_Rx_Handler();
+void MemManage_Handler(void) {
+ __asm("bkpt 1");
+ while (1) {}
}
-/* USER CODE END 1 */
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+void BusFault_Handler(void) {
+ __asm("bkpt 1");
+ while (1) {}
+}
+
+void UsageFault_Handler(void) {
+ __asm("bkpt 1");
+ while (1) {}
+}
+
+void DebugMon_Handler(void) {
+}
+
+void SysTick_Handler(void) {
+ HAL_IncTick();
+}
+
+void TAMP_STAMP_LSECSS_IRQHandler(void) {
+ if (!LL_RCC_LSE_IsReady()) {
+ // TODO: notify user about issue with LSE
+ LL_RCC_ForceBackupDomainReset();
+ LL_RCC_ReleaseBackupDomainReset();
+ NVIC_SystemReset();
+ }
+}
+
+void RCC_IRQHandler(void) {
+}
+
+void EXTI0_IRQHandler(void) {
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
+}
+
+void EXTI1_IRQHandler(void) {
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_1);
+}
+
+void EXTI2_IRQHandler(void) {
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_2);
+}
+
+void EXTI3_IRQHandler(void) {
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_3);
+}
+
+void EXTI4_IRQHandler(void) {
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4);
+}
+
+void EXTI9_5_IRQHandler(void) {
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_5);
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_6);
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_7);
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_8);
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_9);
+}
+
+void EXTI15_10_IRQHandler(void) {
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_10);
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_11);
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_12);
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_14);
+}
+
+void ADC1_IRQHandler(void) {
+ HAL_ADC_IRQHandler(&hadc1);
+}
+
+void USB_LP_IRQHandler(void) {
+ HAL_PCD_IRQHandler(&hpcd_USB_FS);
+}
+
+void COMP_IRQHandler(void) {
+ HAL_COMP_IRQHandler(&hcomp1);
+}
+
+void TIM1_UP_TIM16_IRQHandler(void) {
+ HAL_TIM_IRQHandler(&htim1);
+ HAL_TIM_IRQHandler(&htim16);
+}
+
+void TIM1_TRG_COM_TIM17_IRQHandler(void) {
+ HAL_TIM_IRQHandler(&htim1);
+}
+
+void TIM1_CC_IRQHandler(void) {
+ HAL_TIM_IRQHandler(&htim1);
+}
+
+void TIM2_IRQHandler(void) {
+ HAL_TIM_IRQHandler(&htim2);
+}
+
+void HSEM_IRQHandler(void) {
+ HAL_HSEM_IRQHandler();
+}
+
+void RTC_WKUP_IRQHandler(void){
+ HW_TS_RTC_Wakeup_Handler();
+}
+
+void IPCC_C1_TX_IRQHandler(void){
+ HW_IPCC_Tx_Handler();
+}
+
+void IPCC_C1_RX_IRQHandler(void){
+ HW_IPCC_Rx_Handler();
+}
diff --git a/firmware/targets/f5/api-hal/api-hal-os.c b/firmware/targets/f5/api-hal/api-hal-os.c
index f6b01e0e..7d9dc259 100644
--- a/firmware/targets/f5/api-hal/api-hal-os.c
+++ b/firmware/targets/f5/api-hal/api-hal-os.c
@@ -1,6 +1,7 @@
#include
#include
#include
+#include
#include
#include
@@ -13,10 +14,17 @@
#ifdef API_HAL_OS_DEBUG
#include
+
#define LED_SLEEP_PORT GPIOA
#define LED_SLEEP_PIN LL_GPIO_PIN_7
#define LED_TICK_PORT GPIOA
#define LED_TICK_PIN LL_GPIO_PIN_6
+#define LED_SECOND_PORT GPIOA
+#define LED_SECOND_PIN LL_GPIO_PIN_4
+
+void api_hal_os_timer_callback() {
+ LL_GPIO_TogglePin(LED_SECOND_PORT, LED_SECOND_PIN);
+}
#endif
volatile uint32_t api_hal_os_skew = 0;
@@ -30,6 +38,9 @@ void api_hal_os_init() {
#ifdef API_HAL_OS_DEBUG
LL_GPIO_SetPinMode(LED_SLEEP_PORT, LED_SLEEP_PIN, LL_GPIO_MODE_OUTPUT);
LL_GPIO_SetPinMode(LED_TICK_PORT, LED_TICK_PIN, LL_GPIO_MODE_OUTPUT);
+ LL_GPIO_SetPinMode(LED_SECOND_PORT, LED_SECOND_PIN, LL_GPIO_MODE_OUTPUT);
+ osTimerId_t second_timer = osTimerNew(api_hal_os_timer_callback, osTimerPeriodic, NULL, NULL);
+ osTimerStart(second_timer, 1024);
#endif
}
@@ -52,20 +63,20 @@ void LPTIM2_IRQHandler(void) {
static inline uint32_t api_hal_os_sleep(TickType_t expected_idle_ticks) {
// Stop ticks
api_hal_os_timer_reset();
- HAL_SuspendTick();
+ LL_SYSTICK_DisableIT();
// Start wakeup timer
api_hal_os_timer_single(expected_idle_ticks * API_HAL_OS_CLK_PER_TICK);
#ifdef API_HAL_OS_DEBUG
- LL_GPIO_SetOutputPin(LED_SLEEP_PORT, LED_SLEEP_PIN);
+ LL_GPIO_ResetOutputPin(LED_SLEEP_PORT, LED_SLEEP_PIN);
#endif
- // Go to stop2 mode
- api_hal_power_deep_sleep();
+ // Go to sleep mode
+ api_hal_power_sleep();
#ifdef API_HAL_OS_DEBUG
- LL_GPIO_ResetOutputPin(LED_SLEEP_PORT, LED_SLEEP_PIN);
+ LL_GPIO_SetOutputPin(LED_SLEEP_PORT, LED_SLEEP_PIN);
#endif
// Calculate how much time we spent in the sleep
@@ -73,22 +84,21 @@ static inline uint32_t api_hal_os_sleep(TickType_t expected_idle_ticks) {
uint32_t after_tick = after_cnt / API_HAL_OS_CLK_PER_TICK;
api_hal_os_skew = after_cnt % API_HAL_OS_CLK_PER_TICK;
+ bool cmpm = LL_LPTIM_IsActiveFlag_CMPM(API_HAL_OS_TIMER);
+ bool arrm = LL_LPTIM_IsActiveFlag_ARRM(API_HAL_OS_TIMER);
+ if (cmpm && arrm) after_tick += expected_idle_ticks;
+
// Prepare tick timer for new round
api_hal_os_timer_reset();
// Resume ticks
- HAL_ResumeTick();
+ LL_SYSTICK_EnableIT();
api_hal_os_timer_continuous(API_HAL_OS_CLK_PER_TICK);
return after_tick;
}
void vPortSuppressTicksAndSleep(TickType_t expected_idle_ticks) {
- // Check if sleep is available now
- if (!api_hal_power_deep_available()) {
- return;
- }
-
// Limit mount of ticks to maximum that timer can count
if (expected_idle_ticks > API_HAL_OS_MAX_SLEEP) {
expected_idle_ticks = API_HAL_OS_MAX_SLEEP;
@@ -98,8 +108,6 @@ void vPortSuppressTicksAndSleep(TickType_t expected_idle_ticks) {
__disable_irq();
// Confirm OS that sleep is still possible
- // And check if timer is in safe zone
- // (8 clocks till any IRQ event or ongoing synchronization)
if (eTaskConfirmSleepModeStatus() == eAbortSleep) {
__enable_irq();
return;
diff --git a/firmware/targets/f5/api-hal/api-hal-power.c b/firmware/targets/f5/api-hal/api-hal-power.c
index bbf66f64..12f79fa4 100644
--- a/firmware/targets/f5/api-hal/api-hal-power.c
+++ b/firmware/targets/f5/api-hal/api-hal-power.c
@@ -42,6 +42,10 @@ bool api_hal_power_deep_available() {
return api_hal_bt_is_alive() && api_hal_power_insomnia == 0;
}
+void api_hal_power_light_sleep() {
+ __WFI();
+}
+
void api_hal_power_deep_sleep() {
while( LL_HSEM_1StepLock(HSEM, CFG_HW_RCC_SEMID));
@@ -86,6 +90,15 @@ void api_hal_power_deep_sleep() {
LL_HSEM_ReleaseLock(HSEM, CFG_HW_RCC_SEMID, 0);
}
+void api_hal_power_sleep() {
+ if(api_hal_power_deep_available()) {
+ api_hal_power_deep_sleep();
+ } else {
+ api_hal_power_light_sleep();
+ }
+}
+
+
uint8_t api_hal_power_get_pct() {
return bq27220_get_state_of_charge();
}
@@ -203,4 +216,4 @@ void api_hal_power_enable_external_3_3v(){
void api_hal_power_disable_external_3_3v(){
LL_GPIO_ResetOutputPin(PERIPH_POWER_GPIO_Port, PERIPH_POWER_Pin);
-}
\ No newline at end of file
+}