[FL-944] Preliminary BLE fix: leave PC4 unconfigured. Cleanup code. (#381)
* GPIO: disable CC1101 GD0 pin configuration. API HAL OS: enable sleep. Cleanup interrupts and gpio code. * API HAL: disable deep sleep, add light sleep, use it instead.
This commit is contained in:
parent
799bc89870
commit
4ae5bd3d75
@ -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();
|
||||
|
@ -1,46 +1,6 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file gpio.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of all used GPIO pins.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* 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 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Configure GPIO */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/** Configure pins as
|
||||
* Analog
|
||||
* Input
|
||||
* Output
|
||||
* EVENT_OUT
|
||||
* EXTI
|
||||
*/
|
||||
void MX_GPIO_Init(void)
|
||||
{
|
||||
|
||||
void MX_GPIO_Init(void) {
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
@ -113,7 +73,7 @@ void MX_GPIO_Init(void)
|
||||
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);
|
||||
// HAL_GPIO_Init(CC1101_G0_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PBPin PBPin PBPin */
|
||||
GPIO_InitStruct.Pin = PB2_Pin|iBTN_Pin|PB3_Pin;
|
||||
@ -181,11 +141,4 @@ void MX_GPIO_Init(void)
|
||||
|
||||
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****/
|
||||
|
@ -1,63 +1,8 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32wbxx_it.c
|
||||
* @brief Interrupt Service Routines.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* 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,127 +12,44 @@ extern TIM_HandleTypeDef htim2;
|
||||
extern TIM_HandleTypeDef htim16;
|
||||
extern TIM_HandleTypeDef htim17;
|
||||
|
||||
/* USER CODE BEGIN EV */
|
||||
extern void HW_TS_RTC_Wakeup_Handler();
|
||||
extern void HW_IPCC_Tx_Handler();
|
||||
extern void HW_IPCC_Rx_Handler();
|
||||
|
||||
/* 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 */
|
||||
void NMI_Handler(void) {
|
||||
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 */
|
||||
void HardFault_Handler(void) {
|
||||
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 */
|
||||
}
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Memory management fault.
|
||||
*/
|
||||
void MemManage_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN MemoryManagement_IRQn 0 */
|
||||
void MemManage_Handler(void) {
|
||||
__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 */
|
||||
}
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Prefetch fault, memory access fault.
|
||||
*/
|
||||
void BusFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN BusFault_IRQn 0 */
|
||||
void BusFault_Handler(void) {
|
||||
__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 */
|
||||
}
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Undefined instruction or illegal state.
|
||||
*/
|
||||
void UsageFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN UsageFault_IRQn 0 */
|
||||
void UsageFault_Handler(void) {
|
||||
__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 */
|
||||
}
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 */
|
||||
void DebugMon_Handler(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 */
|
||||
void SysTick_Handler(void) {
|
||||
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)
|
||||
{
|
||||
void TAMP_STAMP_LSECSS_IRQHandler(void) {
|
||||
if (!LL_RCC_LSE_IsReady()) {
|
||||
// TODO: notify user about issue with LSE
|
||||
LL_RCC_ForceBackupDomainReset();
|
||||
@ -196,220 +58,86 @@ void TAMP_STAMP_LSECSS_IRQHandler(void)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 */
|
||||
void RCC_IRQHandler(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles EXTI line1 interrupt.
|
||||
*/
|
||||
void EXTI1_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN EXTI1_IRQn 0 */
|
||||
void EXTI0_IRQHandler(void) {
|
||||
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
|
||||
}
|
||||
|
||||
/* USER CODE END EXTI1_IRQn 0 */
|
||||
void EXTI1_IRQHandler(void) {
|
||||
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 */
|
||||
void EXTI2_IRQHandler(void) {
|
||||
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_2);
|
||||
}
|
||||
|
||||
/* USER CODE END EXTI3_IRQn 0 */
|
||||
void EXTI3_IRQHandler(void) {
|
||||
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 */
|
||||
void EXTI4_IRQHandler(void) {
|
||||
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 */
|
||||
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);
|
||||
/* USER CODE BEGIN EXTI9_5_IRQn 1 */
|
||||
|
||||
/* USER CODE END EXTI9_5_IRQn 1 */
|
||||
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_9);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 */
|
||||
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);
|
||||
/* 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 */
|
||||
void ADC1_IRQHandler(void) {
|
||||
HAL_ADC_IRQHandler(&hadc1);
|
||||
}
|
||||
|
||||
/* USER CODE END HSEM_IRQn 0 */
|
||||
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();
|
||||
/* 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)
|
||||
{
|
||||
void RTC_WKUP_IRQHandler(void){
|
||||
HW_TS_RTC_Wakeup_Handler();
|
||||
}
|
||||
|
||||
void IPCC_C1_TX_IRQHandler(void)
|
||||
{
|
||||
void IPCC_C1_TX_IRQHandler(void){
|
||||
HW_IPCC_Tx_Handler();
|
||||
}
|
||||
|
||||
void IPCC_C1_RX_IRQHandler(void)
|
||||
{
|
||||
void IPCC_C1_RX_IRQHandler(void){
|
||||
HW_IPCC_Rx_Handler();
|
||||
}
|
||||
|
||||
/* USER CODE END 1 */
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <api-hal-os.h>
|
||||
#include <api-hal-os-timer.h>
|
||||
#include <api-hal-power.h>
|
||||
#include <stm32wbxx_ll_cortex.h>
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
#include <cmsis_os.h>
|
||||
@ -13,10 +14,17 @@
|
||||
|
||||
#ifdef API_HAL_OS_DEBUG
|
||||
#include <stm32wbxx_ll_gpio.h>
|
||||
|
||||
#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;
|
||||
|
@ -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
|
||||
}
|
@ -1,46 +1,6 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file gpio.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of all used GPIO pins.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* 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 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Configure GPIO */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/** Configure pins as
|
||||
* Analog
|
||||
* Input
|
||||
* Output
|
||||
* EVENT_OUT
|
||||
* EXTI
|
||||
*/
|
||||
void MX_GPIO_Init(void)
|
||||
{
|
||||
|
||||
void MX_GPIO_Init(void) {
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
@ -120,7 +80,7 @@ void MX_GPIO_Init(void)
|
||||
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);
|
||||
// HAL_GPIO_Init(CC1101_G0_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PBPin PBPin PBPin */
|
||||
GPIO_InitStruct.Pin = PB2_Pin|iBTN_Pin|PB3_Pin;
|
||||
@ -187,11 +147,4 @@ void MX_GPIO_Init(void)
|
||||
|
||||
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****/
|
||||
|
@ -1,63 +1,8 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32wbxx_it.c
|
||||
* @brief Interrupt Service Routines.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* 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,127 +12,44 @@ extern TIM_HandleTypeDef htim2;
|
||||
extern TIM_HandleTypeDef htim16;
|
||||
extern TIM_HandleTypeDef htim17;
|
||||
|
||||
/* USER CODE BEGIN EV */
|
||||
extern void HW_TS_RTC_Wakeup_Handler();
|
||||
extern void HW_IPCC_Tx_Handler();
|
||||
extern void HW_IPCC_Rx_Handler();
|
||||
|
||||
/* 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 */
|
||||
void NMI_Handler(void) {
|
||||
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 */
|
||||
void HardFault_Handler(void) {
|
||||
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 */
|
||||
}
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Memory management fault.
|
||||
*/
|
||||
void MemManage_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN MemoryManagement_IRQn 0 */
|
||||
void MemManage_Handler(void) {
|
||||
__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 */
|
||||
}
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Prefetch fault, memory access fault.
|
||||
*/
|
||||
void BusFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN BusFault_IRQn 0 */
|
||||
void BusFault_Handler(void) {
|
||||
__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 */
|
||||
}
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Undefined instruction or illegal state.
|
||||
*/
|
||||
void UsageFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN UsageFault_IRQn 0 */
|
||||
void UsageFault_Handler(void) {
|
||||
__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 */
|
||||
}
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 */
|
||||
void DebugMon_Handler(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 */
|
||||
void SysTick_Handler(void) {
|
||||
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)
|
||||
{
|
||||
void TAMP_STAMP_LSECSS_IRQHandler(void) {
|
||||
if (!LL_RCC_LSE_IsReady()) {
|
||||
// TODO: notify user about issue with LSE
|
||||
LL_RCC_ForceBackupDomainReset();
|
||||
@ -196,220 +58,86 @@ void TAMP_STAMP_LSECSS_IRQHandler(void)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 */
|
||||
void RCC_IRQHandler(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles EXTI line1 interrupt.
|
||||
*/
|
||||
void EXTI1_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN EXTI1_IRQn 0 */
|
||||
void EXTI0_IRQHandler(void) {
|
||||
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
|
||||
}
|
||||
|
||||
/* USER CODE END EXTI1_IRQn 0 */
|
||||
void EXTI1_IRQHandler(void) {
|
||||
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 */
|
||||
void EXTI2_IRQHandler(void) {
|
||||
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_2);
|
||||
}
|
||||
|
||||
/* USER CODE END EXTI3_IRQn 0 */
|
||||
void EXTI3_IRQHandler(void) {
|
||||
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 */
|
||||
void EXTI4_IRQHandler(void) {
|
||||
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 */
|
||||
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);
|
||||
/* USER CODE BEGIN EXTI9_5_IRQn 1 */
|
||||
|
||||
/* USER CODE END EXTI9_5_IRQn 1 */
|
||||
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_9);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 */
|
||||
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);
|
||||
/* 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 */
|
||||
void ADC1_IRQHandler(void) {
|
||||
HAL_ADC_IRQHandler(&hadc1);
|
||||
}
|
||||
|
||||
/* USER CODE END HSEM_IRQn 0 */
|
||||
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();
|
||||
/* 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)
|
||||
{
|
||||
void RTC_WKUP_IRQHandler(void){
|
||||
HW_TS_RTC_Wakeup_Handler();
|
||||
}
|
||||
|
||||
void IPCC_C1_TX_IRQHandler(void)
|
||||
{
|
||||
void IPCC_C1_TX_IRQHandler(void){
|
||||
HW_IPCC_Tx_Handler();
|
||||
}
|
||||
|
||||
void IPCC_C1_RX_IRQHandler(void)
|
||||
{
|
||||
void IPCC_C1_RX_IRQHandler(void){
|
||||
HW_IPCC_Rx_Handler();
|
||||
}
|
||||
|
||||
/* USER CODE END 1 */
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <api-hal-os.h>
|
||||
#include <api-hal-os-timer.h>
|
||||
#include <api-hal-power.h>
|
||||
#include <stm32wbxx_ll_cortex.h>
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
#include <cmsis_os.h>
|
||||
@ -13,10 +14,17 @@
|
||||
|
||||
#ifdef API_HAL_OS_DEBUG
|
||||
#include <stm32wbxx_ll_gpio.h>
|
||||
|
||||
#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;
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user