This commit is contained in:
2025-03-19 11:06:57 +08:00
commit 49f5db3a10
1343 changed files with 599230 additions and 0 deletions

52
Core/Inc/dma.h Normal file
View File

@ -0,0 +1,52 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file dma.h
* @brief This file contains all the function prototypes for
* the dma.c file
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __DMA_H__
#define __DMA_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* DMA memory to memory transfer handles -------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_DMA_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /* __DMA_H__ */

49
Core/Inc/gpio.h Normal file
View File

@ -0,0 +1,49 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file gpio.h
* @brief This file contains all the function prototypes for
* the gpio.c file
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __GPIO_H__
#define __GPIO_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_GPIO_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /*__ GPIO_H__ */

84
Core/Inc/main.h Normal file
View File

@ -0,0 +1,84 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.h
* @brief : Header for main.c file.
* This file contains the common defines of the application.
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32wlxx_hal.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
/* Private defines -----------------------------------------------------------*/
#define RTC_N_PREDIV_S 10
#define RTC_PREDIV_S ((1<<RTC_N_PREDIV_S)-1)
#define RTC_PREDIV_A ((1<<(15-RTC_N_PREDIV_S))-1)
#define LED2_Pin GPIO_PIN_3
#define LED2_GPIO_Port GPIOB
#define LED3_Pin GPIO_PIN_4
#define LED3_GPIO_Port GPIOB
#define LED1_Pin GPIO_PIN_5
#define LED1_GPIO_Port GPIOB
#define BUT1_Pin GPIO_PIN_0
#define BUT1_GPIO_Port GPIOA
#define BUT1_EXTI_IRQn EXTI0_IRQn
#define USARTx_TX_Pin GPIO_PIN_2
#define USARTx_TX_GPIO_Port GPIOA
#define USARTx_RX_Pin GPIO_PIN_3
#define USARTx_RX_GPIO_Port GPIOA
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
#ifdef __cplusplus
}
#endif
#endif /* __MAIN_H */

77
Core/Inc/platform.h Normal file
View File

@ -0,0 +1,77 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file platform.h
* @author MCD Application Team
* @brief Header for General HW instances configuration
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __PLATFORM_H__
#define __PLATFORM_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
#define USE_BSP_DRIVER
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* Includes ------------------------------------------------------------------*/
#include <stdbool.h>
#include "stm32wlxx.h"
#include "main.h"
#include "stm32wlxx_ll_gpio.h"
#if defined(USE_BSP_DRIVER)
/* code generated by STM32CubeMX does not support BSP. */
/* In order to use BSP, users can add the BSP files in the IDE project space */
/* and define USE_BSP_DRIVER in the preprocessor definitions */
#include "stm32wlxx_LM40x_radio.h"
#include "stm32wlxx_LM40x.h" /* not used by this project*/
#endif /* defined(USE_BSP_DRIVER) */
/* USER CODE BEGIN include */
/* USER CODE END include */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* External variables --------------------------------------------------------*/
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
#ifdef __cplusplus
}
#endif
#endif /* __PLATFORM_H__ */

52
Core/Inc/rtc.h Normal file
View File

@ -0,0 +1,52 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file rtc.h
* @brief This file contains all the function prototypes for
* the rtc.c file
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __RTC_H__
#define __RTC_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
extern RTC_HandleTypeDef hrtc;
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_RTC_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /* __RTC_H__ */

99
Core/Inc/stm32_lpm_if.h Normal file
View File

@ -0,0 +1,99 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32_lpm_if.h
* @author MCD Application Team
* @brief Header for Low Power Manager interface configuration
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32_LPM_IF_H__
#define __STM32_LPM_IF_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32_lpm.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* External variables --------------------------------------------------------*/
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
/**
* @brief Enters Low Power Off Mode
*/
void PWR_EnterOffMode(void);
/**
* @brief Exits Low Power Off Mode
*/
void PWR_ExitOffMode(void);
/**
* @brief Enters Low Power Stop Mode
* @note ARM exists the function when waking up
*/
void PWR_EnterStopMode(void);
/**
* @brief Exits Low Power Stop Mode
* @note Enable the pll at 32MHz
*/
void PWR_ExitStopMode(void);
/**
* @brief Enters Low Power Sleep Mode
* @note ARM exits the function when waking up
*/
void PWR_EnterSleepMode(void);
/**
* @brief Exits Low Power Sleep Mode
* @note ARM exits the function when waking up
*/
void PWR_ExitSleepMode(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
#ifdef __cplusplus
}
#endif
#endif /*__STM32_LPM_IF_H__ */

View File

@ -0,0 +1,337 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32wlxx_hal_conf.h
* @author MCD Application Team
* @brief HAL configuration file.
******************************************************************************
* @attention
*
* Copyright (c) 2020 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef STM32WLxx_HAL_CONF_H
#define STM32WLxx_HAL_CONF_H
#ifdef __cplusplus
extern "C" {
#endif
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* ########################## Module Selection ############################## */
/**
* @brief This is the list of modules to be used in the HAL driver
*/
#define HAL_MODULE_ENABLED
/*#define HAL_ADC_MODULE_ENABLED */
/*#define HAL_COMP_MODULE_ENABLED */
/*#define HAL_CRC_MODULE_ENABLED */
/*#define HAL_CRYP_MODULE_ENABLED */
/*#define HAL_DAC_MODULE_ENABLED */
/*#define HAL_GTZC_MODULE_ENABLED */
/*#define HAL_HSEM_MODULE_ENABLED */
/*#define HAL_I2C_MODULE_ENABLED */
/*#define HAL_I2S_MODULE_ENABLED */
/*#define HAL_IPCC_MODULE_ENABLED */
/*#define HAL_IRDA_MODULE_ENABLED */
/*#define HAL_IWDG_MODULE_ENABLED */
/*#define HAL_LPTIM_MODULE_ENABLED */
/*#define HAL_PKA_MODULE_ENABLED */
/*#define HAL_RNG_MODULE_ENABLED */
#define HAL_RTC_MODULE_ENABLED
/*#define HAL_SMARTCARD_MODULE_ENABLED */
/*#define HAL_SMBUS_MODULE_ENABLED */
/*#define HAL_SPI_MODULE_ENABLED */
#define HAL_SUBGHZ_MODULE_ENABLED
/*#define HAL_TIM_MODULE_ENABLED */
#define HAL_UART_MODULE_ENABLED
/*#define HAL_USART_MODULE_ENABLED */
/*#define HAL_WWDG_MODULE_ENABLED */
#define HAL_EXTI_MODULE_ENABLED
#define HAL_CORTEX_MODULE_ENABLED
#define HAL_DMA_MODULE_ENABLED
#define HAL_FLASH_MODULE_ENABLED
#define HAL_GPIO_MODULE_ENABLED
#define HAL_PWR_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
/* ########################## Register Callbacks selection ############################## */
/**
* @brief This is the list of modules where register callback can be used
*/
#define USE_HAL_ADC_REGISTER_CALLBACKS 0u
#define USE_HAL_COMP_REGISTER_CALLBACKS 0u
#define USE_HAL_CRYP_REGISTER_CALLBACKS 0u
#define USE_HAL_DAC_REGISTER_CALLBACKS 0u
#define USE_HAL_I2C_REGISTER_CALLBACKS 0u
#define USE_HAL_I2S_REGISTER_CALLBACKS 0u
#define USE_HAL_IRDA_REGISTER_CALLBACKS 0u
#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0u
#define USE_HAL_PKA_REGISTER_CALLBACKS 0u
#define USE_HAL_RNG_REGISTER_CALLBACKS 0u
#define USE_HAL_RTC_REGISTER_CALLBACKS 0u
#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0u
#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0u
#define USE_HAL_SPI_REGISTER_CALLBACKS 0u
#define USE_HAL_SUBGHZ_REGISTER_CALLBACKS 0u
#define USE_HAL_TIM_REGISTER_CALLBACKS 0u
#define USE_HAL_UART_REGISTER_CALLBACKS 0u
#define USE_HAL_USART_REGISTER_CALLBACKS 0u
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0u
/* ########################## Oscillator Values adaptation ####################*/
/**
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
* This value is used by the RCC HAL module to compute the system frequency
* (when HSE is used as system clock source, directly or through the PLL).
*/
#if !defined (HSE_VALUE)
#define HSE_VALUE 32000000UL /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
#if !defined (HSE_STARTUP_TIMEOUT)
#define HSE_STARTUP_TIMEOUT 100UL /*!< Time out for HSE start up, in ms */
#endif /* HSE_STARTUP_TIMEOUT */
/**
* @brief Internal Multiple Speed oscillator (MSI) default value.
* This value is the default MSI range value after Reset.
*/
#if !defined (MSI_VALUE)
#define MSI_VALUE 4000000UL /*!< Value of the Internal oscillator in Hz*/
#endif /* MSI_VALUE */
/**
* @brief Internal High Speed oscillator (HSI) value.
* This value is used by the RCC HAL module to compute the system frequency
* (when HSI is used as system clock source, directly or through the PLL).
*/
#if !defined (HSI_VALUE)
#define HSI_VALUE 16000000UL /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI_VALUE */
/**
* @brief Internal Low Speed oscillator (LSI) value.
*/
#if !defined (LSI_VALUE)
#define LSI_VALUE 32000UL /*!< LSI Typical Value in Hz*/
#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
The real value may vary depending on the variations
in voltage and temperature. */
/**
* @brief External Low Speed oscillator (LSE) value.
* This value is used by the UART, RTC HAL module to compute the system frequency
*/
#if !defined (LSE_VALUE)
#define LSE_VALUE 32768UL /*!< Value of the External oscillator in Hz*/
#endif /* LSE_VALUE */
/**
* @brief Internal Multiple Speed oscillator (HSI48) default value.
* This value is the default HSI48 range value after Reset.
*/
#if !defined (HSI48_VALUE)
#define HSI48_VALUE 48000000UL /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI48_VALUE */
#if !defined (LSE_STARTUP_TIMEOUT)
#define LSE_STARTUP_TIMEOUT 5000UL /*!< Time out for LSE start up, in ms */
#endif /* LSE_STARTUP_TIMEOUT */
/* Tip: To avoid modifying this file each time you need to use different HSE,
=== you can define the HSE value in your toolchain compiler preprocessor. */
/* ########################### System Configuration ######################### */
/**
* @brief This is the HAL system configuration section
*/
#define VDD_VALUE 3300U /*!< Value of VDD in mv */
#define TICK_INT_PRIORITY ((1uL <<__NVIC_PRIO_BITS) - 1uL) /*!< tick interrupt priority (lowest by default) */
#define USE_RTOS 0U
#define PREFETCH_ENABLE 0U
#define INSTRUCTION_CACHE_ENABLE 1U
#define DATA_CACHE_ENABLE 1U
/* ########################## Assert Selection ############################## */
/**
* @brief Uncomment the line below to expanse the "assert_param" macro in the
* HAL drivers code
*/
/* #define USE_FULL_ASSERT 1 */
/* ################## SPI peripheral configuration ########################## */
/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver
* Activated: CRC code is present inside driver
* Deactivated: CRC code cleaned from driver
*/
#define USE_SPI_CRC 1U
/* ################## CRYP peripheral configuration ########################## */
#define USE_HAL_CRYP_SUSPEND_RESUME 1U
/* Includes ------------------------------------------------------------------*/
/**
* @brief Include module's header file
*/
#ifdef HAL_DMA_MODULE_ENABLED
#include "stm32wlxx_hal_dma.h"
#endif /* HAL_DMA_MODULE_ENABLED */
#ifdef HAL_ADC_MODULE_ENABLED
#include "stm32wlxx_hal_adc.h"
#endif /* HAL_ADC_MODULE_ENABLED */
#ifdef HAL_COMP_MODULE_ENABLED
#include "stm32wlxx_hal_comp.h"
#endif /* HAL_COMP_MODULE_ENABLED */
#ifdef HAL_CORTEX_MODULE_ENABLED
#include "stm32wlxx_hal_cortex.h"
#endif /* HAL_CORTEX_MODULE_ENABLED */
#ifdef HAL_CRC_MODULE_ENABLED
#include "stm32wlxx_hal_crc.h"
#endif /* HAL_CRC_MODULE_ENABLED */
#ifdef HAL_CRYP_MODULE_ENABLED
#include "stm32wlxx_hal_cryp.h"
#endif /* HAL_CRYP_MODULE_ENABLED */
#ifdef HAL_DAC_MODULE_ENABLED
#include "stm32wlxx_hal_dac.h"
#endif /* HAL_DAC_MODULE_ENABLED */
#ifdef HAL_EXTI_MODULE_ENABLED
#include "stm32wlxx_hal_exti.h"
#endif /* HAL_EXTI_MODULE_ENABLED */
#ifdef HAL_FLASH_MODULE_ENABLED
#include "stm32wlxx_hal_flash.h"
#endif /* HAL_FLASH_MODULE_ENABLED */
#ifdef HAL_GPIO_MODULE_ENABLED
#include "stm32wlxx_hal_gpio.h"
#endif /* HAL_GPIO_MODULE_ENABLED */
#ifdef HAL_GTZC_MODULE_ENABLED
#include "stm32wlxx_hal_gtzc.h"
#endif /* HAL_GTZC_MODULE_ENABLED */
#ifdef HAL_HSEM_MODULE_ENABLED
#include "stm32wlxx_hal_hsem.h"
#endif /* HAL_HSEM_MODULE_ENABLED */
#ifdef HAL_I2C_MODULE_ENABLED
#include "stm32wlxx_hal_i2c.h"
#endif /* HAL_I2C_MODULE_ENABLED */
#ifdef HAL_I2S_MODULE_ENABLED
#include "stm32wlxx_hal_i2s.h"
#endif /* HAL_I2S_MODULE_ENABLED */
#ifdef HAL_IPCC_MODULE_ENABLED
#include "stm32wlxx_hal_ipcc.h"
#endif /* HAL_IPCC_MODULE_ENABLED */
#ifdef HAL_IRDA_MODULE_ENABLED
#include "stm32wlxx_hal_irda.h"
#endif /* HAL_IRDA_MODULE_ENABLED */
#ifdef HAL_IWDG_MODULE_ENABLED
#include "stm32wlxx_hal_iwdg.h"
#endif /* HAL_IWDG_MODULE_ENABLED */
#ifdef HAL_LPTIM_MODULE_ENABLED
#include "stm32wlxx_hal_lptim.h"
#endif /* HAL_LPTIM_MODULE_ENABLED */
#ifdef HAL_PKA_MODULE_ENABLED
#include "stm32wlxx_hal_pka.h"
#endif /* HAL_PKA_MODULE_ENABLED */
#ifdef HAL_PWR_MODULE_ENABLED
#include "stm32wlxx_hal_pwr.h"
#endif /* HAL_PWR_MODULE_ENABLED */
#ifdef HAL_RCC_MODULE_ENABLED
#include "stm32wlxx_hal_rcc.h"
#endif /* HAL_RCC_MODULE_ENABLED */
#ifdef HAL_RNG_MODULE_ENABLED
#include "stm32wlxx_hal_rng.h"
#endif /* HAL_RNG_MODULE_ENABLED */
#ifdef HAL_RTC_MODULE_ENABLED
#include "stm32wlxx_hal_rtc.h"
#endif /* HAL_RTC_MODULE_ENABLED */
#ifdef HAL_SMARTCARD_MODULE_ENABLED
#include "stm32wlxx_hal_smartcard.h"
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
#ifdef HAL_SMBUS_MODULE_ENABLED
#include "stm32wlxx_hal_smbus.h"
#endif /* HAL_SMBUS_MODULE_ENABLED */
#ifdef HAL_SPI_MODULE_ENABLED
#include "stm32wlxx_hal_spi.h"
#endif /* HAL_SPI_MODULE_ENABLED */
#ifdef HAL_SUBGHZ_MODULE_ENABLED
#include "stm32wlxx_hal_subghz.h"
#endif /* HAL_SUBGHZ_MODULE_ENABLED */
#ifdef HAL_TIM_MODULE_ENABLED
#include "stm32wlxx_hal_tim.h"
#endif /* HAL_TIM_MODULE_ENABLED */
#ifdef HAL_UART_MODULE_ENABLED
#include "stm32wlxx_hal_uart.h"
#endif /* HAL_UART_MODULE_ENABLED */
#ifdef HAL_USART_MODULE_ENABLED
#include "stm32wlxx_hal_usart.h"
#endif /* HAL_USART_MODULE_ENABLED */
#ifdef HAL_WWDG_MODULE_ENABLED
#include "stm32wlxx_hal_wwdg.h"
#endif /* HAL_WWDG_MODULE_ENABLED */
/* Exported macro ------------------------------------------------------------*/
#ifdef USE_FULL_ASSERT
/**
* @brief The assert_param macro is used for function's parameters check.
* @param expr If expr is false, it calls assert_failed function
* which reports the name of the source file and the source
* line number of the call that failed.
* If expr is true, it returns no value.
* @retval None
*/
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
void assert_failed(uint8_t* file, uint32_t line);
#else
#define assert_param(expr) ((void)0U)
#endif /* USE_FULL_ASSERT */
#ifdef __cplusplus
}
#endif
#endif /* STM32WLxx_HAL_CONF_H */

72
Core/Inc/stm32wlxx_it.h Normal file
View File

@ -0,0 +1,72 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32wlxx_it.h
* @brief This file contains the headers of the interrupt handlers.
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32WLxx_IT_H
#define __STM32WLxx_IT_H
#ifdef __cplusplus
extern "C" {
#endif
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
void NMI_Handler(void);
void HardFault_Handler(void);
void MemManage_Handler(void);
void BusFault_Handler(void);
void UsageFault_Handler(void);
void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void TAMP_STAMP_LSECSS_SSRU_IRQHandler(void);
void EXTI0_IRQHandler(void);
void DMA1_Channel5_IRQHandler(void);
void USART2_IRQHandler(void);
void RTC_Alarm_IRQHandler(void);
void SUBGHZ_Radio_IRQHandler(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
#ifdef __cplusplus
}
#endif
#endif /* __STM32WLxx_IT_H */

View File

@ -0,0 +1,105 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32wlxx_nucleo_conf.h
* @author MCD Application Team
* @brief STM32WLxx_Nucleo board configuration file.
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef STM32WLXX_NUCLEO_CONF_H
#define STM32WLXX_NUCLEO_CONF_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32wlxx_hal.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32WLXX_NUCLEO
* @{
*/
/** @defgroup STM32WLXX_NUCLEO_CONFIG CONFIG
* @{
*/
/** @defgroup STM32WLXX_NUCLEO_CONFIG_Exported_Constants Exported Constants
* @{
*/
/* COM usage define */
#define USE_BSP_COM_FEATURE 0U
/* COM log define */
#define USE_COM_LOG 0U
/* IRQ priorities */
#define BSP_BUTTON_USER_IT_PRIORITY 14U
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* External variables --------------------------------------------------------*/
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
#ifdef __cplusplus
}
#endif
#endif /* STM32WLXX_NUCLEO_CONF_H */

52
Core/Inc/subghz.h Normal file
View File

@ -0,0 +1,52 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file subghz.h
* @brief This file contains all the function prototypes for
* the subghz.c file
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __SUBGHZ_H__
#define __SUBGHZ_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
extern SUBGHZ_HandleTypeDef hsubghz;
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_SUBGHZ_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /* __SUBGHZ_H__ */

89
Core/Inc/sys_app.h Normal file
View File

@ -0,0 +1,89 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file sys_app.h
* @author MCD Application Team
* @brief Function prototypes for sys_app.c file
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __SYS_APP_H__
#define __SYS_APP_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stdint.h"
#include "sys_conf.h"
#include "stm32_adv_trace.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported defines ----------------------------------------------------------*/
/* USER CODE BEGIN ED */
/* USER CODE END ED */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* External variables --------------------------------------------------------*/
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/* Exported macros -----------------------------------------------------------*/
#define APP_PPRINTF(...) do{ } while( UTIL_ADV_TRACE_OK \
!= UTIL_ADV_TRACE_COND_FSend(VLEVEL_ALWAYS, T_REG_OFF, TS_OFF, __VA_ARGS__) ) /* Polling Mode */
#define APP_TPRINTF(...) do{ {UTIL_ADV_TRACE_COND_FSend(VLEVEL_ALWAYS, T_REG_OFF, TS_ON, __VA_ARGS__);} }while(0); /* with timestamp */
#define APP_PRINTF(...) do{ {UTIL_ADV_TRACE_COND_FSend(VLEVEL_ALWAYS, T_REG_OFF, TS_OFF, __VA_ARGS__);} }while(0);
#if defined (APP_LOG_ENABLED) && (APP_LOG_ENABLED == 1)
#define APP_LOG(TS,VL,...) do{ {UTIL_ADV_TRACE_COND_FSend(VL, T_REG_OFF, TS, __VA_ARGS__);} }while(0);
#elif defined (APP_LOG_ENABLED) && (APP_LOG_ENABLED == 0) /* APP_LOG disabled */
#define APP_LOG(TS,VL,...)
#else
#error "APP_LOG_ENABLED not defined or out of range <0,1>"
#endif /* APP_LOG_ENABLED */
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
/**
* @brief initialize the system (dbg pins, trace, mbmux, sys timer, LPM, ...)
*/
void SystemApp_Init(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
#ifdef __cplusplus
}
#endif
#endif /* __SYS_APP_H__ */

103
Core/Inc/sys_conf.h Normal file
View File

@ -0,0 +1,103 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file sys_conf.h
* @author MCD Application Team
* @brief Applicative configuration, e.g. : debug, trace, low power, sensors
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __SYS_CONF_H__
#define __SYS_CONF_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/**
* @brief Verbose level for all trace logs
*/
#define VERBOSE_LEVEL VLEVEL_M
/**
* @brief Enable trace logs
*/
#define APP_LOG_ENABLED 1
/**
* @brief Activate monitoring (probes) of some internal RF signals for debug purpose
*/
#define DEBUG_SUBGHZSPI_MONITORING_ENABLED 0
#define DEBUG_RF_NRESET_ENABLED_ENABLED 0
#define DEBUG_RF_HSE32RDY_ENABLED_ENABLED 0
#define DEBUG_RF_SMPSRDY_ENABLED 0
#define DEBUG_RF_LDORDY_ENABLED 0
#define DEBUG_RF_DTB1_ENABLED 0
#define DEBUG_RF_BUSY_ENABLED 0
/**
* @brief Enable/Disable MCU Debugger pins (dbg serial wires)
* @note by HW serial wires are ON by default, need to put them OFF to save power
*/
#define DEBUGGER_ENABLED 0
/**
* @brief Disable Low Power mode
* @note 0: LowPowerMode enabled. MCU enters stop2 mode, 1: LowPowerMode disabled. MCU enters sleep mode only
*/
#define LOW_POWER_DISABLE 1
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* External variables --------------------------------------------------------*/
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
#ifdef __cplusplus
}
#endif
#endif /* __SYS_CONF_H__ */

109
Core/Inc/sys_debug.h Normal file
View File

@ -0,0 +1,109 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file sys_debug.h
* @author MCD Application Team
* @brief Configuration of the debug.c instances
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __SYS_DEBUG_H__
#define __SYS_DEBUG_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "sys_conf.h"
#include "platform.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* Pin defines */
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* External variables --------------------------------------------------------*/
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/* Exported macro ------------------------------------------------------------*/
#if !defined (DISABLE_PROBE_GPIO)
/**
* @brief Set pin to x value
*/
#define PROBE_GPIO_WRITE( gpio, n, x ) HAL_GPIO_WritePin( gpio, n, (GPIO_PinState)(x) )
/**
* @brief Set pin to high level
*/
#define PROBE_GPIO_SET_LINE( gpio, n ) LL_GPIO_SetOutputPin( gpio, n )
/**
* @brief Set pin to low level
*/
#define PROBE_GPIO_RST_LINE( gpio, n ) LL_GPIO_ResetOutputPin( gpio, n )
#else /* DISABLE_PROBE_GPIO */
/**
* @brief not usable
*/
#define PROBE_GPIO_WRITE( gpio, n, x )
/**
* @brief not usable
*/
#define PROBE_GPIO_SET_LINE( gpio, n )
/**
* @brief not usable
*/
#define PROBE_GPIO_RST_LINE( gpio, n )
#endif /* DISABLE_PROBE_GPIO */
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
/**
* @brief Initializes the SW probes pins and the monitor RF pins via Alternate Function
*/
void DBG_Init(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
#ifdef __cplusplus
}
#endif
#endif /* __SYS_DEBUG_H__ */

171
Core/Inc/timer_if.h Normal file
View File

@ -0,0 +1,171 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file timer_if.h
* @author MCD Application Team
* @brief configuration of the timer_if.c instances
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __TIMER_IF_H__
#define __TIMER_IF_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32_timer.h"
#include "stm32_systime.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* External variables --------------------------------------------------------*/
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
/**
* @brief Init RTC hardware
* @return Status based on @ref UTIL_TIMER_Status_t
*/
UTIL_TIMER_Status_t TIMER_IF_Init(void);
/**
* @brief Set the alarm
* @note The alarm is set at timeout from timer Reference (TimerContext)
* @param timeout Duration of the Timer in ticks
* @return Status based on @ref UTIL_TIMER_Status_t
*/
UTIL_TIMER_Status_t TIMER_IF_StartTimer(uint32_t timeout);
/**
* @brief Stop the Alarm
* @return Status based on @ref UTIL_TIMER_Status_t
*/
UTIL_TIMER_Status_t TIMER_IF_StopTimer(void);
/**
* @brief set timer Reference (TimerContext)
* @return Timer Reference Value in Ticks
*/
uint32_t TIMER_IF_SetTimerContext(void);
/**
* @brief Get the RTC timer Reference
* @return Timer Value in Ticks
*/
uint32_t TIMER_IF_GetTimerContext(void);
/**
* @brief Get the timer elapsed time since timer Reference (TimerContext) was set
* @return RTC Elapsed time in ticks
*/
uint32_t TIMER_IF_GetTimerElapsedTime(void);
/**
* @brief Get the timer value
* @return RTC Timer value in ticks
*/
uint32_t TIMER_IF_GetTimerValue(void);
/**
* @brief Return the minimum timeout in ticks the RTC is able to handle
* @return minimum value for a timeout in ticks
*/
uint32_t TIMER_IF_GetMinimumTimeout(void);
/**
* @brief a delay of delay ms by polling RTC
* @param delay in ms
*/
void TIMER_IF_DelayMs(uint32_t delay);
/**
* @brief converts time in ms to time in ticks
* @param[in] timeMilliSec time in milliseconds
* @return time in timer ticks
*/
uint32_t TIMER_IF_Convert_ms2Tick(uint32_t timeMilliSec);
/**
* @brief converts time in ticks to time in ms
* @param[in] tick time in timer ticks
* @return time in timer milliseconds
*/
uint32_t TIMER_IF_Convert_Tick2ms(uint32_t tick);
/**
* @brief Get rtc time
* @param[out] subSeconds in ticks
* @return time seconds
*/
uint32_t TIMER_IF_GetTime(uint16_t *subSeconds);
/**
* @brief write seconds in backUp register
* @note Used to store seconds difference between RTC time and Unix time
* @param[in] Seconds time in seconds
*/
void TIMER_IF_BkUp_Write_Seconds(uint32_t Seconds);
/**
* @brief reads seconds from backUp register
* @note Used to store seconds difference between RTC time and Unix time
* @return Time in seconds
*/
uint32_t TIMER_IF_BkUp_Read_Seconds(void);
/**
* @brief writes SubSeconds in backUp register
* @note Used to store SubSeconds difference between RTC time and Unix time
* @param[in] SubSeconds time in SubSeconds
*/
void TIMER_IF_BkUp_Write_SubSeconds(uint32_t SubSeconds);
/**
* @brief reads SubSeconds from backUp register
* @note Used to store SubSeconds difference between RTC time and Unix time
* @return Time in SubSeconds
*/
uint32_t TIMER_IF_BkUp_Read_SubSeconds(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
#ifdef __cplusplus
}
#endif
#endif /* __TIMER_IF_H__ */

52
Core/Inc/usart.h Normal file
View File

@ -0,0 +1,52 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file usart.h
* @brief This file contains all the function prototypes for
* the usart.c file
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USART_H__
#define __USART_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
extern UART_HandleTypeDef huart2;
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_USART2_UART_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /* __USART_H__ */

117
Core/Inc/usart_if.h Normal file
View File

@ -0,0 +1,117 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file usart_if.h
* @author MCD Application Team
* @brief Header for USART interface configuration
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
#include "stm32_adv_trace.h"
#include "usart.h"
#include "dma.h"
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USART_IF_H__
#define __USART_IF_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* External variables --------------------------------------------------------*/
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
/**
* @brief Init the UART and associated DMA.
* @param cb TxCpltCallback
* @return @ref UTIL_ADV_TRACE_Status_t
*/
UTIL_ADV_TRACE_Status_t vcom_Init(void (*cb)(void *));
/**
* @brief init receiver of vcom
* @param RxCb callback when Rx char is received
* @return @ref UTIL_ADV_TRACE_Status_t
*/
UTIL_ADV_TRACE_Status_t vcom_ReceiveInit(void (*RxCb)(uint8_t *rxChar, uint16_t size, uint8_t error));
/**
* @brief DeInit the UART and associated DMA.
* @return @ref UTIL_ADV_TRACE_Status_t
*/
UTIL_ADV_TRACE_Status_t vcom_DeInit(void);
/**
* @brief send buffer \p p_data of size \p size to vcom in polling mode
* @param p_data data to be sent
* @param size of buffer p_data to be sent
*/
void vcom_Trace(uint8_t *p_data, uint16_t size);
/**
* @brief send buffer \p p_data of size \p size to vcom using DMA
* @param p_data data to be sent
* @param size of buffer p_data to be sent
* @return @ref UTIL_ADV_TRACE_Status_t
*/
UTIL_ADV_TRACE_Status_t vcom_Trace_DMA(uint8_t *p_data, uint16_t size);
/**
* @brief last byte has been sent on the uart line
*/
void vcom_IRQHandler(void);
/**
* @brief last byte has been sent from memory to uart data register
*/
void vcom_DMA_TX_IRQHandler(void);
/**
* @brief Resume the UART and associated DMA (used by LPM)
*/
void vcom_Resume(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
#ifdef __cplusplus
}
#endif
#endif /* __USART_IF_H__ */

177
Core/Inc/utilities_conf.h Normal file
View File

@ -0,0 +1,177 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file utilities_conf.h
* @author MCD Application Team
* @brief Header for configuration file to utilities
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __UTILITIES_CONF_H__
#define __UTILITIES_CONF_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "cmsis_compiler.h"
/* definitions to be provided to "sequencer" utility */
#include "stm32_mem.h"
/* definition and callback for tiny_vsnprintf */
#include "stm32_tiny_vsnprintf.h"
/* enum number of task and priority*/
#include "utilities_def.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
#define VLEVEL_OFF 0 /*!< used to set UTIL_ADV_TRACE_SetVerboseLevel() (not as message param) */
#define VLEVEL_ALWAYS 0 /*!< used as message params, if this level is given
trace will be printed even when UTIL_ADV_TRACE_SetVerboseLevel(OFF) */
#define VLEVEL_L 1 /*!< just essential traces */
#define VLEVEL_M 2 /*!< functional traces */
#define VLEVEL_H 3 /*!< all traces */
#define TS_OFF 0 /*!< Log without TimeStamp */
#define TS_ON 1 /*!< Log with TimeStamp */
#define T_REG_OFF 0 /*!< Log without bitmask */
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* External variables --------------------------------------------------------*/
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/* Exported macros -----------------------------------------------------------*/
/******************************************************************************
* common
******************************************************************************/
/**
* @brief Memory placement macro
*/
#if defined(__CC_ARM)
#define UTIL_PLACE_IN_SECTION( __x__ ) __attribute__((section (__x__), zero_init))
#elif defined(__ICCARM__)
#define UTIL_PLACE_IN_SECTION( __x__ ) __attribute__((section (__x__)))
#else /* __GNUC__ */
#define UTIL_PLACE_IN_SECTION( __x__ ) __attribute__((section (__x__)))
#endif /* __CC_ARM | __ICCARM__ | __GNUC__ */
/**
* @brief Memory alignment macro
*/
#undef ALIGN
#ifdef WIN32
#define ALIGN(n)
#else
#define ALIGN(n) __attribute__((aligned(n)))
#endif /* WIN32 */
/**
* @brief macro used to initialize the critical section
*/
#define UTILS_INIT_CRITICAL_SECTION()
/**
* @brief macro used to enter the critical section
*/
#define UTILS_ENTER_CRITICAL_SECTION() uint32_t primask_bit= __get_PRIMASK();\
__disable_irq()
/**
* @brief macro used to exit the critical section
*/
#define UTILS_EXIT_CRITICAL_SECTION() __set_PRIMASK(primask_bit)
/******************************************************************************
* sequencer
******************************************************************************/
/**
* @brief default number of tasks configured in sequencer
*/
#define UTIL_SEQ_CONF_TASK_NBR CFG_SEQ_Task_NBR
/**
* @brief default value of priority task
*/
#define UTIL_SEQ_CONF_PRIO_NBR CFG_SEQ_Prio_NBR
/**
* @brief macro used to initialize the critical section
*/
#define UTIL_SEQ_INIT_CRITICAL_SECTION( ) UTILS_INIT_CRITICAL_SECTION()
/**
* @brief macro used to enter the critical section
*/
#define UTIL_SEQ_ENTER_CRITICAL_SECTION( ) UTILS_ENTER_CRITICAL_SECTION()
/**
* @brief macro used to exit the critical section
*/
#define UTIL_SEQ_EXIT_CRITICAL_SECTION( ) UTILS_EXIT_CRITICAL_SECTION()
/**
* @brief Memset utilities interface to application
*/
#define UTIL_SEQ_MEMSET8( dest, value, size ) UTIL_MEM_set_8( dest, value, size )
/******************************************************************************
* trace\advanced
* the define option
* UTIL_ADV_TRACE_CONDITIONNAL shall be defined if you want use conditional function
* UTIL_ADV_TRACE_UNCHUNK_MODE shall be defined if you want use the unchunk mode
*
******************************************************************************/
#define UTIL_ADV_TRACE_CONDITIONNAL /*!< not used */
#define UTIL_ADV_TRACE_UNCHUNK_MODE /*!< not used */
#define UTIL_ADV_TRACE_DEBUG(...) /*!< not used */
#define UTIL_ADV_TRACE_INIT_CRITICAL_SECTION( ) UTILS_INIT_CRITICAL_SECTION() /*!< init the critical section in trace feature */
#define UTIL_ADV_TRACE_ENTER_CRITICAL_SECTION( ) UTILS_ENTER_CRITICAL_SECTION() /*!< enter the critical section in trace feature */
#define UTIL_ADV_TRACE_EXIT_CRITICAL_SECTION( ) UTILS_EXIT_CRITICAL_SECTION() /*!< exit the critical section in trace feature */
#define UTIL_ADV_TRACE_TMP_BUF_SIZE (256U) /*!< default trace buffer size */
#define UTIL_ADV_TRACE_TMP_MAX_TIMESTMAP_SIZE (15U) /*!< default trace timestamp size */
#define UTIL_ADV_TRACE_FIFO_SIZE (512U) /*!< default trace fifo size */
#define UTIL_ADV_TRACE_MEMSET8( dest, value, size) UTIL_MEM_set_8((dest),(value),(size)) /*!< memset utilities interface to trace feature */
#define UTIL_ADV_TRACE_VSNPRINTF(...) tiny_vsnprintf_like(__VA_ARGS__) /*!< vsnprintf utilities interface to trace feature */
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
#ifdef __cplusplus
}
#endif
#endif /*__UTILITIES_CONF_H__ */

112
Core/Inc/utilities_def.h Normal file
View File

@ -0,0 +1,112 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file utilities_def.h
* @author MCD Application Team
* @brief Definitions for modules requiring utilities
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __UTILITIES_DEF_H__
#define __UTILITIES_DEF_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/******************************************************************************
* LOW POWER MANAGER
******************************************************************************/
/**
* Supported requester to the MCU Low Power Manager - can be increased up to 32
* It lists a bit mapping of all user of the Low Power Manager
*/
typedef enum
{
/* USER CODE BEGIN CFG_LPM_Id_t_0 */
/* USER CODE END CFG_LPM_Id_t_0 */
CFG_LPM_APPLI_Id,
CFG_LPM_UART_TX_Id,
/* USER CODE BEGIN CFG_LPM_Id_t */
/* USER CODE END CFG_LPM_Id_t */
} CFG_LPM_Id_t;
/*---------------------------------------------------------------------------*/
/* sequencer definitions */
/*---------------------------------------------------------------------------*/
/**
* This is the list of priority required by the application
* Each Id shall be in the range 0..31
*/
typedef enum
{
CFG_SEQ_Prio_0,
/* USER CODE BEGIN CFG_SEQ_Prio_Id_t */
/* USER CODE END CFG_SEQ_Prio_Id_t */
CFG_SEQ_Prio_NBR,
} CFG_SEQ_Prio_Id_t;
/**
* This is the list of task id required by the application
* Each Id shall be in the range 0..31
*/
typedef enum
{
CFG_SEQ_Task_SubGHz_Phy_App_Process,
/* USER CODE BEGIN CFG_SEQ_Task_Id_t */
/* USER CODE END CFG_SEQ_Task_Id_t */
CFG_SEQ_Task_NBR
} CFG_SEQ_Task_Id_t;
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* External variables --------------------------------------------------------*/
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
#ifdef __cplusplus
}
#endif
#endif /* __UTILITIES_DEF_H__ */

56
Core/Src/dma.c Normal file
View File

@ -0,0 +1,56 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file dma.c
* @brief This file provides code for the configuration
* of all the requested memory to memory DMA transfers.
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "dma.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/*----------------------------------------------------------------------------*/
/* Configure DMA */
/*----------------------------------------------------------------------------*/
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/**
* Enable DMA controller clock
*/
void MX_DMA_Init(void)
{
/* DMA controller clock enable */
__HAL_RCC_DMAMUX1_CLK_ENABLE();
__HAL_RCC_DMA1_CLK_ENABLE();
/* DMA interrupt init */
/* DMA1_Channel5_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 2, 0);
HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn);
}
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */

76
Core/Src/gpio.c Normal file
View File

@ -0,0 +1,76 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file gpio.c
* @brief This file provides code for the configuration
* of all used GPIO pins.
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* 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)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5, GPIO_PIN_RESET);
/*Configure GPIO pins : PB3 PB4 PB5 */
GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/*Configure GPIO pin : PA0 */
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI0_IRQn);
}
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */

187
Core/Src/main.c Normal file
View File

@ -0,0 +1,187 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "app_subghz_phy.h"
#include "gpio.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* 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 -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_SubGHz_Phy_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
MX_SubGHz_Phy_Process();
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure LSE Drive Capability
*/
HAL_PWR_EnableBkUpAccess();
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
/** Configure the main internal regulator output voltage
*/
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE|RCC_OSCILLATORTYPE_MSI;
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_11;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Configure the SYSCLKSource, HCLK, PCLK1 and PCLK2 clocks dividers
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK3|RCC_CLOCKTYPE_HCLK
|RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1
|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.AHBCLK3Divider = RCC_SYSCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
Error_Handler();
}
}
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

144
Core/Src/rtc.c Normal file
View File

@ -0,0 +1,144 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file rtc.c
* @brief This file provides code for the configuration
* of the RTC instances.
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "rtc.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
RTC_HandleTypeDef hrtc;
/* RTC init function */
void MX_RTC_Init(void)
{
/* USER CODE BEGIN RTC_Init 0 */
/* USER CODE END RTC_Init 0 */
RTC_AlarmTypeDef sAlarm = {0};
/* USER CODE BEGIN RTC_Init 1 */
/* USER CODE END RTC_Init 1 */
/** Initialize RTC Only
*/
hrtc.Instance = RTC;
hrtc.Init.AsynchPrediv = RTC_PREDIV_A;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
hrtc.Init.OutPutPullUp = RTC_OUTPUT_PULLUP_NONE;
hrtc.Init.BinMode = RTC_BINARY_ONLY;
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN Check_RTC_BKUP */
/* USER CODE END Check_RTC_BKUP */
/** Initialize RTC and set the Time and Date
*/
if (HAL_RTCEx_SetSSRU_IT(&hrtc) != HAL_OK)
{
Error_Handler();
}
/** Enable the Alarm A
*/
sAlarm.BinaryAutoClr = RTC_ALARMSUBSECONDBIN_AUTOCLR_NO;
sAlarm.AlarmTime.SubSeconds = 0x0;
sAlarm.AlarmMask = RTC_ALARMMASK_NONE;
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDBINMASK_NONE;
sAlarm.Alarm = RTC_ALARM_A;
if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, 0) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN RTC_Init 2 */
/* USER CODE END RTC_Init 2 */
}
void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle)
{
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
if(rtcHandle->Instance==RTC)
{
/* USER CODE BEGIN RTC_MspInit 0 */
/* USER CODE END RTC_MspInit 0 */
/** Initializes the peripherals clocks
*/
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}
/* RTC clock enable */
__HAL_RCC_RTC_ENABLE();
__HAL_RCC_RTCAPB_CLK_ENABLE();
/* RTC interrupt Init */
HAL_NVIC_SetPriority(TAMP_STAMP_LSECSS_SSRU_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TAMP_STAMP_LSECSS_SSRU_IRQn);
HAL_NVIC_SetPriority(RTC_Alarm_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);
/* USER CODE BEGIN RTC_MspInit 1 */
/* USER CODE END RTC_MspInit 1 */
}
}
void HAL_RTC_MspDeInit(RTC_HandleTypeDef* rtcHandle)
{
if(rtcHandle->Instance==RTC)
{
/* USER CODE BEGIN RTC_MspDeInit 0 */
/* USER CODE END RTC_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_RTC_DISABLE();
__HAL_RCC_RTCAPB_CLK_DISABLE();
/* RTC interrupt Deinit */
HAL_NVIC_DisableIRQ(TAMP_STAMP_LSECSS_SSRU_IRQn);
HAL_NVIC_DisableIRQ(RTC_Alarm_IRQn);
/* USER CODE BEGIN RTC_MspDeInit 1 */
/* USER CODE END RTC_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */

165
Core/Src/stm32_lpm_if.c Normal file
View File

@ -0,0 +1,165 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32_lpm_if.c
* @author MCD Application Team
* @brief Low layer function to enter/exit low power modes (stop, sleep)
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "platform.h"
#include "stm32_lpm.h"
#include "stm32_lpm_if.h"
#include "usart_if.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* External variables ---------------------------------------------------------*/
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/* Private typedef -----------------------------------------------------------*/
/**
* @brief Power driver callbacks handler
*/
const struct UTIL_LPM_Driver_s UTIL_PowerDriver =
{
PWR_EnterSleepMode,
PWR_ExitSleepMode,
PWR_EnterStopMode,
PWR_ExitStopMode,
PWR_EnterOffMode,
PWR_ExitOffMode,
};
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* 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 */
/* Exported functions --------------------------------------------------------*/
void PWR_EnterOffMode(void)
{
/* USER CODE BEGIN EnterOffMode_1 */
/* USER CODE END EnterOffMode_1 */
}
void PWR_ExitOffMode(void)
{
/* USER CODE BEGIN ExitOffMode_1 */
/* USER CODE END ExitOffMode_1 */
}
void PWR_EnterStopMode(void)
{
/* USER CODE BEGIN EnterStopMode_1 */
/* USER CODE END EnterStopMode_1 */
HAL_SuspendTick();
/* Clear Status Flag before entering STOP/STANDBY Mode */
LL_PWR_ClearFlag_C1STOP_C1STB();
/* USER CODE BEGIN EnterStopMode_2 */
/* USER CODE END EnterStopMode_2 */
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
/* USER CODE BEGIN EnterStopMode_3 */
/* USER CODE END EnterStopMode_3 */
}
void PWR_ExitStopMode(void)
{
/* USER CODE BEGIN ExitStopMode_1 */
/* USER CODE END ExitStopMode_1 */
/* Resume sysTick : work around for debugger problem in dual core */
HAL_ResumeTick();
/*Not retained periph:
ADC interface
DAC interface USARTx, TIMx, i2Cx, SPIx
SRAM ctrls, DMAx, DMAMux, AES, RNG, HSEM */
/* Resume not retained USARTx and DMA */
vcom_Resume();
/* USER CODE BEGIN ExitStopMode_2 */
/* USER CODE END ExitStopMode_2 */
}
void PWR_EnterSleepMode(void)
{
/* USER CODE BEGIN EnterSleepMode_1 */
/* USER CODE END EnterSleepMode_1 */
/* Suspend sysTick */
HAL_SuspendTick();
/* USER CODE BEGIN EnterSleepMode_2 */
/* USER CODE END EnterSleepMode_2 */
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
/* USER CODE BEGIN EnterSleepMode_3 */
/* USER CODE END EnterSleepMode_3 */
}
void PWR_ExitSleepMode(void)
{
/* USER CODE BEGIN ExitSleepMode_1 */
/* USER CODE END ExitSleepMode_1 */
/* Resume sysTick */
HAL_ResumeTick();
/* USER CODE BEGIN ExitSleepMode_2 */
/* USER CODE END ExitSleepMode_2 */
}
/* USER CODE BEGIN EF */
/* USER CODE END EF */
/* Private Functions Definition -----------------------------------------------*/
/* USER CODE BEGIN PrFD */
/* USER CODE END PrFD */

View File

@ -0,0 +1,78 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32wlxx_hal_msp.c
* @brief This file provides code for the MSP Initialization
* and de-Initialization codes.
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */
/* USER CODE END TD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN Define */
/* USER CODE END Define */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN Macro */
/* USER CODE END Macro */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* External functions --------------------------------------------------------*/
/* USER CODE BEGIN ExternalFunctions */
/* USER CODE END ExternalFunctions */
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* Initializes the Global MSP.
*/
void HAL_MspInit(void)
{
/* USER CODE BEGIN MspInit 0 */
/* USER CODE END MspInit 0 */
/* System interrupt init*/
/* USER CODE BEGIN MspInit 1 */
/* USER CODE END MspInit 1 */
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */

289
Core/Src/stm32wlxx_it.c Normal file
View File

@ -0,0 +1,289 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32wlxx_it.c
* @brief Interrupt Service Routines.
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32wlxx_it.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 RTC_HandleTypeDef hrtc;
extern SUBGHZ_HandleTypeDef hsubghz;
extern DMA_HandleTypeDef hdma_usart2_tx;
extern UART_HandleTypeDef huart2;
/* 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 */
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */
while (1)
{
}
/* USER CODE END NonMaskableInt_IRQn 1 */
}
/**
* @brief This function handles Hard fault interrupt.
*/
void HardFault_Handler(void)
{
/* USER CODE BEGIN HardFault_IRQn 0 */
/* 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 */
/* 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 */
/* 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 */
/* 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 System service call via SWI instruction.
*/
void SVC_Handler(void)
{
/* USER CODE BEGIN SVCall_IRQn 0 */
/* USER CODE END SVCall_IRQn 0 */
/* USER CODE BEGIN SVCall_IRQn 1 */
/* USER CODE END SVCall_IRQn 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 */
}
/**
* @brief This function handles Pendable request for system service.
*/
void PendSV_Handler(void)
{
/* USER CODE BEGIN PendSV_IRQn 0 */
/* USER CODE END PendSV_IRQn 0 */
/* USER CODE BEGIN PendSV_IRQn 1 */
/* USER CODE END PendSV_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 */
/* USER CODE END SysTick_IRQn 1 */
}
/******************************************************************************/
/* STM32WLxx 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_stm32wlxx.s). */
/******************************************************************************/
/**
* @brief This function handles RTC Tamper, RTC TimeStamp, LSECSS and RTC SSRU Interrupts.
*/
void TAMP_STAMP_LSECSS_SSRU_IRQHandler(void)
{
/* USER CODE BEGIN TAMP_STAMP_LSECSS_SSRU_IRQn 0 */
/* USER CODE END TAMP_STAMP_LSECSS_SSRU_IRQn 0 */
HAL_RTCEx_SSRUIRQHandler(&hrtc);
/* USER CODE BEGIN TAMP_STAMP_LSECSS_SSRU_IRQn 1 */
/* USER CODE END TAMP_STAMP_LSECSS_SSRU_IRQn 1 */
}
/**
* @brief This function handles EXTI Line 0 Interrupt.
*/
void EXTI0_IRQHandler(void)
{
/* USER CODE BEGIN EXTI0_IRQn 0 */
/* USER CODE END EXTI0_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(BUT1_Pin);
/* USER CODE BEGIN EXTI0_IRQn 1 */
/* USER CODE END EXTI0_IRQn 1 */
}
/**
* @brief This function handles DMA1 Channel 5 Interrupt.
*/
void DMA1_Channel5_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Channel5_IRQn 0 */
/* USER CODE END DMA1_Channel5_IRQn 0 */
HAL_DMA_IRQHandler(&hdma_usart2_tx);
/* USER CODE BEGIN DMA1_Channel5_IRQn 1 */
/* USER CODE END DMA1_Channel5_IRQn 1 */
}
/**
* @brief This function handles USART2 Interrupt.
*/
void USART2_IRQHandler(void)
{
/* USER CODE BEGIN USART2_IRQn 0 */
/* USER CODE END USART2_IRQn 0 */
HAL_UART_IRQHandler(&huart2);
/* USER CODE BEGIN USART2_IRQn 1 */
/* USER CODE END USART2_IRQn 1 */
}
/**
* @brief This function handles RTC Alarms (A and B) Interrupt.
*/
void RTC_Alarm_IRQHandler(void)
{
/* USER CODE BEGIN RTC_Alarm_IRQn 0 */
/* USER CODE END RTC_Alarm_IRQn 0 */
HAL_RTC_AlarmIRQHandler(&hrtc);
/* USER CODE BEGIN RTC_Alarm_IRQn 1 */
/* USER CODE END RTC_Alarm_IRQn 1 */
}
/**
* @brief This function handles SUBGHZ Radio Interrupt.
*/
void SUBGHZ_Radio_IRQHandler(void)
{
/* USER CODE BEGIN SUBGHZ_Radio_IRQn 0 */
/* USER CODE END SUBGHZ_Radio_IRQn 0 */
HAL_SUBGHZ_IRQHandler(&hsubghz);
/* USER CODE BEGIN SUBGHZ_Radio_IRQn 1 */
/* USER CODE END SUBGHZ_Radio_IRQn 1 */
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */

86
Core/Src/subghz.c Normal file
View File

@ -0,0 +1,86 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file subghz.c
* @brief This file provides code for the configuration
* of the SUBGHZ instances.
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "subghz.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
SUBGHZ_HandleTypeDef hsubghz;
/* SUBGHZ init function */
void MX_SUBGHZ_Init(void)
{
/* USER CODE BEGIN SUBGHZ_Init 0 */
/* USER CODE END SUBGHZ_Init 0 */
/* USER CODE BEGIN SUBGHZ_Init 1 */
/* USER CODE END SUBGHZ_Init 1 */
hsubghz.Init.BaudratePrescaler = SUBGHZSPI_BAUDRATEPRESCALER_4;
if (HAL_SUBGHZ_Init(&hsubghz) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SUBGHZ_Init 2 */
/* USER CODE END SUBGHZ_Init 2 */
}
void HAL_SUBGHZ_MspInit(SUBGHZ_HandleTypeDef* subghzHandle)
{
/* USER CODE BEGIN SUBGHZ_MspInit 0 */
/* USER CODE END SUBGHZ_MspInit 0 */
/* SUBGHZ clock enable */
__HAL_RCC_SUBGHZSPI_CLK_ENABLE();
/* SUBGHZ interrupt Init */
HAL_NVIC_SetPriority(SUBGHZ_Radio_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(SUBGHZ_Radio_IRQn);
/* USER CODE BEGIN SUBGHZ_MspInit 1 */
/* USER CODE END SUBGHZ_MspInit 1 */
}
void HAL_SUBGHZ_MspDeInit(SUBGHZ_HandleTypeDef* subghzHandle)
{
/* USER CODE BEGIN SUBGHZ_MspDeInit 0 */
/* USER CODE END SUBGHZ_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_SUBGHZSPI_CLK_DISABLE();
/* SUBGHZ interrupt Deinit */
HAL_NVIC_DisableIRQ(SUBGHZ_Radio_IRQn);
/* USER CODE BEGIN SUBGHZ_MspDeInit 1 */
/* USER CODE END SUBGHZ_MspDeInit 1 */
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */

262
Core/Src/sys_app.c Normal file
View File

@ -0,0 +1,262 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file sys_app.c
* @author MCD Application Team
* @brief Initializes HW and SW system entities (not related to the radio)
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include <stdio.h>
#include "platform.h"
#include "sys_app.h"
#include "stm32_seq.h"
#include "stm32_systime.h"
#include "stm32_lpm.h"
#include "timer_if.h"
#include "utilities_def.h"
#include "sys_debug.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* External variables ---------------------------------------------------------*/
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
#define MAX_TS_SIZE (int) 16
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
static uint8_t SYS_TimerInitialisedFlag = 0;
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/**
* @brief Returns sec and msec based on the systime in use
* @param buff to update with timestamp
* @param size of updated buffer
*/
static void TimestampNow(uint8_t *buff, uint16_t *size);
/**
* @brief it calls UTIL_ADV_TRACE_VSNPRINTF
*/
static void tiny_snprintf_like(char *buf, uint32_t maxsize, const char *strFormat, ...);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Exported functions ---------------------------------------------------------*/
void SystemApp_Init(void)
{
/* USER CODE BEGIN SystemApp_Init_1 */
/* USER CODE END SystemApp_Init_1 */
/* Ensure that MSI is wake-up system clock */
__HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_MSI);
/*Initialize timer and RTC*/
UTIL_TIMER_Init();
SYS_TimerInitialisedFlag = 1;
/* Initializes the SW probes pins and the monitor RF pins via Alternate Function */
//DBG_Init();
/*Initialize the terminal */
UTIL_ADV_TRACE_Init();
UTIL_ADV_TRACE_RegisterTimeStampFunction(TimestampNow);
/*Set verbose LEVEL*/
UTIL_ADV_TRACE_SetVerboseLevel(VERBOSE_LEVEL);
/*Init low power manager*/
UTIL_LPM_Init();
/* Disable Stand-by mode */
UTIL_LPM_SetOffMode((1 << CFG_LPM_APPLI_Id), UTIL_LPM_DISABLE);
#if defined (LOW_POWER_DISABLE) && (LOW_POWER_DISABLE == 1)
/* Disable Stop Mode */
UTIL_LPM_SetStopMode((1 << CFG_LPM_APPLI_Id), UTIL_LPM_DISABLE);
#elif !defined (LOW_POWER_DISABLE)
#error LOW_POWER_DISABLE not defined
#endif /* LOW_POWER_DISABLE */
/* USER CODE BEGIN SystemApp_Init_2 */
/* USER CODE END SystemApp_Init_2 */
}
/**
* @brief redefines __weak function in stm32_seq.c such to enter low power
*/
void UTIL_SEQ_Idle(void)
{
/* USER CODE BEGIN UTIL_SEQ_Idle_1 */
/* USER CODE END UTIL_SEQ_Idle_1 */
UTIL_LPM_EnterLowPower();
/* USER CODE BEGIN UTIL_SEQ_Idle_2 */
/* USER CODE END UTIL_SEQ_Idle_2 */
}
/* USER CODE BEGIN EF */
/* USER CODE END EF */
/* Private functions ---------------------------------------------------------*/
static void TimestampNow(uint8_t *buff, uint16_t *size)
{
/* USER CODE BEGIN TimestampNow_1 */
/* USER CODE END TimestampNow_1 */
SysTime_t curtime = SysTimeGet();
tiny_snprintf_like((char *)buff, MAX_TS_SIZE, "%ds%03d:", curtime.Seconds, curtime.SubSeconds);
*size = strlen((char *)buff);
/* USER CODE BEGIN TimestampNow_2 */
/* USER CODE END TimestampNow_2 */
}
/* Disable StopMode when traces need to be printed */
void UTIL_ADV_TRACE_PreSendHook(void)
{
/* USER CODE BEGIN UTIL_ADV_TRACE_PreSendHook_1 */
/* USER CODE END UTIL_ADV_TRACE_PreSendHook_1 */
UTIL_LPM_SetStopMode((1 << CFG_LPM_UART_TX_Id), UTIL_LPM_DISABLE);
/* USER CODE BEGIN UTIL_ADV_TRACE_PreSendHook_2 */
/* USER CODE END UTIL_ADV_TRACE_PreSendHook_2 */
}
/* Re-enable StopMode when traces have been printed */
void UTIL_ADV_TRACE_PostSendHook(void)
{
/* USER CODE BEGIN UTIL_LPM_SetStopMode_1 */
/* USER CODE END UTIL_LPM_SetStopMode_1 */
UTIL_LPM_SetStopMode((1 << CFG_LPM_UART_TX_Id), UTIL_LPM_ENABLE);
/* USER CODE BEGIN UTIL_LPM_SetStopMode_2 */
/* USER CODE END UTIL_LPM_SetStopMode_2 */
}
static void tiny_snprintf_like(char *buf, uint32_t maxsize, const char *strFormat, ...)
{
/* USER CODE BEGIN tiny_snprintf_like_1 */
/* USER CODE END tiny_snprintf_like_1 */
va_list vaArgs;
va_start(vaArgs, strFormat);
UTIL_ADV_TRACE_VSNPRINTF(buf, maxsize, strFormat, vaArgs);
va_end(vaArgs);
/* USER CODE BEGIN tiny_snprintf_like_2 */
/* USER CODE END tiny_snprintf_like_2 */
}
/* USER CODE BEGIN PrFD */
/* USER CODE END PrFD */
/* HAL overload functions ---------------------------------------------------------*/
/**
* @note This function overwrites the __weak one from HAL
*/
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
{
/*Don't enable SysTick if TIMER_IF is based on other counters (e.g. RTC) */
/* USER CODE BEGIN HAL_InitTick_1 */
/* USER CODE END HAL_InitTick_1 */
return HAL_OK;
/* USER CODE BEGIN HAL_InitTick_2 */
/* USER CODE END HAL_InitTick_2 */
}
/**
* @note This function overwrites the __weak one from HAL
*/
uint32_t HAL_GetTick(void)
{
uint32_t ret = 0;
/* TIMER_IF can be based on other counter the SysTick e.g. RTC */
/* USER CODE BEGIN HAL_GetTick_1 */
/* USER CODE END HAL_GetTick_1 */
if (SYS_TimerInitialisedFlag == 0)
{
/* TIMER_IF_GetTimerValue should be used only once UTIL_TIMER_Init() is initialized */
/* If HAL_Delay or a TIMEOUT countdown is necessary during initialization phase */
/* please use temporarily another timebase source (SysTick or TIMx), which implies also */
/* to rework the above function HAL_InitTick() and to call HAL_IncTick() on the timebase IRQ */
/* Note: when TIMER_IF is based on RTC, stm32wlxx_hal_rtc.c calls this function before TimeServer is functional */
/* RTC TIMEOUT will not expire, i.e. if RTC has an hw problem it will keep looping in the RTC_Init function */
/* USER CODE BEGIN HAL_GetTick_EarlyCall */
/* USER CODE END HAL_GetTick_EarlyCall */
}
else
{
ret = TIMER_IF_GetTimerValue();
}
/* USER CODE BEGIN HAL_GetTick_2 */
/* USER CODE END HAL_GetTick_2 */
return ret;
}
/**
* @note This function overwrites the __weak one from HAL
*/
void HAL_Delay(__IO uint32_t Delay)
{
/* TIMER_IF can be based on other counter the SysTick e.g. RTC */
/* USER CODE BEGIN HAL_Delay_1 */
/* USER CODE END HAL_Delay_1 */
TIMER_IF_DelayMs(Delay);
/* USER CODE BEGIN HAL_Delay_2 */
/* USER CODE END HAL_Delay_2 */
}
/* USER CODE BEGIN Overload_HAL_weaks */
/* USER CODE END Overload_HAL_weaks */

187
Core/Src/sys_debug.c Normal file
View File

@ -0,0 +1,187 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file sys_debug.c
* @author MCD Application Team
* @brief Configure probes pins RealTime debugging and JTAG/SerialWires for LowPower
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "platform.h"
#include "sys_debug.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* External variables ---------------------------------------------------------*/
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* 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 */
/* Exported functions --------------------------------------------------------*/
/**
* @brief Initializes the SW probes pins and the monitor RF pins via Alternate Function
*/
void DBG_Init(void)
{
/* USER CODE BEGIN DBG_Init_1 */
/* USER CODE END DBG_Init_1 */
/* SW probes */
#if defined (DEBUGGER_ENABLED) && ( DEBUGGER_ENABLED == 0 )
HAL_DBGMCU_DisableDBGSleepMode();
HAL_DBGMCU_DisableDBGStopMode();
HAL_DBGMCU_DisableDBGStandbyMode();
#elif defined (DEBUGGER_ENABLED) && ( DEBUGGER_ENABLED == 1 )
/*Debug power up request wakeup CBDGPWRUPREQ*/
LL_EXTI_EnableIT_32_63(LL_EXTI_LINE_46);
/* Disabled HAL_DBGMCU_ */
HAL_DBGMCU_EnableDBGSleepMode();
HAL_DBGMCU_EnableDBGStopMode();
HAL_DBGMCU_EnableDBGStandbyMode();
#elif !defined (DEBUGGER_ENABLED)
#error "DEBUGGER_ENABLED not defined or out of range <0,1>"
#endif /* DEBUGGER_OFF */
#if (DEBUG_SUBGHZSPI_MONITORING_ENABLED == 1) || \
(DEBUG_RF_NRESET_ENABLED == 1) || \
(DEBUG_RF_HSE32RDY_ENABLED == 1) || \
(DEBUG_RF_SMPSRDY_ENABLED == 1) || \
(DEBUG_RF_LDORDY_ENABLED == 1) || \
(DEBUG_RF_DTB1_ENABLED == 1) || \
(DEBUG_RF_BUSY_ENABLED == 1)
GPIO_InitTypeDef GPIO_InitStruct = {0};
#endif
/* USER CODE BEGIN DBG_Init_2 */
/* USER CODE END DBG_Init_2 */
/* HW alternate functions for monitoring RF */
#if (DEBUG_SUBGHZSPI_MONITORING_ENABLED == 1)
/*spi dbg*/
GPIO_InitStruct.Pin = (GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF13_DEBUG_SUBGHZSPI;
__HAL_RCC_GPIOA_CLK_ENABLE();
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
#endif /* DEBUG_SUBGHZSPI_MONITORING_ENABLED */
#if (DEBUG_RF_NRESET_ENABLED == 1)
GPIO_InitStruct.Pin = GPIO_PIN_11;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF13_DEBUG_RF;
__HAL_RCC_GPIOA_CLK_ENABLE();
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
#endif /* DEBUG_RF_NRESET_ENABLED */
#if (DEBUG_RF_HSE32RDY_ENABLED == 1)
GPIO_InitStruct.Pin = GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF13_DEBUG_RF;
__HAL_RCC_GPIOA_CLK_ENABLE();
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
#endif /* DEBUG_RF_HSE32RDY_ENABLED */
#if (DEBUG_RF_SMPSRDY_ENABLED == 1)
GPIO_InitStruct.Pin = (GPIO_PIN_2);
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF13_DEBUG_RF;
__HAL_RCC_GPIOB_CLK_ENABLE();
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
#endif /* DEBUG_RF_SMPSRDY_ENABLED */
#if (DEBUG_RF_LDORDY_ENABLED == 1)
GPIO_InitStruct.Pin = (GPIO_PIN_4);
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF13_DEBUG_RF;
__HAL_RCC_GPIOB_CLK_ENABLE();
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
#endif /* DEBUG_RF_LDORDY_ENABLED */
#if (DEBUG_RF_DTB1_ENABLED == 1)
GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF13_DEBUG_RF;
__HAL_RCC_GPIOB_CLK_ENABLE();
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
#endif /* DEBUG_RF_DTB1_ENABLED */
#if (DEBUG_RF_BUSY_ENABLED == 1)
/* Busy */
GPIO_InitStruct.Pin = (GPIO_PIN_12);
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF6_RF_BUSY;
__HAL_RCC_GPIOA_CLK_ENABLE() ;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
#endif /* DEBUG_RF_BUSY_ENABLED */
/* USER CODE BEGIN DBG_Init_3 */
/* USER CODE END DBG_Init_3 */
}
/* USER CODE BEGIN EF */
/* USER CODE END EF */
/* Private Functions Definition -----------------------------------------------*/
/* USER CODE BEGIN PrFD */
/* USER CODE END PrFD */

357
Core/Src/system_stm32wlxx.c Normal file
View File

@ -0,0 +1,357 @@
/**
******************************************************************************
* @file system_stm32wlxx.c
* @author MCD Application Team
* @brief CMSIS Cortex Device Peripheral Access Layer System Source File
*
******************************************************************************
* @attention
*
* Copyright (c) 2020-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
* This file provides two functions and one global variable to be called from
* user application:
* - SystemInit(): This function is called at startup just after reset and
* before branch to main program. This call is made inside
* the "startup_stm32wlxx.s" file.
*
* - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
* by the user application to setup the SysTick
* timer or configure other parameters.
*
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
* be called whenever the core clock is changed
* during program execution.
*
* After each device reset the MSI (4 MHz) is used as system clock source.
* Then SystemInit() function is called, in "startup_stm32wlxx.s" file, to
* configure the system clock before to branch to main program.
*
* This file configures the system clock as follows:
*=============================================================================
*-----------------------------------------------------------------------------
* System Clock source | MSI
*-----------------------------------------------------------------------------
* SYSCLK(Hz) | 4000000
*-----------------------------------------------------------------------------
* HCLK(Hz) | 4000000
*-----------------------------------------------------------------------------
* AHB Prescaler | 1
*-----------------------------------------------------------------------------
* APB1 Prescaler | 1
*-----------------------------------------------------------------------------
* APB2 Prescaler | 1
*-----------------------------------------------------------------------------
* PLL_M | 1
*-----------------------------------------------------------------------------
* PLL_N | 8
*-----------------------------------------------------------------------------
* PLL_P | 7
*-----------------------------------------------------------------------------
* PLL_Q | 2
*-----------------------------------------------------------------------------
* PLL_R | 2
*-----------------------------------------------------------------------------
* PLLSAI1_P | NA
*-----------------------------------------------------------------------------
* PLLSAI1_Q | NA
*-----------------------------------------------------------------------------
* PLLSAI1_R | NA
*-----------------------------------------------------------------------------
* Require 48MHz for USB OTG FS, | Disabled
* SDIO and RNG clock |
*-----------------------------------------------------------------------------
*=============================================================================
*/
/** @addtogroup CMSIS
* @{
*/
/** @addtogroup stm32WLxx_system
* @{
*/
/** @addtogroup stm32WLxx_System_Private_Includes
* @{
*/
#include "stm32wlxx.h"
#if !defined (HSE_VALUE)
#define HSE_VALUE (32000000UL) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
#if !defined (MSI_VALUE)
#define MSI_VALUE (4000000UL) /*!< Value of the Internal oscillator in Hz*/
#endif /* MSI_VALUE */
#if !defined (HSI_VALUE)
#define HSI_VALUE (16000000UL) /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI_VALUE */
#if !defined (LSI_VALUE)
#define LSI_VALUE (32000UL) /*!< Value of LSI in Hz*/
#endif /* LSI_VALUE */
#if !defined (LSE_VALUE)
#define LSE_VALUE (32768UL) /*!< Value of LSE in Hz*/
#endif /* LSE_VALUE */
/**
* @}
*/
/** @addtogroup STM32WLxx_System_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @addtogroup STM32WLxx_System_Private_Defines
* @{
*/
/* Note: Following vector table addresses must be defined in line with linker
configuration. */
/*!< Uncomment the following line if you need to relocate CPU1 CM4 and/or CPU2
CM0+ vector table anywhere in Sram or Flash. Else vector table will be kept
at address 0x00 which correspond to automatic remap of boot address selected */
/* #define USER_VECT_TAB_ADDRESS */
#if defined(USER_VECT_TAB_ADDRESS)
#ifdef CORE_CM0PLUS
/*!< Uncomment this line for user vector table remap in Sram else user remap
will be done in Flash. */
/* #define VECT_TAB_SRAM */
#if defined(VECT_TAB_SRAM)
#define VECT_TAB_BASE_ADDRESS SRAM2_BASE /*!< Vector Table base address field.
This value must be a multiple of 0x100. */
#define VECT_TAB_OFFSET 0x00008000U /*!< Vector Table base offset field.
This value must be a multiple of 0x100. */
#else
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
This value must be a multiple of 0x100. */
#define VECT_TAB_OFFSET 0x00020000U /*!< Vector Table base offset field.
This value must be a multiple of 0x100. */
#endif
#else /* CORE_CM4 */
/*!< Uncomment this line for user vector table remap in Sram else user remap
will be done in Flash. */
/* #define VECT_TAB_SRAM */
#if defined(VECT_TAB_SRAM)
#define VECT_TAB_BASE_ADDRESS SRAM1_BASE /*!< Vector Table base address field.
This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
#else
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
#endif
#endif
#endif
/**
* @}
*/
/** @addtogroup STM32WLxx_System_Private_Macros
* @{
*/
/**
* @}
*/
/** @addtogroup STM32WLxx_System_Private_Variables
* @{
*/
/* The SystemCoreClock variable is updated in three ways:
1) from within HAL_Init()
2) by calling CMSIS function SystemCoreClockUpdate()
3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
*/
uint32_t SystemCoreClock = 4000000UL; /*CPU1: M4 on MSI clock after startup (4MHz)*/
const uint32_t AHBPrescTable[16UL] = {1UL, 3UL, 5UL, 1UL, 1UL, 6UL, 10UL, 32UL, 2UL, 4UL, 8UL, 16UL, 64UL, 128UL, 256UL, 512UL};
const uint32_t APBPrescTable[8UL] = {0UL, 0UL, 0UL, 0UL, 1UL, 2UL, 3UL, 4UL};
const uint32_t MSIRangeTable[16UL] = {100000UL, 200000UL, 400000UL, 800000UL, 1000000UL, 2000000UL, \
4000000UL, 8000000UL, 16000000UL, 24000000UL, 32000000UL, 48000000UL, 0UL, 0UL, 0UL, 0UL}; /* 0UL values are incorrect cases */
/**
* @}
*/
/** @addtogroup STM32WLxx_System_Private_FunctionPrototypes
* @{
*/
/**
* @}
*/
/** @addtogroup STM32WLxx_System_Private_Functions
* @{
*/
/**
* @brief Setup the microcontroller system.
* @param None
* @retval None
*/
void SystemInit(void)
{
#if defined(USER_VECT_TAB_ADDRESS)
/* Configure the Vector Table location add offset address ------------------*/
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET;
#endif
/* FPU settings ------------------------------------------------------------*/
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
SCB->CPACR |= ((3UL << (10UL*2UL))|(3UL << (11UL*2UL))); /* set CP10 and CP11 Full Access */
#endif
}
/**
* @brief Update SystemCoreClock variable according to Clock Register Values.
* The SystemCoreClock variable contains the core clock (HCLK), it can
* be used by the user application to setup the SysTick timer or configure
* other parameters.
*
* @note Each time the core clock (HCLK) changes, this function must be called
* to update SystemCoreClock variable value. Otherwise, any configuration
* based on this variable will be incorrect.
*
* @note - The system frequency computed by this function is not the real
* frequency in the chip. It is calculated based on the predefined
* constant and the selected clock source:
*
* - If SYSCLK source is MSI, SystemCoreClock will contain the MSI_VALUE(*)
*
* - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(**)
*
* - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***)
*
* - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(***)
* or HSI_VALUE(*) or MSI_VALUE(*) multiplied/divided by the PLL factors.
*
* (*) MSI_VALUE is a constant defined in stm32wlxx_hal.h file (default value
* 4 MHz) but the real value may vary depending on the variations
* in voltage and temperature.
*
* (**) HSI_VALUE is a constant defined in stm32wlxx_hal_conf.h file (default value
* 16 MHz) but the real value may vary depending on the variations
* in voltage and temperature.
*
* (***) HSE_VALUE is a constant defined in stm32wlxx_hal_conf.h file (default value
* 32 MHz), user has to ensure that HSE_VALUE is same as the real
* frequency of the crystal used. Otherwise, this function may
* have wrong result.
*
* - The result of this function could be not correct when using fractional
* value for HSE crystal.
*
* @param None
* @retval None
*/
void SystemCoreClockUpdate(void)
{
uint32_t tmp, msirange, pllvco, pllr, pllsource , pllm;
/* Get MSI Range frequency--------------------------------------------------*/
/* Get MSI Range frequency--------------------------------------------------*/
if((RCC->CR & RCC_CR_MSIRGSEL) == 0U)
{ /* MSISRANGE from RCC_CSR applies */
msirange = (RCC->CSR & RCC_CSR_MSISRANGE) >> 8U;
}
else
{ /* MSIRANGE from RCC_CR applies */
msirange = (RCC->CR & RCC_CR_MSIRANGE) >> 4U;
}
/*MSI frequency range in HZ*/
msirange = MSIRangeTable[msirange];
/*SystemCoreClock=HAL_RCC_GetSysClockFreq();*/
/* Get SYSCLK source -------------------------------------------------------*/
switch (RCC->CFGR & RCC_CFGR_SWS)
{
case 0x00: /* MSI used as system clock source */
SystemCoreClock = msirange;
break;
case 0x04: /* HSI used as system clock source */
/* HSI used as system clock source */
SystemCoreClock = HSI_VALUE;
break;
case 0x08: /* HSE used as system clock source */
SystemCoreClock = HSE_VALUE;
break;
case 0x0C: /* PLL used as system clock source */
/* PLL_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLN
SYSCLK = PLL_VCO / PLLR
*/
pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC);
pllm = ((RCC->PLLCFGR & RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1UL ;
switch (pllsource)
{
case 0x02: /* HSI used as PLL clock source */
pllvco = (HSI_VALUE / pllm);
break;
case 0x03: /* HSE used as PLL clock source */
pllvco = (HSE_VALUE / pllm);
break;
default: /* MSI used as PLL clock source */
pllvco = (msirange / pllm);
break;
}
pllvco = pllvco * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> RCC_PLLCFGR_PLLN_Pos);
pllr = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> RCC_PLLCFGR_PLLR_Pos) + 1UL);
SystemCoreClock = pllvco/pllr;
break;
default:
SystemCoreClock = msirange;
break;
}
/* Compute HCLK clock frequency --------------------------------------------*/
#if defined(DUAL_CORE) && defined(CORE_CM0PLUS)
/* Get HCLK2 prescaler */
tmp = AHBPrescTable[((RCC->EXTCFGR & RCC_EXTCFGR_C2HPRE) >> RCC_EXTCFGR_C2HPRE_Pos)];
#else
/* Get HCLK1 prescaler */
tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> RCC_CFGR_HPRE_Pos)];
#endif
/* Core clock frequency */
SystemCoreClock = SystemCoreClock / tmp;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/

522
Core/Src/timer_if.c Normal file
View File

@ -0,0 +1,522 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file timer_if.c
* @author MCD Application Team
* @brief Configure RTC Alarm, Tick and Calendar manager
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include <math.h>
#include "timer_if.h"
#include "main.h" /*for STM32CubeMX generated RTC_N_PREDIV_S and RTC_N_PREDIV_A*/
#include "rtc.h"
#include "stm32_lpm.h"
#include "utilities_def.h"
#include "stm32wlxx_ll_rtc.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* External variables ---------------------------------------------------------*/
/**
* @brief RTC handle
*/
extern RTC_HandleTypeDef hrtc;
/**
* @brief Timer driver callbacks handler
*/
const UTIL_TIMER_Driver_s UTIL_TimerDriver =
{
TIMER_IF_Init,
NULL,
TIMER_IF_StartTimer,
TIMER_IF_StopTimer,
TIMER_IF_SetTimerContext,
TIMER_IF_GetTimerContext,
TIMER_IF_GetTimerElapsedTime,
TIMER_IF_GetTimerValue,
TIMER_IF_GetMinimumTimeout,
TIMER_IF_Convert_ms2Tick,
TIMER_IF_Convert_Tick2ms,
};
/**
* @brief SysTime driver callbacks handler
*/
const UTIL_SYSTIM_Driver_s UTIL_SYSTIMDriver =
{
TIMER_IF_BkUp_Write_Seconds,
TIMER_IF_BkUp_Read_Seconds,
TIMER_IF_BkUp_Write_SubSeconds,
TIMER_IF_BkUp_Read_SubSeconds,
TIMER_IF_GetTime,
};
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/**
* @brief Minimum timeout delay of Alarm in ticks
*/
#define MIN_ALARM_DELAY 3
/**
* @brief Backup seconds register
*/
#define RTC_BKP_SECONDS RTC_BKP_DR0
/**
* @brief Backup subseconds register
*/
#define RTC_BKP_SUBSECONDS RTC_BKP_DR1
/**
* @brief Backup msbticks register
*/
#define RTC_BKP_MSBTICKS RTC_BKP_DR2
/* #define RTIF_DEBUG */
/**
* @brief Map UTIL_TIMER_IRQ can be overridden in utilities_conf.h to Map on Task rather then Isr
*/
#ifndef UTIL_TIMER_IRQ_MAP_INIT
#define UTIL_TIMER_IRQ_MAP_INIT()
#endif /* UTIL_TIMER_IRQ_MAP_INIT */
#ifndef UTIL_TIMER_IRQ_MAP_PROCESS
#define UTIL_TIMER_IRQ_MAP_PROCESS() UTIL_TIMER_IRQ_Handler()
#endif /* UTIL_TIMER_IRQ_MAP_PROCESS */
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
#ifdef RTIF_DEBUG
#include "sys_app.h" /*for app_log*/
/**
* @brief Post the RTC log string format to the circular queue for printing in using the polling mode
*/
#define TIMER_IF_DBG_PRINTF(...) do{ {UTIL_ADV_TRACE_COND_FSend(VLEVEL_ALWAYS, T_REG_OFF, TS_OFF, __VA_ARGS__);} }while(0);
#else
/**
* @brief not used
*/
#define TIMER_IF_DBG_PRINTF(...)
#endif /* RTIF_DEBUG */
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/**
* @brief Indicates if the RTC is already Initialized or not
*/
static bool RTC_Initialized = false;
/**
* @brief RtcTimerContext
*/
static uint32_t RtcTimerContext = 0;
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/**
* @brief Get rtc timer Value in rtc tick
* @return val the rtc timer value (upcounting)
*/
static inline uint32_t GetTimerTicks(void);
/**
* @brief Writes MSBticks to backup register
* Absolute RTC time in tick is (MSBticks)<<32 + (32bits binary counter)
* @note MSBticks incremented every time the 32bits RTC timer wraps around (~44days)
* @param[in] MSBticks
*/
static void TIMER_IF_BkUp_Write_MSBticks(uint32_t MSBticks);
/**
* @brief Reads MSBticks from backup register
* Absolute RTC time in tick is (MSBticks)<<32 + (32bits binary counter)
* @note MSBticks incremented every time the 32bits RTC timer wraps around (~44days)
* @retval MSBticks
*/
static uint32_t TIMER_IF_BkUp_Read_MSBticks(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Exported functions ---------------------------------------------------------*/
UTIL_TIMER_Status_t TIMER_IF_Init(void)
{
UTIL_TIMER_Status_t ret = UTIL_TIMER_OK;
/* USER CODE BEGIN TIMER_IF_Init */
/* USER CODE END TIMER_IF_Init */
if (RTC_Initialized == false)
{
hrtc.IsEnabled.RtcFeatures = UINT32_MAX;
/*Init RTC*/
MX_RTC_Init();
/*Stop Timer */
TIMER_IF_StopTimer();
/** DeActivate the Alarm A enabled by STM32CubeMX during MX_RTC_Init() */
HAL_RTC_DeactivateAlarm(&hrtc, RTC_ALARM_A);
/*overload RTC feature enable*/
hrtc.IsEnabled.RtcFeatures = UINT32_MAX;
/*Enable Direct Read of the calendar registers (not through Shadow) */
HAL_RTCEx_EnableBypassShadow(&hrtc);
/*Initialize MSB ticks*/
TIMER_IF_BkUp_Write_MSBticks(0);
TIMER_IF_SetTimerContext();
/* Register a task to associate to UTIL_TIMER_Irq() interrupt */
UTIL_TIMER_IRQ_MAP_INIT();
RTC_Initialized = true;
}
/* USER CODE BEGIN TIMER_IF_Init_Last */
/* USER CODE END TIMER_IF_Init_Last */
return ret;
}
UTIL_TIMER_Status_t TIMER_IF_StartTimer(uint32_t timeout)
{
UTIL_TIMER_Status_t ret = UTIL_TIMER_OK;
/* USER CODE BEGIN TIMER_IF_StartTimer */
/* USER CODE END TIMER_IF_StartTimer */
RTC_AlarmTypeDef sAlarm = {0};
/*Stop timer if one is already started*/
TIMER_IF_StopTimer();
timeout += RtcTimerContext;
TIMER_IF_DBG_PRINTF("Start timer: time=%d, alarm=%d\n\r", GetTimerTicks(), timeout);
/* starts timer*/
sAlarm.BinaryAutoClr = RTC_ALARMSUBSECONDBIN_AUTOCLR_NO;
sAlarm.AlarmTime.SubSeconds = UINT32_MAX - timeout;
sAlarm.AlarmMask = RTC_ALARMMASK_NONE;
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDBINMASK_NONE;
sAlarm.Alarm = RTC_ALARM_A;
if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BCD) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIMER_IF_StartTimer_Last */
/* USER CODE END TIMER_IF_StartTimer_Last */
return ret;
}
UTIL_TIMER_Status_t TIMER_IF_StopTimer(void)
{
UTIL_TIMER_Status_t ret = UTIL_TIMER_OK;
/* USER CODE BEGIN TIMER_IF_StopTimer */
/* USER CODE END TIMER_IF_StopTimer */
/* Clear RTC Alarm Flag */
__HAL_RTC_ALARM_CLEAR_FLAG(&hrtc, RTC_FLAG_ALRAF);
/* Disable the Alarm A interrupt */
HAL_RTC_DeactivateAlarm(&hrtc, RTC_ALARM_A);
/*overload RTC feature enable*/
hrtc.IsEnabled.RtcFeatures = UINT32_MAX;
/* USER CODE BEGIN TIMER_IF_StopTimer_Last */
/* USER CODE END TIMER_IF_StopTimer_Last */
return ret;
}
uint32_t TIMER_IF_SetTimerContext(void)
{
/*store time context*/
RtcTimerContext = GetTimerTicks();
/* USER CODE BEGIN TIMER_IF_SetTimerContext */
/* USER CODE END TIMER_IF_SetTimerContext */
TIMER_IF_DBG_PRINTF("TIMER_IF_SetTimerContext=%d\n\r", RtcTimerContext);
/*return time context*/
return RtcTimerContext;
}
uint32_t TIMER_IF_GetTimerContext(void)
{
/* USER CODE BEGIN TIMER_IF_GetTimerContext */
/* USER CODE END TIMER_IF_GetTimerContext */
TIMER_IF_DBG_PRINTF("TIMER_IF_GetTimerContext=%d\n\r", RtcTimerContext);
/*return time context*/
return RtcTimerContext;
}
uint32_t TIMER_IF_GetTimerElapsedTime(void)
{
uint32_t ret = 0;
/* USER CODE BEGIN TIMER_IF_GetTimerElapsedTime */
/* USER CODE END TIMER_IF_GetTimerElapsedTime */
ret = ((uint32_t)(GetTimerTicks() - RtcTimerContext));
/* USER CODE BEGIN TIMER_IF_GetTimerElapsedTime_Last */
/* USER CODE END TIMER_IF_GetTimerElapsedTime_Last */
return ret;
}
uint32_t TIMER_IF_GetTimerValue(void)
{
uint32_t ret = 0;
/* USER CODE BEGIN TIMER_IF_GetTimerValue */
/* USER CODE END TIMER_IF_GetTimerValue */
if (RTC_Initialized == true)
{
ret = GetTimerTicks();
}
/* USER CODE BEGIN TIMER_IF_GetTimerValue_Last */
/* USER CODE END TIMER_IF_GetTimerValue_Last */
return ret;
}
uint32_t TIMER_IF_GetMinimumTimeout(void)
{
uint32_t ret = 0;
/* USER CODE BEGIN TIMER_IF_GetMinimumTimeout */
/* USER CODE END TIMER_IF_GetMinimumTimeout */
ret = (MIN_ALARM_DELAY);
/* USER CODE BEGIN TIMER_IF_GetMinimumTimeout_Last */
/* USER CODE END TIMER_IF_GetMinimumTimeout_Last */
return ret;
}
uint32_t TIMER_IF_Convert_ms2Tick(uint32_t timeMilliSec)
{
uint32_t ret = 0;
/* USER CODE BEGIN TIMER_IF_Convert_ms2Tick */
/* USER CODE END TIMER_IF_Convert_ms2Tick */
ret = ((uint32_t)((((uint64_t) timeMilliSec) << RTC_N_PREDIV_S) / 1000));
/* USER CODE BEGIN TIMER_IF_Convert_ms2Tick_Last */
/* USER CODE END TIMER_IF_Convert_ms2Tick_Last */
return ret;
}
uint32_t TIMER_IF_Convert_Tick2ms(uint32_t tick)
{
uint32_t ret = 0;
/* USER CODE BEGIN TIMER_IF_Convert_Tick2ms */
/* USER CODE END TIMER_IF_Convert_Tick2ms */
ret = ((uint32_t)((((uint64_t)(tick)) * 1000) >> RTC_N_PREDIV_S));
/* USER CODE BEGIN TIMER_IF_Convert_Tick2ms_Last */
/* USER CODE END TIMER_IF_Convert_Tick2ms_Last */
return ret;
}
void TIMER_IF_DelayMs(uint32_t delay)
{
/* USER CODE BEGIN TIMER_IF_DelayMs */
/* USER CODE END TIMER_IF_DelayMs */
uint32_t delayTicks = TIMER_IF_Convert_ms2Tick(delay);
uint32_t timeout = GetTimerTicks();
/* Wait delay ms */
while (((GetTimerTicks() - timeout)) < delayTicks)
{
__NOP();
}
/* USER CODE BEGIN TIMER_IF_DelayMs_Last */
/* USER CODE END TIMER_IF_DelayMs_Last */
}
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
{
/* USER CODE BEGIN HAL_RTC_AlarmAEventCallback */
/* USER CODE END HAL_RTC_AlarmAEventCallback */
UTIL_TIMER_IRQ_MAP_PROCESS();
/* USER CODE BEGIN HAL_RTC_AlarmAEventCallback_Last */
/* USER CODE END HAL_RTC_AlarmAEventCallback_Last */
}
void HAL_RTCEx_SSRUEventCallback(RTC_HandleTypeDef *hrtc)
{
/* USER CODE BEGIN HAL_RTCEx_SSRUEventCallback */
/* USER CODE END HAL_RTCEx_SSRUEventCallback */
/*called every 48 days with 1024 ticks per seconds*/
TIMER_IF_DBG_PRINTF(">>Handler SSRUnderflow at %d\n\r", GetTimerTicks());
/*Increment MSBticks*/
uint32_t MSB_ticks = TIMER_IF_BkUp_Read_MSBticks();
TIMER_IF_BkUp_Write_MSBticks(MSB_ticks + 1);
/* USER CODE BEGIN HAL_RTCEx_SSRUEventCallback_Last */
/* USER CODE END HAL_RTCEx_SSRUEventCallback_Last */
}
uint32_t TIMER_IF_GetTime(uint16_t *mSeconds)
{
uint32_t seconds = 0;
/* USER CODE BEGIN TIMER_IF_GetTime */
/* USER CODE END TIMER_IF_GetTime */
uint64_t ticks;
uint32_t timerValueLsb = GetTimerTicks();
uint32_t timerValueMSB = TIMER_IF_BkUp_Read_MSBticks();
ticks = (((uint64_t) timerValueMSB) << 32) + timerValueLsb;
seconds = (uint32_t)(ticks >> RTC_N_PREDIV_S);
ticks = (uint32_t) ticks & RTC_PREDIV_S;
*mSeconds = TIMER_IF_Convert_Tick2ms(ticks);
/* USER CODE BEGIN TIMER_IF_GetTime_Last */
/* USER CODE END TIMER_IF_GetTime_Last */
return seconds;
}
void TIMER_IF_BkUp_Write_Seconds(uint32_t Seconds)
{
/* USER CODE BEGIN TIMER_IF_BkUp_Write_Seconds */
/* USER CODE END TIMER_IF_BkUp_Write_Seconds */
HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_SECONDS, Seconds);
/* USER CODE BEGIN TIMER_IF_BkUp_Write_Seconds_Last */
/* USER CODE END TIMER_IF_BkUp_Write_Seconds_Last */
}
void TIMER_IF_BkUp_Write_SubSeconds(uint32_t SubSeconds)
{
/* USER CODE BEGIN TIMER_IF_BkUp_Write_SubSeconds */
/* USER CODE END TIMER_IF_BkUp_Write_SubSeconds */
HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_SUBSECONDS, SubSeconds);
/* USER CODE BEGIN TIMER_IF_BkUp_Write_SubSeconds_Last */
/* USER CODE END TIMER_IF_BkUp_Write_SubSeconds_Last */
}
uint32_t TIMER_IF_BkUp_Read_Seconds(void)
{
uint32_t ret = 0;
/* USER CODE BEGIN TIMER_IF_BkUp_Read_Seconds */
/* USER CODE END TIMER_IF_BkUp_Read_Seconds */
ret = HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_SECONDS);
/* USER CODE BEGIN TIMER_IF_BkUp_Read_Seconds_Last */
/* USER CODE END TIMER_IF_BkUp_Read_Seconds_Last */
return ret;
}
uint32_t TIMER_IF_BkUp_Read_SubSeconds(void)
{
uint32_t ret = 0;
/* USER CODE BEGIN TIMER_IF_BkUp_Read_SubSeconds */
/* USER CODE END TIMER_IF_BkUp_Read_SubSeconds */
ret = HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_SUBSECONDS);
/* USER CODE BEGIN TIMER_IF_BkUp_Read_SubSeconds_Last */
/* USER CODE END TIMER_IF_BkUp_Read_SubSeconds_Last */
return ret;
}
/* USER CODE BEGIN EF */
/* USER CODE END EF */
/* Private functions ---------------------------------------------------------*/
static void TIMER_IF_BkUp_Write_MSBticks(uint32_t MSBticks)
{
/* USER CODE BEGIN TIMER_IF_BkUp_Write_MSBticks */
/* USER CODE END TIMER_IF_BkUp_Write_MSBticks */
HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_MSBTICKS, MSBticks);
/* USER CODE BEGIN TIMER_IF_BkUp_Write_MSBticks_Last */
/* USER CODE END TIMER_IF_BkUp_Write_MSBticks_Last */
}
static uint32_t TIMER_IF_BkUp_Read_MSBticks(void)
{
/* USER CODE BEGIN TIMER_IF_BkUp_Read_MSBticks */
/* USER CODE END TIMER_IF_BkUp_Read_MSBticks */
uint32_t MSBticks;
MSBticks = HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_MSBTICKS);
return MSBticks;
/* USER CODE BEGIN TIMER_IF_BkUp_Read_MSBticks_Last */
/* USER CODE END TIMER_IF_BkUp_Read_MSBticks_Last */
}
static inline uint32_t GetTimerTicks(void)
{
/* USER CODE BEGIN GetTimerTicks */
/* USER CODE END GetTimerTicks */
uint32_t ssr = LL_RTC_TIME_GetSubSecond(RTC);
/* read twice to make sure value it valid*/
while (ssr != LL_RTC_TIME_GetSubSecond(RTC))
{
ssr = LL_RTC_TIME_GetSubSecond(RTC);
}
return UINT32_MAX - ssr;
/* USER CODE BEGIN GetTimerTicks_Last */
/* USER CODE END GetTimerTicks_Last */
}
/* USER CODE BEGIN PrFD */
/* USER CODE END PrFD */

167
Core/Src/usart.c Normal file
View File

@ -0,0 +1,167 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file usart.c
* @brief This file provides code for the configuration
* of the USART instances.
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "usart.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
UART_HandleTypeDef huart2;
DMA_HandleTypeDef hdma_usart2_tx;
/* USART2 init function */
void MX_USART2_UART_Init(void)
{
/* USER CODE BEGIN USART2_Init 0 */
/* USER CODE END USART2_Init 0 */
/* USER CODE BEGIN USART2_Init 1 */
/* USER CODE END USART2_Init 1 */
huart2.Instance = USART2;
huart2.Init.BaudRate = 115200;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1;
huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart2) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetTxFifoThreshold(&huart2, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetRxFifoThreshold(&huart2, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_EnableFifoMode(&huart2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART2_Init 2 */
/* USER CODE END USART2_Init 2 */
}
void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
if(uartHandle->Instance==USART2)
{
/* USER CODE BEGIN USART2_MspInit 0 */
/* USER CODE END USART2_MspInit 0 */
/** Initializes the peripherals clocks
*/
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART2;
PeriphClkInitStruct.Usart2ClockSelection = RCC_USART2CLKSOURCE_SYSCLK;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}
/* USART2 clock enable */
__HAL_RCC_USART2_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/**USART2 GPIO Configuration
PA2 ------> USART2_TX
PA3 ------> USART2_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* USART2 DMA Init */
/* USART2_TX Init */
hdma_usart2_tx.Instance = DMA1_Channel5;
hdma_usart2_tx.Init.Request = DMA_REQUEST_USART2_TX;
hdma_usart2_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
hdma_usart2_tx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_usart2_tx.Init.MemInc = DMA_MINC_ENABLE;
hdma_usart2_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_usart2_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_usart2_tx.Init.Mode = DMA_NORMAL;
hdma_usart2_tx.Init.Priority = DMA_PRIORITY_LOW;
if (HAL_DMA_Init(&hdma_usart2_tx) != HAL_OK)
{
Error_Handler();
}
__HAL_LINKDMA(uartHandle,hdmatx,hdma_usart2_tx);
/* USART2 interrupt Init */
HAL_NVIC_SetPriority(USART2_IRQn, 2, 0);
HAL_NVIC_EnableIRQ(USART2_IRQn);
/* USER CODE BEGIN USART2_MspInit 1 */
/* USER CODE END USART2_MspInit 1 */
}
}
void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
{
if(uartHandle->Instance==USART2)
{
/* USER CODE BEGIN USART2_MspDeInit 0 */
/* USER CODE END USART2_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_USART2_CLK_DISABLE();
/**USART2 GPIO Configuration
PA2 ------> USART2_TX
PA3 ------> USART2_RX
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
/* USART2 DMA DeInit */
HAL_DMA_DeInit(uartHandle->hdmatx);
/* USART2 interrupt Deinit */
HAL_NVIC_DisableIRQ(USART2_IRQn);
/* USER CODE BEGIN USART2_MspDeInit 1 */
/* USER CODE END USART2_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */

260
Core/Src/usart_if.c Normal file
View File

@ -0,0 +1,260 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file usart_if.c
* @author MCD Application Team
* @brief Configuration of UART driver interface for hyperterminal communication
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "usart_if.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* External variables ---------------------------------------------------------*/
/**
* @brief DMA handle
*/
extern DMA_HandleTypeDef hdma_usart2_tx;
/**
* @brief UART handle
*/
extern UART_HandleTypeDef huart2;
/**
* @brief buffer to receive 1 character
*/
uint8_t charRx;
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/* Private typedef -----------------------------------------------------------*/
/**
* @brief Trace driver callbacks handler
*/
const UTIL_ADV_TRACE_Driver_s UTIL_TraceDriver =
{
vcom_Init,
vcom_DeInit,
vcom_ReceiveInit,
vcom_Trace_DMA,
};
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/**
* @brief TX complete callback
* @return none
*/
static void (*TxCpltCallback)(void *);
/**
* @brief RX complete callback
* @param rxChar ptr of chars buffer sent by user
* @param size buffer size
* @param error errorcode
* @return none
*/
static void (*RxCpltCallback)(uint8_t *rxChar, uint16_t size, uint8_t error);
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Exported functions --------------------------------------------------------*/
UTIL_ADV_TRACE_Status_t vcom_Init(void (*cb)(void *))
{
/* USER CODE BEGIN vcom_Init_1 */
/* USER CODE END vcom_Init_1 */
TxCpltCallback = cb;
MX_DMA_Init();
MX_USART2_UART_Init();
LL_EXTI_EnableIT_0_31(LL_EXTI_LINE_27);
return UTIL_ADV_TRACE_OK;
/* USER CODE BEGIN vcom_Init_2 */
/* USER CODE END vcom_Init_2 */
}
UTIL_ADV_TRACE_Status_t vcom_DeInit(void)
{
/* USER CODE BEGIN vcom_DeInit_1 */
/* USER CODE END vcom_DeInit_1 */
/* ##-1- Reset peripherals ################################################## */
__HAL_RCC_USART2_FORCE_RESET();
__HAL_RCC_USART2_RELEASE_RESET();
/* ##-2- MspDeInit ################################################## */
HAL_UART_MspDeInit(&huart2);
/* ##-3- Disable the NVIC for DMA ########################################### */
/* USER CODE BEGIN 1 */
HAL_NVIC_DisableIRQ(DMA1_Channel5_IRQn);
return UTIL_ADV_TRACE_OK;
/* USER CODE END 1 */
/* USER CODE BEGIN vcom_DeInit_2 */
/* USER CODE END vcom_DeInit_2 */
}
void vcom_Trace(uint8_t *p_data, uint16_t size)
{
/* USER CODE BEGIN vcom_Trace_1 */
/* USER CODE END vcom_Trace_1 */
HAL_UART_Transmit(&huart2, p_data, size, 1000);
/* USER CODE BEGIN vcom_Trace_2 */
/* USER CODE END vcom_Trace_2 */
}
UTIL_ADV_TRACE_Status_t vcom_Trace_DMA(uint8_t *p_data, uint16_t size)
{
/* USER CODE BEGIN vcom_Trace_DMA_1 */
/* USER CODE END vcom_Trace_DMA_1 */
HAL_UART_Transmit_DMA(&huart2, p_data, size);
return UTIL_ADV_TRACE_OK;
/* USER CODE BEGIN vcom_Trace_DMA_2 */
/* USER CODE END vcom_Trace_DMA_2 */
}
UTIL_ADV_TRACE_Status_t vcom_ReceiveInit(void (*RxCb)(uint8_t *rxChar, uint16_t size, uint8_t error))
{
/* USER CODE BEGIN vcom_ReceiveInit_1 */
/* USER CODE END vcom_ReceiveInit_1 */
UART_WakeUpTypeDef WakeUpSelection;
/*record call back*/
RxCpltCallback = RxCb;
/*Set wakeUp event on start bit*/
WakeUpSelection.WakeUpEvent = UART_WAKEUP_ON_STARTBIT;
HAL_UARTEx_StopModeWakeUpSourceConfig(&huart2, WakeUpSelection);
/* Make sure that no UART transfer is on-going */
while (__HAL_UART_GET_FLAG(&huart2, USART_ISR_BUSY) == SET);
/* Make sure that UART is ready to receive) */
while (__HAL_UART_GET_FLAG(&huart2, USART_ISR_REACK) == RESET);
/* Enable USART interrupt */
__HAL_UART_ENABLE_IT(&huart2, UART_IT_WUF);
/*Enable wakeup from stop mode*/
HAL_UARTEx_EnableStopMode(&huart2);
/*Start LPUART receive on IT*/
HAL_UART_Receive_IT(&huart2, &charRx, 1);
return UTIL_ADV_TRACE_OK;
/* USER CODE BEGIN vcom_ReceiveInit_2 */
/* USER CODE END vcom_ReceiveInit_2 */
}
void vcom_Resume(void)
{
/* USER CODE BEGIN vcom_Resume_1 */
/* USER CODE END vcom_Resume_1 */
/*to re-enable lost UART settings*/
if (HAL_UART_Init(&huart2) != HAL_OK)
{
Error_Handler();
}
/*to re-enable lost DMA settings*/
if (HAL_DMA_Init(&hdma_usart2_tx) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN vcom_Resume_2 */
/* USER CODE END vcom_Resume_2 */
}
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
/* USER CODE BEGIN HAL_UART_TxCpltCallback_1 */
/* USER CODE END HAL_UART_TxCpltCallback_1 */
/* buffer transmission complete*/
if (huart->Instance == USART2)
{
TxCpltCallback(NULL);
}
/* USER CODE BEGIN HAL_UART_TxCpltCallback_2 */
/* USER CODE END HAL_UART_TxCpltCallback_2 */
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
/* USER CODE BEGIN HAL_UART_RxCpltCallback_1 */
/* USER CODE END HAL_UART_RxCpltCallback_1 */
if (huart->Instance == USART2)
{
if ((NULL != RxCpltCallback) && (HAL_UART_ERROR_NONE == huart->ErrorCode))
{
RxCpltCallback(&charRx, 1, 0);
}
HAL_UART_Receive_IT(huart, &charRx, 1);
}
/* USER CODE BEGIN HAL_UART_RxCpltCallback_2 */
/* USER CODE END HAL_UART_RxCpltCallback_2 */
}
/* USER CODE BEGIN EF */
/* USER CODE END EF */
/* Private Functions Definition -----------------------------------------------*/
/* USER CODE BEGIN PrFD */
/* USER CODE END PrFD */