first
This commit is contained in:
56
Core/Src/dma.c
Normal file
56
Core/Src/dma.c
Normal 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
76
Core/Src/gpio.c
Normal 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
187
Core/Src/main.c
Normal 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
144
Core/Src/rtc.c
Normal 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
165
Core/Src/stm32_lpm_if.c
Normal 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 */
|
||||
78
Core/Src/stm32wlxx_hal_msp.c
Normal file
78
Core/Src/stm32wlxx_hal_msp.c
Normal 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
289
Core/Src/stm32wlxx_it.c
Normal 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
86
Core/Src/subghz.c
Normal 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
262
Core/Src/sys_app.c
Normal 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
187
Core/Src/sys_debug.c
Normal 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
357
Core/Src/system_stm32wlxx.c
Normal 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
522
Core/Src/timer_if.c
Normal 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
167
Core/Src/usart.c
Normal 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
260
Core/Src/usart_if.c
Normal 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 */
|
||||
Reference in New Issue
Block a user