@@ -6,10 +6,12 @@ PROG = lora.irr | |||
PROGEXT = .elf | |||
SRCS = main.c | |||
SRCS+= board.c | |||
SRCS+= strobe_rng_init.c | |||
CFLAGS+= -I$(.CURDIR) | |||
CFLAGS+= -DNDEBUG | |||
CFLAGS+= -g | |||
#CFLAGS+= -DNDEBUG | |||
# Strobe | |||
.PATH: $(.CURDIR)/strobe | |||
@@ -21,13 +23,40 @@ SRCS+= strobe.c \ | |||
STM32=$(.CURDIR)/stm32 | |||
.PATH: $(STM32)/l151ccux | |||
LINKER_SCRIPT=$(STM32)/l151ccux/STM32L151CCUX_FLASH.ld | |||
SRCS+= startup_stm32l151ccux.s \ | |||
SRCS+= \ | |||
startup_stm32l151ccux.s \ | |||
stm32l1xx_hal.c \ | |||
stm32l1xx_hal_cortex.c \ | |||
stm32l1xx_hal_gpio.c \ | |||
stm32l1xx_hal_pcd.c \ | |||
stm32l1xx_hal_pcd_ex.c \ | |||
stm32l1xx_hal_rcc.c \ | |||
stm32l1xx_hal_rcc_ex.c \ | |||
system_stm32l1xx.c | |||
SRCS+= \ | |||
stm32l1xx_it.c \ | |||
stm32l1xx_hal_msp.c | |||
CFLAGS+= -I$(STM32) | |||
CFLAGS+= -I$(STM32)/l151ccux | |||
CFLAGS+= -DSTM32L151xC | |||
# USB | |||
.PATH: $(STM32)/usb | |||
SRCS+= \ | |||
stm32l1xx_ll_usb.c \ | |||
usb_device.c \ | |||
usbd_cdc.c \ | |||
usbd_cdc_if.c \ | |||
usbd_conf.c \ | |||
usbd_core.c \ | |||
usbd_ctlreq.c \ | |||
usbd_desc.c \ | |||
usbd_ioreq.c | |||
CFLAGS+= -I$(STM32)/usb | |||
OBJS = $(SRCS:C/.c$/.o/) | |||
CFLAGS+= -Werror -Wall | |||
@@ -46,7 +75,7 @@ $(PROG).list: $(PROG)$(PROGEXT) | |||
.PHONY: runbuild | |||
runbuild: | |||
for i in $$(gsed ':x; /\\$$/ { N; s/\\\n//; tx }' < .depend | sed -e 's/^[^:]*://'); do echo $$i; done | entr -d sh -c 'cd $(.CURDIR) && $(MAKE) all' | |||
for i in $(.MAKEFILE_LIST) $$(gsed ':x; /\\$$/ { N; s/\\\n//; tx }' < .depend | sed -e 's/^[^:]*://'); do echo $$i; done | entr -d sh -c 'cd $(.CURDIR) && $(MAKE) depend && $(MAKE) all' | |||
.PHONY: runtests | |||
runtests: | |||
@@ -0,0 +1,129 @@ | |||
#include <stm32l1xx_hal.h> | |||
#include <usbd_cdc_if.h> | |||
#include <usb_device.h> | |||
#include <board.h> | |||
static void gpio_init(void); | |||
static void clock_config(void); | |||
void | |||
board_init(void) | |||
{ | |||
HAL_Init(); | |||
clock_config(); | |||
gpio_init(); | |||
MX_USB_DEVICE_Init(); | |||
} | |||
/* | |||
* Wait for a device to connect to the VCP | |||
*/ | |||
void | |||
wait_for_vcp(void) | |||
{ | |||
for (;;) { | |||
if (vcp_status(&hUsbDeviceFS.request)) | |||
break; | |||
} | |||
} | |||
void | |||
Error_Handler(void) | |||
{ | |||
/* XXX - handle error */ | |||
} | |||
static void | |||
clock_config(void) | |||
{ | |||
RCC_OscInitTypeDef RCC_OscInitStruct; | |||
RCC_ClkInitTypeDef RCC_ClkInitStruct; | |||
RCC_PeriphCLKInitTypeDef PeriphClkInit; | |||
/* Configure internal regulator output voltage */ | |||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); | |||
/* Initializes CPU, AHB and APB busses clocks */ | |||
RCC_OscInitStruct = (RCC_OscInitTypeDef){ | |||
.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE, | |||
.HSEState = RCC_HSE_ON, | |||
.LSIState = RCC_LSI_ON, | |||
.PLL.PLLState = RCC_PLL_ON, | |||
.PLL.PLLSource = RCC_PLLSOURCE_HSE, | |||
.PLL.PLLMUL = RCC_PLL_MUL12, | |||
.PLL.PLLDIV = RCC_PLL_DIV3, | |||
}; | |||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { | |||
Error_Handler(); | |||
} | |||
/* Initializes CPU, AHB and APB busses clocks */ | |||
RCC_ClkInitStruct = (RCC_ClkInitTypeDef){ | |||
.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK | |||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2, | |||
.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK, | |||
.AHBCLKDivider = RCC_SYSCLK_DIV1, | |||
.APB1CLKDivider = RCC_HCLK_DIV1, | |||
.APB2CLKDivider = RCC_HCLK_DIV1, | |||
}; | |||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) { | |||
Error_Handler(); | |||
} | |||
PeriphClkInit = (RCC_PeriphCLKInitTypeDef){ | |||
.PeriphClockSelection = RCC_PERIPHCLK_RTC, | |||
.RTCClockSelection = RCC_RTCCLKSOURCE_LSI, | |||
}; | |||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { | |||
Error_Handler(); | |||
} | |||
} | |||
static void | |||
gpio_init(void) | |||
{ | |||
GPIO_InitTypeDef GPIO_InitStruct; | |||
__HAL_RCC_GPIOC_CLK_ENABLE(); | |||
__HAL_RCC_GPIOH_CLK_ENABLE(); | |||
__HAL_RCC_GPIOA_CLK_ENABLE(); | |||
__HAL_RCC_GPIOB_CLK_ENABLE(); | |||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_3|GPIO_PIN_4, GPIO_PIN_RESET); | |||
/* configure PA3 and PA4 */ | |||
GPIO_InitStruct = (GPIO_InitTypeDef){ | |||
.Pin = GPIO_PIN_3|GPIO_PIN_4, | |||
.Mode = GPIO_MODE_OUTPUT_PP, | |||
.Pull = GPIO_NOPULL, | |||
.Speed = GPIO_SPEED_FREQ_LOW, | |||
}; | |||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |||
/* configure PB0, PB1, PB10 and PB11 */ | |||
GPIO_InitStruct = (GPIO_InitTypeDef){ | |||
.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_10|GPIO_PIN_11, | |||
.Mode = GPIO_MODE_INPUT, | |||
.Pull = GPIO_NOPULL, | |||
.Speed = GPIO_SPEED_FREQ_LOW, | |||
}; | |||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); | |||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_RESET); | |||
/* configure PB8 */ | |||
GPIO_InitStruct = (GPIO_InitTypeDef){ | |||
.Pin = GPIO_PIN_8, | |||
.Mode = GPIO_MODE_OUTPUT_PP, | |||
.Pull = GPIO_NOPULL, | |||
.Speed = GPIO_SPEED_FREQ_LOW, | |||
}; | |||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); | |||
} |
@@ -0,0 +1,3 @@ | |||
void board_init(void); | |||
void Error_Handler(void); | |||
void wait_for_vcp(void); |
@@ -1,8 +1,20 @@ | |||
#include <usbd_cdc_if.h> | |||
#include <strobe_rng_init.h> | |||
#include <board.h> | |||
int | |||
main(void) | |||
{ | |||
strobe_rng_init(); | |||
board_init(); | |||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_SET); | |||
wait_for_vcp(); | |||
usb_printf("foo\r\n"); | |||
} |
@@ -0,0 +1,71 @@ | |||
/* USER CODE BEGIN Header */ | |||
/** | |||
****************************************************************************** | |||
* @file : main.h | |||
* @brief : Header for main.c file. | |||
* This file contains the common defines of the application. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2020 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* USER CODE END Header */ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __MAIN_H | |||
#define __MAIN_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx_hal.h" | |||
/* Private includes ----------------------------------------------------------*/ | |||
/* USER CODE BEGIN Includes */ | |||
/* USER CODE END Includes */ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/* USER CODE BEGIN ET */ | |||
/* USER CODE END ET */ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/* USER CODE BEGIN EC */ | |||
/* USER CODE END EC */ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/* USER CODE BEGIN EM */ | |||
/* USER CODE END EM */ | |||
/* Exported functions prototypes ---------------------------------------------*/ | |||
void Error_Handler(void); | |||
/* USER CODE BEGIN EFP */ | |||
/* USER CODE END EFP */ | |||
/* Private defines -----------------------------------------------------------*/ | |||
/* USER CODE BEGIN Private defines */ | |||
/* USER CODE END Private defines */ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __MAIN_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,559 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_hal.c | |||
* @author MCD Application Team | |||
* @brief HAL module driver. | |||
* This is the common part of the HAL initialization | |||
* | |||
@verbatim | |||
============================================================================== | |||
##### How to use this driver ##### | |||
============================================================================== | |||
[..] | |||
The common HAL driver contains a set of generic and common APIs that can be | |||
used by the PPP peripheral drivers and the user to start using the HAL. | |||
[..] | |||
The HAL contains two APIs categories: | |||
(+) Common HAL APIs | |||
(+) Services HAL APIs | |||
@endverbatim | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx_hal.h" | |||
/** @addtogroup STM32L1xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @defgroup HAL HAL | |||
* @brief HAL module driver. | |||
* @{ | |||
*/ | |||
#ifdef HAL_MODULE_ENABLED | |||
/* Private typedef -----------------------------------------------------------*/ | |||
/* Private define ------------------------------------------------------------*/ | |||
/** @defgroup HAL_Private_Defines HAL Private Defines | |||
* @{ | |||
*/ | |||
/** | |||
* @brief STM32L1xx HAL Driver version number | |||
*/ | |||
#define __STM32L1xx_HAL_VERSION_MAIN (0x01) /*!< [31:24] main version */ | |||
#define __STM32L1xx_HAL_VERSION_SUB1 (0x04) /*!< [23:16] sub1 version */ | |||
#define __STM32L1xx_HAL_VERSION_SUB2 (0x00) /*!< [15:8] sub2 version */ | |||
#define __STM32L1xx_HAL_VERSION_RC (0x00) /*!< [7:0] release candidate */ | |||
#define __STM32L1xx_HAL_VERSION ((__STM32L1xx_HAL_VERSION_MAIN << 24)\ | |||
|(__STM32L1xx_HAL_VERSION_SUB1 << 16)\ | |||
|(__STM32L1xx_HAL_VERSION_SUB2 << 8 )\ | |||
|(__STM32L1xx_HAL_VERSION_RC)) | |||
#define IDCODE_DEVID_MASK (0x00000FFFU) | |||
/** | |||
* @} | |||
*/ | |||
/* Private macro -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private function prototypes -----------------------------------------------*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/* Exported variables --------------------------------------------------------*/ | |||
/** @addtogroup HAL_Exported_Variables | |||
* @{ | |||
*/ | |||
__IO uint32_t uwTick; | |||
uint32_t uwTickPrio = (1UL << __NVIC_PRIO_BITS); /* Invalid priority */ | |||
uint32_t uwTickFreq = HAL_TICK_FREQ_DEFAULT; /* 1KHz */ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @defgroup HAL_Exported_Functions HAL Exported Functions | |||
* @{ | |||
*/ | |||
/** @defgroup HAL_Exported_Functions_Group1 Initialization and de-initialization Functions | |||
* @brief Initialization and de-initialization functions | |||
* | |||
@verbatim | |||
=============================================================================== | |||
##### Initialization and de-initialization functions ##### | |||
=============================================================================== | |||
[..] This section provides functions allowing to: | |||
(+) Initialize the Flash interface, the NVIC allocation and initial clock | |||
configuration. It initializes the source of time base also when timeout | |||
is needed and the backup domain when enabled. | |||
(+) De-initialize common part of the HAL. | |||
(+) Configure the time base source to have 1ms time base with a dedicated | |||
Tick interrupt priority. | |||
(++) SysTick timer is used by default as source of time base, but user | |||
can eventually implement his proper time base source (a general purpose | |||
timer for example or other time source), keeping in mind that Time base | |||
duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and | |||
handled in milliseconds basis. | |||
(++) Time base configuration function (HAL_InitTick ()) is called automatically | |||
at the beginning of the program after reset by HAL_Init() or at any time | |||
when clock is configured, by HAL_RCC_ClockConfig(). | |||
(++) Source of time base is configured to generate interrupts at regular | |||
time intervals. Care must be taken if HAL_Delay() is called from a | |||
peripheral ISR process, the Tick interrupt line must have higher priority | |||
(numerically lower) than the peripheral interrupt. Otherwise the caller | |||
ISR process will be blocked. | |||
(++) functions affecting time base configurations are declared as __weak | |||
to make override possible in case of other implementations in user file. | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief This function configures the Flash prefetch, | |||
* configures time base source, NVIC and Low level hardware | |||
* @note This function is called at the beginning of program after reset and before | |||
* the clock configuration | |||
* @note The time base configuration is based on MSI clock when exiting from Reset. | |||
* Once done, time base tick start incrementing. | |||
* In the default implementation,Systick is used as source of time base. | |||
* the tick variable is incremented each 1ms in its ISR. | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_Init(void) | |||
{ | |||
HAL_StatusTypeDef status = HAL_OK; | |||
/* Configure Flash prefetch */ | |||
#if (PREFETCH_ENABLE != 0) | |||
__HAL_FLASH_PREFETCH_BUFFER_ENABLE(); | |||
#endif /* PREFETCH_ENABLE */ | |||
/* Set Interrupt Group Priority */ | |||
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); | |||
/* Use systick as time base source and configure 1ms tick (default clock after Reset is MSI) */ | |||
if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) | |||
{ | |||
status = HAL_ERROR; | |||
} | |||
else | |||
{ | |||
/* Init the low level hardware */ | |||
HAL_MspInit(); | |||
} | |||
/* Return function status */ | |||
return status; | |||
} | |||
/** | |||
* @brief This function de-initializes common part of the HAL and stops the source | |||
* of time base. | |||
* @note This function is optional. | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_DeInit(void) | |||
{ | |||
/* Reset of all peripherals */ | |||
__HAL_RCC_APB1_FORCE_RESET(); | |||
__HAL_RCC_APB1_RELEASE_RESET(); | |||
__HAL_RCC_APB2_FORCE_RESET(); | |||
__HAL_RCC_APB2_RELEASE_RESET(); | |||
__HAL_RCC_AHB_FORCE_RESET(); | |||
__HAL_RCC_AHB_RELEASE_RESET(); | |||
/* De-Init the low level hardware */ | |||
HAL_MspDeInit(); | |||
/* Return function status */ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Initialize the MSP. | |||
* @retval None | |||
*/ | |||
__weak void HAL_MspInit(void) | |||
{ | |||
/* NOTE : This function should not be modified, when the callback is needed, | |||
the HAL_MspInit could be implemented in the user file | |||
*/ | |||
} | |||
/** | |||
* @brief DeInitialize the MSP. | |||
* @retval None | |||
*/ | |||
__weak void HAL_MspDeInit(void) | |||
{ | |||
/* NOTE : This function should not be modified, when the callback is needed, | |||
the HAL_MspDeInit could be implemented in the user file | |||
*/ | |||
} | |||
/** | |||
* @brief This function configures the source of the time base: | |||
* The time source is configured to have 1ms time base with a dedicated | |||
* Tick interrupt priority. | |||
* @note This function is called automatically at the beginning of program after | |||
* reset by HAL_Init() or at any time when clock is reconfigured by HAL_RCC_ClockConfig(). | |||
* @note In the default implementation, SysTick timer is the source of time base. | |||
* It is used to generate interrupts at regular time intervals. | |||
* Care must be taken if HAL_Delay() is called from a peripheral ISR process, | |||
* The SysTick interrupt must have higher priority (numerically lower) | |||
* than the peripheral interrupt. Otherwise the caller ISR process will be blocked. | |||
* The function is declared as __weak to be overwritten in case of other | |||
* implementation in user file. | |||
* @param TickPriority Tick interrupt priority. | |||
* @retval HAL status | |||
*/ | |||
__weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) | |||
{ | |||
HAL_StatusTypeDef status = HAL_OK; | |||
if (uwTickFreq != 0U) | |||
{ | |||
/*Configure the SysTick to have interrupt in 1ms time basis*/ | |||
if (HAL_SYSTICK_Config(SystemCoreClock / (1000U / uwTickFreq)) == 0U) | |||
{ | |||
/* Configure the SysTick IRQ priority */ | |||
if (TickPriority < (1UL << __NVIC_PRIO_BITS)) | |||
{ | |||
HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U); | |||
uwTickPrio = TickPriority; | |||
} | |||
else | |||
{ | |||
status = HAL_ERROR; | |||
} | |||
} | |||
else | |||
{ | |||
status = HAL_ERROR; | |||
} | |||
} | |||
else | |||
{ | |||
status = HAL_ERROR; | |||
} | |||
/* Return function status */ | |||
return status; | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup HAL_Exported_Functions_Group2 HAL Control functions | |||
* @brief HAL Control functions | |||
* | |||
@verbatim | |||
=============================================================================== | |||
##### HAL Control functions ##### | |||
=============================================================================== | |||
[..] This section provides functions allowing to: | |||
(+) Provide a tick value in millisecond | |||
(+) Provide a blocking delay in millisecond | |||
(+) Suspend the time base source interrupt | |||
(+) Resume the time base source interrupt | |||
(+) Get the HAL API driver version | |||
(+) Get the device identifier | |||
(+) Get the device revision identifier | |||
(+) Get the unique device identifier | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief This function is called to increment a global variable "uwTick" | |||
* used as application time base. | |||
* @note In the default implementation, this variable is incremented each 1ms | |||
* in SysTick ISR. | |||
* @note This function is declared as __weak to be overwritten in case of other | |||
* implementations in user file. | |||
* @retval None | |||
*/ | |||
__weak void HAL_IncTick(void) | |||
{ | |||
uwTick += uwTickFreq; | |||
} | |||
/** | |||
* @brief Provide a tick value in millisecond. | |||
* @note This function is declared as __weak to be overwritten in case of other | |||
* implementations in user file. | |||
* @retval tick value | |||
*/ | |||
__weak uint32_t HAL_GetTick(void) | |||
{ | |||
return uwTick; | |||
} | |||
/** | |||
* @brief This function returns a tick priority. | |||
* @retval tick priority | |||
*/ | |||
uint32_t HAL_GetTickPrio(void) | |||
{ | |||
return uwTickPrio; | |||
} | |||
/** | |||
* @brief Set new tick Freq. | |||
* @param Freq tick frequency | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_SetTickFreq(uint32_t Freq) | |||
{ | |||
HAL_StatusTypeDef status = HAL_OK; | |||
assert_param(IS_TICKFREQ(Freq)); | |||
if (uwTickFreq != Freq) | |||
{ | |||
/* Apply the new tick Freq */ | |||
status = HAL_InitTick(uwTickPrio); | |||
if (status == HAL_OK) | |||
{ | |||
uwTickFreq = Freq; | |||
} | |||
} | |||
return status; | |||
} | |||
/** | |||
* @brief Return tick frequency. | |||
* @retval tick period in Hz | |||
*/ | |||
uint32_t HAL_GetTickFreq(void) | |||
{ | |||
return uwTickFreq; | |||
} | |||
/** | |||
* @brief This function provides minimum delay (in milliseconds) based | |||
* on variable incremented. | |||
* @note In the default implementation , SysTick timer is the source of time base. | |||
* It is used to generate interrupts at regular time intervals where uwTick | |||
* is incremented. | |||
* @note This function is declared as __weak to be overwritten in case of other | |||
* implementations in user file. | |||
* @param Delay specifies the delay time length, in milliseconds. | |||
* @retval None | |||
*/ | |||
__weak void HAL_Delay(uint32_t Delay) | |||
{ | |||
uint32_t tickstart = HAL_GetTick(); | |||
uint32_t wait = Delay; | |||
/* Add a period to guaranty minimum wait */ | |||
if (wait < HAL_MAX_DELAY) | |||
{ | |||
wait += (uint32_t)(uwTickFreq); | |||
} | |||
while((HAL_GetTick() - tickstart) < wait) | |||
{ | |||
} | |||
} | |||
/** | |||
* @brief Suspend the Tick increment. | |||
* @note In the default implementation , SysTick timer is the source of time base. It is | |||
* used to generate interrupts at regular time intervals. Once HAL_SuspendTick() | |||
* is called, the SysTick interrupt will be disabled and so Tick increment | |||
* is suspended. | |||
* @note This function is declared as __weak to be overwritten in case of other | |||
* implementations in user file. | |||
* @retval None | |||
*/ | |||
__weak void HAL_SuspendTick(void) | |||
{ | |||
/* Disable SysTick Interrupt */ | |||
CLEAR_BIT(SysTick->CTRL,SysTick_CTRL_TICKINT_Msk); | |||
} | |||
/** | |||
* @brief Resume the Tick increment. | |||
* @note In the default implementation , SysTick timer is the source of time base. It is | |||
* used to generate interrupts at regular time intervals. Once HAL_ResumeTick() | |||
* is called, the SysTick interrupt will be enabled and so Tick increment | |||
* is resumed. | |||
* @note This function is declared as __weak to be overwritten in case of other | |||
* implementations in user file. | |||
* @retval None | |||
*/ | |||
__weak void HAL_ResumeTick(void) | |||
{ | |||
/* Enable SysTick Interrupt */ | |||
SET_BIT(SysTick->CTRL,SysTick_CTRL_TICKINT_Msk); | |||
} | |||
/** | |||
* @brief Return the HAL revision | |||
* @retval version: 0xXYZR (8bits for each decimal, R for RC) | |||
*/ | |||
uint32_t HAL_GetHalVersion(void) | |||
{ | |||
return __STM32L1xx_HAL_VERSION; | |||
} | |||
/** | |||
* @brief Return the device revision identifier. | |||
* @retval Device revision identifier | |||
*/ | |||
uint32_t HAL_GetREVID(void) | |||
{ | |||
return((DBGMCU->IDCODE) >> 16U); | |||
} | |||
/** | |||
* @brief Return the device identifier. | |||
* @retval Device identifier | |||
*/ | |||
uint32_t HAL_GetDEVID(void) | |||
{ | |||
return((DBGMCU->IDCODE) & IDCODE_DEVID_MASK); | |||
} | |||
/** | |||
* @brief Return the first word of the unique device identifier (UID based on 96 bits) | |||
* @retval Device identifier 31:0 bits | |||
*/ | |||
uint32_t HAL_GetUIDw0(void) | |||
{ | |||
return(READ_REG(*((uint32_t *)UID_BASE))); | |||
} | |||
/** | |||
* @brief Return the second word of the unique device identifier (UID based on 96 bits) | |||
* @retval Device identifier 63:32 bits | |||
*/ | |||
uint32_t HAL_GetUIDw1(void) | |||
{ | |||
return(READ_REG(*((uint32_t *)(UID_BASE + 0x4U)))); | |||
} | |||
/** | |||
* @brief Return the third word of the unique device identifier (UID based on 96 bits) | |||
* @retval Device identifier 95:64 bits | |||
*/ | |||
uint32_t HAL_GetUIDw2(void) | |||
{ | |||
return(READ_REG(*((uint32_t *)(UID_BASE + 0x14U)))); | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup HAL_Exported_Functions_Group3 DBGMCU Peripheral Control functions | |||
* @brief DBGMCU Peripheral Control functions | |||
* | |||
@verbatim | |||
=============================================================================== | |||
##### DBGMCU Peripheral Control functions ##### | |||
=============================================================================== | |||
[..] This section provides functions allowing to: | |||
(+) Enable/Disable Debug module during SLEEP mode | |||
(+) Enable/Disable Debug module during STOP mode | |||
(+) Enable/Disable Debug module during STANDBY mode | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Enable the Debug Module during SLEEP mode | |||
* @retval None | |||
*/ | |||
void HAL_DBGMCU_EnableDBGSleepMode(void) | |||
{ | |||
SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP); | |||
} | |||
/** | |||
* @brief Disable the Debug Module during SLEEP mode | |||
* @retval None | |||
*/ | |||
void HAL_DBGMCU_DisableDBGSleepMode(void) | |||
{ | |||
CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP); | |||
} | |||
/** | |||
* @brief Enable the Debug Module during STOP mode | |||
* @retval None | |||
*/ | |||
void HAL_DBGMCU_EnableDBGStopMode(void) | |||
{ | |||
SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP); | |||
} | |||
/** | |||
* @brief Disable the Debug Module during STOP mode | |||
* @retval None | |||
*/ | |||
void HAL_DBGMCU_DisableDBGStopMode(void) | |||
{ | |||
CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP); | |||
} | |||
/** | |||
* @brief Enable the Debug Module during STANDBY mode | |||
* @retval None | |||
*/ | |||
void HAL_DBGMCU_EnableDBGStandbyMode(void) | |||
{ | |||
SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY); | |||
} | |||
/** | |||
* @brief Disable the Debug Module during STANDBY mode | |||
* @retval None | |||
*/ | |||
void HAL_DBGMCU_DisableDBGStandbyMode(void) | |||
{ | |||
CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY); | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#endif /* HAL_MODULE_ENABLED */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,996 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_hal.h | |||
* @author MCD Application Team | |||
* @brief This file contains all the functions prototypes for the HAL | |||
* module driver. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32L1xx_HAL_H | |||
#define __STM32L1xx_HAL_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx_hal_conf.h" | |||
/** @addtogroup STM32L1xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup HAL | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup HAL_Exported_Constants HAL Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup HAL_TICK_FREQ Tick Frequency | |||
* @{ | |||
*/ | |||
#define HAL_TICK_FREQ_10HZ 100U | |||
#define HAL_TICK_FREQ_100HZ 10U | |||
#define HAL_TICK_FREQ_1KHZ 1U | |||
#define HAL_TICK_FREQ_DEFAULT HAL_TICK_FREQ_1KHZ | |||
#define IS_TICKFREQ(__FREQ__) (((__FREQ__) == HAL_TICK_FREQ_10HZ) || \ | |||
((__FREQ__) == HAL_TICK_FREQ_100HZ) || \ | |||
((__FREQ__) == HAL_TICK_FREQ_1KHZ)) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SYSCFG_Exported_Constants SYSCFG Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup SYSCFG_Constants SYSCFG: SYStem ConFiG | |||
* @{ | |||
*/ | |||
/** @defgroup SYSCFG_BootMode Boot Mode | |||
* @{ | |||
*/ | |||
#define SYSCFG_BOOT_MAINFLASH (0x00000000U) | |||
#define SYSCFG_BOOT_SYSTEMFLASH ((uint32_t)SYSCFG_MEMRMP_BOOT_MODE_0) | |||
#if defined(FSMC_R_BASE) | |||
#define SYSCFG_BOOT_FSMC ((uint32_t)SYSCFG_MEMRMP_BOOT_MODE_1) | |||
#endif /* FSMC_R_BASE */ | |||
#define SYSCFG_BOOT_SRAM ((uint32_t)SYSCFG_MEMRMP_BOOT_MODE) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RI_Constants RI: Routing Interface | |||
* @{ | |||
*/ | |||
/** @defgroup RI_InputCapture Input Capture | |||
* @{ | |||
*/ | |||
#define RI_INPUTCAPTURE_IC1 RI_ICR_IC1 /*!< Input Capture 1 */ | |||
#define RI_INPUTCAPTURE_IC2 RI_ICR_IC2 /*!< Input Capture 2 */ | |||
#define RI_INPUTCAPTURE_IC3 RI_ICR_IC3 /*!< Input Capture 3 */ | |||
#define RI_INPUTCAPTURE_IC4 RI_ICR_IC4 /*!< Input Capture 4 */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup TIM_Select TIM Select | |||
* @{ | |||
*/ | |||
#define TIM_SELECT_NONE (0x00000000U) /*!< None selected */ | |||
#define TIM_SELECT_TIM2 ((uint32_t)RI_ICR_TIM_0) /*!< Timer 2 selected */ | |||
#define TIM_SELECT_TIM3 ((uint32_t)RI_ICR_TIM_1) /*!< Timer 3 selected */ | |||
#define TIM_SELECT_TIM4 ((uint32_t)RI_ICR_TIM) /*!< Timer 4 selected */ | |||
#define IS_RI_TIM(__TIM__) (((__TIM__) == TIM_SELECT_NONE) || \ | |||
((__TIM__) == TIM_SELECT_TIM2) || \ | |||
((__TIM__) == TIM_SELECT_TIM3) || \ | |||
((__TIM__) == TIM_SELECT_TIM4)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RI_InputCaptureRouting Input Capture Routing | |||
* @{ | |||
*/ | |||
/* TIMx_IC1 TIMx_IC2 TIMx_IC3 TIMx_IC4 */ | |||
#define RI_INPUTCAPTUREROUTING_0 (0x00000000U) /* PA0 PA1 PA2 PA3 */ | |||
#define RI_INPUTCAPTUREROUTING_1 (0x00000001U) /* PA4 PA5 PA6 PA7 */ | |||
#define RI_INPUTCAPTUREROUTING_2 (0x00000002U) /* PA8 PA9 PA10 PA11 */ | |||
#define RI_INPUTCAPTUREROUTING_3 (0x00000003U) /* PA12 PA13 PA14 PA15 */ | |||
#define RI_INPUTCAPTUREROUTING_4 (0x00000004U) /* PC0 PC1 PC2 PC3 */ | |||
#define RI_INPUTCAPTUREROUTING_5 (0x00000005U) /* PC4 PC5 PC6 PC7 */ | |||
#define RI_INPUTCAPTUREROUTING_6 (0x00000006U) /* PC8 PC9 PC10 PC11 */ | |||
#define RI_INPUTCAPTUREROUTING_7 (0x00000007U) /* PC12 PC13 PC14 PC15 */ | |||
#define RI_INPUTCAPTUREROUTING_8 (0x00000008U) /* PD0 PD1 PD2 PD3 */ | |||
#define RI_INPUTCAPTUREROUTING_9 (0x00000009U) /* PD4 PD5 PD6 PD7 */ | |||
#define RI_INPUTCAPTUREROUTING_10 (0x0000000AU) /* PD8 PD9 PD10 PD11 */ | |||
#define RI_INPUTCAPTUREROUTING_11 (0x0000000BU) /* PD12 PD13 PD14 PD15 */ | |||
#define RI_INPUTCAPTUREROUTING_12 (0x0000000CU) /* PE0 PE1 PE2 PE3 */ | |||
#define RI_INPUTCAPTUREROUTING_13 (0x0000000DU) /* PE4 PE5 PE6 PE7 */ | |||
#define RI_INPUTCAPTUREROUTING_14 (0x0000000EU) /* PE8 PE9 PE10 PE11 */ | |||
#define RI_INPUTCAPTUREROUTING_15 (0x0000000FU) /* PE12 PE13 PE14 PE15 */ | |||
#define IS_RI_INPUTCAPTURE_ROUTING(__ROUTING__) (((__ROUTING__) == RI_INPUTCAPTUREROUTING_0) || \ | |||
((__ROUTING__) == RI_INPUTCAPTUREROUTING_1) || \ | |||
((__ROUTING__) == RI_INPUTCAPTUREROUTING_2) || \ | |||
((__ROUTING__) == RI_INPUTCAPTUREROUTING_3) || \ | |||
((__ROUTING__) == RI_INPUTCAPTUREROUTING_4) || \ | |||
((__ROUTING__) == RI_INPUTCAPTUREROUTING_5) || \ | |||
((__ROUTING__) == RI_INPUTCAPTUREROUTING_6) || \ | |||
((__ROUTING__) == RI_INPUTCAPTUREROUTING_7) || \ | |||
((__ROUTING__) == RI_INPUTCAPTUREROUTING_8) || \ | |||
((__ROUTING__) == RI_INPUTCAPTUREROUTING_9) || \ | |||
((__ROUTING__) == RI_INPUTCAPTUREROUTING_10) || \ | |||
((__ROUTING__) == RI_INPUTCAPTUREROUTING_11) || \ | |||
((__ROUTING__) == RI_INPUTCAPTUREROUTING_12) || \ | |||
((__ROUTING__) == RI_INPUTCAPTUREROUTING_13) || \ | |||
((__ROUTING__) == RI_INPUTCAPTUREROUTING_14) || \ | |||
((__ROUTING__) == RI_INPUTCAPTUREROUTING_15)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RI_IOSwitch IO Switch | |||
* @{ | |||
*/ | |||
#define RI_ASCR1_REGISTER (0x80000000U) | |||
/* ASCR1 I/O switch: bit 31 is set to '1' to indicate that the mask is in ASCR1 register */ | |||
#define RI_IOSWITCH_CH0 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_0) | |||
#define RI_IOSWITCH_CH1 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_1) | |||
#define RI_IOSWITCH_CH2 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_2) | |||
#define RI_IOSWITCH_CH3 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_3) | |||
#define RI_IOSWITCH_CH4 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_4) | |||
#define RI_IOSWITCH_CH5 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_5) | |||
#define RI_IOSWITCH_CH6 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_6) | |||
#define RI_IOSWITCH_CH7 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_7) | |||
#define RI_IOSWITCH_CH8 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_8) | |||
#define RI_IOSWITCH_CH9 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_9) | |||
#define RI_IOSWITCH_CH10 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_10) | |||
#define RI_IOSWITCH_CH11 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_11) | |||
#define RI_IOSWITCH_CH12 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_12) | |||
#define RI_IOSWITCH_CH13 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_13) | |||
#define RI_IOSWITCH_CH14 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_14) | |||
#define RI_IOSWITCH_CH15 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_15) | |||
#define RI_IOSWITCH_CH18 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_18) | |||
#define RI_IOSWITCH_CH19 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_19) | |||
#define RI_IOSWITCH_CH20 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_20) | |||
#define RI_IOSWITCH_CH21 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_21) | |||
#define RI_IOSWITCH_CH22 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_22) | |||
#define RI_IOSWITCH_CH23 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_23) | |||
#define RI_IOSWITCH_CH24 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_24) | |||
#define RI_IOSWITCH_CH25 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_25) | |||
#define RI_IOSWITCH_VCOMP ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_VCOMP) /* VCOMP (ADC channel 26) is an internal switch used to connect selected channel to COMP1 non inverting input */ | |||
#if defined (RI_ASCR2_CH1b) /* STM32L1 devices category Cat.4 and Cat.5 */ | |||
#define RI_IOSWITCH_CH27 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_27) | |||
#define RI_IOSWITCH_CH28 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_28) | |||
#define RI_IOSWITCH_CH29 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_29) | |||
#define RI_IOSWITCH_CH30 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_30) | |||
#define RI_IOSWITCH_CH31 ((uint32_t)RI_ASCR1_REGISTER | RI_ASCR1_CH_31) | |||
#endif /* RI_ASCR2_CH1b */ | |||
/* ASCR2 IO switch: bit 31 is set to '0' to indicate that the mask is in ASCR2 register */ | |||
#define RI_IOSWITCH_GR10_1 ((uint32_t)RI_ASCR2_GR10_1) | |||
#define RI_IOSWITCH_GR10_2 ((uint32_t)RI_ASCR2_GR10_2) | |||
#define RI_IOSWITCH_GR10_3 ((uint32_t)RI_ASCR2_GR10_3) | |||
#define RI_IOSWITCH_GR10_4 ((uint32_t)RI_ASCR2_GR10_4) | |||
#define RI_IOSWITCH_GR6_1 ((uint32_t)RI_ASCR2_GR6_1) | |||
#define RI_IOSWITCH_GR6_2 ((uint32_t)RI_ASCR2_GR6_2) | |||
#define RI_IOSWITCH_GR5_1 ((uint32_t)RI_ASCR2_GR5_1) | |||
#define RI_IOSWITCH_GR5_2 ((uint32_t)RI_ASCR2_GR5_2) | |||
#define RI_IOSWITCH_GR5_3 ((uint32_t)RI_ASCR2_GR5_3) | |||
#define RI_IOSWITCH_GR4_1 ((uint32_t)RI_ASCR2_GR4_1) | |||
#define RI_IOSWITCH_GR4_2 ((uint32_t)RI_ASCR2_GR4_2) | |||
#define RI_IOSWITCH_GR4_3 ((uint32_t)RI_ASCR2_GR4_3) | |||
#if defined (RI_ASCR2_CH0b) /* STM32L1 devices category Cat.3, Cat.4 and Cat.5 */ | |||
#define RI_IOSWITCH_CH0b ((uint32_t)RI_ASCR2_CH0b) | |||
#if defined (RI_ASCR2_CH1b) /* STM32L1 devices category Cat.4 and Cat.5 */ | |||
#define RI_IOSWITCH_CH1b ((uint32_t)RI_ASCR2_CH1b) | |||
#define RI_IOSWITCH_CH2b ((uint32_t)RI_ASCR2_CH2b) | |||
#define RI_IOSWITCH_CH3b ((uint32_t)RI_ASCR2_CH3b) | |||
#define RI_IOSWITCH_CH6b ((uint32_t)RI_ASCR2_CH6b) | |||
#define RI_IOSWITCH_CH7b ((uint32_t)RI_ASCR2_CH7b) | |||
#define RI_IOSWITCH_CH8b ((uint32_t)RI_ASCR2_CH8b) | |||
#define RI_IOSWITCH_CH9b ((uint32_t)RI_ASCR2_CH9b) | |||
#define RI_IOSWITCH_CH10b ((uint32_t)RI_ASCR2_CH10b) | |||
#define RI_IOSWITCH_CH11b ((uint32_t)RI_ASCR2_CH11b) | |||
#define RI_IOSWITCH_CH12b ((uint32_t)RI_ASCR2_CH12b) | |||
#endif /* RI_ASCR2_CH1b */ | |||
#define RI_IOSWITCH_GR6_3 ((uint32_t)RI_ASCR2_GR6_3) | |||
#define RI_IOSWITCH_GR6_4 ((uint32_t)RI_ASCR2_GR6_4) | |||
#endif /* RI_ASCR2_CH0b */ | |||
#if defined (RI_ASCR2_CH1b) /* STM32L1 devices category Cat.4 and Cat.5 */ | |||
#define IS_RI_IOSWITCH(__IOSWITCH__) (((__IOSWITCH__) == RI_IOSWITCH_CH0) || ((__IOSWITCH__) == RI_IOSWITCH_CH1) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH2) || ((__IOSWITCH__) == RI_IOSWITCH_CH3) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH4) || ((__IOSWITCH__) == RI_IOSWITCH_CH5) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH6) || ((__IOSWITCH__) == RI_IOSWITCH_CH7) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH8) || ((__IOSWITCH__) == RI_IOSWITCH_CH9) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH10) || ((__IOSWITCH__) == RI_IOSWITCH_CH11) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH12) || ((__IOSWITCH__) == RI_IOSWITCH_CH13) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH14) || ((__IOSWITCH__) == RI_IOSWITCH_CH15) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH18) || ((__IOSWITCH__) == RI_IOSWITCH_CH19) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH20) || ((__IOSWITCH__) == RI_IOSWITCH_CH21) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH22) || ((__IOSWITCH__) == RI_IOSWITCH_CH23) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH24) || ((__IOSWITCH__) == RI_IOSWITCH_CH25) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_VCOMP) || ((__IOSWITCH__) == RI_IOSWITCH_CH27) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH28) || ((__IOSWITCH__) == RI_IOSWITCH_CH29) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH30) || ((__IOSWITCH__) == RI_IOSWITCH_CH31) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_GR10_1) || ((__IOSWITCH__) == RI_IOSWITCH_GR10_2) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_GR10_3) || ((__IOSWITCH__) == RI_IOSWITCH_GR10_4) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_GR6_1) || ((__IOSWITCH__) == RI_IOSWITCH_GR6_2) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_GR6_3) || ((__IOSWITCH__) == RI_IOSWITCH_GR6_4) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_GR5_1) || ((__IOSWITCH__) == RI_IOSWITCH_GR5_2) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_GR5_3) || ((__IOSWITCH__) == RI_IOSWITCH_GR4_1) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_GR4_2) || ((__IOSWITCH__) == RI_IOSWITCH_GR4_3) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH0b) || ((__IOSWITCH__) == RI_IOSWITCH_CH1b) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH2b) || ((__IOSWITCH__) == RI_IOSWITCH_CH3b) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH6b) || ((__IOSWITCH__) == RI_IOSWITCH_CH7b) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH8b) || ((__IOSWITCH__) == RI_IOSWITCH_CH9b) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH10b) || ((__IOSWITCH__) == RI_IOSWITCH_CH11b) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH12b)) | |||
#else /* !RI_ASCR2_CH1b */ | |||
#if defined (RI_ASCR2_CH0b) /* STM32L1 devices category Cat.3 */ | |||
#define IS_RI_IOSWITCH(__IOSWITCH__) (((__IOSWITCH__) == RI_IOSWITCH_CH0) || ((__IOSWITCH__) == RI_IOSWITCH_CH1) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH2) || ((__IOSWITCH__) == RI_IOSWITCH_CH3) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH4) || ((__IOSWITCH__) == RI_IOSWITCH_CH5) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH6) || ((__IOSWITCH__) == RI_IOSWITCH_CH7) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH8) || ((__IOSWITCH__) == RI_IOSWITCH_CH9) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH10) || ((__IOSWITCH__) == RI_IOSWITCH_CH11) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH12) || ((__IOSWITCH__) == RI_IOSWITCH_CH13) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH14) || ((__IOSWITCH__) == RI_IOSWITCH_CH15) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH18) || ((__IOSWITCH__) == RI_IOSWITCH_CH19) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH20) || ((__IOSWITCH__) == RI_IOSWITCH_CH21) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH22) || ((__IOSWITCH__) == RI_IOSWITCH_CH23) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH24) || ((__IOSWITCH__) == RI_IOSWITCH_CH25) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_VCOMP) || ((__IOSWITCH__) == RI_IOSWITCH_GR10_1) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_GR10_2) || ((__IOSWITCH__) == RI_IOSWITCH_GR10_3) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_GR10_4) || ((__IOSWITCH__) == RI_IOSWITCH_GR6_1) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_GR6_2) || ((__IOSWITCH__) == RI_IOSWITCH_GR5_1) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_GR5_2) || ((__IOSWITCH__) == RI_IOSWITCH_GR5_3) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_GR4_1) || ((__IOSWITCH__) == RI_IOSWITCH_GR4_2) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_GR4_3) || ((__IOSWITCH__) == RI_IOSWITCH_CH0b)) | |||
#else /* !RI_ASCR2_CH0b */ /* STM32L1 devices category Cat.1 and Cat.2 */ | |||
#define IS_RI_IOSWITCH(__IOSWITCH__) (((__IOSWITCH__) == RI_IOSWITCH_CH0) || ((__IOSWITCH__) == RI_IOSWITCH_CH1) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH2) || ((__IOSWITCH__) == RI_IOSWITCH_CH3) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH4) || ((__IOSWITCH__) == RI_IOSWITCH_CH5) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH6) || ((__IOSWITCH__) == RI_IOSWITCH_CH7) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH8) || ((__IOSWITCH__) == RI_IOSWITCH_CH9) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH10) || ((__IOSWITCH__) == RI_IOSWITCH_CH11) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH12) || ((__IOSWITCH__) == RI_IOSWITCH_CH13) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH14) || ((__IOSWITCH__) == RI_IOSWITCH_CH15) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH18) || ((__IOSWITCH__) == RI_IOSWITCH_CH19) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH20) || ((__IOSWITCH__) == RI_IOSWITCH_CH21) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH22) || ((__IOSWITCH__) == RI_IOSWITCH_CH23) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_CH24) || ((__IOSWITCH__) == RI_IOSWITCH_CH25) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_VCOMP) || ((__IOSWITCH__) == RI_IOSWITCH_GR10_1) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_GR10_2) || ((__IOSWITCH__) == RI_IOSWITCH_GR10_3) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_GR10_4) || ((__IOSWITCH__) == RI_IOSWITCH_GR6_1) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_GR6_2) || ((__IOSWITCH__) == RI_IOSWITCH_GR5_1) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_GR5_2) || ((__IOSWITCH__) == RI_IOSWITCH_GR5_3) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_GR4_1) || ((__IOSWITCH__) == RI_IOSWITCH_GR4_2) || \ | |||
((__IOSWITCH__) == RI_IOSWITCH_GR4_3)) | |||
#endif /* RI_ASCR2_CH0b */ | |||
#endif /* RI_ASCR2_CH1b */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RI_Pin PIN define | |||
* @{ | |||
*/ | |||
#define RI_PIN_0 ((uint16_t)0x0001) /*!< Pin 0 selected */ | |||
#define RI_PIN_1 ((uint16_t)0x0002) /*!< Pin 1 selected */ | |||
#define RI_PIN_2 ((uint16_t)0x0004) /*!< Pin 2 selected */ | |||
#define RI_PIN_3 ((uint16_t)0x0008) /*!< Pin 3 selected */ | |||
#define RI_PIN_4 ((uint16_t)0x0010) /*!< Pin 4 selected */ | |||
#define RI_PIN_5 ((uint16_t)0x0020) /*!< Pin 5 selected */ | |||
#define RI_PIN_6 ((uint16_t)0x0040) /*!< Pin 6 selected */ | |||
#define RI_PIN_7 ((uint16_t)0x0080) /*!< Pin 7 selected */ | |||
#define RI_PIN_8 ((uint16_t)0x0100) /*!< Pin 8 selected */ | |||
#define RI_PIN_9 ((uint16_t)0x0200) /*!< Pin 9 selected */ | |||
#define RI_PIN_10 ((uint16_t)0x0400) /*!< Pin 10 selected */ | |||
#define RI_PIN_11 ((uint16_t)0x0800) /*!< Pin 11 selected */ | |||
#define RI_PIN_12 ((uint16_t)0x1000) /*!< Pin 12 selected */ | |||
#define RI_PIN_13 ((uint16_t)0x2000) /*!< Pin 13 selected */ | |||
#define RI_PIN_14 ((uint16_t)0x4000) /*!< Pin 14 selected */ | |||
#define RI_PIN_15 ((uint16_t)0x8000) /*!< Pin 15 selected */ | |||
#define RI_PIN_ALL ((uint16_t)0xFFFF) /*!< All pins selected */ | |||
#define IS_RI_PIN(__PIN__) ((__PIN__) != (uint16_t)0x00) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macros -----------------------------------------------------------*/ | |||
/** @defgroup HAL_Exported_Macros HAL Exported Macros | |||
* @{ | |||
*/ | |||
/** @defgroup DBGMCU_Macros DBGMCU: Debug MCU | |||
* @{ | |||
*/ | |||
/** @defgroup DBGMCU_Freeze_Unfreeze Freeze Unfreeze Peripherals in Debug mode | |||
* @brief Freeze/Unfreeze Peripherals in Debug mode | |||
* @{ | |||
*/ | |||
/** | |||
* @brief TIM2 Peripherals Debug mode | |||
*/ | |||
#if defined (DBGMCU_APB1_FZ_DBG_TIM2_STOP) | |||
#define __HAL_DBGMCU_FREEZE_TIM2() SET_BIT(DBGMCU->APB1FZ, DBGMCU_APB1_FZ_DBG_TIM2_STOP) | |||
#define __HAL_DBGMCU_UNFREEZE_TIM2() CLEAR_BIT(DBGMCU->APB1FZ, DBGMCU_APB1_FZ_DBG_TIM2_STOP) | |||
#endif | |||
/** | |||
* @brief TIM3 Peripherals Debug mode | |||
*/ | |||
#if defined (DBGMCU_APB1_FZ_DBG_TIM3_STOP) | |||
#define __HAL_DBGMCU_FREEZE_TIM3() SET_BIT(DBGMCU->APB1FZ, DBGMCU_APB1_FZ_DBG_TIM3_STOP) | |||
#define __HAL_DBGMCU_UNFREEZE_TIM3() CLEAR_BIT(DBGMCU->APB1FZ, DBGMCU_APB1_FZ_DBG_TIM3_STOP) | |||
#endif | |||
/** | |||
* @brief TIM4 Peripherals Debug mode | |||
*/ | |||
#if defined (DBGMCU_APB1_FZ_DBG_TIM4_STOP) | |||
#define __HAL_DBGMCU_FREEZE_TIM4() SET_BIT(DBGMCU->APB1FZ, DBGMCU_APB1_FZ_DBG_TIM4_STOP) | |||
#define __HAL_DBGMCU_UNFREEZE_TIM4() CLEAR_BIT(DBGMCU->APB1FZ, DBGMCU_APB1_FZ_DBG_TIM4_STOP) | |||
#endif | |||
/** | |||
* @brief TIM5 Peripherals Debug mode | |||
*/ | |||
#if defined (DBGMCU_APB1_FZ_DBG_TIM5_STOP) | |||
#define __HAL_DBGMCU_FREEZE_TIM5() SET_BIT(DBGMCU->APB1FZ, DBGMCU_APB1_FZ_DBG_TIM5_STOP) | |||
#define __HAL_DBGMCU_UNFREEZE_TIM5() CLEAR_BIT(DBGMCU->APB1FZ, DBGMCU_APB1_FZ_DBG_TIM5_STOP) | |||
#endif | |||
/** | |||
* @brief TIM6 Peripherals Debug mode | |||
*/ | |||
#if defined (DBGMCU_APB1_FZ_DBG_TIM6_STOP) | |||
#define __HAL_DBGMCU_FREEZE_TIM6() SET_BIT(DBGMCU->APB1FZ, DBGMCU_APB1_FZ_DBG_TIM6_STOP) | |||
#define __HAL_DBGMCU_UNFREEZE_TIM6() CLEAR_BIT(DBGMCU->APB1FZ, DBGMCU_APB1_FZ_DBG_TIM6_STOP) | |||
#endif | |||
/** | |||
* @brief TIM7 Peripherals Debug mode | |||
*/ | |||
#if defined (DBGMCU_APB1_FZ_DBG_TIM7_STOP) | |||
#define __HAL_DBGMCU_FREEZE_TIM7() SET_BIT(DBGMCU->APB1FZ, DBGMCU_APB1_FZ_DBG_TIM7_STOP) | |||
#define __HAL_DBGMCU_UNFREEZE_TIM7() CLEAR_BIT(DBGMCU->APB1FZ, DBGMCU_APB1_FZ_DBG_TIM7_STOP) | |||
#endif | |||
/** | |||
* @brief RTC Peripherals Debug mode | |||
*/ | |||
#if defined (DBGMCU_APB1_FZ_DBG_RTC_STOP) | |||
#define __HAL_DBGMCU_FREEZE_RTC() SET_BIT(DBGMCU->APB1FZ, DBGMCU_APB1_FZ_DBG_RTC_STOP) | |||
#define __HAL_DBGMCU_UNFREEZE_RTC() CLEAR_BIT(DBGMCU->APB1FZ, DBGMCU_APB1_FZ_DBG_RTC_STOP) | |||
#endif | |||
/** | |||
* @brief WWDG Peripherals Debug mode | |||
*/ | |||
#if defined (DBGMCU_APB1_FZ_DBG_WWDG_STOP) | |||
#define __HAL_DBGMCU_FREEZE_WWDG() SET_BIT(DBGMCU->APB1FZ, DBGMCU_APB1_FZ_DBG_WWDG_STOP) | |||
#define __HAL_DBGMCU_UNFREEZE_WWDG() CLEAR_BIT(DBGMCU->APB1FZ, DBGMCU_APB1_FZ_DBG_WWDG_STOP) | |||
#endif | |||
/** | |||
* @brief IWDG Peripherals Debug mode | |||
*/ | |||
#if defined (DBGMCU_APB1_FZ_DBG_IWDG_STOP) | |||
#define __HAL_DBGMCU_FREEZE_IWDG() SET_BIT(DBGMCU->APB1FZ, DBGMCU_APB1_FZ_DBG_IWDG_STOP) | |||
#define __HAL_DBGMCU_UNFREEZE_IWDG() CLEAR_BIT(DBGMCU->APB1FZ, DBGMCU_APB1_FZ_DBG_IWDG_STOP) | |||
#endif | |||
/** | |||
* @brief I2C1 Peripherals Debug mode | |||
*/ | |||
#if defined (DBGMCU_APB1_FZ_DBG_I2C1_SMBUS_TIMEOUT) | |||
#define __HAL_DBGMCU_FREEZE_I2C1_TIMEOUT() SET_BIT(DBGMCU->APB1FZ, DBGMCU_APB1_FZ_DBG_I2C1_SMBUS_TIMEOUT) | |||
#define __HAL_DBGMCU_UNFREEZE_I2C1_TIMEOUT() CLEAR_BIT(DBGMCU->APB1FZ, DBGMCU_APB1_FZ_DBG_I2C1_SMBUS_TIMEOUT) | |||
#endif | |||
/** | |||
* @brief I2C2 Peripherals Debug mode | |||
*/ | |||
#if defined (DBGMCU_APB1_FZ_DBG_I2C2_SMBUS_TIMEOUT) | |||
#define __HAL_DBGMCU_FREEZE_I2C2_TIMEOUT() SET_BIT(DBGMCU->APB1FZ, DBGMCU_APB1_FZ_DBG_I2C2_SMBUS_TIMEOUT) | |||
#define __HAL_DBGMCU_UNFREEZE_I2C2_TIMEOUT() CLEAR_BIT(DBGMCU->APB1FZ, DBGMCU_APB1_FZ_DBG_I2C2_SMBUS_TIMEOUT) | |||
#endif | |||
/** | |||
* @brief TIM9 Peripherals Debug mode | |||
*/ | |||
#if defined (DBGMCU_APB2_FZ_DBG_TIM9_STOP) | |||
#define __HAL_DBGMCU_FREEZE_TIM9() SET_BIT(DBGMCU->APB2FZ, DBGMCU_APB2_FZ_DBG_TIM9_STOP) | |||
#define __HAL_DBGMCU_UNFREEZE_TIM9() CLEAR_BIT(DBGMCU->APB2FZ, DBGMCU_APB2_FZ_DBG_TIM9_STOP) | |||
#endif | |||
/** | |||
* @brief TIM10 Peripherals Debug mode | |||
*/ | |||
#if defined (DBGMCU_APB2_FZ_DBG_TIM10_STOP) | |||
#define __HAL_DBGMCU_FREEZE_TIM10() SET_BIT(DBGMCU->APB2FZ, DBGMCU_APB2_FZ_DBG_TIM10_STOP) | |||
#define __HAL_DBGMCU_UNFREEZE_TIM10() CLEAR_BIT(DBGMCU->APB2FZ, DBGMCU_APB2_FZ_DBG_TIM10_STOP) | |||
#endif | |||
/** | |||
* @brief TIM11 Peripherals Debug mode | |||
*/ | |||
#if defined (DBGMCU_APB2_FZ_DBG_TIM11_STOP) | |||
#define __HAL_DBGMCU_FREEZE_TIM11() SET_BIT(DBGMCU->APB2FZ, DBGMCU_APB2_FZ_DBG_TIM11_STOP) | |||
#define __HAL_DBGMCU_UNFREEZE_TIM11() CLEAR_BIT(DBGMCU->APB2FZ, DBGMCU_APB2_FZ_DBG_TIM11_STOP) | |||
#endif | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SYSCFG_Macros SYSCFG: SYStem ConFiG | |||
* @{ | |||
*/ | |||
/** @defgroup SYSCFG_VrefInt VREFINT configuration | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Enables or disables the output of internal reference voltage | |||
* (VrefInt) on I/O pin. | |||
* @note The VrefInt output can be routed to any I/O in group 3: | |||
* - For Cat.1 and Cat.2 devices: CH8 (PB0) or CH9 (PB1). | |||
* - For Cat.3 devices: CH8 (PB0), CH9 (PB1) or CH0b (PB2). | |||
* - For Cat.4 and Cat.5 devices: CH8 (PB0), CH9 (PB1), CH0b (PB2), | |||
* CH1b (PF11) or CH2b (PF12). | |||
* Note: Comparator peripheral clock must be preliminarily enabled, | |||
* either in COMP user function "HAL_COMP_MspInit()" (should be | |||
* done if comparators are used) or by direct clock enable: | |||
* Refer to macro "__HAL_RCC_COMP_CLK_ENABLE()". | |||
* Note: In addition with this macro, VrefInt output buffer must be | |||
* connected to the selected I/O pin. Refer to macro | |||
* "__HAL_RI_IOSWITCH_CLOSE()". | |||
* @note VrefInt output enable: Internal reference voltage connected to I/O group 3 | |||
* VrefInt output disable: Internal reference voltage disconnected from I/O group 3 | |||
* @retval None | |||
*/ | |||
#define __HAL_SYSCFG_VREFINT_OUT_ENABLE() SET_BIT(COMP->CSR, COMP_CSR_VREFOUTEN) | |||
#define __HAL_SYSCFG_VREFINT_OUT_DISABLE() CLEAR_BIT(COMP->CSR, COMP_CSR_VREFOUTEN) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SYSCFG_BootModeConfig Boot Mode Configuration | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Main Flash memory mapped at 0x00000000 | |||
*/ | |||
#define __HAL_SYSCFG_REMAPMEMORY_FLASH() CLEAR_BIT(SYSCFG->MEMRMP, SYSCFG_MEMRMP_MEM_MODE) | |||
/** @brief System Flash memory mapped at 0x00000000 | |||
*/ | |||
#define __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH() MODIFY_REG(SYSCFG->MEMRMP, SYSCFG_MEMRMP_MEM_MODE, SYSCFG_MEMRMP_MEM_MODE_0) | |||
/** @brief Embedded SRAM mapped at 0x00000000 | |||
*/ | |||
#define __HAL_SYSCFG_REMAPMEMORY_SRAM() MODIFY_REG(SYSCFG->MEMRMP, SYSCFG_MEMRMP_MEM_MODE, SYSCFG_MEMRMP_MEM_MODE_0 | SYSCFG_MEMRMP_MEM_MODE_1) | |||
#if defined(FSMC_R_BASE) | |||
/** @brief FSMC Bank1 (NOR/PSRAM 1 and 2) mapped at 0x00000000 | |||
*/ | |||
#define __HAL_SYSCFG_REMAPMEMORY_FSMC() MODIFY_REG(SYSCFG->MEMRMP, SYSCFG_MEMRMP_MEM_MODE, SYSCFG_MEMRMP_MEM_MODE_1) | |||
#endif /* FSMC_R_BASE */ | |||
/** | |||
* @brief Returns the boot mode as configured by user. | |||
* @retval The boot mode as configured by user. The returned value can be one | |||
* of the following values: | |||
* @arg SYSCFG_BOOT_MAINFLASH | |||
* @arg SYSCFG_BOOT_SYSTEMFLASH | |||
* @arg SYSCFG_BOOT_FSMC (available only for STM32L151xD, STM32L152xD & STM32L162xD) | |||
* @arg SYSCFG_BOOT_SRAM | |||
*/ | |||
#define __HAL_SYSCFG_GET_BOOT_MODE() READ_BIT(SYSCFG->MEMRMP, SYSCFG_MEMRMP_BOOT_MODE) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SYSCFG_USBConfig USB DP line Configuration | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Control the internal pull-up on USB DP line. | |||
*/ | |||
#define __HAL_SYSCFG_USBPULLUP_ENABLE() SET_BIT(SYSCFG->PMC, SYSCFG_PMC_USB_PU) | |||
#define __HAL_SYSCFG_USBPULLUP_DISABLE() CLEAR_BIT(SYSCFG->PMC, SYSCFG_PMC_USB_PU) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RI_Macris RI: Routing Interface | |||
* @{ | |||
*/ | |||
/** @defgroup RI_InputCaputureConfig Input Capture configuration | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Configures the routing interface to map Input Capture 1 of TIMx to a selected I/O pin. | |||
* @param __TIMSELECT__ Timer select. | |||
* This parameter can be one of the following values: | |||
* @arg TIM_SELECT_NONE: No timer selected and default Timer mapping is enabled. | |||
* @arg TIM_SELECT_TIM2: Timer 2 Input Captures to be routed. | |||
* @arg TIM_SELECT_TIM3: Timer 3 Input Captures to be routed. | |||
* @arg TIM_SELECT_TIM4: Timer 4 Input Captures to be routed. | |||
* @param __INPUT__ selects which pin to be routed to Input Capture. | |||
* This parameter must be a value of @ref RI_InputCaptureRouting | |||
* e.g. | |||
* __HAL_RI_REMAP_INPUTCAPTURE1(TIM_SELECT_TIM2, RI_INPUTCAPTUREROUTING_1) | |||
* allows routing of Input capture IC1 of TIM2 to PA4. | |||
* For details about correspondence between RI_INPUTCAPTUREROUTING_x | |||
* and I/O pins refer to the parameters' description in the header file | |||
* or refer to the product reference manual. | |||
* @note Input capture selection bits are not reset by this function. | |||
* To reset input capture selection bits, use SYSCFG_RIDeInit() function. | |||
* @note The I/O should be configured in alternate function mode (AF14) using | |||
* GPIO_PinAFConfig() function. | |||
* @retval None. | |||
*/ | |||
#define __HAL_RI_REMAP_INPUTCAPTURE1(__TIMSELECT__, __INPUT__) \ | |||
do {assert_param(IS_RI_TIM(__TIMSELECT__)); \ | |||
assert_param(IS_RI_INPUTCAPTURE_ROUTING(__INPUT__)); \ | |||
MODIFY_REG(RI->ICR, RI_ICR_TIM, (__TIMSELECT__)); \ | |||
SET_BIT(RI->ICR, RI_INPUTCAPTURE_IC1); \ | |||
MODIFY_REG(RI->ICR, RI_ICR_IC1OS, (__INPUT__) << POSITION_VAL(RI_ICR_IC1OS)); \ | |||
}while(0) | |||
/** | |||
* @brief Configures the routing interface to map Input Capture 2 of TIMx to a selected I/O pin. | |||
* @param __TIMSELECT__ Timer select. | |||
* This parameter can be one of the following values: | |||
* @arg TIM_SELECT_NONE: No timer selected and default Timer mapping is enabled. | |||
* @arg TIM_SELECT_TIM2: Timer 2 Input Captures to be routed. | |||
* @arg TIM_SELECT_TIM3: Timer 3 Input Captures to be routed. | |||
* @arg TIM_SELECT_TIM4: Timer 4 Input Captures to be routed. | |||
* @param __INPUT__ selects which pin to be routed to Input Capture. | |||
* This parameter must be a value of @ref RI_InputCaptureRouting | |||
* @retval None. | |||
*/ | |||
#define __HAL_RI_REMAP_INPUTCAPTURE2(__TIMSELECT__, __INPUT__) \ | |||
do {assert_param(IS_RI_TIM(__TIMSELECT__)); \ | |||
assert_param(IS_RI_INPUTCAPTURE_ROUTING(__INPUT__)); \ | |||
MODIFY_REG(RI->ICR, RI_ICR_TIM, (__TIMSELECT__)); \ | |||
SET_BIT(RI->ICR, RI_INPUTCAPTURE_IC2); \ | |||
MODIFY_REG(RI->ICR, RI_ICR_IC2OS, (__INPUT__) << POSITION_VAL(RI_ICR_IC2OS)); \ | |||
}while(0) | |||
/** | |||
* @brief Configures the routing interface to map Input Capture 3 of TIMx to a selected I/O pin. | |||
* @param __TIMSELECT__ Timer select. | |||
* This parameter can be one of the following values: | |||
* @arg TIM_SELECT_NONE: No timer selected and default Timer mapping is enabled. | |||
* @arg TIM_SELECT_TIM2: Timer 2 Input Captures to be routed. | |||
* @arg TIM_SELECT_TIM3: Timer 3 Input Captures to be routed. | |||
* @arg TIM_SELECT_TIM4: Timer 4 Input Captures to be routed. | |||
* @param __INPUT__ selects which pin to be routed to Input Capture. | |||
* This parameter must be a value of @ref RI_InputCaptureRouting | |||
* @retval None. | |||
*/ | |||
#define __HAL_RI_REMAP_INPUTCAPTURE3(__TIMSELECT__, __INPUT__) \ | |||
do {assert_param(IS_RI_TIM(__TIMSELECT__)); \ | |||
assert_param(IS_RI_INPUTCAPTURE_ROUTING(__INPUT__)); \ | |||
MODIFY_REG(RI->ICR, RI_ICR_TIM, (__TIMSELECT__)); \ | |||
SET_BIT(RI->ICR, RI_INPUTCAPTURE_IC3); \ | |||
MODIFY_REG(RI->ICR, RI_ICR_IC3OS, (__INPUT__) << POSITION_VAL(RI_ICR_IC3OS)); \ | |||
}while(0) | |||
/** | |||
* @brief Configures the routing interface to map Input Capture 4 of TIMx to a selected I/O pin. | |||
* @param __TIMSELECT__ Timer select. | |||
* This parameter can be one of the following values: | |||
* @arg TIM_SELECT_NONE: No timer selected and default Timer mapping is enabled. | |||
* @arg TIM_SELECT_TIM2: Timer 2 Input Captures to be routed. | |||
* @arg TIM_SELECT_TIM3: Timer 3 Input Captures to be routed. | |||
* @arg TIM_SELECT_TIM4: Timer 4 Input Captures to be routed. | |||
* @param __INPUT__ selects which pin to be routed to Input Capture. | |||
* This parameter must be a value of @ref RI_InputCaptureRouting | |||
* @retval None. | |||
*/ | |||
#define __HAL_RI_REMAP_INPUTCAPTURE4(__TIMSELECT__, __INPUT__) \ | |||
do {assert_param(IS_RI_TIM(__TIMSELECT__)); \ | |||
assert_param(IS_RI_INPUTCAPTURE_ROUTING(__INPUT__)); \ | |||
MODIFY_REG(RI->ICR, RI_ICR_TIM, (__TIMSELECT__)); \ | |||
SET_BIT(RI->ICR, RI_INPUTCAPTURE_IC4); \ | |||
MODIFY_REG(RI->ICR, RI_ICR_IC4OS, (__INPUT__) << POSITION_VAL(RI_ICR_IC4OS)); \ | |||
}while(0) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RI_SwitchControlConfig Switch Control configuration | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Enable or disable the switch control mode. | |||
* @note ENABLE: ADC analog switches closed if the corresponding | |||
* I/O switch is also closed. | |||
* When using COMP1, switch control mode must be enabled. | |||
* @note DISABLE: ADC analog switches open or controlled by the ADC interface. | |||
* When using the ADC for acquisition, switch control mode | |||
* must be disabled. | |||
* @note COMP1 comparator and ADC cannot be used at the same time since | |||
* they share the ADC switch matrix. | |||
* @retval None | |||
*/ | |||
#define __HAL_RI_SWITCHCONTROLMODE_ENABLE() SET_BIT(RI->ASCR1, RI_ASCR1_SCM) | |||
#define __HAL_RI_SWITCHCONTROLMODE_DISABLE() CLEAR_BIT(RI->ASCR1, RI_ASCR1_SCM) | |||
/* | |||
* @brief Close or Open the routing interface Input Output switches. | |||
* @param __IOSWITCH__ selects the I/O analog switch number. | |||
* This parameter must be a value of @ref RI_IOSwitch | |||
* @retval None | |||
*/ | |||
#define __HAL_RI_IOSWITCH_CLOSE(__IOSWITCH__) do { assert_param(IS_RI_IOSWITCH(__IOSWITCH__)); \ | |||
if ((__IOSWITCH__) >> 31 != 0 ) \ | |||
{ \ | |||
SET_BIT(RI->ASCR1, (__IOSWITCH__) & 0x7FFFFFFF); \ | |||
} \ | |||
else \ | |||
{ \ | |||
SET_BIT(RI->ASCR2, (__IOSWITCH__)); \ | |||
} \ | |||
}while(0) | |||
#define __HAL_RI_IOSWITCH_OPEN(__IOSWITCH__) do { assert_param(IS_RI_IOSWITCH(__IOSWITCH__)); \ | |||
if ((__IOSWITCH__) >> 31 != 0 ) \ | |||
{ \ | |||
CLEAR_BIT(RI->ASCR1, (__IOSWITCH__) & 0x7FFFFFFF); \ | |||
} \ | |||
else \ | |||
{ \ | |||
CLEAR_BIT(RI->ASCR2, (__IOSWITCH__)); \ | |||
} \ | |||
}while(0) | |||
#if defined (COMP_CSR_SW1) | |||
/** | |||
* @brief Close or open the internal switch COMP1_SW1. | |||
* This switch connects I/O pin PC3 (can be used as ADC channel 13) | |||
* and OPAMP3 ouput to ADC switch matrix (ADC channel VCOMP, channel | |||
* 26) and COMP1 non-inverting input. | |||
* Pin PC3 connection depends on another switch setting, refer to | |||
* macro "__HAL_ADC_CHANNEL_SPEED_FAST()". | |||
* @retval None. | |||
*/ | |||
#define __HAL_RI_SWITCH_COMP1_SW1_CLOSE() SET_BIT(COMP->CSR, COMP_CSR_SW1) | |||
#define __HAL_RI_SWITCH_COMP1_SW1_OPEN() CLEAR_BIT(COMP->CSR, COMP_CSR_SW1) | |||
#endif /* COMP_CSR_SW1 */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RI_HystConfig Hysteresis Activation and Deactivation | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Enable or disable Hysteresis of the input schmitt triger of Ports A | |||
* When the I/Os are programmed in input mode by standard I/O port | |||
* registers, the Schmitt trigger and the hysteresis are enabled by default. | |||
* When hysteresis is disabled, it is possible to read the | |||
* corresponding port with a trigger level of VDDIO/2. | |||
* @param __IOPIN__ : Selects the pin(s) on which to enable or disable hysteresis. | |||
* This parameter must be a value of @ref RI_Pin | |||
* @retval None | |||
*/ | |||
#define __HAL_RI_HYSTERIS_PORTA_ON(__IOPIN__) do {assert_param(IS_RI_PIN(__IOPIN__)); \ | |||
CLEAR_BIT(RI->HYSCR1, (__IOPIN__)); \ | |||
} while(0) | |||
#define __HAL_RI_HYSTERIS_PORTA_OFF(__IOPIN__) do {assert_param(IS_RI_PIN(__IOPIN__)); \ | |||
SET_BIT(RI->HYSCR1, (__IOPIN__)); \ | |||
} while(0) | |||
/** | |||
* @brief Enable or disable Hysteresis of the input schmitt triger of Ports B | |||
* When the I/Os are programmed in input mode by standard I/O port | |||
* registers, the Schmitt trigger and the hysteresis are enabled by default. | |||
* When hysteresis is disabled, it is possible to read the | |||
* corresponding port with a trigger level of VDDIO/2. | |||
* @param __IOPIN__ : Selects the pin(s) on which to enable or disable hysteresis. | |||
* This parameter must be a value of @ref RI_Pin | |||
* @retval None | |||
*/ | |||
#define __HAL_RI_HYSTERIS_PORTB_ON(__IOPIN__) do {assert_param(IS_RI_PIN(__IOPIN__)); \ | |||
CLEAR_BIT(RI->HYSCR1, (__IOPIN__) << 16 ); \ | |||
} while(0) | |||
#define __HAL_RI_HYSTERIS_PORTB_OFF(__IOPIN__) do {assert_param(IS_RI_PIN(__IOPIN__)); \ | |||
SET_BIT(RI->HYSCR1, (__IOPIN__) << 16 ); \ | |||
} while(0) | |||
/** | |||
* @brief Enable or disable Hysteresis of the input schmitt triger of Ports C | |||
* When the I/Os are programmed in input mode by standard I/O port | |||
* registers, the Schmitt trigger and the hysteresis are enabled by default. | |||
* When hysteresis is disabled, it is possible to read the | |||
* corresponding port with a trigger level of VDDIO/2. | |||
* @param __IOPIN__ : Selects the pin(s) on which to enable or disable hysteresis. | |||
* This parameter must be a value of @ref RI_Pin | |||
* @retval None | |||
*/ | |||
#define __HAL_RI_HYSTERIS_PORTC_ON(__IOPIN__) do {assert_param(IS_RI_PIN(__IOPIN__)); \ | |||
CLEAR_BIT(RI->HYSCR2, (__IOPIN__)); \ | |||
} while(0) | |||
#define __HAL_RI_HYSTERIS_PORTC_OFF(__IOPIN__) do {assert_param(IS_RI_PIN(__IOPIN__)); \ | |||
SET_BIT(RI->HYSCR2, (__IOPIN__)); \ | |||
} while(0) | |||
/** | |||
* @brief Enable or disable Hysteresis of the input schmitt triger of Ports D | |||
* When the I/Os are programmed in input mode by standard I/O port | |||
* registers, the Schmitt trigger and the hysteresis are enabled by default. | |||
* When hysteresis is disabled, it is possible to read the | |||
* corresponding port with a trigger level of VDDIO/2. | |||
* @param __IOPIN__ : Selects the pin(s) on which to enable or disable hysteresis. | |||
* This parameter must be a value of @ref RI_Pin | |||
* @retval None | |||
*/ | |||
#define __HAL_RI_HYSTERIS_PORTD_ON(__IOPIN__) do {assert_param(IS_RI_PIN(__IOPIN__)); \ | |||
CLEAR_BIT(RI->HYSCR2, (__IOPIN__) << 16 ); \ | |||
} while(0) | |||
#define __HAL_RI_HYSTERIS_PORTD_OFF(__IOPIN__) do {assert_param(IS_RI_PIN(__IOPIN__)); \ | |||
SET_BIT(RI->HYSCR2, (__IOPIN__) << 16 ); \ | |||
} while(0) | |||
#if defined (GPIOE_BASE) | |||
/** | |||
* @brief Enable or disable Hysteresis of the input schmitt triger of Ports E | |||
* When the I/Os are programmed in input mode by standard I/O port | |||
* registers, the Schmitt trigger and the hysteresis are enabled by default. | |||
* When hysteresis is disabled, it is possible to read the | |||
* corresponding port with a trigger level of VDDIO/2. | |||
* @param __IOPIN__ : Selects the pin(s) on which to enable or disable hysteresis. | |||
* This parameter must be a value of @ref RI_Pin | |||
* @retval None | |||
*/ | |||
#define __HAL_RI_HYSTERIS_PORTE_ON(__IOPIN__) do {assert_param(IS_RI_PIN(__IOPIN__)); \ | |||
CLEAR_BIT(RI->HYSCR3, (__IOPIN__)); \ | |||
} while(0) | |||
#define __HAL_RI_HYSTERIS_PORTE_OFF(__IOPIN__) do {assert_param(IS_RI_PIN(__IOPIN__)); \ | |||
SET_BIT(RI->HYSCR3, (__IOPIN__)); \ | |||
} while(0) | |||
#endif /* GPIOE_BASE */ | |||
#if defined(GPIOF_BASE) || defined(GPIOG_BASE) | |||
/** | |||
* @brief Enable or disable Hysteresis of the input schmitt triger of Ports F | |||
* When the I/Os are programmed in input mode by standard I/O port | |||
* registers, the Schmitt trigger and the hysteresis are enabled by default. | |||
* When hysteresis is disabled, it is possible to read the | |||
* corresponding port with a trigger level of VDDIO/2. | |||
* @param __IOPIN__ : Selects the pin(s) on which to enable or disable hysteresis. | |||
* This parameter must be a value of @ref RI_Pin | |||
* @retval None | |||
*/ | |||
#define __HAL_RI_HYSTERIS_PORTF_ON(__IOPIN__) do {assert_param(IS_RI_PIN(__IOPIN__)); \ | |||
CLEAR_BIT(RI->HYSCR3, (__IOPIN__) << 16 ); \ | |||
} while(0) | |||
#define __HAL_RI_HYSTERIS_PORTF_OFF(__IOPIN__) do {assert_param(IS_RI_PIN(__IOPIN__)); \ | |||
SET_BIT(RI->HYSCR3, (__IOPIN__) << 16 ); \ | |||
} while(0) | |||
/** | |||
* @brief Enable or disable Hysteresis of the input schmitt triger of Ports G | |||
* When the I/Os are programmed in input mode by standard I/O port | |||
* registers, the Schmitt trigger and the hysteresis are enabled by default. | |||
* When hysteresis is disabled, it is possible to read the | |||
* corresponding port with a trigger level of VDDIO/2. | |||
* @param __IOPIN__ : Selects the pin(s) on which to enable or disable hysteresis. | |||
* This parameter must be a value of @ref RI_Pin | |||
* @retval None | |||
*/ | |||
#define __HAL_RI_HYSTERIS_PORTG_ON(__IOPIN__) do {assert_param(IS_RI_PIN(__IOPIN__)); \ | |||
CLEAR_BIT(RI->HYSCR4, (__IOPIN__)); \ | |||
} while(0) | |||
#define __HAL_RI_HYSTERIS_PORTG_OFF(__IOPIN__) do {assert_param(IS_RI_PIN(__IOPIN__)); \ | |||
SET_BIT(RI->HYSCR4, (__IOPIN__)); \ | |||
} while(0) | |||
#endif /* GPIOF_BASE || GPIOG_BASE */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported variables --------------------------------------------------------*/ | |||
/** @defgroup HAL_Exported_Variables HAL Exported Variables | |||
* @{ | |||
*/ | |||
extern __IO uint32_t uwTick; | |||
extern uint32_t uwTickPrio; | |||
extern uint32_t uwTickFreq; | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup HAL_Exported_Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup HAL_Exported_Functions_Group1 | |||
* @{ | |||
*/ | |||
/* Initialization and de-initialization functions ******************************/ | |||
HAL_StatusTypeDef HAL_Init(void); | |||
HAL_StatusTypeDef HAL_DeInit(void); | |||
void HAL_MspInit(void); | |||
void HAL_MspDeInit(void); | |||
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup HAL_Exported_Functions_Group2 | |||
* @{ | |||
*/ | |||
/* Peripheral Control functions ************************************************/ | |||
void HAL_IncTick(void); | |||
void HAL_Delay(uint32_t Delay); | |||
uint32_t HAL_GetTick(void); | |||
uint32_t HAL_GetTickPrio(void); | |||
HAL_StatusTypeDef HAL_SetTickFreq(uint32_t Freq); | |||
uint32_t HAL_GetTickFreq(void); | |||
void HAL_SuspendTick(void); | |||
void HAL_ResumeTick(void); | |||
uint32_t HAL_GetHalVersion(void); | |||
uint32_t HAL_GetREVID(void); | |||
uint32_t HAL_GetDEVID(void); | |||
uint32_t HAL_GetUIDw0(void); | |||
uint32_t HAL_GetUIDw1(void); | |||
uint32_t HAL_GetUIDw2(void); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup HAL_Exported_Functions_Group3 | |||
* @{ | |||
*/ | |||
/* DBGMCU Peripheral Control functions *****************************************/ | |||
void HAL_DBGMCU_EnableDBGSleepMode(void); | |||
void HAL_DBGMCU_DisableDBGSleepMode(void); | |||
void HAL_DBGMCU_EnableDBGStopMode(void); | |||
void HAL_DBGMCU_DisableDBGStopMode(void); | |||
void HAL_DBGMCU_EnableDBGStandbyMode(void); | |||
void HAL_DBGMCU_DisableDBGStandbyMode(void); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32L1xx_HAL_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,335 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_hal_conf.h | |||
* @brief HAL configuration file. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© COPYRIGHT(c) 2020 STMicroelectronics</center></h2> | |||
* | |||
* Redistribution and use in source and binary forms, with or without modification, | |||
* are permitted provided that the following conditions are met: | |||
* 1. Redistributions of source code must retain the above copyright notice, | |||
* this list of conditions and the following disclaimer. | |||
* 2. Redistributions in binary form must reproduce the above copyright notice, | |||
* this list of conditions and the following disclaimer in the documentation | |||
* and/or other materials provided with the distribution. | |||
* 3. Neither the name of STMicroelectronics nor the names of its contributors | |||
* may be used to endorse or promote products derived from this software | |||
* without specific prior written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32L1xx_HAL_CONF_H | |||
#define __STM32L1xx_HAL_CONF_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Exported types ------------------------------------------------------------*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/* ########################## Module Selection ############################## */ | |||
/** | |||
* @brief This is the list of modules to be used in the HAL driver | |||
*/ | |||
#define HAL_MODULE_ENABLED | |||
/*#define HAL_ADC_MODULE_ENABLED */ | |||
/*#define HAL_CRYP_MODULE_ENABLED */ | |||
/*#define HAL_COMP_MODULE_ENABLED */ | |||
/*#define HAL_CRC_MODULE_ENABLED */ | |||
/*#define HAL_CRYP_MODULE_ENABLED */ | |||
/*#define HAL_DAC_MODULE_ENABLED */ | |||
/*#define HAL_I2C_MODULE_ENABLED */ | |||
/*#define HAL_I2S_MODULE_ENABLED */ | |||
/*#define HAL_IRDA_MODULE_ENABLED */ | |||
/*#define HAL_IWDG_MODULE_ENABLED */ | |||
/*#define HAL_LCD_MODULE_ENABLED */ | |||
/*#define HAL_NOR_MODULE_ENABLED */ | |||
/*#define HAL_OPAMP_MODULE_ENABLED */ | |||
#define HAL_PCD_MODULE_ENABLED | |||
#define HAL_RTC_MODULE_ENABLED | |||
/*#define HAL_SD_MODULE_ENABLED */ | |||
/*#define HAL_SMARTCARD_MODULE_ENABLED */ | |||
#define HAL_SPI_MODULE_ENABLED | |||
/*#define HAL_SRAM_MODULE_ENABLED */ | |||
#define HAL_TIM_MODULE_ENABLED | |||
/*#define HAL_UART_MODULE_ENABLED */ | |||
/*#define HAL_USART_MODULE_ENABLED */ | |||
/*#define HAL_WWDG_MODULE_ENABLED */ | |||
/*#define HAL_EXTI_MODULE_ENABLED */ | |||
#define HAL_GPIO_MODULE_ENABLED | |||
#define HAL_DMA_MODULE_ENABLED | |||
#define HAL_RCC_MODULE_ENABLED | |||
#define HAL_FLASH_MODULE_ENABLED | |||
#define HAL_PWR_MODULE_ENABLED | |||
#define HAL_CORTEX_MODULE_ENABLED | |||
/* ########################## Oscillator Values adaptation ####################*/ | |||
/** | |||
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application. | |||
* This value is used by the RCC HAL module to compute the system frequency | |||
* (when HSE is used as system clock source, directly or through the PLL). | |||
*/ | |||
#if !defined (HSE_VALUE) | |||
#define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */ | |||
#endif /* HSE_VALUE */ | |||
#if !defined (HSE_STARTUP_TIMEOUT) | |||
#define HSE_STARTUP_TIMEOUT ((uint32_t)100) /*!< Time out for HSE start up, in ms */ | |||
#endif /* HSE_STARTUP_TIMEOUT */ | |||
/** | |||
* @brief Internal Multiple Speed oscillator (MSI) default value. | |||
* This value is the default MSI range value after Reset. | |||
*/ | |||
#if !defined (MSI_VALUE) | |||
#define MSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/ | |||
#endif /* MSI_VALUE */ | |||
/** | |||
* @brief Internal High Speed oscillator (HSI) value. | |||
* This value is used by the RCC HAL module to compute the system frequency | |||
* (when HSI is used as system clock source, directly or through the PLL). | |||
*/ | |||
#if !defined (HSI_VALUE) | |||
#define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/ | |||
#endif /* HSI_VALUE */ | |||
/** | |||
* @brief Internal Low Speed oscillator (LSI) value. | |||
*/ | |||
#if !defined (LSI_VALUE) | |||
#define LSI_VALUE (37000U) /*!< LSI Typical Value in Hz*/ | |||
#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz | |||
The real value may vary depending on the variations | |||
in voltage and temperature.*/ | |||
/** | |||
* @brief External Low Speed oscillator (LSE) value. | |||
* This value is used by the UART, RTC HAL module to compute the system frequency | |||
*/ | |||
#if !defined (LSE_VALUE) | |||
#define LSE_VALUE ((uint32_t)32768) /*!< Value of the External oscillator in Hz*/ | |||
#endif /* LSE_VALUE */ | |||
#if !defined (LSE_STARTUP_TIMEOUT) | |||
#define LSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for LSE start up, in ms */ | |||
#endif /* HSE_STARTUP_TIMEOUT */ | |||
/* Tip: To avoid modifying this file each time you need to use different HSE, | |||
=== you can define the HSE value in your toolchain compiler preprocessor. */ | |||
/* ########################### System Configuration ######################### */ | |||
/** | |||
* @brief This is the HAL system configuration section | |||
*/ | |||
#define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */ | |||
#define TICK_INT_PRIORITY ((uint32_t)0) /*!< tick interrupt priority */ | |||
#define USE_RTOS 0 | |||
#define PREFETCH_ENABLE 0 | |||
#define INSTRUCTION_CACHE_ENABLE 1 | |||
#define DATA_CACHE_ENABLE 1 | |||
/* ########################## Assert Selection ############################## */ | |||
/** | |||
* @brief Uncomment the line below to expanse the "assert_param" macro in the | |||
* HAL drivers code | |||
*/ | |||
/* #define USE_FULL_ASSERT 1U */ | |||
/* ################## Register callback feature configuration ############### */ | |||
/** | |||
* @brief Set below the peripheral configuration to "1U" to add the support | |||
* of HAL callback registration/deregistration feature for the HAL | |||
* driver(s). This allows user application to provide specific callback | |||
* functions thanks to HAL_PPP_RegisterCallback() rather than overwriting | |||
* the default weak callback functions (see each stm32l0xx_hal_ppp.h file | |||
* for possible callback identifiers defined in HAL_PPP_CallbackIDTypeDef | |||
* for each PPP peripheral). | |||
*/ | |||
#define USE_HAL_ADC_REGISTER_CALLBACKS 0U | |||
#define USE_HAL_COMP_REGISTER_CALLBACKS 0U | |||
#define USE_HAL_DAC_REGISTER_CALLBACKS 0U | |||
#define USE_HAL_I2C_REGISTER_CALLBACKS 0U | |||
#define USE_HAL_I2S_REGISTER_CALLBACKS 0U | |||
#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U | |||
#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U | |||
#define USE_HAL_PCD_REGISTER_CALLBACKS 0U | |||
#define USE_HAL_RTC_REGISTER_CALLBACKS 0U | |||
#define USE_HAL_SDMMC_REGISTER_CALLBACKS 0U | |||
#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U | |||
#define USE_HAL_SPI_REGISTER_CALLBACKS 0U | |||
#define USE_HAL_TIM_REGISTER_CALLBACKS 0U | |||
#define USE_HAL_UART_REGISTER_CALLBACKS 0U | |||
#define USE_HAL_USART_REGISTER_CALLBACKS 0U | |||
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U | |||
/* ################## SPI peripheral configuration ########################## */ | |||
/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver | |||
* Activated: CRC code is present inside driver | |||
* Deactivated: CRC code cleaned from driver | |||
*/ | |||
#define USE_SPI_CRC 0U | |||
/* Includes ------------------------------------------------------------------*/ | |||
/** | |||
* @brief Include module's header file | |||
*/ | |||
#ifdef HAL_RCC_MODULE_ENABLED | |||
#include "stm32l1xx_hal_rcc.h" | |||
#endif /* HAL_RCC_MODULE_ENABLED */ | |||
#ifdef HAL_GPIO_MODULE_ENABLED | |||
#include "stm32l1xx_hal_gpio.h" | |||
#endif /* HAL_GPIO_MODULE_ENABLED */ | |||
#ifdef HAL_DMA_MODULE_ENABLED | |||
#include "stm32l1xx_hal_dma.h" | |||
#endif /* HAL_DMA_MODULE_ENABLED */ | |||
#ifdef HAL_CORTEX_MODULE_ENABLED | |||
#include "stm32l1xx_hal_cortex.h" | |||
#endif /* HAL_CORTEX_MODULE_ENABLED */ | |||
#ifdef HAL_ADC_MODULE_ENABLED | |||
#include "stm32l1xx_hal_adc.h" | |||
#endif /* HAL_ADC_MODULE_ENABLED */ | |||
#ifdef HAL_COMP_MODULE_ENABLED | |||
#include "stm32l1xx_hal_comp.h" | |||
#endif /* HAL_COMP_MODULE_ENABLED */ | |||
#ifdef HAL_CRC_MODULE_ENABLED | |||
#include "stm32l1xx_hal_crc.h" | |||
#endif /* HAL_CRC_MODULE_ENABLED */ | |||
#ifdef HAL_CRYP_MODULE_ENABLED | |||
#include "stm32l1xx_hal_cryp.h" | |||
#endif /* HAL_CRYP_MODULE_ENABLED */ | |||
#ifdef HAL_DAC_MODULE_ENABLED | |||
#include "stm32l1xx_hal_dac.h" | |||
#endif /* HAL_DAC_MODULE_ENABLED */ | |||
#ifdef HAL_FLASH_MODULE_ENABLED | |||
#include "stm32l1xx_hal_flash.h" | |||
#endif /* HAL_FLASH_MODULE_ENABLED */ | |||
#ifdef HAL_SRAM_MODULE_ENABLED | |||
#include "stm32l1xx_hal_sram.h" | |||
#endif /* HAL_SRAM_MODULE_ENABLED */ | |||
#ifdef HAL_NOR_MODULE_ENABLED | |||
#include "stm32l1xx_hal_nor.h" | |||
#endif /* HAL_NOR_MODULE_ENABLED */ | |||
#ifdef HAL_I2C_MODULE_ENABLED | |||
#include "stm32l1xx_hal_i2c.h" | |||
#endif /* HAL_I2C_MODULE_ENABLED */ | |||
#ifdef HAL_I2S_MODULE_ENABLED | |||
#include "stm32l1xx_hal_i2s.h" | |||
#endif /* HAL_I2S_MODULE_ENABLED */ | |||
#ifdef HAL_IWDG_MODULE_ENABLED | |||
#include "stm32l1xx_hal_iwdg.h" | |||
#endif /* HAL_IWDG_MODULE_ENABLED */ | |||
#ifdef HAL_LCD_MODULE_ENABLED | |||
#include "stm32l1xx_hal_lcd.h" | |||
#endif /* HAL_LCD_MODULE_ENABLED */ | |||
#ifdef HAL_OPAMP_MODULE_ENABLED | |||
#include "stm32l1xx_hal_opamp.h" | |||
#endif /* HAL_OPAMP_MODULE_ENABLED */ | |||
#ifdef HAL_PWR_MODULE_ENABLED | |||
#include "stm32l1xx_hal_pwr.h" | |||
#endif /* HAL_PWR_MODULE_ENABLED */ | |||
#ifdef HAL_RTC_MODULE_ENABLED | |||
#include "stm32l1xx_hal_rtc.h" | |||
#endif /* HAL_RTC_MODULE_ENABLED */ | |||
#ifdef HAL_SD_MODULE_ENABLED | |||
#include "stm32l1xx_hal_sd.h" | |||
#endif /* HAL_SD_MODULE_ENABLED */ | |||
#ifdef HAL_SPI_MODULE_ENABLED | |||
#include "stm32l1xx_hal_spi.h" | |||
#endif /* HAL_SPI_MODULE_ENABLED */ | |||
#ifdef HAL_TIM_MODULE_ENABLED | |||
#include "stm32l1xx_hal_tim.h" | |||
#endif /* HAL_TIM_MODULE_ENABLED */ | |||
#ifdef HAL_UART_MODULE_ENABLED | |||
#include "stm32l1xx_hal_uart.h" | |||
#endif /* HAL_UART_MODULE_ENABLED */ | |||
#ifdef HAL_USART_MODULE_ENABLED | |||
#include "stm32l1xx_hal_usart.h" | |||
#endif /* HAL_USART_MODULE_ENABLED */ | |||
#ifdef HAL_IRDA_MODULE_ENABLED | |||
#include "stm32l1xx_hal_irda.h" | |||
#endif /* HAL_IRDA_MODULE_ENABLED */ | |||
#ifdef HAL_SMARTCARD_MODULE_ENABLED | |||
#include "stm32l1xx_hal_smartcard.h" | |||
#endif /* HAL_SMARTCARD_MODULE_ENABLED */ | |||
#ifdef HAL_WWDG_MODULE_ENABLED | |||
#include "stm32l1xx_hal_wwdg.h" | |||
#endif /* HAL_WWDG_MODULE_ENABLED */ | |||
#ifdef HAL_PCD_MODULE_ENABLED | |||
#include "stm32l1xx_hal_pcd.h" | |||
#endif /* HAL_PCD_MODULE_ENABLED */ | |||
#ifdef HAL_EXTI_MODULE_ENABLED | |||
#include "stm32l1xx_hal_exti.h" | |||
#endif /* HAL_EXTI_MODULE_ENABLED */ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
#ifdef USE_FULL_ASSERT | |||
/** | |||
* @brief The assert_param macro is used for function's parameters check. | |||
* @param expr: If expr is false, it calls assert_failed function | |||
* which reports the name of the source file and the source | |||
* line number of the call that failed. | |||
* If expr is true, it returns no value. | |||
* @retval None | |||
*/ | |||
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) | |||
/* Exported functions ------------------------------------------------------- */ | |||
void assert_failed(uint8_t* file, uint32_t line); | |||
#else | |||
#define assert_param(expr) ((void)0U) | |||
#endif /* USE_FULL_ASSERT */ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32L1xx_HAL_CONF_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,513 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_hal_cortex.c | |||
* @author MCD Application Team | |||
* @brief CORTEX HAL module driver. | |||
* | |||
* This file provides firmware functions to manage the following | |||
* functionalities of the CORTEX: | |||
* + Initialization and de-initialization functions | |||
* + Peripheral Control functions | |||
* | |||
* @verbatim | |||
============================================================================== | |||
##### How to use this driver ##### | |||
============================================================================== | |||
[..] | |||
*** How to configure Interrupts using Cortex HAL driver *** | |||
=========================================================== | |||
[..] | |||
This section provide functions allowing to configure the NVIC interrupts (IRQ). | |||
The Cortex-M3 exceptions are managed by CMSIS functions. | |||
(#) Configure the NVIC Priority Grouping using HAL_NVIC_SetPriorityGrouping() function | |||
(#) Configure the priority of the selected IRQ Channels using HAL_NVIC_SetPriority() | |||
(#) Enable the selected IRQ Channels using HAL_NVIC_EnableIRQ() | |||
-@- When the NVIC_PRIORITYGROUP_0 is selected, IRQ pre-emption is no more possible. | |||
The pending IRQ priority will be managed only by the sub priority. | |||
-@- IRQ priority order (sorted by highest to lowest priority): | |||
(+@) Lowest pre-emption priority | |||
(+@) Lowest sub priority | |||
(+@) Lowest hardware priority (IRQ number) | |||
[..] | |||
*** How to configure Systick using Cortex HAL driver *** | |||
======================================================== | |||
[..] | |||
Setup SysTick Timer for 1 msec interrupts. | |||
(+) The HAL_SYSTICK_Config()function calls the SysTick_Config() function which | |||
is a CMSIS function that: | |||
(++) Configures the SysTick Reload register with value passed as function parameter. | |||
(++) Configures the SysTick IRQ priority to the lowest value (0x0F). | |||
(++) Resets the SysTick Counter register. | |||
(++) Configures the SysTick Counter clock source to be Core Clock Source (HCLK). | |||
(++) Enables the SysTick Interrupt. | |||
(++) Starts the SysTick Counter. | |||
(+) You can change the SysTick Clock source to be HCLK_Div8 by calling the macro | |||
__HAL_CORTEX_SYSTICKCLK_CONFIG(SYSTICK_CLKSOURCE_HCLK_DIV8) just after the | |||
HAL_SYSTICK_Config() function call. The __HAL_CORTEX_SYSTICKCLK_CONFIG() macro is defined | |||
inside the stm32l1xx_hal_cortex.h file. | |||
(+) You can change the SysTick IRQ priority by calling the | |||
HAL_NVIC_SetPriority(SysTick_IRQn,...) function just after the HAL_SYSTICK_Config() function | |||
call. The HAL_NVIC_SetPriority() call the NVIC_SetPriority() function which is a CMSIS function. | |||
(+) To adjust the SysTick time base, use the following formula: | |||
Reload Value = SysTick Counter Clock (Hz) x Desired Time base (s) | |||
(++) Reload Value is the parameter to be passed for HAL_SYSTICK_Config() function | |||
(++) Reload Value should not exceed 0xFFFFFF | |||
@endverbatim | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* | |||
Additional Tables: CORTEX_NVIC_Priority_Table | |||
The table below gives the allowed values of the pre-emption priority and subpriority according | |||
to the Priority Grouping configuration performed by HAL_NVIC_SetPriorityGrouping() function. | |||
========================================================================================================================== | |||
NVIC_PriorityGroup | NVIC_IRQChannelPreemptionPriority | NVIC_IRQChannelSubPriority | Description | |||
========================================================================================================================== | |||
NVIC_PRIORITYGROUP_0 | 0 | 0-15 | 0 bits for pre-emption priority | |||
| | | 4 bits for subpriority | |||
-------------------------------------------------------------------------------------------------------------------------- | |||
NVIC_PRIORITYGROUP_1 | 0-1 | 0-7 | 1 bits for pre-emption priority | |||
| | | 3 bits for subpriority | |||
-------------------------------------------------------------------------------------------------------------------------- | |||
NVIC_PRIORITYGROUP_2 | 0-3 | 0-3 | 2 bits for pre-emption priority | |||
| | | 2 bits for subpriority | |||
-------------------------------------------------------------------------------------------------------------------------- | |||
NVIC_PRIORITYGROUP_3 | 0-7 | 0-1 | 3 bits for pre-emption priority | |||
| | | 1 bits for subpriority | |||
-------------------------------------------------------------------------------------------------------------------------- | |||
NVIC_PRIORITYGROUP_4 | 0-15 | 0 | 4 bits for pre-emption priority | |||
| | | 0 bits for subpriority | |||
========================================================================================================================== | |||
*/ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx_hal.h" | |||
/** @addtogroup STM32L1xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @defgroup CORTEX CORTEX | |||
* @brief CORTEX HAL module driver | |||
* @{ | |||
*/ | |||
#ifdef HAL_CORTEX_MODULE_ENABLED | |||
/* Private typedef -----------------------------------------------------------*/ | |||
/* Private define ------------------------------------------------------------*/ | |||
/* Private macro -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private function prototypes -----------------------------------------------*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** @defgroup CORTEX_Exported_Functions CORTEX Exported Functions | |||
* @{ | |||
*/ | |||
/** @defgroup CORTEX_Exported_Functions_Group1 Initialization and de-initialization functions | |||
* @brief Initialization and Configuration functions | |||
* | |||
@verbatim | |||
============================================================================== | |||
##### Initialization and de-initialization functions ##### | |||
============================================================================== | |||
[..] | |||
This section provide the Cortex HAL driver functions allowing to configure Interrupts | |||
Systick functionalities | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Sets the priority grouping field (pre-emption priority and subpriority) | |||
* using the required unlock sequence. | |||
* @param PriorityGroup The priority grouping bits length. | |||
* This parameter can be one of the following values: | |||
* @arg NVIC_PRIORITYGROUP_0: 0 bits for pre-emption priority | |||
* 4 bits for subpriority | |||
* @arg NVIC_PRIORITYGROUP_1: 1 bits for pre-emption priority | |||
* 3 bits for subpriority | |||
* @arg NVIC_PRIORITYGROUP_2: 2 bits for pre-emption priority | |||
* 2 bits for subpriority | |||
* @arg NVIC_PRIORITYGROUP_3: 3 bits for pre-emption priority | |||
* 1 bits for subpriority | |||
* @arg NVIC_PRIORITYGROUP_4: 4 bits for pre-emption priority | |||
* 0 bits for subpriority | |||
* @note When the NVIC_PriorityGroup_0 is selected, IRQ pre-emption is no more possible. | |||
* The pending IRQ priority will be managed only by the subpriority. | |||
* @retval None | |||
*/ | |||
void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup)); | |||
/* Set the PRIGROUP[10:8] bits according to the PriorityGroup parameter value */ | |||
NVIC_SetPriorityGrouping(PriorityGroup); | |||
} | |||
/** | |||
* @brief Sets the priority of an interrupt. | |||
* @param IRQn External interrupt number | |||
* This parameter can be an enumerator of IRQn_Type enumeration | |||
* (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32l1xx.h)) | |||
* @param PreemptPriority The pre-emption priority for the IRQn channel. | |||
* This parameter can be a value between 0 and 15 | |||
* A lower priority value indicates a higher priority | |||
* @param SubPriority the subpriority level for the IRQ channel. | |||
* This parameter can be a value between 0 and 15 | |||
* A lower priority value indicates a higher priority. | |||
* @retval None | |||
*/ | |||
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority) | |||
{ | |||
uint32_t prioritygroup = 0x00; | |||
/* Check the parameters */ | |||
assert_param(IS_NVIC_SUB_PRIORITY(SubPriority)); | |||
assert_param(IS_NVIC_PREEMPTION_PRIORITY(PreemptPriority)); | |||
prioritygroup = NVIC_GetPriorityGrouping(); | |||
NVIC_SetPriority(IRQn, NVIC_EncodePriority(prioritygroup, PreemptPriority, SubPriority)); | |||
} | |||
/** | |||
* @brief Enables a device specific interrupt in the NVIC interrupt controller. | |||
* @note To configure interrupts priority correctly, the NVIC_PriorityGroupConfig() | |||
* function should be called before. | |||
* @param IRQn External interrupt number | |||
* This parameter can be an enumerator of IRQn_Type enumeration | |||
* (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32l1xx.h)) | |||
* @retval None | |||
*/ | |||
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_NVIC_DEVICE_IRQ(IRQn)); | |||
/* Enable interrupt */ | |||
NVIC_EnableIRQ(IRQn); | |||
} | |||
/** | |||
* @brief Disables a device specific interrupt in the NVIC interrupt controller. | |||
* @param IRQn External interrupt number | |||
* This parameter can be an enumerator of IRQn_Type enumeration | |||
* (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32l1xxxx.h)) | |||
* @retval None | |||
*/ | |||
void HAL_NVIC_DisableIRQ(IRQn_Type IRQn) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_NVIC_DEVICE_IRQ(IRQn)); | |||
/* Disable interrupt */ | |||
NVIC_DisableIRQ(IRQn); | |||
} | |||
/** | |||
* @brief Initiates a system reset request to reset the MCU. | |||
* @retval None | |||
*/ | |||
void HAL_NVIC_SystemReset(void) | |||
{ | |||
/* System Reset */ | |||
NVIC_SystemReset(); | |||
} | |||
/** | |||
* @brief Initializes the System Timer and its interrupt, and starts the System Tick Timer. | |||
* Counter is in free running mode to generate periodic interrupts. | |||
* @param TicksNumb Specifies the ticks Number of ticks between two interrupts. | |||
* @retval status: - 0 Function succeeded. | |||
* - 1 Function failed. | |||
*/ | |||
uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb) | |||
{ | |||
return SysTick_Config(TicksNumb); | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CORTEX_Exported_Functions_Group2 Peripheral Control functions | |||
* @brief Cortex control functions | |||
* | |||
@verbatim | |||
============================================================================== | |||
##### Peripheral Control functions ##### | |||
============================================================================== | |||
[..] | |||
This subsection provides a set of functions allowing to control the CORTEX | |||
(NVIC, SYSTICK, MPU) functionalities. | |||
@endverbatim | |||
* @{ | |||
*/ | |||
#if (__MPU_PRESENT == 1) | |||
/** | |||
* @brief Enable the MPU. | |||
* @param MPU_Control Specifies the control mode of the MPU during hard fault, | |||
* NMI, FAULTMASK and privileged accessto the default memory | |||
* This parameter can be one of the following values: | |||
* @arg MPU_HFNMI_PRIVDEF_NONE | |||
* @arg MPU_HARDFAULT_NMI | |||
* @arg MPU_PRIVILEGED_DEFAULT | |||
* @arg MPU_HFNMI_PRIVDEF | |||
* @retval None | |||
*/ | |||
void HAL_MPU_Enable(uint32_t MPU_Control) | |||
{ | |||
/* Enable the MPU */ | |||
MPU->CTRL = (MPU_Control | MPU_CTRL_ENABLE_Msk); | |||
/* Ensure MPU setting take effects */ | |||
__DSB(); | |||
__ISB(); | |||
} | |||
/** | |||
* @brief Disable the MPU. | |||
* @retval None | |||
*/ | |||
void HAL_MPU_Disable(void) | |||
{ | |||
/* Make sure outstanding transfers are done */ | |||
__DMB(); | |||
/* Disable the MPU and clear the control register*/ | |||
MPU->CTRL = 0; | |||
} | |||
/** | |||
* @brief Initializes and configures the Region and the memory to be protected. | |||
* @param MPU_Init Pointer to a MPU_Region_InitTypeDef structure that contains | |||
* the initialization and configuration information. | |||
* @retval None | |||
*/ | |||
void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_MPU_REGION_NUMBER(MPU_Init->Number)); | |||
assert_param(IS_MPU_REGION_ENABLE(MPU_Init->Enable)); | |||
/* Set the Region number */ | |||
MPU->RNR = MPU_Init->Number; | |||
if ((MPU_Init->Enable) != RESET) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_MPU_INSTRUCTION_ACCESS(MPU_Init->DisableExec)); | |||
assert_param(IS_MPU_REGION_PERMISSION_ATTRIBUTE(MPU_Init->AccessPermission)); | |||
assert_param(IS_MPU_TEX_LEVEL(MPU_Init->TypeExtField)); | |||
assert_param(IS_MPU_ACCESS_SHAREABLE(MPU_Init->IsShareable)); | |||
assert_param(IS_MPU_ACCESS_CACHEABLE(MPU_Init->IsCacheable)); | |||
assert_param(IS_MPU_ACCESS_BUFFERABLE(MPU_Init->IsBufferable)); | |||
assert_param(IS_MPU_SUB_REGION_DISABLE(MPU_Init->SubRegionDisable)); | |||
assert_param(IS_MPU_REGION_SIZE(MPU_Init->Size)); | |||
MPU->RBAR = MPU_Init->BaseAddress; | |||
MPU->RASR = ((uint32_t)MPU_Init->DisableExec << MPU_RASR_XN_Pos) | | |||
((uint32_t)MPU_Init->AccessPermission << MPU_RASR_AP_Pos) | | |||
((uint32_t)MPU_Init->TypeExtField << MPU_RASR_TEX_Pos) | | |||
((uint32_t)MPU_Init->IsShareable << MPU_RASR_S_Pos) | | |||
((uint32_t)MPU_Init->IsCacheable << MPU_RASR_C_Pos) | | |||
((uint32_t)MPU_Init->IsBufferable << MPU_RASR_B_Pos) | | |||
((uint32_t)MPU_Init->SubRegionDisable << MPU_RASR_SRD_Pos) | | |||
((uint32_t)MPU_Init->Size << MPU_RASR_SIZE_Pos) | | |||
((uint32_t)MPU_Init->Enable << MPU_RASR_ENABLE_Pos); | |||
} | |||
else | |||
{ | |||
MPU->RBAR = 0x00; | |||
MPU->RASR = 0x00; | |||
} | |||
} | |||
#endif /* __MPU_PRESENT */ | |||
/** | |||
* @brief Gets the priority grouping field from the NVIC Interrupt Controller. | |||
* @retval Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field) | |||
*/ | |||
uint32_t HAL_NVIC_GetPriorityGrouping(void) | |||
{ | |||
/* Get the PRIGROUP[10:8] field value */ | |||
return NVIC_GetPriorityGrouping(); | |||
} | |||
/** | |||
* @brief Gets the priority of an interrupt. | |||
* @param IRQn External interrupt number | |||
* This parameter can be an enumerator of IRQn_Type enumeration | |||
* (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32l1xxxx.h)) | |||
* @param PriorityGroup the priority grouping bits length. | |||
* This parameter can be one of the following values: | |||
* @arg NVIC_PRIORITYGROUP_0: 0 bits for pre-emption priority | |||
* 4 bits for subpriority | |||
* @arg NVIC_PRIORITYGROUP_1: 1 bits for pre-emption priority | |||
* 3 bits for subpriority | |||
* @arg NVIC_PRIORITYGROUP_2: 2 bits for pre-emption priority | |||
* 2 bits for subpriority | |||
* @arg NVIC_PRIORITYGROUP_3: 3 bits for pre-emption priority | |||
* 1 bits for subpriority | |||
* @arg NVIC_PRIORITYGROUP_4: 4 bits for pre-emption priority | |||
* 0 bits for subpriority | |||
* @param pPreemptPriority Pointer on the Preemptive priority value (starting from 0). | |||
* @param pSubPriority Pointer on the Subpriority value (starting from 0). | |||
* @retval None | |||
*/ | |||
void HAL_NVIC_GetPriority(IRQn_Type IRQn, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup)); | |||
/* Get priority for Cortex-M system or device specific interrupts */ | |||
NVIC_DecodePriority(NVIC_GetPriority(IRQn), PriorityGroup, pPreemptPriority, pSubPriority); | |||
} | |||
/** | |||
* @brief Sets Pending bit of an external interrupt. | |||
* @param IRQn External interrupt number | |||
* This parameter can be an enumerator of IRQn_Type enumeration | |||
* (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32l1xxxx.h)) | |||
* @retval None | |||
*/ | |||
void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn) | |||
{ | |||
/* Set interrupt pending */ | |||
NVIC_SetPendingIRQ(IRQn); | |||
} | |||
/** | |||
* @brief Gets Pending Interrupt (reads the pending register in the NVIC | |||
* and returns the pending bit for the specified interrupt). | |||
* @param IRQn External interrupt number | |||
* This parameter can be an enumerator of IRQn_Type enumeration | |||
* (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32l1xxxx.h)) | |||
* @retval status: - 0 Interrupt status is not pending. | |||
* - 1 Interrupt status is pending. | |||
*/ | |||
uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn) | |||
{ | |||
/* Return 1 if pending else 0 */ | |||
return NVIC_GetPendingIRQ(IRQn); | |||
} | |||
/** | |||
* @brief Clears the pending bit of an external interrupt. | |||
* @param IRQn External interrupt number | |||
* This parameter can be an enumerator of IRQn_Type enumeration | |||
* (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32l1xxxx.h)) | |||
* @retval None | |||
*/ | |||
void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn) | |||
{ | |||
/* Clear pending interrupt */ | |||
NVIC_ClearPendingIRQ(IRQn); | |||
} | |||
/** | |||
* @brief Gets active interrupt ( reads the active register in NVIC and returns the active bit). | |||
* @param IRQn External interrupt number | |||
* This parameter can be an enumerator of IRQn_Type enumeration | |||
* (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32l1xxxx.h)) | |||
* @retval status: - 0 Interrupt status is not pending. | |||
* - 1 Interrupt status is pending. | |||
*/ | |||
uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn) | |||
{ | |||
/* Return 1 if active else 0 */ | |||
return NVIC_GetActive(IRQn); | |||
} | |||
/** | |||
* @brief Configures the SysTick clock source. | |||
* @param CLKSource specifies the SysTick clock source. | |||
* This parameter can be one of the following values: | |||
* @arg SYSTICK_CLKSOURCE_HCLK_DIV8: AHB clock divided by 8 selected as SysTick clock source. | |||
* @arg SYSTICK_CLKSOURCE_HCLK: AHB clock selected as SysTick clock source. | |||
* @retval None | |||
*/ | |||
void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_SYSTICK_CLK_SOURCE(CLKSource)); | |||
if (CLKSource == SYSTICK_CLKSOURCE_HCLK) | |||
{ | |||
SysTick->CTRL |= SYSTICK_CLKSOURCE_HCLK; | |||
} | |||
else | |||
{ | |||
SysTick->CTRL &= ~SYSTICK_CLKSOURCE_HCLK; | |||
} | |||
} | |||
/** | |||
* @brief This function handles SYSTICK interrupt request. | |||
* @retval None | |||
*/ | |||
void HAL_SYSTICK_IRQHandler(void) | |||
{ | |||
HAL_SYSTICK_Callback(); | |||
} | |||
/** | |||
* @brief SYSTICK callback. | |||
* @retval None | |||
*/ | |||
__weak void HAL_SYSTICK_Callback(void) | |||
{ | |||
/* NOTE : This function Should not be modified, when the callback is needed, | |||
the HAL_SYSTICK_Callback could be implemented in the user file | |||
*/ | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#endif /* HAL_CORTEX_MODULE_ENABLED */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,437 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_hal_cortex.h | |||
* @author MCD Application Team | |||
* @brief Header file of CORTEX HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32L1xx_HAL_CORTEX_H | |||
#define __STM32L1xx_HAL_CORTEX_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx_hal_def.h" | |||
/** @addtogroup STM32L1xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup CORTEX | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup CORTEX_Exported_Types Cortex Exported Types | |||
* @{ | |||
*/ | |||
#if (__MPU_PRESENT == 1) | |||
/** @defgroup CORTEX_MPU_Region_Initialization_Structure_definition MPU Region Initialization Structure Definition | |||
* @brief MPU Region initialization structure | |||
* @{ | |||
*/ | |||
typedef struct | |||
{ | |||
uint8_t Enable; /*!< Specifies the status of the region. | |||
This parameter can be a value of @ref CORTEX_MPU_Region_Enable */ | |||
uint8_t Number; /*!< Specifies the number of the region to protect. | |||
This parameter can be a value of @ref CORTEX_MPU_Region_Number */ | |||
uint32_t BaseAddress; /*!< Specifies the base address of the region to protect. */ | |||
uint8_t Size; /*!< Specifies the size of the region to protect. | |||
This parameter can be a value of @ref CORTEX_MPU_Region_Size */ | |||
uint8_t SubRegionDisable; /*!< Specifies the number of the subregion protection to disable. | |||
This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF */ | |||
uint8_t TypeExtField; /*!< Specifies the TEX field level. | |||
This parameter can be a value of @ref CORTEX_MPU_TEX_Levels */ | |||
uint8_t AccessPermission; /*!< Specifies the region access permission type. | |||
This parameter can be a value of @ref CORTEX_MPU_Region_Permission_Attributes */ | |||
uint8_t DisableExec; /*!< Specifies the instruction access status. | |||
This parameter can be a value of @ref CORTEX_MPU_Instruction_Access */ | |||
uint8_t IsShareable; /*!< Specifies the shareability status of the protected region. | |||
This parameter can be a value of @ref CORTEX_MPU_Access_Shareable */ | |||
uint8_t IsCacheable; /*!< Specifies the cacheable status of the region protected. | |||
This parameter can be a value of @ref CORTEX_MPU_Access_Cacheable */ | |||
uint8_t IsBufferable; /*!< Specifies the bufferable status of the protected region. | |||
This parameter can be a value of @ref CORTEX_MPU_Access_Bufferable */ | |||
}MPU_Region_InitTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
#endif /* __MPU_PRESENT */ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup CORTEX_Exported_Constants CORTEX Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup CORTEX_Preemption_Priority_Group CORTEX Preemption Priority Group | |||
* @{ | |||
*/ | |||
#define NVIC_PRIORITYGROUP_0 (0x00000007U) /*!< 0 bits for pre-emption priority | |||
4 bits for subpriority */ | |||
#define NVIC_PRIORITYGROUP_1 (0x00000006U) /*!< 1 bits for pre-emption priority | |||
3 bits for subpriority */ | |||
#define NVIC_PRIORITYGROUP_2 (0x00000005U) /*!< 2 bits for pre-emption priority | |||
2 bits for subpriority */ | |||
#define NVIC_PRIORITYGROUP_3 (0x00000004U) /*!< 3 bits for pre-emption priority | |||
1 bits for subpriority */ | |||
#define NVIC_PRIORITYGROUP_4 (0x00000003U) /*!< 4 bits for pre-emption priority | |||
0 bits for subpriority */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CORTEX_SysTick_clock_source CORTEX SysTick clock source | |||
* @{ | |||
*/ | |||
#define SYSTICK_CLKSOURCE_HCLK_DIV8 (0x00000000U) | |||
#define SYSTICK_CLKSOURCE_HCLK (0x00000004U) | |||
/** | |||
* @} | |||
*/ | |||
#if (__MPU_PRESENT == 1) | |||
/** @defgroup CORTEX_MPU_HFNMI_PRIVDEF_Control MPU HFNMI and PRIVILEGED Access control | |||
* @{ | |||
*/ | |||
#define MPU_HFNMI_PRIVDEF_NONE (0x00000000U) | |||
#define MPU_HARDFAULT_NMI (MPU_CTRL_HFNMIENA_Msk) | |||
#define MPU_PRIVILEGED_DEFAULT (MPU_CTRL_PRIVDEFENA_Msk) | |||
#define MPU_HFNMI_PRIVDEF (MPU_CTRL_HFNMIENA_Msk | MPU_CTRL_PRIVDEFENA_Msk) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CORTEX_MPU_Region_Enable CORTEX MPU Region Enable | |||
* @{ | |||
*/ | |||
#define MPU_REGION_ENABLE ((uint8_t)0x01) | |||
#define MPU_REGION_DISABLE ((uint8_t)0x00) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CORTEX_MPU_Instruction_Access CORTEX MPU Instruction Access | |||
* @{ | |||
*/ | |||
#define MPU_INSTRUCTION_ACCESS_ENABLE ((uint8_t)0x00) | |||
#define MPU_INSTRUCTION_ACCESS_DISABLE ((uint8_t)0x01) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CORTEX_MPU_Access_Shareable CORTEX MPU Instruction Access Shareable | |||
* @{ | |||
*/ | |||
#define MPU_ACCESS_SHAREABLE ((uint8_t)0x01) | |||
#define MPU_ACCESS_NOT_SHAREABLE ((uint8_t)0x00) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CORTEX_MPU_Access_Cacheable CORTEX MPU Instruction Access Cacheable | |||
* @{ | |||
*/ | |||
#define MPU_ACCESS_CACHEABLE ((uint8_t)0x01) | |||
#define MPU_ACCESS_NOT_CACHEABLE ((uint8_t)0x00) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CORTEX_MPU_Access_Bufferable CORTEX MPU Instruction Access Bufferable | |||
* @{ | |||
*/ | |||
#define MPU_ACCESS_BUFFERABLE ((uint8_t)0x01) | |||
#define MPU_ACCESS_NOT_BUFFERABLE ((uint8_t)0x00) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CORTEX_MPU_TEX_Levels MPU TEX Levels | |||
* @{ | |||
*/ | |||
#define MPU_TEX_LEVEL0 ((uint8_t)0x00) | |||
#define MPU_TEX_LEVEL1 ((uint8_t)0x01) | |||
#define MPU_TEX_LEVEL2 ((uint8_t)0x02) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CORTEX_MPU_Region_Size CORTEX MPU Region Size | |||
* @{ | |||
*/ | |||
#define MPU_REGION_SIZE_32B ((uint8_t)0x04) | |||
#define MPU_REGION_SIZE_64B ((uint8_t)0x05) | |||
#define MPU_REGION_SIZE_128B ((uint8_t)0x06) | |||
#define MPU_REGION_SIZE_256B ((uint8_t)0x07) | |||
#define MPU_REGION_SIZE_512B ((uint8_t)0x08) | |||
#define MPU_REGION_SIZE_1KB ((uint8_t)0x09) | |||
#define MPU_REGION_SIZE_2KB ((uint8_t)0x0A) | |||
#define MPU_REGION_SIZE_4KB ((uint8_t)0x0B) | |||
#define MPU_REGION_SIZE_8KB ((uint8_t)0x0C) | |||
#define MPU_REGION_SIZE_16KB ((uint8_t)0x0D) | |||
#define MPU_REGION_SIZE_32KB ((uint8_t)0x0E) | |||
#define MPU_REGION_SIZE_64KB ((uint8_t)0x0F) | |||
#define MPU_REGION_SIZE_128KB ((uint8_t)0x10) | |||
#define MPU_REGION_SIZE_256KB ((uint8_t)0x11) | |||
#define MPU_REGION_SIZE_512KB ((uint8_t)0x12) | |||
#define MPU_REGION_SIZE_1MB ((uint8_t)0x13) | |||
#define MPU_REGION_SIZE_2MB ((uint8_t)0x14) | |||
#define MPU_REGION_SIZE_4MB ((uint8_t)0x15) | |||
#define MPU_REGION_SIZE_8MB ((uint8_t)0x16) | |||
#define MPU_REGION_SIZE_16MB ((uint8_t)0x17) | |||
#define MPU_REGION_SIZE_32MB ((uint8_t)0x18) | |||
#define MPU_REGION_SIZE_64MB ((uint8_t)0x19) | |||
#define MPU_REGION_SIZE_128MB ((uint8_t)0x1A) | |||
#define MPU_REGION_SIZE_256MB ((uint8_t)0x1B) | |||
#define MPU_REGION_SIZE_512MB ((uint8_t)0x1C) | |||
#define MPU_REGION_SIZE_1GB ((uint8_t)0x1D) | |||
#define MPU_REGION_SIZE_2GB ((uint8_t)0x1E) | |||
#define MPU_REGION_SIZE_4GB ((uint8_t)0x1F) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CORTEX_MPU_Region_Permission_Attributes CORTEX MPU Region Permission Attributes | |||
* @{ | |||
*/ | |||
#define MPU_REGION_NO_ACCESS ((uint8_t)0x00) | |||
#define MPU_REGION_PRIV_RW ((uint8_t)0x01) | |||
#define MPU_REGION_PRIV_RW_URO ((uint8_t)0x02) | |||
#define MPU_REGION_FULL_ACCESS ((uint8_t)0x03) | |||
#define MPU_REGION_PRIV_RO ((uint8_t)0x05) | |||
#define MPU_REGION_PRIV_RO_URO ((uint8_t)0x06) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup CORTEX_MPU_Region_Number CORTEX MPU Region Number | |||
* @{ | |||
*/ | |||
#define MPU_REGION_NUMBER0 ((uint8_t)0x00) | |||
#define MPU_REGION_NUMBER1 ((uint8_t)0x01) | |||
#define MPU_REGION_NUMBER2 ((uint8_t)0x02) | |||
#define MPU_REGION_NUMBER3 ((uint8_t)0x03) | |||
#define MPU_REGION_NUMBER4 ((uint8_t)0x04) | |||
#define MPU_REGION_NUMBER5 ((uint8_t)0x05) | |||
#define MPU_REGION_NUMBER6 ((uint8_t)0x06) | |||
#define MPU_REGION_NUMBER7 ((uint8_t)0x07) | |||
/** | |||
* @} | |||
*/ | |||
#endif /* __MPU_PRESENT */ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported Macros -----------------------------------------------------------*/ | |||
/** @defgroup CORTEX_Exported_Macros CORTEX Exported Macros | |||
* @{ | |||
*/ | |||
/** @defgroup CORTEX_Preemption_Priority_Group_Macro CORTEX Preemption Priority Group | |||
* @{ | |||
*/ | |||
#define IS_NVIC_PRIORITY_GROUP(GROUP) (((GROUP) == NVIC_PRIORITYGROUP_0) || \ | |||
((GROUP) == NVIC_PRIORITYGROUP_1) || \ | |||
((GROUP) == NVIC_PRIORITYGROUP_2) || \ | |||
((GROUP) == NVIC_PRIORITYGROUP_3) || \ | |||
((GROUP) == NVIC_PRIORITYGROUP_4)) | |||
#define IS_NVIC_PREEMPTION_PRIORITY(PRIORITY) ((PRIORITY) < 0x10) | |||
#define IS_NVIC_SUB_PRIORITY(PRIORITY) ((PRIORITY) < 0x10) | |||
#define IS_NVIC_DEVICE_IRQ(IRQ) ((IRQ) >= 0x00) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private macro -------------------------------------------------------------*/ | |||
/** @defgroup CORTEX_Private_Macros CORTEX Private Macros | |||
* @{ | |||
*/ | |||
/** @defgroup CORTEX_SysTick_clock_source_Macro_Private CORTEX SysTick clock source | |||
* @{ | |||
*/ | |||
#define IS_SYSTICK_CLK_SOURCE(SOURCE) (((SOURCE) == SYSTICK_CLKSOURCE_HCLK) || \ | |||
((SOURCE) == SYSTICK_CLKSOURCE_HCLK_DIV8)) | |||
/** | |||
* @} | |||
*/ | |||
#if (__MPU_PRESENT == 1) | |||
#define IS_MPU_REGION_ENABLE(STATE) (((STATE) == MPU_REGION_ENABLE) || \ | |||
((STATE) == MPU_REGION_DISABLE)) | |||
#define IS_MPU_INSTRUCTION_ACCESS(STATE) (((STATE) == MPU_INSTRUCTION_ACCESS_ENABLE) || \ | |||
((STATE) == MPU_INSTRUCTION_ACCESS_DISABLE)) | |||
#define IS_MPU_ACCESS_SHAREABLE(STATE) (((STATE) == MPU_ACCESS_SHAREABLE) || \ | |||
((STATE) == MPU_ACCESS_NOT_SHAREABLE)) | |||
#define IS_MPU_ACCESS_CACHEABLE(STATE) (((STATE) == MPU_ACCESS_CACHEABLE) || \ | |||
((STATE) == MPU_ACCESS_NOT_CACHEABLE)) | |||
#define IS_MPU_ACCESS_BUFFERABLE(STATE) (((STATE) == MPU_ACCESS_BUFFERABLE) || \ | |||
((STATE) == MPU_ACCESS_NOT_BUFFERABLE)) | |||
#define IS_MPU_TEX_LEVEL(TYPE) (((TYPE) == MPU_TEX_LEVEL0) || \ | |||
((TYPE) == MPU_TEX_LEVEL1) || \ | |||
((TYPE) == MPU_TEX_LEVEL2)) | |||
#define IS_MPU_REGION_PERMISSION_ATTRIBUTE(TYPE) (((TYPE) == MPU_REGION_NO_ACCESS) || \ | |||
((TYPE) == MPU_REGION_PRIV_RW) || \ | |||
((TYPE) == MPU_REGION_PRIV_RW_URO) || \ | |||
((TYPE) == MPU_REGION_FULL_ACCESS) || \ | |||
((TYPE) == MPU_REGION_PRIV_RO) || \ | |||
((TYPE) == MPU_REGION_PRIV_RO_URO)) | |||
#define IS_MPU_REGION_NUMBER(NUMBER) (((NUMBER) == MPU_REGION_NUMBER0) || \ | |||
((NUMBER) == MPU_REGION_NUMBER1) || \ | |||
((NUMBER) == MPU_REGION_NUMBER2) || \ | |||
((NUMBER) == MPU_REGION_NUMBER3) || \ | |||
((NUMBER) == MPU_REGION_NUMBER4) || \ | |||
((NUMBER) == MPU_REGION_NUMBER5) || \ | |||
((NUMBER) == MPU_REGION_NUMBER6) || \ | |||
((NUMBER) == MPU_REGION_NUMBER7)) | |||
#define IS_MPU_REGION_SIZE(SIZE) (((SIZE) == MPU_REGION_SIZE_32B) || \ | |||
((SIZE) == MPU_REGION_SIZE_64B) || \ | |||
((SIZE) == MPU_REGION_SIZE_128B) || \ | |||
((SIZE) == MPU_REGION_SIZE_256B) || \ | |||
((SIZE) == MPU_REGION_SIZE_512B) || \ | |||
((SIZE) == MPU_REGION_SIZE_1KB) || \ | |||
((SIZE) == MPU_REGION_SIZE_2KB) || \ | |||
((SIZE) == MPU_REGION_SIZE_4KB) || \ | |||
((SIZE) == MPU_REGION_SIZE_8KB) || \ | |||
((SIZE) == MPU_REGION_SIZE_16KB) || \ | |||
((SIZE) == MPU_REGION_SIZE_32KB) || \ | |||
((SIZE) == MPU_REGION_SIZE_64KB) || \ | |||
((SIZE) == MPU_REGION_SIZE_128KB) || \ | |||
((SIZE) == MPU_REGION_SIZE_256KB) || \ | |||
((SIZE) == MPU_REGION_SIZE_512KB) || \ | |||
((SIZE) == MPU_REGION_SIZE_1MB) || \ | |||
((SIZE) == MPU_REGION_SIZE_2MB) || \ | |||
((SIZE) == MPU_REGION_SIZE_4MB) || \ | |||
((SIZE) == MPU_REGION_SIZE_8MB) || \ | |||
((SIZE) == MPU_REGION_SIZE_16MB) || \ | |||
((SIZE) == MPU_REGION_SIZE_32MB) || \ | |||
((SIZE) == MPU_REGION_SIZE_64MB) || \ | |||
((SIZE) == MPU_REGION_SIZE_128MB) || \ | |||
((SIZE) == MPU_REGION_SIZE_256MB) || \ | |||
((SIZE) == MPU_REGION_SIZE_512MB) || \ | |||
((SIZE) == MPU_REGION_SIZE_1GB) || \ | |||
((SIZE) == MPU_REGION_SIZE_2GB) || \ | |||
((SIZE) == MPU_REGION_SIZE_4GB)) | |||
#define IS_MPU_SUB_REGION_DISABLE(SUBREGION) ((SUBREGION) < (uint16_t)0x00FF) | |||
#endif /* __MPU_PRESENT */ | |||
/** | |||
* @} | |||
*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** @defgroup CORTEX_Private_Functions CORTEX Private Functions | |||
* @brief CORTEX private functions | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup CORTEX_Exported_Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup CORTEX_Exported_Functions_Group1 | |||
* @{ | |||
*/ | |||
/* Initialization and de-initialization functions *****************************/ | |||
void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup); | |||
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority); | |||
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn); | |||
void HAL_NVIC_DisableIRQ(IRQn_Type IRQn); | |||
void HAL_NVIC_SystemReset(void); | |||
uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup CORTEX_Exported_Functions_Group2 | |||
* @{ | |||
*/ | |||
/* Peripheral Control functions ***********************************************/ | |||
#if (__MPU_PRESENT == 1) | |||
void HAL_MPU_Enable(uint32_t MPU_Control); | |||
void HAL_MPU_Disable(void); | |||
void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init); | |||
#endif /* __MPU_PRESENT */ | |||
uint32_t HAL_NVIC_GetPriorityGrouping(void); | |||
void HAL_NVIC_GetPriority(IRQn_Type IRQn, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority); | |||
uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn); | |||
void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn); | |||
void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn); | |||
uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn); | |||
void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource); | |||
void HAL_SYSTICK_IRQHandler(void); | |||
void HAL_SYSTICK_Callback(void); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32L1xx_HAL_CORTEX_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,198 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_hal_def.h | |||
* @author MCD Application Team | |||
* @brief This file contains HAL common defines, enumeration, macros and | |||
* structures definitions. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32L1xx_HAL_DEF | |||
#define __STM32L1xx_HAL_DEF | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx.h" | |||
#include "Legacy/stm32_hal_legacy.h" | |||
#include <stddef.h> | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** | |||
* @brief HAL Status structures definition | |||
*/ | |||
typedef enum | |||
{ | |||
HAL_OK = 0x00U, | |||
HAL_ERROR = 0x01U, | |||
HAL_BUSY = 0x02U, | |||
HAL_TIMEOUT = 0x03U | |||
} HAL_StatusTypeDef; | |||
/** | |||
* @brief HAL Lock structures definition | |||
*/ | |||
typedef enum | |||
{ | |||
HAL_UNLOCKED = 0x00U, | |||
HAL_LOCKED = 0x01U | |||
} HAL_LockTypeDef; | |||
/* Exported macro ------------------------------------------------------------*/ | |||
#define UNUSED(X) (void)X /* To avoid gcc/g++ warnings */ | |||
#define HAL_MAX_DELAY 0xFFFFFFFFU | |||
#define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) == (BIT)) | |||
#define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == 0U) | |||
#define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD_, __DMA_HANDLE_) \ | |||
do{ \ | |||
(__HANDLE__)->__PPP_DMA_FIELD_ = &(__DMA_HANDLE_); \ | |||
(__DMA_HANDLE_).Parent = (__HANDLE__); \ | |||
} while(0) | |||
/** @brief Reset the Handle's State field. | |||
* @param __HANDLE__: specifies the Peripheral Handle. | |||
* @note This macro can be used for the following purpose: | |||
* - When the Handle is declared as local variable; before passing it as parameter | |||
* to HAL_PPP_Init() for the first time, it is mandatory to use this macro | |||
* to set to 0 the Handle's "State" field. | |||
* Otherwise, "State" field may have any random value and the first time the function | |||
* HAL_PPP_Init() is called, the low level hardware initialization will be missed | |||
* (i.e. HAL_PPP_MspInit() will not be executed). | |||
* - When there is a need to reconfigure the low level hardware: instead of calling | |||
* HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init(). | |||
* In this later function, when the Handle's "State" field is set to 0, it will execute the function | |||
* HAL_PPP_MspInit() which will reconfigure the low level hardware. | |||
* @retval None | |||
*/ | |||
#define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0U) | |||
#if (USE_RTOS == 1) | |||
/* Reserved for future use */ | |||
#error "USE_RTOS should be 0 in the current HAL release" | |||
#else | |||
#define __HAL_LOCK(__HANDLE__) \ | |||
do{ \ | |||
if((__HANDLE__)->Lock == HAL_LOCKED) \ | |||
{ \ | |||
return HAL_BUSY; \ | |||
} \ | |||
else \ | |||
{ \ | |||
(__HANDLE__)->Lock = HAL_LOCKED; \ | |||
} \ | |||
}while (0) | |||
#define __HAL_UNLOCK(__HANDLE__) \ | |||
do{ \ | |||
(__HANDLE__)->Lock = HAL_UNLOCKED; \ | |||
}while (0) | |||
#endif /* USE_RTOS */ | |||
#if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ | |||
#ifndef __weak | |||
#define __weak __attribute__((weak)) | |||
#endif /* __weak */ | |||
#ifndef __packed | |||
#define __packed __attribute__((__packed__)) | |||
#endif /* __packed */ | |||
#endif /* __GNUC__ */ | |||
/* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */ | |||
#if defined (__GNUC__) && !defined (__CC_ARM) /* GNU Compiler */ | |||
#ifndef __ALIGN_END | |||
#define __ALIGN_END __attribute__ ((aligned (4))) | |||
#endif /* __ALIGN_END */ | |||
#ifndef __ALIGN_BEGIN | |||
#define __ALIGN_BEGIN | |||
#endif /* __ALIGN_BEGIN */ | |||
#else | |||
#ifndef __ALIGN_END | |||
#define __ALIGN_END | |||
#endif /* __ALIGN_END */ | |||
#ifndef __ALIGN_BEGIN | |||
#if defined (__CC_ARM) /* ARM Compiler */ | |||
#define __ALIGN_BEGIN __align(4) | |||
#elif defined (__ICCARM__) /* IAR Compiler */ | |||
#define __ALIGN_BEGIN | |||
#endif /* __CC_ARM */ | |||
#endif /* __ALIGN_BEGIN */ | |||
#endif /* __GNUC__ */ | |||
/** | |||
* @brief __RAM_FUNC definition | |||
*/ | |||
#if defined ( __CC_ARM ) | |||
/* ARM Compiler | |||
------------ | |||
RAM functions are defined using the toolchain options. | |||
Functions that are executed in RAM should reside in a separate source module. | |||
Using the 'Options for File' dialog you can simply change the 'Code / Const' | |||
area of a module to a memory space in physical RAM. | |||
Available memory areas are declared in the 'Target' tab of the 'Options for Target' | |||
dialog. | |||
*/ | |||
#define __RAM_FUNC | |||
#elif defined ( __ICCARM__ ) | |||
/* ICCARM Compiler | |||
--------------- | |||
RAM functions are defined using a specific toolchain keyword "__ramfunc". | |||
*/ | |||
#define __RAM_FUNC __ramfunc | |||
#elif defined ( __GNUC__ ) | |||
/* GNU Compiler | |||
------------ | |||
RAM functions are defined using a specific toolchain attribute | |||
"__attribute__((section(".RamFunc")))". | |||
*/ | |||
#define __RAM_FUNC __attribute__((section(".RamFunc"))) | |||
#endif | |||
/** | |||
* @brief __NOINLINE definition | |||
*/ | |||
#if defined ( __CC_ARM ) || defined ( __GNUC__ ) | |||
/* ARM & GNUCompiler | |||
---------------- | |||
*/ | |||
#define __NOINLINE __attribute__ ( (noinline) ) | |||
#elif defined ( __ICCARM__ ) | |||
/* ICCARM Compiler | |||
--------------- | |||
*/ | |||
#define __NOINLINE _Pragma("optimize = no_inline") | |||
#endif | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* ___STM32L1xx_HAL_DEF */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,652 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_hal_dma.h | |||
* @author MCD Application Team | |||
* @brief Header file of DMA HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef STM32L1xx_HAL_DMA_H | |||
#define STM32L1xx_HAL_DMA_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx_hal_def.h" | |||
/** @addtogroup STM32L1xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup DMA | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup DMA_Exported_Types DMA Exported Types | |||
* @{ | |||
*/ | |||
/** | |||
* @brief DMA Configuration Structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t Direction; /*!< Specifies if the data will be transferred from memory to peripheral, | |||
from memory to memory or from peripheral to memory. | |||
This parameter can be a value of @ref DMA_Data_transfer_direction */ | |||
uint32_t PeriphInc; /*!< Specifies whether the Peripheral address register should be incremented or not. | |||
This parameter can be a value of @ref DMA_Peripheral_incremented_mode */ | |||
uint32_t MemInc; /*!< Specifies whether the memory address register should be incremented or not. | |||
This parameter can be a value of @ref DMA_Memory_incremented_mode */ | |||
uint32_t PeriphDataAlignment; /*!< Specifies the Peripheral data width. | |||
This parameter can be a value of @ref DMA_Peripheral_data_size */ | |||
uint32_t MemDataAlignment; /*!< Specifies the Memory data width. | |||
This parameter can be a value of @ref DMA_Memory_data_size */ | |||
uint32_t Mode; /*!< Specifies the operation mode of the DMAy Channelx. | |||
This parameter can be a value of @ref DMA_mode | |||
@note The circular buffer mode cannot be used if the memory-to-memory | |||
data transfer is configured on the selected Channel */ | |||
uint32_t Priority; /*!< Specifies the software priority for the DMAy Channelx. | |||
This parameter can be a value of @ref DMA_Priority_level */ | |||
} DMA_InitTypeDef; | |||
/** | |||
* @brief HAL DMA State structures definition | |||
*/ | |||
typedef enum | |||
{ | |||
HAL_DMA_STATE_RESET = 0x00U, /*!< DMA not yet initialized or disabled */ | |||
HAL_DMA_STATE_READY = 0x01U, /*!< DMA initialized and ready for use */ | |||
HAL_DMA_STATE_BUSY = 0x02U, /*!< DMA process is ongoing */ | |||
HAL_DMA_STATE_TIMEOUT = 0x03U, /*!< DMA timeout state */ | |||
}HAL_DMA_StateTypeDef; | |||
/** | |||
* @brief HAL DMA Error Code structure definition | |||
*/ | |||
typedef enum | |||
{ | |||
HAL_DMA_FULL_TRANSFER = 0x00U, /*!< Full transfer */ | |||
HAL_DMA_HALF_TRANSFER = 0x01U /*!< Half Transfer */ | |||
}HAL_DMA_LevelCompleteTypeDef; | |||
/** | |||
* @brief HAL DMA Callback ID structure definition | |||
*/ | |||
typedef enum | |||
{ | |||
HAL_DMA_XFER_CPLT_CB_ID = 0x00U, /*!< Full transfer */ | |||
HAL_DMA_XFER_HALFCPLT_CB_ID = 0x01U, /*!< Half transfer */ | |||
HAL_DMA_XFER_ERROR_CB_ID = 0x02U, /*!< Error */ | |||
HAL_DMA_XFER_ABORT_CB_ID = 0x03U, /*!< Abort */ | |||
HAL_DMA_XFER_ALL_CB_ID = 0x04U /*!< All */ | |||
}HAL_DMA_CallbackIDTypeDef; | |||
/** | |||
* @brief DMA handle Structure definition | |||
*/ | |||
typedef struct __DMA_HandleTypeDef | |||
{ | |||
DMA_Channel_TypeDef *Instance; /*!< Register base address */ | |||
DMA_InitTypeDef Init; /*!< DMA communication parameters */ | |||
HAL_LockTypeDef Lock; /*!< DMA locking object */ | |||
__IO HAL_DMA_StateTypeDef State; /*!< DMA transfer state */ | |||
void *Parent; /*!< Parent object state */ | |||
void (* XferCpltCallback)(struct __DMA_HandleTypeDef * hdma); /*!< DMA transfer complete callback */ | |||
void (* XferHalfCpltCallback)(struct __DMA_HandleTypeDef * hdma); /*!< DMA Half transfer complete callback */ | |||
void (* XferErrorCallback)(struct __DMA_HandleTypeDef * hdma); /*!< DMA transfer error callback */ | |||
void (* XferAbortCallback)(struct __DMA_HandleTypeDef * hdma); /*!< DMA transfer abort callback */ | |||
__IO uint32_t ErrorCode; /*!< DMA Error code */ | |||
DMA_TypeDef *DmaBaseAddress; /*!< DMA Channel Base Address */ | |||
uint32_t ChannelIndex; /*!< DMA Channel Index */ | |||
}DMA_HandleTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup DMA_Exported_Constants DMA Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup DMA_Error_Code DMA Error Code | |||
* @{ | |||
*/ | |||
#define HAL_DMA_ERROR_NONE 0x00000000U /*!< No error */ | |||
#define HAL_DMA_ERROR_TE 0x00000001U /*!< Transfer error */ | |||
#define HAL_DMA_ERROR_NO_XFER 0x00000004U /*!< Abort requested with no Xfer ongoing */ | |||
#define HAL_DMA_ERROR_TIMEOUT 0x00000020U /*!< Timeout error */ | |||
#define HAL_DMA_ERROR_NOT_SUPPORTED 0x00000100U /*!< Not supported mode */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DMA_Data_transfer_direction DMA Data transfer direction | |||
* @{ | |||
*/ | |||
#define DMA_PERIPH_TO_MEMORY 0x00000000U /*!< Peripheral to memory direction */ | |||
#define DMA_MEMORY_TO_PERIPH DMA_CCR_DIR /*!< Memory to peripheral direction */ | |||
#define DMA_MEMORY_TO_MEMORY DMA_CCR_MEM2MEM /*!< Memory to memory direction */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DMA_Peripheral_incremented_mode DMA Peripheral incremented mode | |||
* @{ | |||
*/ | |||
#define DMA_PINC_ENABLE DMA_CCR_PINC /*!< Peripheral increment mode Enable */ | |||
#define DMA_PINC_DISABLE 0x00000000U /*!< Peripheral increment mode Disable */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DMA_Memory_incremented_mode DMA Memory incremented mode | |||
* @{ | |||
*/ | |||
#define DMA_MINC_ENABLE DMA_CCR_MINC /*!< Memory increment mode Enable */ | |||
#define DMA_MINC_DISABLE 0x00000000U /*!< Memory increment mode Disable */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DMA_Peripheral_data_size DMA Peripheral data size | |||
* @{ | |||
*/ | |||
#define DMA_PDATAALIGN_BYTE 0x00000000U /*!< Peripheral data alignment : Byte */ | |||
#define DMA_PDATAALIGN_HALFWORD DMA_CCR_PSIZE_0 /*!< Peripheral data alignment : HalfWord */ | |||
#define DMA_PDATAALIGN_WORD DMA_CCR_PSIZE_1 /*!< Peripheral data alignment : Word */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DMA_Memory_data_size DMA Memory data size | |||
* @{ | |||
*/ | |||
#define DMA_MDATAALIGN_BYTE 0x00000000U /*!< Memory data alignment : Byte */ | |||
#define DMA_MDATAALIGN_HALFWORD DMA_CCR_MSIZE_0 /*!< Memory data alignment : HalfWord */ | |||
#define DMA_MDATAALIGN_WORD DMA_CCR_MSIZE_1 /*!< Memory data alignment : Word */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DMA_mode DMA mode | |||
* @{ | |||
*/ | |||
#define DMA_NORMAL 0x00000000U /*!< Normal mode */ | |||
#define DMA_CIRCULAR DMA_CCR_CIRC /*!< Circular mode */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DMA_Priority_level DMA Priority level | |||
* @{ | |||
*/ | |||
#define DMA_PRIORITY_LOW 0x00000000U /*!< Priority level : Low */ | |||
#define DMA_PRIORITY_MEDIUM DMA_CCR_PL_0 /*!< Priority level : Medium */ | |||
#define DMA_PRIORITY_HIGH DMA_CCR_PL_1 /*!< Priority level : High */ | |||
#define DMA_PRIORITY_VERY_HIGH DMA_CCR_PL /*!< Priority level : Very_High */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DMA_interrupt_enable_definitions DMA interrupt enable definitions | |||
* @{ | |||
*/ | |||
#define DMA_IT_TC DMA_CCR_TCIE | |||
#define DMA_IT_HT DMA_CCR_HTIE | |||
#define DMA_IT_TE DMA_CCR_TEIE | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup DMA_flag_definitions DMA flag definitions | |||
* @{ | |||
*/ | |||
#define DMA_FLAG_GL1 DMA_ISR_GIF1 | |||
#define DMA_FLAG_TC1 DMA_ISR_TCIF1 | |||
#define DMA_FLAG_HT1 DMA_ISR_HTIF1 | |||
#define DMA_FLAG_TE1 DMA_ISR_TEIF1 | |||
#define DMA_FLAG_GL2 DMA_ISR_GIF2 | |||
#define DMA_FLAG_TC2 DMA_ISR_TCIF2 | |||
#define DMA_FLAG_HT2 DMA_ISR_HTIF2 | |||
#define DMA_FLAG_TE2 DMA_ISR_TEIF2 | |||
#define DMA_FLAG_GL3 DMA_ISR_GIF3 | |||
#define DMA_FLAG_TC3 DMA_ISR_TCIF3 | |||
#define DMA_FLAG_HT3 DMA_ISR_HTIF3 | |||
#define DMA_FLAG_TE3 DMA_ISR_TEIF3 | |||
#define DMA_FLAG_GL4 DMA_ISR_GIF4 | |||
#define DMA_FLAG_TC4 DMA_ISR_TCIF4 | |||
#define DMA_FLAG_HT4 DMA_ISR_HTIF4 | |||
#define DMA_FLAG_TE4 DMA_ISR_TEIF4 | |||
#define DMA_FLAG_GL5 DMA_ISR_GIF5 | |||
#define DMA_FLAG_TC5 DMA_ISR_TCIF5 | |||
#define DMA_FLAG_HT5 DMA_ISR_HTIF5 | |||
#define DMA_FLAG_TE5 DMA_ISR_TEIF5 | |||
#define DMA_FLAG_GL6 DMA_ISR_GIF6 | |||
#define DMA_FLAG_TC6 DMA_ISR_TCIF6 | |||
#define DMA_FLAG_HT6 DMA_ISR_HTIF6 | |||
#define DMA_FLAG_TE6 DMA_ISR_TEIF6 | |||
#define DMA_FLAG_GL7 DMA_ISR_GIF7 | |||
#define DMA_FLAG_TC7 DMA_ISR_TCIF7 | |||
#define DMA_FLAG_HT7 DMA_ISR_HTIF7 | |||
#define DMA_FLAG_TE7 DMA_ISR_TEIF7 | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macros -----------------------------------------------------------*/ | |||
/** @defgroup DMA_Exported_Macros DMA Exported Macros | |||
* @{ | |||
*/ | |||
/** @brief Reset DMA handle state. | |||
* @param __HANDLE__ DMA handle | |||
* @retval None | |||
*/ | |||
#define __HAL_DMA_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_DMA_STATE_RESET) | |||
/** | |||
* @brief Enable the specified DMA Channel. | |||
* @param __HANDLE__ DMA handle | |||
* @retval None | |||
*/ | |||
#define __HAL_DMA_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CCR |= DMA_CCR_EN) | |||
/** | |||
* @brief Disable the specified DMA Channel. | |||
* @param __HANDLE__ DMA handle | |||
* @retval None | |||
*/ | |||
#define __HAL_DMA_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CCR &= ~DMA_CCR_EN) | |||
/* Interrupt & Flag management */ | |||
#if defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || \ | |||
defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || \ | |||
defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) | |||
/** | |||
* @brief Return the current DMA Channel transfer complete flag. | |||
* @param __HANDLE__ DMA handle | |||
* @retval The specified transfer complete flag index. | |||
*/ | |||
#define __HAL_DMA_GET_TC_FLAG_INDEX(__HANDLE__) \ | |||
(((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_TC1 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel1))? DMA_FLAG_TC1 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_TC2 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel2))? DMA_FLAG_TC2 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_TC3 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel3))? DMA_FLAG_TC3 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_TC4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel4))? DMA_FLAG_TC4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_FLAG_TC5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel5))? DMA_FLAG_TC5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_FLAG_TC6 :\ | |||
DMA_FLAG_TC7) | |||
/** | |||
* @brief Return the current DMA Channel half transfer complete flag. | |||
* @param __HANDLE__ DMA handle | |||
* @retval The specified half transfer complete flag index. | |||
*/ | |||
#define __HAL_DMA_GET_HT_FLAG_INDEX(__HANDLE__)\ | |||
(((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_HT1 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel1))? DMA_FLAG_HT1 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_HT2 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel2))? DMA_FLAG_HT2 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_HT3 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel3))? DMA_FLAG_HT3 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_HT4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel4))? DMA_FLAG_HT4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_FLAG_HT5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel5))? DMA_FLAG_HT5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_FLAG_HT6 :\ | |||
DMA_FLAG_HT7) | |||
/** | |||
* @brief Return the current DMA Channel transfer error flag. | |||
* @param __HANDLE__ DMA handle | |||
* @retval The specified transfer error flag index. | |||
*/ | |||
#define __HAL_DMA_GET_TE_FLAG_INDEX(__HANDLE__)\ | |||
(((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_TE1 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel1))? DMA_FLAG_TE1 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_TE2 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel2))? DMA_FLAG_TE2 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_TE3 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel3))? DMA_FLAG_TE3 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_TE4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel4))? DMA_FLAG_TE4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_FLAG_TE5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel5))? DMA_FLAG_TE5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_FLAG_TE6 :\ | |||
DMA_FLAG_TE7) | |||
/** | |||
* @brief Return the current DMA Channel Global interrupt flag. | |||
* @param __HANDLE__ DMA handle | |||
* @retval The specified transfer error flag index. | |||
*/ | |||
#define __HAL_DMA_GET_GI_FLAG_INDEX(__HANDLE__)\ | |||
(((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_ISR_GIF1 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel1))? DMA_ISR_GIF1 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_ISR_GIF2 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel2))? DMA_ISR_GIF2 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_ISR_GIF3 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel3))? DMA_ISR_GIF3 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_ISR_GIF4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel4))? DMA_ISR_GIF4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_ISR_GIF5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA2_Channel5))? DMA_ISR_GIF5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_ISR_GIF6 :\ | |||
DMA_ISR_GIF7) | |||
/** | |||
* @brief Get the DMA Channel pending flags. | |||
* @param __HANDLE__ DMA handle | |||
* @param __FLAG__ Get the specified flag. | |||
* This parameter can be any combination of the following values: | |||
* @arg DMA_FLAG_TCx: Transfer complete flag | |||
* @arg DMA_FLAG_HTx: Half transfer complete flag | |||
* @arg DMA_FLAG_TEx: Transfer error flag | |||
* @arg DMA_FLAG_GLx: Global interrupt flag | |||
* Where x can be from 1 to 7 to select the DMA Channel x flag. | |||
* @retval The state of FLAG (SET or RESET). | |||
*/ | |||
#define __HAL_DMA_GET_FLAG(__HANDLE__, __FLAG__) (((uint32_t)((__HANDLE__)->Instance) > ((uint32_t)DMA1_Channel7))? \ | |||
(DMA2->ISR & (__FLAG__)) : (DMA1->ISR & (__FLAG__))) | |||
/** | |||
* @brief Clear the DMA Channel pending flags. | |||
* @param __HANDLE__ DMA handle | |||
* @param __FLAG__ specifies the flag to clear. | |||
* This parameter can be any combination of the following values: | |||
* @arg DMA_FLAG_TCx: Transfer complete flag | |||
* @arg DMA_FLAG_HTx: Half transfer complete flag | |||
* @arg DMA_FLAG_TEx: Transfer error flag | |||
* @arg DMA_FLAG_GLx: Global interrupt flag | |||
* Where x can be from 1 to 7 to select the DMA Channel x flag. | |||
* @retval None | |||
*/ | |||
#define __HAL_DMA_CLEAR_FLAG(__HANDLE__, __FLAG__) (((uint32_t)((__HANDLE__)->Instance) > ((uint32_t)DMA1_Channel7))? \ | |||
(DMA2->IFCR = (__FLAG__)) : (DMA1->IFCR = (__FLAG__))) | |||
#else | |||
/** | |||
* @brief Return the current DMA Channel transfer complete flag. | |||
* @param __HANDLE__ DMA handle | |||
* @retval The specified transfer complete flag index. | |||
*/ | |||
#define __HAL_DMA_GET_TC_FLAG_INDEX(__HANDLE__) \ | |||
(((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_TC1 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_TC2 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_TC3 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_TC4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_FLAG_TC5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_FLAG_TC6 :\ | |||
DMA_FLAG_TC7) | |||
/** | |||
* @brief Return the current DMA Channel half transfer complete flag. | |||
* @param __HANDLE__ DMA handle | |||
* @retval The specified half transfer complete flag index. | |||
*/ | |||
#define __HAL_DMA_GET_HT_FLAG_INDEX(__HANDLE__)\ | |||
(((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_HT1 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_HT2 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_HT3 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_HT4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_FLAG_HT5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_FLAG_HT6 :\ | |||
DMA_FLAG_HT7) | |||
/** | |||
* @brief Return the current DMA Channel transfer error flag. | |||
* @param __HANDLE__ DMA handle | |||
* @retval The specified transfer error flag index. | |||
*/ | |||
#define __HAL_DMA_GET_TE_FLAG_INDEX(__HANDLE__)\ | |||
(((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_FLAG_TE1 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_FLAG_TE2 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_FLAG_TE3 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_FLAG_TE4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_FLAG_TE5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_FLAG_TE6 :\ | |||
DMA_FLAG_TE7) | |||
/** | |||
* @brief Return the current DMA Channel Global interrupt flag. | |||
* @param __HANDLE__ DMA handle | |||
* @retval The specified transfer error flag index. | |||
*/ | |||
#define __HAL_DMA_GET_GI_FLAG_INDEX(__HANDLE__)\ | |||
(((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel1))? DMA_ISR_GIF1 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel2))? DMA_ISR_GIF2 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel3))? DMA_ISR_GIF3 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel4))? DMA_ISR_GIF4 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel5))? DMA_ISR_GIF5 :\ | |||
((uint32_t)((__HANDLE__)->Instance) == ((uint32_t)DMA1_Channel6))? DMA_ISR_GIF6 :\ | |||
DMA_ISR_GIF7) | |||
/** | |||
* @brief Get the DMA Channel pending flags. | |||
* @param __HANDLE__ DMA handle | |||
* @param __FLAG__ Get the specified flag. | |||
* This parameter can be any combination of the following values: | |||
* @arg DMA_FLAG_TCIFx: Transfer complete flag | |||
* @arg DMA_FLAG_HTIFx: Half transfer complete flag | |||
* @arg DMA_FLAG_TEIFx: Transfer error flag | |||
* @arg DMA_ISR_GIFx: Global interrupt flag | |||
* Where x can be from 1 to 7 to select the DMA Channel x flag. | |||
* @retval The state of FLAG (SET or RESET). | |||
*/ | |||
#define __HAL_DMA_GET_FLAG(__HANDLE__, __FLAG__) (DMA1->ISR & (__FLAG__)) | |||
/** | |||
* @brief Clear the DMA Channel pending flags. | |||
* @param __HANDLE__ DMA handle | |||
* @param __FLAG__ specifies the flag to clear. | |||
* This parameter can be any combination of the following values: | |||
* @arg DMA_FLAG_TCx: Transfer complete flag | |||
* @arg DMA_FLAG_HTx: Half transfer complete flag | |||
* @arg DMA_FLAG_TEx: Transfer error flag | |||
* @arg DMA_FLAG_GLx: Global interrupt flag | |||
* Where x can be from 1 to 7 to select the DMA Channel x flag. | |||
* @retval None | |||
*/ | |||
#define __HAL_DMA_CLEAR_FLAG(__HANDLE__, __FLAG__) (DMA1->IFCR = (__FLAG__)) | |||
#endif /* STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ | |||
/** | |||
* @brief Enable the specified DMA Channel interrupts. | |||
* @param __HANDLE__ DMA handle | |||
* @param __INTERRUPT__ specifies the DMA interrupt sources to be enabled or disabled. | |||
* This parameter can be any combination of the following values: | |||
* @arg DMA_IT_TC: Transfer complete interrupt mask | |||
* @arg DMA_IT_HT: Half transfer complete interrupt mask | |||
* @arg DMA_IT_TE: Transfer error interrupt mask | |||
* @retval None | |||
*/ | |||
#define __HAL_DMA_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CCR |= (__INTERRUPT__)) | |||
/** | |||
* @brief Disable the specified DMA Channel interrupts. | |||
* @param __HANDLE__ DMA handle | |||
* @param __INTERRUPT__ specifies the DMA interrupt sources to be enabled or disabled. | |||
* This parameter can be any combination of the following values: | |||
* @arg DMA_IT_TC: Transfer complete interrupt mask | |||
* @arg DMA_IT_HT: Half transfer complete interrupt mask | |||
* @arg DMA_IT_TE: Transfer error interrupt mask | |||
* @retval None | |||
*/ | |||
#define __HAL_DMA_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CCR &= ~(__INTERRUPT__)) | |||
/** | |||
* @brief Check whether the specified DMA Channel interrupt is enabled or not. | |||
* @param __HANDLE__ DMA handle | |||
* @param __INTERRUPT__ specifies the DMA interrupt source to check. | |||
* This parameter can be one of the following values: | |||
* @arg DMA_IT_TC: Transfer complete interrupt mask | |||
* @arg DMA_IT_HT: Half transfer complete interrupt mask | |||
* @arg DMA_IT_TE: Transfer error interrupt mask | |||
* @retval The state of DMA_IT (SET or RESET). | |||
*/ | |||
#define __HAL_DMA_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CCR & (__INTERRUPT__))) | |||
/** | |||
* @brief Return the number of remaining data units in the current DMA Channel transfer. | |||
* @param __HANDLE__ DMA handle | |||
* @retval The number of remaining data units in the current DMA Channel transfer. | |||
*/ | |||
#define __HAL_DMA_GET_COUNTER(__HANDLE__) ((__HANDLE__)->Instance->CNDTR) | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup DMA_Exported_Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup DMA_Exported_Functions_Group1 | |||
* @{ | |||
*/ | |||
/* Initialization and de-initialization functions *****************************/ | |||
HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma); | |||
HAL_StatusTypeDef HAL_DMA_DeInit (DMA_HandleTypeDef *hdma); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup DMA_Exported_Functions_Group2 | |||
* @{ | |||
*/ | |||
/* IO operation functions *****************************************************/ | |||
HAL_StatusTypeDef HAL_DMA_Start (DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength); | |||
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength); | |||
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma); | |||
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma); | |||
HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, HAL_DMA_LevelCompleteTypeDef CompleteLevel, uint32_t Timeout); | |||
void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma); | |||
HAL_StatusTypeDef HAL_DMA_RegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID, void (* pCallback)( DMA_HandleTypeDef * _hdma)); | |||
HAL_StatusTypeDef HAL_DMA_UnRegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup DMA_Exported_Functions_Group3 | |||
* @{ | |||
*/ | |||
/* Peripheral State and Error functions ***************************************/ | |||
HAL_DMA_StateTypeDef HAL_DMA_GetState(DMA_HandleTypeDef *hdma); | |||
uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/** @defgroup DMA_Private_Macros DMA Private Macros | |||
* @{ | |||
*/ | |||
#define IS_DMA_DIRECTION(DIRECTION) (((DIRECTION) == DMA_PERIPH_TO_MEMORY ) || \ | |||
((DIRECTION) == DMA_MEMORY_TO_PERIPH) || \ | |||
((DIRECTION) == DMA_MEMORY_TO_MEMORY)) | |||
#define IS_DMA_BUFFER_SIZE(SIZE) (((SIZE) >= 0x1U) && ((SIZE) < 0x10000U)) | |||
#define IS_DMA_PERIPHERAL_INC_STATE(STATE) (((STATE) == DMA_PINC_ENABLE) || \ | |||
((STATE) == DMA_PINC_DISABLE)) | |||
#define IS_DMA_MEMORY_INC_STATE(STATE) (((STATE) == DMA_MINC_ENABLE) || \ | |||
((STATE) == DMA_MINC_DISABLE)) | |||
#define IS_DMA_PERIPHERAL_DATA_SIZE(SIZE) (((SIZE) == DMA_PDATAALIGN_BYTE) || \ | |||
((SIZE) == DMA_PDATAALIGN_HALFWORD) || \ | |||
((SIZE) == DMA_PDATAALIGN_WORD)) | |||
#define IS_DMA_MEMORY_DATA_SIZE(SIZE) (((SIZE) == DMA_MDATAALIGN_BYTE) || \ | |||
((SIZE) == DMA_MDATAALIGN_HALFWORD) || \ | |||
((SIZE) == DMA_MDATAALIGN_WORD )) | |||
#define IS_DMA_MODE(MODE) (((MODE) == DMA_NORMAL ) || \ | |||
((MODE) == DMA_CIRCULAR)) | |||
#define IS_DMA_PRIORITY(PRIORITY) (((PRIORITY) == DMA_PRIORITY_LOW ) || \ | |||
((PRIORITY) == DMA_PRIORITY_MEDIUM) || \ | |||
((PRIORITY) == DMA_PRIORITY_HIGH) || \ | |||
((PRIORITY) == DMA_PRIORITY_VERY_HIGH)) | |||
/** | |||
* @} | |||
*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* STM32L1xx_HAL_DMA_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,409 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_hal_flash.h | |||
* @author MCD Application Team | |||
* @brief Header file of Flash HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32L1xx_HAL_FLASH_H | |||
#define __STM32L1xx_HAL_FLASH_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx_hal_def.h" | |||
/** @addtogroup STM32L1xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup FLASH | |||
* @{ | |||
*/ | |||
/** @addtogroup FLASH_Private_Constants | |||
* @{ | |||
*/ | |||
#define FLASH_TIMEOUT_VALUE (50000U) /* 50 s */ | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup FLASH_Private_Macros | |||
* @{ | |||
*/ | |||
#define IS_FLASH_TYPEPROGRAM(_VALUE_) ((_VALUE_) == FLASH_TYPEPROGRAM_WORD) | |||
#define IS_FLASH_LATENCY(__LATENCY__) (((__LATENCY__) == FLASH_LATENCY_0) || \ | |||
((__LATENCY__) == FLASH_LATENCY_1)) | |||
/** | |||
* @} | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup FLASH_Exported_Types FLASH Exported Types | |||
* @{ | |||
*/ | |||
/** | |||
* @brief FLASH Procedure structure definition | |||
*/ | |||
typedef enum | |||
{ | |||
FLASH_PROC_NONE = 0U, | |||
FLASH_PROC_PAGEERASE = 1U, | |||
FLASH_PROC_PROGRAM = 2U, | |||
} FLASH_ProcedureTypeDef; | |||
/** | |||
* @brief FLASH handle Structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
__IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*!< Internal variable to indicate which procedure is ongoing or not in IT context */ | |||
__IO uint32_t NbPagesToErase; /*!< Internal variable to save the remaining sectors to erase in IT context*/ | |||
__IO uint32_t Address; /*!< Internal variable to save address selected for program or erase */ | |||
__IO uint32_t Page; /*!< Internal variable to define the current page which is erasing */ | |||
HAL_LockTypeDef Lock; /*!< FLASH locking object */ | |||
__IO uint32_t ErrorCode; /*!< FLASH error code | |||
This parameter can be a value of @ref FLASH_Error_Codes */ | |||
} FLASH_ProcessTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup FLASH_Exported_Constants FLASH Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup FLASH_Error_Codes FLASH Error Codes | |||
* @{ | |||
*/ | |||
#define HAL_FLASH_ERROR_NONE 0x00U /*!< No error */ | |||
#define HAL_FLASH_ERROR_PGA 0x01U /*!< Programming alignment error */ | |||
#define HAL_FLASH_ERROR_WRP 0x02U /*!< Write protection error */ | |||
#define HAL_FLASH_ERROR_OPTV 0x04U /*!< Option validity error */ | |||
#define HAL_FLASH_ERROR_SIZE 0x08U /*!< */ | |||
#define HAL_FLASH_ERROR_RD 0x10U /*!< Read protected error */ | |||
#define HAL_FLASH_ERROR_OPTVUSR 0x20U /*!< Option UserValidity Error. */ | |||
#define HAL_FLASH_ERROR_OPERATION 0x40U /*!< Not used */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASH_Page_Size FLASH size information | |||
* @{ | |||
*/ | |||
#define FLASH_SIZE (uint32_t)((*((uint32_t *)FLASHSIZE_BASE)&0xFFFFU) * 1024U) | |||
#define FLASH_PAGE_SIZE (256U) /*!< FLASH Page Size in bytes */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASH_Type_Program FLASH Type Program | |||
* @{ | |||
*/ | |||
#define FLASH_TYPEPROGRAM_WORD (0x02U) /*!<Program a word (32-bit) at a specified address.*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASH_Latency FLASH Latency | |||
* @{ | |||
*/ | |||
#define FLASH_LATENCY_0 (0x00000000U) /*!< FLASH Zero Latency cycle */ | |||
#define FLASH_LATENCY_1 FLASH_ACR_LATENCY /*!< FLASH One Latency cycle */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASH_Interrupts FLASH Interrupts | |||
* @{ | |||
*/ | |||
#define FLASH_IT_EOP FLASH_PECR_EOPIE /*!< End of programming interrupt source */ | |||
#define FLASH_IT_ERR FLASH_PECR_ERRIE /*!< Error interrupt source */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASH_Flags FLASH Flags | |||
* @{ | |||
*/ | |||
#define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */ | |||
#define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of Programming flag */ | |||
#define FLASH_FLAG_ENDHV FLASH_SR_ENDHV /*!< FLASH End of High Voltage flag */ | |||
#define FLASH_FLAG_READY FLASH_SR_READY /*!< FLASH Ready flag after low power mode */ | |||
#define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protected error flag */ | |||
#define FLASH_FLAG_PGAERR FLASH_SR_PGAERR /*!< FLASH Programming Alignment error flag */ | |||
#define FLASH_FLAG_SIZERR FLASH_SR_SIZERR /*!< FLASH Size error flag */ | |||
#define FLASH_FLAG_OPTVERR FLASH_SR_OPTVERR /*!< FLASH Option Validity error flag */ | |||
/* Cat2 & Cat3*/ | |||
#if defined(FLASH_SR_RDERR) | |||
#define FLASH_FLAG_RDERR FLASH_SR_RDERR /*!< Read protected error flag */ | |||
#endif /* FLASH_SR_RDERR */ | |||
/* Cat3, Cat4 & Cat5*/ | |||
#if defined(FLASH_SR_OPTVERRUSR) | |||
#define FLASH_FLAG_OPTVERRUSR FLASH_SR_OPTVERRUSR /*!< FLASH Option User Validity error flag */ | |||
#endif /* FLASH_SR_OPTVERRUSR */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASH_Keys FLASH Keys | |||
* @{ | |||
*/ | |||
#define FLASH_PDKEY1 (0x04152637U) /*!< Flash power down key1 */ | |||
#define FLASH_PDKEY2 (0xFAFBFCFDU) /*!< Flash power down key2: used with FLASH_PDKEY1 | |||
to unlock the RUN_PD bit in FLASH_ACR */ | |||
#define FLASH_PEKEY1 (0x89ABCDEFU) /*!< Flash program erase key1 */ | |||
#define FLASH_PEKEY2 (0x02030405U) /*!< Flash program erase key: used with FLASH_PEKEY2 | |||
to unlock the write access to the FLASH_PECR register and | |||
data EEPROM */ | |||
#define FLASH_PRGKEY1 (0x8C9DAEBFU) /*!< Flash program memory key1 */ | |||
#define FLASH_PRGKEY2 (0x13141516U) /*!< Flash program memory key2: used with FLASH_PRGKEY2 | |||
to unlock the program memory */ | |||
#define FLASH_OPTKEY1 (0xFBEAD9C8U) /*!< Flash option key1 */ | |||
#define FLASH_OPTKEY2 (0x24252627U) /*!< Flash option key2: used with FLASH_OPTKEY1 to | |||
unlock the write access to the option byte block */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/** @defgroup FLASH_Exported_Macros FLASH Exported Macros | |||
* @brief macros to control FLASH features | |||
* @{ | |||
*/ | |||
/** @defgroup FLASH_Interrupt FLASH Interrupts | |||
* @brief macros to handle FLASH interrupts | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Enable the specified FLASH interrupt. | |||
* @param __INTERRUPT__ FLASH interrupt | |||
* This parameter can be any combination of the following values: | |||
* @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt | |||
* @arg @ref FLASH_IT_ERR Error Interrupt | |||
* @retval none | |||
*/ | |||
#define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) SET_BIT((FLASH->PECR), (__INTERRUPT__)) | |||
/** | |||
* @brief Disable the specified FLASH interrupt. | |||
* @param __INTERRUPT__ FLASH interrupt | |||
* This parameter can be any combination of the following values: | |||
* @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt | |||
* @arg @ref FLASH_IT_ERR Error Interrupt | |||
* @retval none | |||
*/ | |||
#define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) CLEAR_BIT((FLASH->PECR), (uint32_t)(__INTERRUPT__)) | |||
/** | |||
* @brief Get the specified FLASH flag status. | |||
* @param __FLAG__ specifies the FLASH flag to check. | |||
* This parameter can be one of the following values: | |||
* @arg @ref FLASH_FLAG_BSY FLASH Busy flag | |||
* @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag | |||
* @arg @ref FLASH_FLAG_ENDHV FLASH End of High Voltage flag | |||
* @arg @ref FLASH_FLAG_READY FLASH Ready flag after low power mode | |||
* @arg @ref FLASH_FLAG_PGAERR FLASH Programming Alignment error flag | |||
* @arg @ref FLASH_FLAG_SIZERR FLASH Size error flag | |||
* @arg @ref FLASH_FLAG_OPTVERR FLASH Option validity error error flag | |||
@if STM32L100xB | |||
@elif STM32L100xBA | |||
* @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP) | |||
@elif STM32L151xB | |||
@elif STM32L151xBA | |||
* @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP) | |||
@elif STM32L152xB | |||
@elif STM32L152xBA | |||
* @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP) | |||
@elif STM32L100xC | |||
* @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP) | |||
* @arg @ref FLASH_FLAG_OPTVERRUSR FLASH Option User validity error | |||
@elif STM32L151xC | |||
* @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP) | |||
* @arg @ref FLASH_FLAG_OPTVERRUSR FLASH Option User validity error | |||
@elif STM32L152xC | |||
* @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP) | |||
* @arg @ref FLASH_FLAG_OPTVERRUSR FLASH Option User validity error | |||
@elif STM32L162xC | |||
* @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP) | |||
* @arg @ref FLASH_FLAG_OPTVERRUSR FLASH Option User validity error | |||
@else | |||
* @arg @ref FLASH_FLAG_OPTVERRUSR FLASH Option User validity error | |||
@endif | |||
* @arg @ref FLASH_FLAG_WRPERR FLASH Write protected error flag | |||
* @retval The new state of __FLAG__ (SET or RESET). | |||
*/ | |||
#define __HAL_FLASH_GET_FLAG(__FLAG__) (((FLASH->SR) & (__FLAG__)) == (__FLAG__)) | |||
/** | |||
* @brief Clear the specified FLASH flag. | |||
* @param __FLAG__ specifies the FLASH flags to clear. | |||
* This parameter can be any combination of the following values: | |||
* @arg @ref FLASH_FLAG_EOP FLASH End of Operation flag | |||
* @arg @ref FLASH_FLAG_PGAERR FLASH Programming Alignment error flag | |||
* @arg @ref FLASH_FLAG_SIZERR FLASH Size error flag | |||
* @arg @ref FLASH_FLAG_OPTVERR FLASH Option validity error error flag | |||
@if STM32L100xB | |||
@elif STM32L100xBA | |||
* @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP) | |||
@elif STM32L151xB | |||
@elif STM32L151xBA | |||
* @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP) | |||
@elif STM32L152xB | |||
@elif STM32L152xBA | |||
* @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP) | |||
@elif STM32L100xC | |||
* @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP) | |||
* @arg @ref FLASH_FLAG_OPTVERRUSR FLASH Option User validity error | |||
@elif STM32L151xC | |||
* @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP) | |||
* @arg @ref FLASH_FLAG_OPTVERRUSR FLASH Option User validity error | |||
@elif STM32L152xC | |||
* @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP) | |||
* @arg @ref FLASH_FLAG_OPTVERRUSR FLASH Option User validity error | |||
@elif STM32L162xC | |||
* @arg @ref FLASH_FLAG_RDERR FLASH Read Protection error flag (PCROP) | |||
* @arg @ref FLASH_FLAG_OPTVERRUSR FLASH Option User validity error | |||
@else | |||
* @arg @ref FLASH_FLAG_OPTVERRUSR FLASH Option User validity error | |||
@endif | |||
* @arg @ref FLASH_FLAG_WRPERR FLASH Write protected error flag | |||
* @retval none | |||
*/ | |||
#define __HAL_FLASH_CLEAR_FLAG(__FLAG__) ((FLASH->SR) = (__FLAG__)) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Include FLASH HAL Extended module */ | |||
#include "stm32l1xx_hal_flash_ex.h" | |||
#include "stm32l1xx_hal_flash_ramfunc.h" | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup FLASH_Exported_Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup FLASH_Exported_Functions_Group1 | |||
* @{ | |||
*/ | |||
/* IO operation functions *****************************************************/ | |||
HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint32_t Data); | |||
HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint32_t Data); | |||
/* FLASH IRQ handler function */ | |||
void HAL_FLASH_IRQHandler(void); | |||
/* Callbacks in non blocking modes */ | |||
void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue); | |||
void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup FLASH_Exported_Functions_Group2 | |||
* @{ | |||
*/ | |||
/* Peripheral Control functions ***********************************************/ | |||
HAL_StatusTypeDef HAL_FLASH_Unlock(void); | |||
HAL_StatusTypeDef HAL_FLASH_Lock(void); | |||
HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void); | |||
HAL_StatusTypeDef HAL_FLASH_OB_Lock(void); | |||
HAL_StatusTypeDef HAL_FLASH_OB_Launch(void); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup FLASH_Exported_Functions_Group3 | |||
* @{ | |||
*/ | |||
/* Peripheral State and Error functions ***************************************/ | |||
uint32_t HAL_FLASH_GetError(void); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private function -------------------------------------------------*/ | |||
/** @addtogroup FLASH_Private_Functions | |||
* @{ | |||
*/ | |||
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32L1xx_HAL_FLASH_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | |||
@@ -0,0 +1,968 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_hal_flash_ex.h | |||
* @author MCD Application Team | |||
* @brief Header file of Flash HAL Extended module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32L1xx_HAL_FLASH_EX_H | |||
#define __STM32L1xx_HAL_FLASH_EX_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx_hal_def.h" | |||
/** @addtogroup STM32L1xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup FLASHEx | |||
* @{ | |||
*/ | |||
/** @addtogroup FLASHEx_Private_Constants | |||
* @{ | |||
*/ | |||
#if defined(FLASH_SR_RDERR) && defined(FLASH_SR_OPTVERRUSR) | |||
#define FLASH_FLAG_MASK ( FLASH_FLAG_EOP | FLASH_FLAG_ENDHV | FLASH_FLAG_WRPERR | \ | |||
FLASH_FLAG_OPTVERR | FLASH_FLAG_PGAERR | FLASH_FLAG_SIZERR | \ | |||
FLASH_FLAG_OPTVERRUSR | FLASH_FLAG_RDERR) | |||
#elif defined(FLASH_SR_RDERR) | |||
#define FLASH_FLAG_MASK ( FLASH_FLAG_EOP | FLASH_FLAG_ENDHV | FLASH_FLAG_WRPERR | \ | |||
FLASH_FLAG_OPTVERR | FLASH_FLAG_PGAERR | FLASH_FLAG_SIZERR | \ | |||
FLASH_FLAG_RDERR) | |||
#elif defined(FLASH_SR_OPTVERRUSR) | |||
#define FLASH_FLAG_MASK ( FLASH_FLAG_EOP | FLASH_FLAG_ENDHV | FLASH_FLAG_WRPERR | \ | |||
FLASH_FLAG_OPTVERR | FLASH_FLAG_PGAERR | FLASH_FLAG_SIZERR | \ | |||
FLASH_FLAG_OPTVERRUSR) | |||
#else | |||
#define FLASH_FLAG_MASK ( FLASH_FLAG_EOP | FLASH_FLAG_ENDHV | FLASH_FLAG_WRPERR | \ | |||
FLASH_FLAG_OPTVERR | FLASH_FLAG_PGAERR | FLASH_FLAG_SIZERR) | |||
#endif /* FLASH_SR_RDERR & FLASH_SR_OPTVERRUSR */ | |||
#if defined(STM32L100xB) || defined(STM32L151xB) || defined(STM32L152xB) || defined(STM32L100xBA) \ | |||
|| defined(STM32L151xBA) || defined(STM32L152xBA) | |||
/******* Devices with FLASH 128K *******/ | |||
#define FLASH_NBPAGES_MAX 512U /* 512 pages from page 0 to page 511U */ | |||
#elif defined(STM32L100xC) || defined(STM32L151xC) || defined(STM32L152xC) || defined(STM32L162xC) \ | |||
|| defined(STM32L151xCA) || defined(STM32L152xCA) || defined(STM32L162xCA) | |||
/******* Devices with FLASH 256K *******/ | |||
#define FLASH_NBPAGES_MAX 1025U /* 1025 pages from page 0 to page 1024U */ | |||
#elif defined(STM32L151xD) || defined(STM32L151xDX) || defined(STM32L152xD) || defined(STM32L152xDX) \ | |||
|| defined(STM32L162xD) || defined(STM32L162xDX) | |||
/******* Devices with FLASH 384K *******/ | |||
#define FLASH_NBPAGES_MAX 1536U /* 1536 pages from page 0 to page 1535U */ | |||
#elif defined(STM32L151xE) || defined(STM32L152xE) || defined(STM32L162xE) | |||
/******* Devices with FLASH 512K *******/ | |||
#define FLASH_NBPAGES_MAX 2048U /* 2048 pages from page 0 to page 2047U */ | |||
#endif /* STM32L100xB || STM32L151xB || STM32L152xB || STM32L100xBA || STM32L151xBA || STM32L152xBA */ | |||
#define WRP_MASK_LOW (0x0000FFFFU) | |||
#define WRP_MASK_HIGH (0xFFFF0000U) | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup FLASHEx_Private_Macros | |||
* @{ | |||
*/ | |||
#define IS_FLASH_TYPEERASE(__VALUE__) (((__VALUE__) == FLASH_TYPEERASE_PAGES)) | |||
#define IS_OPTIONBYTE(__VALUE__) (((__VALUE__) <= (OPTIONBYTE_WRP|OPTIONBYTE_RDP|OPTIONBYTE_USER|OPTIONBYTE_BOR))) | |||
#define IS_WRPSTATE(__VALUE__) (((__VALUE__) == OB_WRPSTATE_DISABLE) || \ | |||
((__VALUE__) == OB_WRPSTATE_ENABLE)) | |||
#define IS_OB_WRP(__PAGE__) (((__PAGE__) != 0x0000000U)) | |||
#define IS_OB_RDP(__LEVEL__) (((__LEVEL__) == OB_RDP_LEVEL_0) ||\ | |||
((__LEVEL__) == OB_RDP_LEVEL_1) ||\ | |||
((__LEVEL__) == OB_RDP_LEVEL_2)) | |||
#define IS_OB_BOR_LEVEL(__LEVEL__) (((__LEVEL__) == OB_BOR_OFF) || \ | |||
((__LEVEL__) == OB_BOR_LEVEL1) || \ | |||
((__LEVEL__) == OB_BOR_LEVEL2) || \ | |||
((__LEVEL__) == OB_BOR_LEVEL3) || \ | |||
((__LEVEL__) == OB_BOR_LEVEL4) || \ | |||
((__LEVEL__) == OB_BOR_LEVEL5)) | |||
#define IS_OB_IWDG_SOURCE(__SOURCE__) (((__SOURCE__) == OB_IWDG_SW) || ((__SOURCE__) == OB_IWDG_HW)) | |||
#define IS_OB_STOP_SOURCE(__SOURCE__) (((__SOURCE__) == OB_STOP_NORST) || ((__SOURCE__) == OB_STOP_RST)) | |||
#define IS_OB_STDBY_SOURCE(__SOURCE__) (((__SOURCE__) == OB_STDBY_NORST) || ((__SOURCE__) == OB_STDBY_RST)) | |||
#if defined(FLASH_OBR_SPRMOD) && defined(FLASH_OBR_nRST_BFB2) | |||
#define IS_OBEX(__VALUE__) (((__VALUE__) == OPTIONBYTE_PCROP) || ((__VALUE__) == OPTIONBYTE_BOOTCONFIG)) | |||
#elif defined(FLASH_OBR_SPRMOD) && !defined(FLASH_OBR_nRST_BFB2) | |||
#define IS_OBEX(__VALUE__) ((__VALUE__) == OPTIONBYTE_PCROP) | |||
#elif !defined(FLASH_OBR_SPRMOD) && defined(FLASH_OBR_nRST_BFB2) | |||
#define IS_OBEX(__VALUE__) ((__VALUE__) == OPTIONBYTE_BOOTCONFIG) | |||
#endif /* FLASH_OBR_SPRMOD && FLASH_OBR_nRST_BFB2 */ | |||
#if defined(FLASH_OBR_SPRMOD) | |||
#define IS_PCROPSTATE(__VALUE__) (((__VALUE__) == OB_PCROP_STATE_DISABLE) || \ | |||
((__VALUE__) == OB_PCROP_STATE_ENABLE)) | |||
#define IS_OB_PCROP(__PAGE__) (((__PAGE__) != 0x0000000U)) | |||
#endif /* FLASH_OBR_SPRMOD */ | |||
#if defined(FLASH_OBR_nRST_BFB2) | |||
#define IS_OB_BOOT_BANK(__BANK__) (((__BANK__) == OB_BOOT_BANK2) || ((__BANK__) == OB_BOOT_BANK1)) | |||
#endif /* FLASH_OBR_nRST_BFB2 */ | |||
#define IS_TYPEERASEDATA(__VALUE__) (((__VALUE__) == FLASH_TYPEERASEDATA_BYTE) || \ | |||
((__VALUE__) == FLASH_TYPEERASEDATA_HALFWORD) || \ | |||
((__VALUE__) == FLASH_TYPEERASEDATA_WORD)) | |||
#define IS_TYPEPROGRAMDATA(__VALUE__) (((__VALUE__) == FLASH_TYPEPROGRAMDATA_BYTE) || \ | |||
((__VALUE__) == FLASH_TYPEPROGRAMDATA_HALFWORD) || \ | |||
((__VALUE__) == FLASH_TYPEPROGRAMDATA_WORD) || \ | |||
((__VALUE__) == FLASH_TYPEPROGRAMDATA_FASTBYTE) || \ | |||
((__VALUE__) == FLASH_TYPEPROGRAMDATA_FASTHALFWORD) || \ | |||
((__VALUE__) == FLASH_TYPEPROGRAMDATA_FASTWORD)) | |||
/** @defgroup FLASHEx_Address FLASHEx Address | |||
* @{ | |||
*/ | |||
#define IS_FLASH_DATA_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= FLASH_EEPROM_BASE) && ((__ADDRESS__) <= FLASH_EEPROM_END)) | |||
#if defined(STM32L100xB) || defined(STM32L151xB) || defined(STM32L152xB) || defined(STM32L100xBA) \ | |||
|| defined(STM32L151xBA) || defined(STM32L152xBA) || defined(STM32L100xC) || defined(STM32L151xC) \ | |||
|| defined(STM32L152xC) || defined(STM32L162xC) || defined(STM32L151xCA) || defined(STM32L152xCA) \ | |||
|| defined(STM32L162xCA) | |||
#define IS_FLASH_PROGRAM_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= FLASH_BASE) && ((__ADDRESS__) <= FLASH_END)) | |||
#else /*STM32L151xD || STM32L152xD || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ | |||
#define IS_FLASH_PROGRAM_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= FLASH_BASE) && ((__ADDRESS__) <= FLASH_BANK2_END)) | |||
#define IS_FLASH_PROGRAM_BANK1_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= FLASH_BASE) && ((__ADDRESS__) <= FLASH_BANK1_END)) | |||
#define IS_FLASH_PROGRAM_BANK2_ADDRESS(__ADDRESS__) (((__ADDRESS__) >= FLASH_BANK2_BASE) && ((__ADDRESS__) <= FLASH_BANK2_END)) | |||
#endif /* STM32L100xB || STM32L151xB || STM32L152xB || (...) || STM32L151xCA || STM32L152xCA || STM32L162xCA */ | |||
#define IS_NBPAGES(__PAGES__) (((__PAGES__) >= 1U) && ((__PAGES__) <= FLASH_NBPAGES_MAX)) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup FLASHEx_Exported_Types FLASHEx Exported Types | |||
* @{ | |||
*/ | |||
/** | |||
* @brief FLASH Erase structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t TypeErase; /*!< TypeErase: Page Erase only. | |||
This parameter can be a value of @ref FLASHEx_Type_Erase */ | |||
uint32_t PageAddress; /*!< PageAddress: Initial FLASH address to be erased | |||
This parameter must be a value belonging to FLASH Programm address (depending on the devices) */ | |||
uint32_t NbPages; /*!< NbPages: Number of pages to be erased. | |||
This parameter must be a value between 1 and (max number of pages - value of Initial page)*/ | |||
} FLASH_EraseInitTypeDef; | |||
/** | |||
* @brief FLASH Option Bytes PROGRAM structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t OptionType; /*!< OptionType: Option byte to be configured. | |||
This parameter can be a value of @ref FLASHEx_Option_Type */ | |||
uint32_t WRPState; /*!< WRPState: Write protection activation or deactivation. | |||
This parameter can be a value of @ref FLASHEx_WRP_State */ | |||
uint32_t WRPSector0To31; /*!< WRPSector0To31: specifies the sector(s) which are write protected between Sector 0 to 31 | |||
This parameter can be a combination of @ref FLASHEx_Option_Bytes_Write_Protection1 */ | |||
#if defined(STM32L100xC) || defined(STM32L151xC) || defined(STM32L152xC) || defined(STM32L162xC) \ | |||
|| defined(STM32L151xCA) || defined(STM32L151xD) || defined(STM32L151xDX) || defined(STM32L152xCA) \ | |||
|| defined(STM32L152xD) || defined(STM32L152xDX) || defined(STM32L162xCA) || defined(STM32L162xD) \ | |||
|| defined(STM32L162xDX) || defined(STM32L151xE) || defined(STM32L152xE) || defined(STM32L162xE) | |||
uint32_t WRPSector32To63; /*!< WRPSector32To63: specifies the sector(s) which are write protected between Sector 32 to 63 | |||
This parameter can be a combination of @ref FLASHEx_Option_Bytes_Write_Protection2 */ | |||
#endif /* STM32L100xC || STM32L151xC || STM32L152xC || (...) || STM32L151xE || STM32L152xE || STM32L162xE */ | |||
#if defined(STM32L151xD) || defined(STM32L151xDX) || defined(STM32L152xD) || defined(STM32L152xDX) \ | |||
|| defined(STM32L162xD) || defined(STM32L162xDX) || defined(STM32L151xE) || defined(STM32L152xE) \ | |||
|| defined(STM32L162xE) | |||
uint32_t WRPSector64To95; /*!< WRPSector64to95: specifies the sector(s) which are write protected between Sector 64 to 95 | |||
This parameter can be a combination of @ref FLASHEx_Option_Bytes_Write_Protection3 */ | |||
#endif /* STM32L151xD || STM32L152xD || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ | |||
#if defined(STM32L151xE) || defined(STM32L152xE) || defined(STM32L162xE) || defined(STM32L151xDX) \ | |||
|| defined(STM32L152xDX) || defined(STM32L162xDX) | |||
uint32_t WRPSector96To127; /*!< WRPSector96To127: specifies the sector(s) which are write protected between Sector 96 to 127 or | |||
Sectors 96 to 111 for STM32L1xxxDX devices. | |||
This parameter can be a combination of @ref FLASHEx_Option_Bytes_Write_Protection4 */ | |||
#endif /* STM32L151xE || STM32L152xE || STM32L162xE || STM32L151xDX || ... */ | |||
uint8_t RDPLevel; /*!< RDPLevel: Set the read protection level. | |||
This parameter can be a value of @ref FLASHEx_Option_Bytes_Read_Protection */ | |||
uint8_t BORLevel; /*!< BORLevel: Set the BOR Level. | |||
This parameter can be a value of @ref FLASHEx_Option_Bytes_BOR_Level */ | |||
uint8_t USERConfig; /*!< USERConfig: Program the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY. | |||
This parameter can be a combination of @ref FLASHEx_Option_Bytes_IWatchdog, | |||
@ref FLASHEx_Option_Bytes_nRST_STOP and @ref FLASHEx_Option_Bytes_nRST_STDBY*/ | |||
} FLASH_OBProgramInitTypeDef; | |||
#if defined(FLASH_OBR_SPRMOD) || defined(FLASH_OBR_nRST_BFB2) | |||
/** | |||
* @brief FLASH Advanced Option Bytes Program structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t OptionType; /*!< OptionType: Option byte to be configured for extension . | |||
This parameter can be a value of @ref FLASHEx_OptionAdv_Type */ | |||
#if defined(FLASH_OBR_SPRMOD) | |||
uint32_t PCROPState; /*!< PCROPState: PCROP activation or deactivation. | |||
This parameter can be a value of @ref FLASHEx_PCROP_State */ | |||
uint32_t PCROPSector0To31; /*!< PCROPSector0To31: specifies the sector(s) set for PCROP | |||
This parameter can be a value of @ref FLASHEx_Option_Bytes_PC_ReadWrite_Protection1 */ | |||
#if defined(STM32L151xC) || defined(STM32L152xC) || defined(STM32L162xC) | |||
uint32_t PCROPSector32To63; /*!< PCROPSector32To63: specifies the sector(s) set for PCROP | |||
This parameter can be a value of @ref FLASHEx_Option_Bytes_PC_ReadWrite_Protection2 */ | |||
#endif /* STM32L151xC || STM32L152xC || STM32L162xC */ | |||
#endif /* FLASH_OBR_SPRMOD */ | |||
#if defined(FLASH_OBR_nRST_BFB2) | |||
uint16_t BootConfig; /*!< BootConfig: specifies Option bytes for boot config | |||
This parameter can be a value of @ref FLASHEx_Option_Bytes_BOOT */ | |||
#endif /* FLASH_OBR_nRST_BFB2*/ | |||
} FLASH_AdvOBProgramInitTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
#endif /* FLASH_OBR_SPRMOD || FLASH_OBR_nRST_BFB2 */ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup FLASHEx_Exported_Constants FLASHEx Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup FLASHEx_Type_Erase FLASHEx_Type_Erase | |||
* @{ | |||
*/ | |||
#define FLASH_TYPEERASE_PAGES (0x00U) /*!<Page erase only*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASHEx_Option_Type FLASHEx Option Type | |||
* @{ | |||
*/ | |||
#define OPTIONBYTE_WRP (0x01U) /*!<WRP option byte configuration*/ | |||
#define OPTIONBYTE_RDP (0x02U) /*!<RDP option byte configuration*/ | |||
#define OPTIONBYTE_USER (0x04U) /*!<USER option byte configuration*/ | |||
#define OPTIONBYTE_BOR (0x08U) /*!<BOR option byte configuration*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASHEx_WRP_State FLASHEx WRP State | |||
* @{ | |||
*/ | |||
#define OB_WRPSTATE_DISABLE (0x00U) /*!<Disable the write protection of the desired sectors*/ | |||
#define OB_WRPSTATE_ENABLE (0x01U) /*!<Enable the write protection of the desired sectors*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASHEx_Option_Bytes_Write_Protection1 FLASHEx Option Bytes Write Protection1 | |||
* @{ | |||
*/ | |||
/* Common pages for Cat1, Cat2, Cat3, Cat4 & Cat5 devices */ | |||
#define OB_WRP1_PAGES0TO15 (0x00000001U) /* Write protection of Sector0 */ | |||
#define OB_WRP1_PAGES16TO31 (0x00000002U) /* Write protection of Sector1 */ | |||
#define OB_WRP1_PAGES32TO47 (0x00000004U) /* Write protection of Sector2 */ | |||
#define OB_WRP1_PAGES48TO63 (0x00000008U) /* Write protection of Sector3 */ | |||
#define OB_WRP1_PAGES64TO79 (0x00000010U) /* Write protection of Sector4 */ | |||
#define OB_WRP1_PAGES80TO95 (0x00000020U) /* Write protection of Sector5 */ | |||
#define OB_WRP1_PAGES96TO111 (0x00000040U) /* Write protection of Sector6 */ | |||
#define OB_WRP1_PAGES112TO127 (0x00000080U) /* Write protection of Sector7 */ | |||
#define OB_WRP1_PAGES128TO143 (0x00000100U) /* Write protection of Sector8 */ | |||
#define OB_WRP1_PAGES144TO159 (0x00000200U) /* Write protection of Sector9 */ | |||
#define OB_WRP1_PAGES160TO175 (0x00000400U) /* Write protection of Sector10 */ | |||
#define OB_WRP1_PAGES176TO191 (0x00000800U) /* Write protection of Sector11 */ | |||
#define OB_WRP1_PAGES192TO207 (0x00001000U) /* Write protection of Sector12 */ | |||
#define OB_WRP1_PAGES208TO223 (0x00002000U) /* Write protection of Sector13 */ | |||
#define OB_WRP1_PAGES224TO239 (0x00004000U) /* Write protection of Sector14 */ | |||
#define OB_WRP1_PAGES240TO255 (0x00008000U) /* Write protection of Sector15 */ | |||
#define OB_WRP1_PAGES256TO271 (0x00010000U) /* Write protection of Sector16 */ | |||
#define OB_WRP1_PAGES272TO287 (0x00020000U) /* Write protection of Sector17 */ | |||
#define OB_WRP1_PAGES288TO303 (0x00040000U) /* Write protection of Sector18 */ | |||
#define OB_WRP1_PAGES304TO319 (0x00080000U) /* Write protection of Sector19 */ | |||
#define OB_WRP1_PAGES320TO335 (0x00100000U) /* Write protection of Sector20 */ | |||
#define OB_WRP1_PAGES336TO351 (0x00200000U) /* Write protection of Sector21 */ | |||
#define OB_WRP1_PAGES352TO367 (0x00400000U) /* Write protection of Sector22 */ | |||
#define OB_WRP1_PAGES368TO383 (0x00800000U) /* Write protection of Sector23 */ | |||
#define OB_WRP1_PAGES384TO399 (0x01000000U) /* Write protection of Sector24 */ | |||
#define OB_WRP1_PAGES400TO415 (0x02000000U) /* Write protection of Sector25 */ | |||
#define OB_WRP1_PAGES416TO431 (0x04000000U) /* Write protection of Sector26 */ | |||
#define OB_WRP1_PAGES432TO447 (0x08000000U) /* Write protection of Sector27 */ | |||
#define OB_WRP1_PAGES448TO463 (0x10000000U) /* Write protection of Sector28 */ | |||
#define OB_WRP1_PAGES464TO479 (0x20000000U) /* Write protection of Sector29 */ | |||
#define OB_WRP1_PAGES480TO495 (0x40000000U) /* Write protection of Sector30 */ | |||
#define OB_WRP1_PAGES496TO511 (0x80000000U) /* Write protection of Sector31 */ | |||
#define OB_WRP1_ALLPAGES ((uint32_t)FLASH_WRPR1_WRP) /*!< Write protection of all Sectors */ | |||
/** | |||
* @} | |||
*/ | |||
#if defined(STM32L100xC) || defined(STM32L151xC) || defined(STM32L152xC) || defined(STM32L162xC) \ | |||
|| defined(STM32L151xCA) || defined(STM32L151xD) || defined(STM32L151xDX) || defined(STM32L152xCA) \ | |||
|| defined(STM32L152xD) || defined(STM32L152xDX) || defined(STM32L162xCA) || defined(STM32L162xD) \ | |||
|| defined(STM32L162xDX) || defined(STM32L151xE) || defined(STM32L152xE) || defined(STM32L162xE) | |||
/** @defgroup FLASHEx_Option_Bytes_Write_Protection2 FLASHEx Option Bytes Write Protection2 | |||
* @{ | |||
*/ | |||
/* Pages for Cat3, Cat4 & Cat5 devices*/ | |||
#define OB_WRP2_PAGES512TO527 (0x00000001U) /* Write protection of Sector32 */ | |||
#define OB_WRP2_PAGES528TO543 (0x00000002U) /* Write protection of Sector33 */ | |||
#define OB_WRP2_PAGES544TO559 (0x00000004U) /* Write protection of Sector34 */ | |||
#define OB_WRP2_PAGES560TO575 (0x00000008U) /* Write protection of Sector35 */ | |||
#define OB_WRP2_PAGES576TO591 (0x00000010U) /* Write protection of Sector36 */ | |||
#define OB_WRP2_PAGES592TO607 (0x00000020U) /* Write protection of Sector37 */ | |||
#define OB_WRP2_PAGES608TO623 (0x00000040U) /* Write protection of Sector38 */ | |||
#define OB_WRP2_PAGES624TO639 (0x00000080U) /* Write protection of Sector39 */ | |||
#define OB_WRP2_PAGES640TO655 (0x00000100U) /* Write protection of Sector40 */ | |||
#define OB_WRP2_PAGES656TO671 (0x00000200U) /* Write protection of Sector41 */ | |||
#define OB_WRP2_PAGES672TO687 (0x00000400U) /* Write protection of Sector42 */ | |||
#define OB_WRP2_PAGES688TO703 (0x00000800U) /* Write protection of Sector43 */ | |||
#define OB_WRP2_PAGES704TO719 (0x00001000U) /* Write protection of Sector44 */ | |||
#define OB_WRP2_PAGES720TO735 (0x00002000U) /* Write protection of Sector45 */ | |||
#define OB_WRP2_PAGES736TO751 (0x00004000U) /* Write protection of Sector46 */ | |||
#define OB_WRP2_PAGES752TO767 (0x00008000U) /* Write protection of Sector47 */ | |||
#if defined(STM32L100xC) || defined(STM32L151xC) || defined(STM32L152xC) || defined(STM32L162xC) \ | |||
|| defined(STM32L151xCA) || defined(STM32L151xD) || defined(STM32L152xCA) || defined(STM32L152xD) \ | |||
|| defined(STM32L162xCA) || defined(STM32L162xD) || defined(STM32L151xE) || defined(STM32L152xE) \ | |||
|| defined(STM32L162xE) | |||
#define OB_WRP2_PAGES768TO783 (0x00010000U) /* Write protection of Sector48 */ | |||
#define OB_WRP2_PAGES784TO799 (0x00020000U) /* Write protection of Sector49 */ | |||
#define OB_WRP2_PAGES800TO815 (0x00040000U) /* Write protection of Sector50 */ | |||
#define OB_WRP2_PAGES816TO831 (0x00080000U) /* Write protection of Sector51 */ | |||
#define OB_WRP2_PAGES832TO847 (0x00100000U) /* Write protection of Sector52 */ | |||
#define OB_WRP2_PAGES848TO863 (0x00200000U) /* Write protection of Sector53 */ | |||
#define OB_WRP2_PAGES864TO879 (0x00400000U) /* Write protection of Sector54 */ | |||
#define OB_WRP2_PAGES880TO895 (0x00800000U) /* Write protection of Sector55 */ | |||
#define OB_WRP2_PAGES896TO911 (0x01000000U) /* Write protection of Sector56 */ | |||
#define OB_WRP2_PAGES912TO927 (0x02000000U) /* Write protection of Sector57 */ | |||
#define OB_WRP2_PAGES928TO943 (0x04000000U) /* Write protection of Sector58 */ | |||
#define OB_WRP2_PAGES944TO959 (0x08000000U) /* Write protection of Sector59 */ | |||
#define OB_WRP2_PAGES960TO975 (0x10000000U) /* Write protection of Sector60 */ | |||
#define OB_WRP2_PAGES976TO991 (0x20000000U) /* Write protection of Sector61 */ | |||
#define OB_WRP2_PAGES992TO1007 (0x40000000U) /* Write protection of Sector62 */ | |||
#define OB_WRP2_PAGES1008TO1023 (0x80000000U) /* Write protection of Sector63 */ | |||
#endif /* STM32L100xC || STM32L151xC || STM32L152xC || (...) || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE */ | |||
#define OB_WRP2_ALLPAGES ((uint32_t)FLASH_WRPR2_WRP) /*!< Write protection of all Sectors */ | |||
/** | |||
* @} | |||
*/ | |||
#endif /* STM32L100xC || STM32L151xC || STM32L152xC || (...) || STM32L162xD || STM32L151xDX || STM32L152xE || STM32L162xE */ | |||
#if defined(STM32L151xD) || defined(STM32L151xDX) || defined(STM32L152xD) || defined(STM32L152xDX) \ | |||
|| defined(STM32L162xD) || defined(STM32L162xDX) || defined(STM32L151xE) || defined(STM32L152xE) \ | |||
|| defined(STM32L162xE) | |||
/** @defgroup FLASHEx_Option_Bytes_Write_Protection3 FLASHEx Option Bytes Write Protection3 | |||
* @{ | |||
*/ | |||
/* Pages for devices with FLASH >= 256KB*/ | |||
#define OB_WRP3_PAGES1024TO1039 (0x00000001U) /* Write protection of Sector64 */ | |||
#define OB_WRP3_PAGES1040TO1055 (0x00000002U) /* Write protection of Sector65 */ | |||
#define OB_WRP3_PAGES1056TO1071 (0x00000004U) /* Write protection of Sector66 */ | |||
#define OB_WRP3_PAGES1072TO1087 (0x00000008U) /* Write protection of Sector67 */ | |||
#define OB_WRP3_PAGES1088TO1103 (0x00000010U) /* Write protection of Sector68 */ | |||
#define OB_WRP3_PAGES1104TO1119 (0x00000020U) /* Write protection of Sector69 */ | |||
#define OB_WRP3_PAGES1120TO1135 (0x00000040U) /* Write protection of Sector70 */ | |||
#define OB_WRP3_PAGES1136TO1151 (0x00000080U) /* Write protection of Sector71 */ | |||
#define OB_WRP3_PAGES1152TO1167 (0x00000100U) /* Write protection of Sector72 */ | |||
#define OB_WRP3_PAGES1168TO1183 (0x00000200U) /* Write protection of Sector73 */ | |||
#define OB_WRP3_PAGES1184TO1199 (0x00000400U) /* Write protection of Sector74 */ | |||
#define OB_WRP3_PAGES1200TO1215 (0x00000800U) /* Write protection of Sector75 */ | |||
#define OB_WRP3_PAGES1216TO1231 (0x00001000U) /* Write protection of Sector76 */ | |||
#define OB_WRP3_PAGES1232TO1247 (0x00002000U) /* Write protection of Sector77 */ | |||
#define OB_WRP3_PAGES1248TO1263 (0x00004000U) /* Write protection of Sector78 */ | |||
#define OB_WRP3_PAGES1264TO1279 (0x00008000U) /* Write protection of Sector79 */ | |||
#define OB_WRP3_PAGES1280TO1295 (0x00010000U) /* Write protection of Sector80 */ | |||
#define OB_WRP3_PAGES1296TO1311 (0x00020000U) /* Write protection of Sector81 */ | |||
#define OB_WRP3_PAGES1312TO1327 (0x00040000U) /* Write protection of Sector82 */ | |||
#define OB_WRP3_PAGES1328TO1343 (0x00080000U) /* Write protection of Sector83 */ | |||
#define OB_WRP3_PAGES1344TO1359 (0x00100000U) /* Write protection of Sector84 */ | |||
#define OB_WRP3_PAGES1360TO1375 (0x00200000U) /* Write protection of Sector85 */ | |||
#define OB_WRP3_PAGES1376TO1391 (0x00400000U) /* Write protection of Sector86 */ | |||
#define OB_WRP3_PAGES1392TO1407 (0x00800000U) /* Write protection of Sector87 */ | |||
#define OB_WRP3_PAGES1408TO1423 (0x01000000U) /* Write protection of Sector88 */ | |||
#define OB_WRP3_PAGES1424TO1439 (0x02000000U) /* Write protection of Sector89 */ | |||
#define OB_WRP3_PAGES1440TO1455 (0x04000000U) /* Write protection of Sector90 */ | |||
#define OB_WRP3_PAGES1456TO1471 (0x08000000U) /* Write protection of Sector91 */ | |||
#define OB_WRP3_PAGES1472TO1487 (0x10000000U) /* Write protection of Sector92 */ | |||
#define OB_WRP3_PAGES1488TO1503 (0x20000000U) /* Write protection of Sector93 */ | |||
#define OB_WRP3_PAGES1504TO1519 (0x40000000U) /* Write protection of Sector94 */ | |||
#define OB_WRP3_PAGES1520TO1535 (0x80000000U) /* Write protection of Sector95 */ | |||
#define OB_WRP3_ALLPAGES ((uint32_t)FLASH_WRPR3_WRP) /*!< Write protection of all Sectors */ | |||
/** | |||
* @} | |||
*/ | |||
#endif /* STM32L151xD || STM32L152xD || STM32L162xD || STM32L151xE || STM32L152xE || STM32L162xE*/ | |||
#if defined(STM32L151xE) || defined(STM32L152xE) || defined(STM32L162xE) || defined(STM32L151xDX) \ | |||
|| defined(STM32L152xDX) || defined(STM32L162xDX) | |||
/** @defgroup FLASHEx_Option_Bytes_Write_Protection4 FLASHEx Option Bytes Write Protection4 | |||
* @{ | |||
*/ | |||
/* Pages for Cat5 devices*/ | |||
#define OB_WRP4_PAGES1536TO1551 (0x00000001U)/* Write protection of Sector96*/ | |||
#define OB_WRP4_PAGES1552TO1567 (0x00000002U)/* Write protection of Sector97*/ | |||
#define OB_WRP4_PAGES1568TO1583 (0x00000004U)/* Write protection of Sector98*/ | |||
#define OB_WRP4_PAGES1584TO1599 (0x00000008U)/* Write protection of Sector99*/ | |||
#define OB_WRP4_PAGES1600TO1615 (0x00000010U) /* Write protection of Sector100*/ | |||
#define OB_WRP4_PAGES1616TO1631 (0x00000020U) /* Write protection of Sector101*/ | |||
#define OB_WRP4_PAGES1632TO1647 (0x00000040U) /* Write protection of Sector102*/ | |||
#define OB_WRP4_PAGES1648TO1663 (0x00000080U) /* Write protection of Sector103*/ | |||
#define OB_WRP4_PAGES1664TO1679 (0x00000100U) /* Write protection of Sector104*/ | |||
#define OB_WRP4_PAGES1680TO1695 (0x00000200U) /* Write protection of Sector105*/ | |||
#define OB_WRP4_PAGES1696TO1711 (0x00000400U) /* Write protection of Sector106*/ | |||
#define OB_WRP4_PAGES1712TO1727 (0x00000800U) /* Write protection of Sector107*/ | |||
#define OB_WRP4_PAGES1728TO1743 (0x00001000U) /* Write protection of Sector108*/ | |||
#define OB_WRP4_PAGES1744TO1759 (0x00002000U) /* Write protection of Sector109*/ | |||
#define OB_WRP4_PAGES1760TO1775 (0x00004000U) /* Write protection of Sector110*/ | |||
#define OB_WRP4_PAGES1776TO1791 (0x00008000U) /* Write protection of Sector111*/ | |||
#if defined(STM32L151xE) || defined(STM32L152xE) || defined(STM32L162xE) | |||
#define OB_WRP4_PAGES1792TO1807 (0x00010000U) /* Write protection of Sector112*/ | |||
#define OB_WRP4_PAGES1808TO1823 (0x00020000U) /* Write protection of Sector113*/ | |||
#define OB_WRP4_PAGES1824TO1839 (0x00040000U) /* Write protection of Sector114*/ | |||
#define OB_WRP4_PAGES1840TO1855 (0x00080000U) /* Write protection of Sector115*/ | |||
#define OB_WRP4_PAGES1856TO1871 (0x00100000U) /* Write protection of Sector116*/ | |||
#define OB_WRP4_PAGES1872TO1887 (0x00200000U) /* Write protection of Sector117*/ | |||
#define OB_WRP4_PAGES1888TO1903 (0x00400000U) /* Write protection of Sector118*/ | |||
#define OB_WRP4_PAGES1904TO1919 (0x00800000U) /* Write protection of Sector119*/ | |||
#define OB_WRP4_PAGES1920TO1935 (0x01000000U) /* Write protection of Sector120*/ | |||
#define OB_WRP4_PAGES1936TO1951 (0x02000000U) /* Write protection of Sector121*/ | |||
#define OB_WRP4_PAGES1952TO1967 (0x04000000U) /* Write protection of Sector122*/ | |||
#define OB_WRP4_PAGES1968TO1983 (0x08000000U) /* Write protection of Sector123*/ | |||
#define OB_WRP4_PAGES1984TO1999 (0x10000000U) /* Write protection of Sector124*/ | |||
#define OB_WRP4_PAGES2000TO2015 (0x20000000U) /* Write protection of Sector125*/ | |||
#define OB_WRP4_PAGES2016TO2031 (0x40000000U) /* Write protection of Sector126*/ | |||
#define OB_WRP4_PAGES2032TO2047 (0x80000000U) /* Write protection of Sector127*/ | |||
#endif /* STM32L151xE || STM32L152xE || STM32L162xE */ | |||
#define OB_WRP4_ALLPAGES ((uint32_t)FLASH_WRPR4_WRP) /*!< Write protection of all Sectors */ | |||
/** | |||
* @} | |||
*/ | |||
#endif /* STM32L151xE || STM32L152xE || STM32L162xE || STM32L151xDX || ... */ | |||
/** @defgroup FLASHEx_Option_Bytes_Read_Protection FLASHEx Option Bytes Read Protection | |||
* @{ | |||
*/ | |||
#define OB_RDP_LEVEL_0 ((uint8_t)0xAAU) | |||
#define OB_RDP_LEVEL_1 ((uint8_t)0xBBU) | |||
#define OB_RDP_LEVEL_2 ((uint8_t)0xCCU) /* Warning: When enabling read protection level 2 | |||
it is no more possible to go back to level 1 or 0 */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASHEx_Option_Bytes_BOR_Level FLASHEx Option Bytes BOR Level | |||
* @{ | |||
*/ | |||
#define OB_BOR_OFF ((uint8_t)0x00U) /*!< BOR is disabled at power down, the reset is asserted when the VDD | |||
power supply reaches the PDR(Power Down Reset) threshold (1.5V) */ | |||
#define OB_BOR_LEVEL1 ((uint8_t)0x08U) /*!< BOR Reset threshold levels for 1.7V - 1.8V VDD power supply */ | |||
#define OB_BOR_LEVEL2 ((uint8_t)0x09U) /*!< BOR Reset threshold levels for 1.9V - 2.0V VDD power supply */ | |||
#define OB_BOR_LEVEL3 ((uint8_t)0x0AU) /*!< BOR Reset threshold levels for 2.3V - 2.4V VDD power supply */ | |||
#define OB_BOR_LEVEL4 ((uint8_t)0x0BU) /*!< BOR Reset threshold levels for 2.55V - 2.65V VDD power supply */ | |||
#define OB_BOR_LEVEL5 ((uint8_t)0x0CU) /*!< BOR Reset threshold levels for 2.8V - 2.9V VDD power supply */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASHEx_Option_Bytes_IWatchdog FLASHEx Option Bytes IWatchdog | |||
* @{ | |||
*/ | |||
#define OB_IWDG_SW ((uint8_t)0x10U) /*!< Software WDG selected */ | |||
#define OB_IWDG_HW ((uint8_t)0x00U) /*!< Hardware WDG selected */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASHEx_Option_Bytes_nRST_STOP FLASHEx Option Bytes nRST_STOP | |||
* @{ | |||
*/ | |||
#define OB_STOP_NORST ((uint8_t)0x20U) /*!< No reset generated when entering in STOP */ | |||
#define OB_STOP_RST ((uint8_t)0x00U) /*!< Reset generated when entering in STOP */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASHEx_Option_Bytes_nRST_STDBY FLASHEx Option Bytes nRST_STDBY | |||
* @{ | |||
*/ | |||
#define OB_STDBY_NORST ((uint8_t)0x40U) /*!< No reset generated when entering in STANDBY */ | |||
#define OB_STDBY_RST ((uint8_t)0x00U) /*!< Reset generated when entering in STANDBY */ | |||
/** | |||
* @} | |||
*/ | |||
#if defined(FLASH_OBR_SPRMOD) | |||
/** @defgroup FLASHEx_OptionAdv_Type FLASHEx Option Advanced Type | |||
* @{ | |||
*/ | |||
#define OPTIONBYTE_PCROP (0x01U) /*!<PCROP option byte configuration*/ | |||
/** | |||
* @} | |||
*/ | |||
#endif /* FLASH_OBR_SPRMOD */ | |||
#if defined(FLASH_OBR_nRST_BFB2) | |||
/** @defgroup FLASHEx_OptionAdv_Type FLASHEx Option Advanced Type | |||
* @{ | |||
*/ | |||
#define OPTIONBYTE_BOOTCONFIG (0x02U) /*!<BOOTConfig option byte configuration*/ | |||
/** | |||
* @} | |||
*/ | |||
#endif /* FLASH_OBR_nRST_BFB2 */ | |||
#if defined(FLASH_OBR_SPRMOD) | |||
/** @defgroup FLASHEx_PCROP_State FLASHEx PCROP State | |||
* @{ | |||
*/ | |||
#define OB_PCROP_STATE_DISABLE (0x00U) /*!<Disable PCROP for selected sectors */ | |||
#define OB_PCROP_STATE_ENABLE (0x01U) /*!<Enable PCROP for selected sectors */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASHEx_Selection_Protection_Mode FLASHEx Selection Protection Mode | |||
* @{ | |||
*/ | |||
#define OB_PCROP_DESELECTED ((uint16_t)0x0000U) /*!< Disabled PCROP, nWPRi bits used for Write Protection on sector i */ | |||
#define OB_PCROP_SELECTED ((uint16_t)FLASH_OBR_SPRMOD) /*!< Enable PCROP, nWPRi bits used for PCRoP Protection on sector i */ | |||
/** | |||
* @} | |||
*/ | |||
#endif /* FLASH_OBR_SPRMOD */ | |||
#if defined(STM32L151xBA) || defined(STM32L152xBA) || defined(STM32L151xC) || defined(STM32L152xC) \ | |||
|| defined(STM32L162xC) | |||
/** @defgroup FLASHEx_Option_Bytes_PC_ReadWrite_Protection1 FLASHEx Option Bytes PC ReadWrite Protection 1 | |||
* @{ | |||
*/ | |||
/* Common pages for Cat1, Cat2, Cat3, Cat4 & Cat5 devices */ | |||
#define OB_PCROP1_PAGES0TO15 (0x00000001U) /* PC Read/Write protection of Sector0 */ | |||
#define OB_PCROP1_PAGES16TO31 (0x00000002U) /* PC Read/Write protection of Sector1 */ | |||
#define OB_PCROP1_PAGES32TO47 (0x00000004U) /* PC Read/Write protection of Sector2 */ | |||
#define OB_PCROP1_PAGES48TO63 (0x00000008U) /* PC Read/Write protection of Sector3 */ | |||
#define OB_PCROP1_PAGES64TO79 (0x00000010U) /* PC Read/Write protection of Sector4 */ | |||
#define OB_PCROP1_PAGES80TO95 (0x00000020U) /* PC Read/Write protection of Sector5 */ | |||
#define OB_PCROP1_PAGES96TO111 (0x00000040U) /* PC Read/Write protection of Sector6 */ | |||
#define OB_PCROP1_PAGES112TO127 (0x00000080U) /* PC Read/Write protection of Sector7 */ | |||
#define OB_PCROP1_PAGES128TO143 (0x00000100U) /* PC Read/Write protection of Sector8 */ | |||
#define OB_PCROP1_PAGES144TO159 (0x00000200U) /* PC Read/Write protection of Sector9 */ | |||
#define OB_PCROP1_PAGES160TO175 (0x00000400U) /* PC Read/Write protection of Sector10 */ | |||
#define OB_PCROP1_PAGES176TO191 (0x00000800U) /* PC Read/Write protection of Sector11 */ | |||
#define OB_PCROP1_PAGES192TO207 (0x00001000U) /* PC Read/Write protection of Sector12 */ | |||
#define OB_PCROP1_PAGES208TO223 (0x00002000U) /* PC Read/Write protection of Sector13 */ | |||
#define OB_PCROP1_PAGES224TO239 (0x00004000U) /* PC Read/Write protection of Sector14 */ | |||
#define OB_PCROP1_PAGES240TO255 (0x00008000U) /* PC Read/Write protection of Sector15 */ | |||
#define OB_PCROP1_PAGES256TO271 (0x00010000U) /* PC Read/Write protection of Sector16 */ | |||
#define OB_PCROP1_PAGES272TO287 (0x00020000U) /* PC Read/Write protection of Sector17 */ | |||
#define OB_PCROP1_PAGES288TO303 (0x00040000U) /* PC Read/Write protection of Sector18 */ | |||
#define OB_PCROP1_PAGES304TO319 (0x00080000U) /* PC Read/Write protection of Sector19 */ | |||
#define OB_PCROP1_PAGES320TO335 (0x00100000U) /* PC Read/Write protection of Sector20 */ | |||
#define OB_PCROP1_PAGES336TO351 (0x00200000U) /* PC Read/Write protection of Sector21 */ | |||
#define OB_PCROP1_PAGES352TO367 (0x00400000U) /* PC Read/Write protection of Sector22 */ | |||
#define OB_PCROP1_PAGES368TO383 (0x00800000U) /* PC Read/Write protection of Sector23 */ | |||
#define OB_PCROP1_PAGES384TO399 (0x01000000U) /* PC Read/Write protection of Sector24 */ | |||
#define OB_PCROP1_PAGES400TO415 (0x02000000U) /* PC Read/Write protection of Sector25 */ | |||
#define OB_PCROP1_PAGES416TO431 (0x04000000U) /* PC Read/Write protection of Sector26 */ | |||
#define OB_PCROP1_PAGES432TO447 (0x08000000U) /* PC Read/Write protection of Sector27 */ | |||
#define OB_PCROP1_PAGES448TO463 (0x10000000U) /* PC Read/Write protection of Sector28 */ | |||
#define OB_PCROP1_PAGES464TO479 (0x20000000U) /* PC Read/Write protection of Sector29 */ | |||
#define OB_PCROP1_PAGES480TO495 (0x40000000U) /* PC Read/Write protection of Sector30 */ | |||
#define OB_PCROP1_PAGES496TO511 (0x80000000U) /* PC Read/Write protection of Sector31 */ | |||
#define OB_PCROP1_ALLPAGES (0xFFFFFFFFU) /*!< PC Read/Write protection of all Sectors */ | |||
/** | |||
* @} | |||
*/ | |||
#endif /* STM32L151xBA || STM32L152xBA || STM32L151xC || STM32L152xC || STM32L162xC */ | |||
#if defined(STM32L151xC) || defined(STM32L152xC) || defined(STM32L162xC) | |||
/** @defgroup FLASHEx_Option_Bytes_PC_ReadWrite_Protection2 FLASHEx Option Bytes PC ReadWrite Protection 2 | |||
* @{ | |||
*/ | |||
/* Pages for Cat3, Cat4 & Cat5 devices*/ | |||
#define OB_PCROP2_PAGES512TO527 (0x00000001U) /* PC Read/Write protection of Sector32 */ | |||
#define OB_PCROP2_PAGES528TO543 (0x00000002U) /* PC Read/Write protection of Sector33 */ | |||
#define OB_PCROP2_PAGES544TO559 (0x00000004U) /* PC Read/Write protection of Sector34 */ | |||
#define OB_PCROP2_PAGES560TO575 (0x00000008U) /* PC Read/Write protection of Sector35 */ | |||
#define OB_PCROP2_PAGES576TO591 (0x00000010U) /* PC Read/Write protection of Sector36 */ | |||
#define OB_PCROP2_PAGES592TO607 (0x00000020U) /* PC Read/Write protection of Sector37 */ | |||
#define OB_PCROP2_PAGES608TO623 (0x00000040U) /* PC Read/Write protection of Sector38 */ | |||
#define OB_PCROP2_PAGES624TO639 (0x00000080U) /* PC Read/Write protection of Sector39 */ | |||
#define OB_PCROP2_PAGES640TO655 (0x00000100U) /* PC Read/Write protection of Sector40 */ | |||
#define OB_PCROP2_PAGES656TO671 (0x00000200U) /* PC Read/Write protection of Sector41 */ | |||
#define OB_PCROP2_PAGES672TO687 (0x00000400U) /* PC Read/Write protection of Sector42 */ | |||
#define OB_PCROP2_PAGES688TO703 (0x00000800U) /* PC Read/Write protection of Sector43 */ | |||
#define OB_PCROP2_PAGES704TO719 (0x00001000U) /* PC Read/Write protection of Sector44 */ | |||
#define OB_PCROP2_PAGES720TO735 (0x00002000U) /* PC Read/Write protection of Sector45 */ | |||
#define OB_PCROP2_PAGES736TO751 (0x00004000U) /* PC Read/Write protection of Sector46 */ | |||
#define OB_PCROP2_PAGES752TO767 (0x00008000U) /* PC Read/Write protection of Sector47 */ | |||
#define OB_PCROP2_PAGES768TO783 (0x00010000U) /* PC Read/Write protection of Sector48 */ | |||
#define OB_PCROP2_PAGES784TO799 (0x00020000U) /* PC Read/Write protection of Sector49 */ | |||
#define OB_PCROP2_PAGES800TO815 (0x00040000U) /* PC Read/Write protection of Sector50 */ | |||
#define OB_PCROP2_PAGES816TO831 (0x00080000U) /* PC Read/Write protection of Sector51 */ | |||
#define OB_PCROP2_PAGES832TO847 (0x00100000U) /* PC Read/Write protection of Sector52 */ | |||
#define OB_PCROP2_PAGES848TO863 (0x00200000U) /* PC Read/Write protection of Sector53 */ | |||
#define OB_PCROP2_PAGES864TO879 (0x00400000U) /* PC Read/Write protection of Sector54 */ | |||
#define OB_PCROP2_PAGES880TO895 (0x00800000U) /* PC Read/Write protection of Sector55 */ | |||
#define OB_PCROP2_PAGES896TO911 (0x01000000U) /* PC Read/Write protection of Sector56 */ | |||
#define OB_PCROP2_PAGES912TO927 (0x02000000U) /* PC Read/Write protection of Sector57 */ | |||
#define OB_PCROP2_PAGES928TO943 (0x04000000U) /* PC Read/Write protection of Sector58 */ | |||
#define OB_PCROP2_PAGES944TO959 (0x08000000U) /* PC Read/Write protection of Sector59 */ | |||
#define OB_PCROP2_PAGES960TO975 (0x10000000U) /* PC Read/Write protection of Sector60 */ | |||
#define OB_PCROP2_PAGES976TO991 (0x20000000U) /* PC Read/Write protection of Sector61 */ | |||
#define OB_PCROP2_PAGES992TO1007 (0x40000000U) /* PC Read/Write protection of Sector62 */ | |||
#define OB_PCROP2_PAGES1008TO1023 (0x80000000U) /* PC Read/Write protection of Sector63 */ | |||
#define OB_PCROP2_ALLPAGES (0xFFFFFFFFU) /*!< PC Read/Write protection of all Sectors */ | |||
/** | |||
* @} | |||
*/ | |||
#endif /* STM32L151xC || STM32L152xC || STM32L162xC */ | |||
/** @defgroup FLASHEx_Type_Erase_Data FLASHEx Type Erase Data | |||
* @{ | |||
*/ | |||
#define FLASH_TYPEERASEDATA_BYTE (0x00U) /*!<Erase byte (8-bit) at a specified address.*/ | |||
#define FLASH_TYPEERASEDATA_HALFWORD (0x01U) /*!<Erase a half-word (16-bit) at a specified address.*/ | |||
#define FLASH_TYPEERASEDATA_WORD (0x02U) /*!<Erase a word (32-bit) at a specified address.*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup FLASHEx_Type_Program_Data FLASHEx Type Program Data | |||
* @{ | |||
*/ | |||
#define FLASH_TYPEPROGRAMDATA_BYTE (0x00U) /*!<Program byte (8-bit) at a specified address.*/ | |||
#define FLASH_TYPEPROGRAMDATA_HALFWORD (0x01U) /*!<Program a half-word (16-bit) at a specified address.*/ | |||
#define FLASH_TYPEPROGRAMDATA_WORD (0x02U) /*!<Program a word (32-bit) at a specified address.*/ | |||
#define FLASH_TYPEPROGRAMDATA_FASTBYTE (0x04U) /*!<Fast Program byte (8-bit) at a specified address.*/ | |||
#define FLASH_TYPEPROGRAMDATA_FASTHALFWORD (0x08U) /*!<Fast Program a half-word (16-bit) at a specified address.*/ | |||
#define FLASH_TYPEPROGRAMDATA_FASTWORD (0x10U) /*!<Fast Program a word (32-bit) at a specified address.*/ | |||
/** | |||
* @} | |||
*/ | |||
#if defined(FLASH_OBR_nRST_BFB2) | |||
/** @defgroup FLASHEx_Option_Bytes_BOOT FLASHEx Option Bytes BOOT | |||
* @{ | |||
*/ | |||
#define OB_BOOT_BANK2 ((uint8_t)0x00U) /*!< At startup, if boot pins are set in boot from user Flash position | |||
and this parameter is selected the device will boot from Bank 2 | |||
or Bank 1, depending on the activation of the bank */ | |||
#define OB_BOOT_BANK1 ((uint8_t)(FLASH_OBR_nRST_BFB2 >> 16U)) /*!< At startup, if boot pins are set in boot from user Flash position | |||
and this parameter is selected the device will boot from Bank1(Default) */ | |||
/** | |||
* @} | |||
*/ | |||
#endif /* FLASH_OBR_nRST_BFB2 */ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/** @defgroup FLASHEx_Exported_Macros FLASHEx Exported Macros | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Set the FLASH Latency. | |||
* @param __LATENCY__ FLASH Latency | |||
* This parameter can be one of the following values: | |||
* @arg @ref FLASH_LATENCY_0 FLASH Zero Latency cycle | |||
* @arg @ref FLASH_LATENCY_1 FLASH One Latency cycle | |||
* @retval none | |||
*/ | |||
#define __HAL_FLASH_SET_LATENCY(__LATENCY__) do { \ | |||
if ((__LATENCY__) == FLASH_LATENCY_1) {__HAL_FLASH_ACC64_ENABLE();} \ | |||
MODIFY_REG((FLASH->ACR), FLASH_ACR_LATENCY, (__LATENCY__)); \ | |||
} while(0U) | |||
/** | |||
* @brief Get the FLASH Latency. | |||
* @retval FLASH Latency | |||
* This parameter can be one of the following values: | |||
* @arg @ref FLASH_LATENCY_0 FLASH Zero Latency cycle | |||
* @arg @ref FLASH_LATENCY_1 FLASH One Latency cycle | |||
*/ | |||
#define __HAL_FLASH_GET_LATENCY() (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY)) | |||
/** | |||
* @brief Enable the FLASH 64-bit access. | |||
* @note Read access 64 bit is used. | |||
* @note This bit cannot be written at the same time as the LATENCY and | |||
* PRFTEN bits. | |||
* @retval none | |||
*/ | |||
#define __HAL_FLASH_ACC64_ENABLE() (SET_BIT((FLASH->ACR), FLASH_ACR_ACC64)) | |||
/** | |||
* @brief Disable the FLASH 64-bit access. | |||
* @note Read access 32 bit is used | |||
* @note To reset this bit, the LATENCY should be zero wait state and the | |||
* prefetch off. | |||
* @retval none | |||
*/ | |||
#define __HAL_FLASH_ACC64_DISABLE() (CLEAR_BIT((FLASH->ACR), FLASH_ACR_ACC64)) | |||
/** | |||
* @brief Enable the FLASH prefetch buffer. | |||
* @retval none | |||
*/ | |||
#define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() do { __HAL_FLASH_ACC64_ENABLE(); \ | |||
SET_BIT((FLASH->ACR), FLASH_ACR_PRFTEN); \ | |||
} while(0U) | |||
/** | |||
* @brief Disable the FLASH prefetch buffer. | |||
* @retval none | |||
*/ | |||
#define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() CLEAR_BIT((FLASH->ACR), FLASH_ACR_PRFTEN) | |||
/** | |||
* @brief Enable the FLASH power down during Sleep mode | |||
* @retval none | |||
*/ | |||
#define __HAL_FLASH_SLEEP_POWERDOWN_ENABLE() SET_BIT(FLASH->ACR, FLASH_ACR_SLEEP_PD) | |||
/** | |||
* @brief Disable the FLASH power down during Sleep mode | |||
* @retval none | |||
*/ | |||
#define __HAL_FLASH_SLEEP_POWERDOWN_DISABLE() CLEAR_BIT(FLASH->ACR, FLASH_ACR_SLEEP_PD) | |||
/** | |||
* @brief Enable the Flash Run power down mode. | |||
* @note Writing this bit to 0 this bit, automatically the keys are | |||
* loss and a new unlock sequence is necessary to re-write it to 1. | |||
*/ | |||
#define __HAL_FLASH_POWER_DOWN_ENABLE() do { FLASH->PDKEYR = FLASH_PDKEY1; \ | |||
FLASH->PDKEYR = FLASH_PDKEY2; \ | |||
SET_BIT((FLASH->ACR), FLASH_ACR_RUN_PD); \ | |||
} while (0U) | |||
/** | |||
* @brief Disable the Flash Run power down mode. | |||
* @note Writing this bit to 0 this bit, automatically the keys are | |||
* loss and a new unlock sequence is necessary to re-write it to 1. | |||
*/ | |||
#define __HAL_FLASH_POWER_DOWN_DISABLE() do { FLASH->PDKEYR = FLASH_PDKEY1; \ | |||
FLASH->PDKEYR = FLASH_PDKEY2; \ | |||
CLEAR_BIT((FLASH->ACR), FLASH_ACR_RUN_PD); \ | |||
} while (0U) | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup FLASHEx_Exported_Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup FLASHEx_Exported_Functions_Group1 | |||
* @{ | |||
*/ | |||
HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError); | |||
HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup FLASHEx_Exported_Functions_Group2 | |||
* @{ | |||
*/ | |||
HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit); | |||
void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit); | |||
#if defined(FLASH_OBR_SPRMOD) || defined(FLASH_OBR_nRST_BFB2) | |||
HAL_StatusTypeDef HAL_FLASHEx_AdvOBProgram (FLASH_AdvOBProgramInitTypeDef *pAdvOBInit); | |||
void HAL_FLASHEx_AdvOBGetConfig(FLASH_AdvOBProgramInitTypeDef *pAdvOBInit); | |||
#endif /* FLASH_OBR_SPRMOD || FLASH_OBR_nRST_BFB2 */ | |||
#if defined(FLASH_OBR_SPRMOD) | |||
HAL_StatusTypeDef HAL_FLASHEx_OB_SelectPCROP(void); | |||
HAL_StatusTypeDef HAL_FLASHEx_OB_DeSelectPCROP(void); | |||
#endif /* FLASH_OBR_SPRMOD */ | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup FLASHEx_Exported_Functions_Group3 | |||
* @{ | |||
*/ | |||
HAL_StatusTypeDef HAL_FLASHEx_DATAEEPROM_Unlock(void); | |||
HAL_StatusTypeDef HAL_FLASHEx_DATAEEPROM_Lock(void); | |||
HAL_StatusTypeDef HAL_FLASHEx_DATAEEPROM_Erase(uint32_t TypeErase, uint32_t Address); | |||
HAL_StatusTypeDef HAL_FLASHEx_DATAEEPROM_Program(uint32_t TypeProgram, uint32_t Address, uint32_t Data); | |||
void HAL_FLASHEx_DATAEEPROM_EnableFixedTimeProgram(void); | |||
void HAL_FLASHEx_DATAEEPROM_DisableFixedTimeProgram(void); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32L1xx_HAL_FLASH_EX_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,119 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_hal_flash_ramfunc.h | |||
* @author MCD Application Team | |||
* @brief Header file of FLASH RAMFUNC driver. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32L1xx_FLASH_RAMFUNC_H | |||
#define __STM32L1xx_FLASH_RAMFUNC_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx_hal_def.h" | |||
/** @addtogroup STM32L1xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup FLASH_RAMFUNC | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup FLASH_RAMFUNC_Exported_Functions | |||
* @{ | |||
*/ | |||
/* | |||
* @brief FLASH memory functions that should be executed from internal SRAM. | |||
* These functions are defined inside the "stm32l1xx_hal_flash_ramfunc.c" | |||
* file. | |||
*/ | |||
/** @addtogroup FLASH_RAMFUNC_Exported_Functions_Group1 | |||
* @{ | |||
*/ | |||
__RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableRunPowerDown(void); | |||
__RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableRunPowerDown(void); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup FLASH_RAMFUNC_Exported_Functions_Group2 | |||
* @{ | |||
*/ | |||
#if defined(FLASH_PECR_PARALLBANK) | |||
__RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EraseParallelPage(uint32_t Page_Address1, uint32_t Page_Address2); | |||
__RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_ProgramParallelHalfPage(uint32_t Address1, uint32_t* pBuffer1, uint32_t Address2, uint32_t* pBuffer2); | |||
#endif /* FLASH_PECR_PARALLBANK */ | |||
__RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_HalfPageProgram(uint32_t Address, uint32_t* pBuffer); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup FLASH_RAMFUNC_Exported_Functions_Group3 | |||
* @{ | |||
*/ | |||
__RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_GetError(uint32_t *Error); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup FLASH_RAMFUNC_Exported_Functions_Group4 | |||
* @{ | |||
*/ | |||
__RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DATAEEPROM_EraseDoubleWord(uint32_t Address); | |||
__RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DATAEEPROM_ProgramDoubleWord(uint32_t Address, uint64_t Data); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32L1xx_FLASH_RAMFUNC_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,552 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_hal_gpio.c | |||
* @author MCD Application Team | |||
* @brief GPIO HAL module driver. | |||
* This file provides firmware functions to manage the following | |||
* functionalities of the General Purpose Input/Output (GPIO) peripheral: | |||
* + Initialization and de-initialization functions | |||
* + IO operation functions | |||
* | |||
@verbatim | |||
============================================================================== | |||
##### GPIO Peripheral features ##### | |||
============================================================================== | |||
[..] | |||
Each port bit of the general-purpose I/O (GPIO) ports can be individually | |||
configured by software in several modes: | |||
(+) Input mode | |||
(+) Analog mode | |||
(+) Output mode | |||
(+) Alternate function mode | |||
(+) External interrupt/event lines | |||
[..] | |||
During and just after reset, the alternate functions and external interrupt | |||
lines are not active and the I/O ports are configured in input floating mode. | |||
[..] | |||
All GPIO pins have weak internal pull-up and pull-down resistors, which can be | |||
activated or not. | |||
[..] | |||
In Output or Alternate mode, each IO can be configured on open-drain or push-pull | |||
type and the IO speed can be selected depending on the VDD value. | |||
[..] | |||
The microcontroller IO pins are connected to onboard peripherals/modules through a | |||
multiplexer that allows only one peripheral s alternate function (AF) connected | |||
to an IO pin at a time. In this way, there can be no conflict between peripherals | |||
sharing the same IO pin. | |||
[..] | |||
All ports have external interrupt/event capability. To use external interrupt | |||
lines, the port must be configured in input mode. All available GPIO pins are | |||
connected to the 16 external interrupt/event lines from EXTI0 to EXTI15. | |||
[..] | |||
The external interrupt/event controller consists of up to 28 edge detectors | |||
(depending on products 16 lines are connected to GPIO) for generating event/interrupt | |||
requests (each input line can be independently configured to select the type | |||
(interrupt or event) and the corresponding trigger event (rising or falling or both). | |||
Each line can also be masked independently. | |||
##### How to use this driver ##### | |||
============================================================================== | |||
[..] | |||
(#) Enable the GPIO AHB clock using the following function : __GPIOx_CLK_ENABLE(). | |||
(#) Configure the GPIO pin(s) using HAL_GPIO_Init(). | |||
(++) Configure the IO mode using "Mode" member from GPIO_InitTypeDef structure | |||
(++) Activate Pull-up, Pull-down resistor using "Pull" member from GPIO_InitTypeDef | |||
structure. | |||
(++) In case of Output or alternate function mode selection: the speed is | |||
configured through "Speed" member from GPIO_InitTypeDef structure, | |||
the speed is configurable: Low, Medium and High. | |||
(++) If alternate mode is selected, the alternate function connected to the IO | |||
is configured through "Alternate" member from GPIO_InitTypeDef structure | |||
(++) Analog mode is required when a pin is to be used as ADC channel | |||
or DAC output. | |||
(++) In case of external interrupt/event selection the "Mode" member from | |||
GPIO_InitTypeDef structure select the type (interrupt or event) and | |||
the corresponding trigger event (rising or falling or both). | |||
(#) In case of external interrupt/event mode selection, configure NVIC IRQ priority | |||
mapped to the EXTI line using HAL_NVIC_SetPriority() and enable it using | |||
HAL_NVIC_EnableIRQ(). | |||
(#) HAL_GPIO_DeInit allows to set register values to their reset value. It's also | |||
recommended to use it to unconfigure pin which was used as an external interrupt | |||
or in event mode. That's the only way to reset corresponding bit in EXTI & SYSCFG | |||
registers. | |||
(#) To get the level of a pin configured in input mode use HAL_GPIO_ReadPin(). | |||
(#) To set/reset the level of a pin configured in output mode use | |||
HAL_GPIO_WritePin()/HAL_GPIO_TogglePin(). | |||
(#) To lock pin configuration until next reset use HAL_GPIO_LockPin(). | |||
(#) During and just after reset, the alternate functions are not | |||
active and the GPIO pins are configured in input floating mode (except JTAG | |||
pins). | |||
(#) The LSE oscillator pins OSC32_IN and OSC32_OUT can be used as general purpose | |||
(PC14 and PC15, respectively) when the LSE oscillator is off. The LSE has | |||
priority over the GPIO function. | |||
(#) The HSE oscillator pins OSC_IN/OSC_OUT can be used as | |||
general purpose PH0 and PH1, respectively, when the HSE oscillator is off. | |||
The HSE has priority over the GPIO function. | |||
@endverbatim | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx_hal.h" | |||
/** @addtogroup STM32L1xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup GPIO | |||
* @brief GPIO HAL module driver | |||
* @{ | |||
*/ | |||
#ifdef HAL_GPIO_MODULE_ENABLED | |||
/* Private typedef -----------------------------------------------------------*/ | |||
/* Private define ------------------------------------------------------------*/ | |||
/** @addtogroup GPIO_Private_Constants | |||
* @{ | |||
*/ | |||
#define GPIO_MODE (0x00000003U) | |||
#define EXTI_MODE (0x10000000U) | |||
#define GPIO_MODE_IT (0x00010000U) | |||
#define GPIO_MODE_EVT (0x00020000U) | |||
#define RISING_EDGE (0x00100000U) | |||
#define FALLING_EDGE (0x00200000U) | |||
#define GPIO_OUTPUT_TYPE (0x00000010U) | |||
#define GPIO_NUMBER (16U) | |||
/** | |||
* @} | |||
*/ | |||
/* Private macro -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private function prototypes -----------------------------------------------*/ | |||
/* Exported functions ---------------------------------------------------------*/ | |||
/** @addtogroup GPIO_Exported_Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup GPIO_Exported_Functions_Group1 | |||
* @brief Initialization and Configuration functions | |||
* | |||
@verbatim | |||
=============================================================================== | |||
##### Initialization and Configuration functions ##### | |||
=============================================================================== | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Initializes the GPIOx peripheral according to the specified parameters in the GPIO_Init. | |||
* @param GPIOx where x can be (A..G depending on device used) to select the GPIO peripheral for STM32L1XX family devices | |||
* @param GPIO_Init pointer to a GPIO_InitTypeDef structure that contains | |||
* the configuration information for the specified GPIO peripheral. | |||
* @retval None | |||
*/ | |||
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init) | |||
{ | |||
uint32_t position = 0x00; | |||
uint32_t iocurrent = 0x00; | |||
uint32_t temp = 0x00; | |||
/* Check the parameters */ | |||
assert_param(IS_GPIO_ALL_INSTANCE(GPIOx)); | |||
assert_param(IS_GPIO_PIN(GPIO_Init->Pin)); | |||
assert_param(IS_GPIO_MODE(GPIO_Init->Mode)); | |||
assert_param(IS_GPIO_PULL(GPIO_Init->Pull)); | |||
/* Configure the port pins */ | |||
while (((GPIO_Init->Pin) >> position) != 0) | |||
{ | |||
/* Get current io position */ | |||
iocurrent = (GPIO_Init->Pin) & (1U << position); | |||
if(iocurrent) | |||
{ | |||
/*--------------------- GPIO Mode Configuration ------------------------*/ | |||
/* In case of Alternate function mode selection */ | |||
if((GPIO_Init->Mode == GPIO_MODE_AF_PP) || (GPIO_Init->Mode == GPIO_MODE_AF_OD)) | |||
{ | |||
/* Check the Alternate function parameters */ | |||
assert_param(IS_GPIO_AF_INSTANCE(GPIOx)); | |||
assert_param(IS_GPIO_AF(GPIO_Init->Alternate)); | |||
/* Configure Alternate function mapped with the current IO */ | |||
/* Identify AFRL or AFRH register based on IO position*/ | |||
temp = GPIOx->AFR[position >> 3]; | |||
CLEAR_BIT(temp, 0xFU << ((uint32_t)(position & 0x07U) * 4)) ; | |||
SET_BIT(temp, (uint32_t)(GPIO_Init->Alternate) << (((uint32_t)position & 0x07U) * 4)); | |||
GPIOx->AFR[position >> 3] = temp; | |||
} | |||
/* Configure IO Direction mode (Input, Output, Alternate or Analog) */ | |||
temp = GPIOx->MODER; | |||
CLEAR_BIT(temp, GPIO_MODER_MODER0 << (position * 2)); | |||
SET_BIT(temp, (GPIO_Init->Mode & GPIO_MODE) << (position * 2)); | |||
GPIOx->MODER = temp; | |||
/* In case of Output or Alternate function mode selection */ | |||
if ((GPIO_Init->Mode == GPIO_MODE_OUTPUT_PP) || (GPIO_Init->Mode == GPIO_MODE_AF_PP) || | |||
(GPIO_Init->Mode == GPIO_MODE_OUTPUT_OD) || (GPIO_Init->Mode == GPIO_MODE_AF_OD)) | |||
{ | |||
/* Check the Speed parameter */ | |||
assert_param(IS_GPIO_SPEED(GPIO_Init->Speed)); | |||
/* Configure the IO Speed */ | |||
temp = GPIOx->OSPEEDR; | |||
CLEAR_BIT(temp, GPIO_OSPEEDER_OSPEEDR0 << (position * 2)); | |||
SET_BIT(temp, GPIO_Init->Speed << (position * 2)); | |||
GPIOx->OSPEEDR = temp; | |||
/* Configure the IO Output Type */ | |||
temp = GPIOx->OTYPER; | |||
CLEAR_BIT(temp, GPIO_OTYPER_OT_0 << position) ; | |||
SET_BIT(temp, ((GPIO_Init->Mode & GPIO_OUTPUT_TYPE) >> 4) << position); | |||
GPIOx->OTYPER = temp; | |||
} | |||
/* Activate the Pull-up or Pull down resistor for the current IO */ | |||
temp = GPIOx->PUPDR; | |||
CLEAR_BIT(temp, GPIO_PUPDR_PUPDR0 << (position * 2)); | |||
SET_BIT(temp, (GPIO_Init->Pull) << (position * 2)); | |||
GPIOx->PUPDR = temp; | |||
/*--------------------- EXTI Mode Configuration ------------------------*/ | |||
/* Configure the External Interrupt or event for the current IO */ | |||
if((GPIO_Init->Mode & EXTI_MODE) == EXTI_MODE) | |||
{ | |||
/* Enable SYSCFG Clock */ | |||
__HAL_RCC_SYSCFG_CLK_ENABLE(); | |||
temp = SYSCFG->EXTICR[position >> 2]; | |||
CLEAR_BIT(temp, (0x0FU) << (4 * (position & 0x03))); | |||
SET_BIT(temp, (GPIO_GET_INDEX(GPIOx)) << (4 * (position & 0x03))); | |||
SYSCFG->EXTICR[position >> 2] = temp; | |||
/* Clear EXTI line configuration */ | |||
temp = EXTI->IMR; | |||
CLEAR_BIT(temp, (uint32_t)iocurrent); | |||
if((GPIO_Init->Mode & GPIO_MODE_IT) == GPIO_MODE_IT) | |||
{ | |||
SET_BIT(temp, iocurrent); | |||
} | |||
EXTI->IMR = temp; | |||
temp = EXTI->EMR; | |||
CLEAR_BIT(temp, (uint32_t)iocurrent); | |||
if((GPIO_Init->Mode & GPIO_MODE_EVT) == GPIO_MODE_EVT) | |||
{ | |||
SET_BIT(temp, iocurrent); | |||
} | |||
EXTI->EMR = temp; | |||
/* Clear Rising Falling edge configuration */ | |||
temp = EXTI->RTSR; | |||
CLEAR_BIT(temp, (uint32_t)iocurrent); | |||
if((GPIO_Init->Mode & RISING_EDGE) == RISING_EDGE) | |||
{ | |||
SET_BIT(temp, iocurrent); | |||
} | |||
EXTI->RTSR = temp; | |||
temp = EXTI->FTSR; | |||
CLEAR_BIT(temp, (uint32_t)iocurrent); | |||
if((GPIO_Init->Mode & FALLING_EDGE) == FALLING_EDGE) | |||
{ | |||
SET_BIT(temp, iocurrent); | |||
} | |||
EXTI->FTSR = temp; | |||
} | |||
} | |||
position++; | |||
} | |||
} | |||
/** | |||
* @brief De-initializes the GPIOx peripheral registers to their default reset values. | |||
* @param GPIOx where x can be (A..G depending on device used) to select the GPIO peripheral for STM32L1XX family devices | |||
* @param GPIO_Pin specifies the port bit to be written. | |||
* This parameter can be one of GPIO_PIN_x where x can be (0..15). | |||
* @retval None | |||
*/ | |||
void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin) | |||
{ | |||
uint32_t position = 0x00; | |||
uint32_t iocurrent = 0x00; | |||
uint32_t tmp = 0x00; | |||
/* Check the parameters */ | |||
assert_param(IS_GPIO_ALL_INSTANCE(GPIOx)); | |||
assert_param(IS_GPIO_PIN(GPIO_Pin)); | |||
/* Configure the port pins */ | |||
while ((GPIO_Pin >> position) != 0) | |||
{ | |||
/* Get current io position */ | |||
iocurrent = (GPIO_Pin) & (1U << position); | |||
if (iocurrent) | |||
{ | |||
/*------------------------- EXTI Mode Configuration --------------------*/ | |||
/* Clear the External Interrupt or Event for the current IO */ | |||
tmp = SYSCFG->EXTICR[position >> 2]; | |||
tmp &= ((0x0FU) << (4 * (position & 0x03))); | |||
if(tmp == (GPIO_GET_INDEX(GPIOx) << (4 * (position & 0x03)))) | |||
{ | |||
tmp = (0x0FU) << (4 * (position & 0x03)); | |||
CLEAR_BIT(SYSCFG->EXTICR[position >> 2], tmp); | |||
/* Clear EXTI line configuration */ | |||
CLEAR_BIT(EXTI->IMR, (uint32_t)iocurrent); | |||
CLEAR_BIT(EXTI->EMR, (uint32_t)iocurrent); | |||
/* Clear Rising Falling edge configuration */ | |||
CLEAR_BIT(EXTI->RTSR, (uint32_t)iocurrent); | |||
CLEAR_BIT(EXTI->FTSR, (uint32_t)iocurrent); | |||
} | |||
/*------------------------- GPIO Mode Configuration --------------------*/ | |||
/* Configure IO Direction in Input Floting Mode */ | |||
CLEAR_BIT(GPIOx->MODER, GPIO_MODER_MODER0 << (position * 2)); | |||
/* Configure the default Alternate Function in current IO */ | |||
CLEAR_BIT(GPIOx->AFR[position >> 3], 0xFU << ((uint32_t)(position & 0x07U) * 4)) ; | |||
/* Configure the default value for IO Speed */ | |||
CLEAR_BIT(GPIOx->OSPEEDR, GPIO_OSPEEDER_OSPEEDR0 << (position * 2)); | |||
/* Configure the default value IO Output Type */ | |||
CLEAR_BIT(GPIOx->OTYPER, GPIO_OTYPER_OT_0 << position) ; | |||
/* Deactivate the Pull-up oand Pull-down resistor for the current IO */ | |||
CLEAR_BIT(GPIOx->PUPDR, GPIO_PUPDR_PUPDR0 << (position * 2)); | |||
} | |||
position++; | |||
} | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup GPIO_Exported_Functions_Group2 | |||
* @brief GPIO Read, Write, Toggle, Lock and EXTI management functions. | |||
* | |||
@verbatim | |||
=============================================================================== | |||
##### IO operation functions ##### | |||
=============================================================================== | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Reads the specified input port pin. | |||
* @param GPIOx where x can be (A..G depending on device used) to select the GPIO peripheral for STM32L1XX family devices | |||
* @param GPIO_Pin specifies the port bit to read. | |||
* This parameter can be GPIO_PIN_x where x can be (0..15). | |||
* @retval The input port pin value. | |||
*/ | |||
GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) | |||
{ | |||
GPIO_PinState bitstatus; | |||
/* Check the parameters */ | |||
assert_param(IS_GPIO_PIN(GPIO_Pin)); | |||
if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)GPIO_PIN_RESET) | |||
{ | |||
bitstatus = GPIO_PIN_SET; | |||
} | |||
else | |||
{ | |||
bitstatus = GPIO_PIN_RESET; | |||
} | |||
return bitstatus; | |||
} | |||
/** | |||
* @brief Sets or clears the selected data port bit. | |||
* @note This function uses GPIOx_BSRR register to allow atomic read/modify | |||
* accesses. In this way, there is no risk of an IRQ occurring between | |||
* the read and the modify access. | |||
* @param GPIOx where x can be (A..G depending on device used) to select the GPIO peripheral for STM32L1XX family devices | |||
* @param GPIO_Pin specifies the port bit to be written. | |||
* This parameter can be one of GPIO_PIN_x where x can be (0..15). | |||
* @param PinState specifies the value to be written to the selected bit. | |||
* This parameter can be one of the GPIO_PinState enum values: | |||
* @arg GPIO_PIN_RESET: to clear the port pin | |||
* @arg GPIO_PIN_SET: to set the port pin | |||
* @retval None | |||
*/ | |||
void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_GPIO_PIN(GPIO_Pin)); | |||
assert_param(IS_GPIO_PIN_ACTION(PinState)); | |||
if (PinState != GPIO_PIN_RESET) | |||
{ | |||
GPIOx->BSRR = (uint32_t)GPIO_Pin; | |||
} | |||
else | |||
{ | |||
GPIOx->BSRR = (uint32_t)GPIO_Pin << 16 ; | |||
} | |||
} | |||
/** | |||
* @brief Toggles the specified GPIO pin | |||
* @param GPIOx where x can be (A..G depending on device used) to select the GPIO peripheral for STM32L1XX family devices | |||
* @param GPIO_Pin specifies the pins to be toggled. | |||
* @retval None | |||
*/ | |||
void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) | |||
{ | |||
/* Check the parameters */ | |||
assert_param(IS_GPIO_PIN(GPIO_Pin)); | |||
if ((GPIOx->ODR & GPIO_Pin) != 0x00u) | |||
{ | |||
GPIOx->BSRR = (uint32_t)GPIO_Pin << GPIO_NUMBER; | |||
} | |||
else | |||
{ | |||
GPIOx->BSRR = (uint32_t)GPIO_Pin; | |||
} | |||
} | |||
/** | |||
* @brief Locks GPIO Pins configuration registers. | |||
* @note The locked registers are GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR, | |||
* GPIOx_PUPDR, GPIOx_AFRL and GPIOx_AFRH. | |||
* @note The configuration of the locked GPIO pins can no longer be modified | |||
* until the next reset. | |||
* @note Limitation concerning GPIOx_OTYPER: Locking of GPIOx_OTYPER[i] with i = 15..8 | |||
* depends from setting of GPIOx_LCKR[i-8] and not from GPIOx_LCKR[i]. | |||
* GPIOx_LCKR[i-8] is locking GPIOx_OTYPER[i] together with GPIOx_OTYPER[i-8]. | |||
* It is not possible to lock GPIOx_OTYPER[i] with i = 15..8, without locking also | |||
* GPIOx_OTYPER[i-8]. | |||
* Workaround: When calling HAL_GPIO_LockPin with GPIO_Pin from GPIO_PIN_8 to GPIO_PIN_15, | |||
* you must call also HAL_GPIO_LockPin with GPIO_Pin - 8. | |||
* (When locking a pin from GPIO_PIN_8 to GPIO_PIN_15, you must lock also the corresponding | |||
* GPIO_PIN_0 to GPIO_PIN_7). | |||
* @param GPIOx where x can be (A..G depending on device used) to select the GPIO peripheral for STM32L1XX family devices | |||
* @param GPIO_Pin Specifies the port bit to be locked. | |||
* This parameter can be any combination of GPIO_Pin_x where x can be (0..15). | |||
* @retval None | |||
*/ | |||
HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) | |||
{ | |||
__IO uint32_t tmp = GPIO_LCKR_LCKK; | |||
/* Check the parameters */ | |||
assert_param(IS_GPIO_LOCK_INSTANCE(GPIOx)); | |||
assert_param(IS_GPIO_PIN(GPIO_Pin)); | |||
/* Apply lock key write sequence */ | |||
SET_BIT(tmp, GPIO_Pin); | |||
/* Set LCKx bit(s): LCKK='1' + LCK[15-0] */ | |||
GPIOx->LCKR = tmp; | |||
/* Reset LCKx bit(s): LCKK='0' + LCK[15-0] */ | |||
GPIOx->LCKR = GPIO_Pin; | |||
/* Set LCKx bit(s): LCKK='1' + LCK[15-0] */ | |||
GPIOx->LCKR = tmp; | |||
/* Read LCKK register. This read is mandatory to complete key lock sequence */ | |||
tmp = GPIOx->LCKR; | |||
/* Read again in order to confirm lock is active */ | |||
if((GPIOx->LCKR & GPIO_LCKR_LCKK) != RESET) | |||
{ | |||
return HAL_OK; | |||
} | |||
else | |||
{ | |||
return HAL_ERROR; | |||
} | |||
} | |||
/** | |||
* @brief This function handles EXTI interrupt request. | |||
* @param GPIO_Pin Specifies the port pin connected to corresponding EXTI line. | |||
* @retval None | |||
*/ | |||
void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin) | |||
{ | |||
/* EXTI line interrupt detected */ | |||
if(__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != RESET) | |||
{ | |||
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin); | |||
HAL_GPIO_EXTI_Callback(GPIO_Pin); | |||
} | |||
} | |||
/** | |||
* @brief EXTI line detection callbacks. | |||
* @param GPIO_Pin Specifies the port pin connected to corresponding EXTI line. | |||
* @retval None | |||
*/ | |||
__weak void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) | |||
{ | |||
/* Prevent unused argument(s) compilation warning */ | |||
UNUSED(GPIO_Pin); | |||
/* NOTE : This function Should not be modified, when the callback is needed, | |||
the HAL_GPIO_EXTI_Callback could be implemented in the user file | |||
*/ | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#endif /* HAL_GPIO_MODULE_ENABLED */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,320 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_hal_gpio.h | |||
* @author MCD Application Team | |||
* @brief Header file of GPIO HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32L1xx_HAL_GPIO_H | |||
#define __STM32L1xx_HAL_GPIO_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx_hal_def.h" | |||
/** @addtogroup STM32L1xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @defgroup GPIO GPIO | |||
* @brief GPIO HAL module driver | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup GPIO_Exported_Types GPIO Exported Types | |||
* @{ | |||
*/ | |||
/** | |||
* @brief GPIO Init structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t Pin; /*!< Specifies the GPIO pins to be configured. | |||
This parameter can be any value of @ref GPIO_pins */ | |||
uint32_t Mode; /*!< Specifies the operating mode for the selected pins. | |||
This parameter can be a value of @ref GPIO_mode */ | |||
uint32_t Pull; /*!< Specifies the Pull-up or Pull-Down activation for the selected pins. | |||
This parameter can be a value of @ref GPIO_pull */ | |||
uint32_t Speed; /*!< Specifies the speed for the selected pins. | |||
This parameter can be a value of @ref GPIO_speed */ | |||
uint32_t Alternate; /*!< Peripheral to be connected to the selected pins | |||
This parameter can be a value of @ref GPIOEx_Alternate_function_selection */ | |||
}GPIO_InitTypeDef; | |||
/** | |||
* @brief GPIO Bit SET and Bit RESET enumeration | |||
*/ | |||
typedef enum | |||
{ | |||
GPIO_PIN_RESET = 0, | |||
GPIO_PIN_SET | |||
}GPIO_PinState; | |||
/** | |||
* @} | |||
*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup GPIO_Exported_Constants GPIO Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup GPIO_pins GPIO pins | |||
* @{ | |||
*/ | |||
#define GPIO_PIN_0 ((uint16_t)0x0001U) /* Pin 0 selected */ | |||
#define GPIO_PIN_1 ((uint16_t)0x0002U) /* Pin 1 selected */ | |||
#define GPIO_PIN_2 ((uint16_t)0x0004U) /* Pin 2 selected */ | |||
#define GPIO_PIN_3 ((uint16_t)0x0008U) /* Pin 3 selected */ | |||
#define GPIO_PIN_4 ((uint16_t)0x0010U) /* Pin 4 selected */ | |||
#define GPIO_PIN_5 ((uint16_t)0x0020U) /* Pin 5 selected */ | |||
#define GPIO_PIN_6 ((uint16_t)0x0040U) /* Pin 6 selected */ | |||
#define GPIO_PIN_7 ((uint16_t)0x0080U) /* Pin 7 selected */ | |||
#define GPIO_PIN_8 ((uint16_t)0x0100U) /* Pin 8 selected */ | |||
#define GPIO_PIN_9 ((uint16_t)0x0200U) /* Pin 9 selected */ | |||
#define GPIO_PIN_10 ((uint16_t)0x0400U) /* Pin 10 selected */ | |||
#define GPIO_PIN_11 ((uint16_t)0x0800U) /* Pin 11 selected */ | |||
#define GPIO_PIN_12 ((uint16_t)0x1000U) /* Pin 12 selected */ | |||
#define GPIO_PIN_13 ((uint16_t)0x2000U) /* Pin 13 selected */ | |||
#define GPIO_PIN_14 ((uint16_t)0x4000U) /* Pin 14 selected */ | |||
#define GPIO_PIN_15 ((uint16_t)0x8000U) /* Pin 15 selected */ | |||
#define GPIO_PIN_All ((uint16_t)0xFFFFU) /* All pins selected */ | |||
#define GPIO_PIN_MASK (0x0000FFFFU) /* PIN mask for assert test */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup GPIO_mode GPIO mode | |||
* @brief GPIO Configuration Mode | |||
* Elements values convention: 0xX0yz00YZ | |||
* - X : GPIO mode or EXTI Mode | |||
* - y : External IT or Event trigger detection | |||
* - z : IO configuration on External IT or Event | |||
* - Y : Output type (Push Pull or Open Drain) | |||
* - Z : IO Direction mode (Input, Output, Alternate or Analog) | |||
* @{ | |||
*/ | |||
#define GPIO_MODE_INPUT (0x00000000U) /*!< Input Floating Mode */ | |||
#define GPIO_MODE_OUTPUT_PP (0x00000001U) /*!< Output Push Pull Mode */ | |||
#define GPIO_MODE_OUTPUT_OD (0x00000011U) /*!< Output Open Drain Mode */ | |||
#define GPIO_MODE_AF_PP (0x00000002U) /*!< Alternate Function Push Pull Mode */ | |||
#define GPIO_MODE_AF_OD (0x00000012U) /*!< Alternate Function Open Drain Mode */ | |||
#define GPIO_MODE_ANALOG (0x00000003U) /*!< Analog Mode */ | |||
#define GPIO_MODE_IT_RISING (0x10110000U) /*!< External Interrupt Mode with Rising edge trigger detection */ | |||
#define GPIO_MODE_IT_FALLING (0x10210000U) /*!< External Interrupt Mode with Falling edge trigger detection */ | |||
#define GPIO_MODE_IT_RISING_FALLING (0x10310000U) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */ | |||
#define GPIO_MODE_EVT_RISING (0x10120000U) /*!< External Event Mode with Rising edge trigger detection */ | |||
#define GPIO_MODE_EVT_FALLING (0x10220000U) /*!< External Event Mode with Falling edge trigger detection */ | |||
#define GPIO_MODE_EVT_RISING_FALLING (0x10320000U) /*!< External Event Mode with Rising/Falling edge trigger detection */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup GPIO_speed GPIO speed | |||
* @brief GPIO Output Maximum frequency | |||
* @{ | |||
*/ | |||
#define GPIO_SPEED_FREQ_LOW (0x00000000U) /*!< max: 400 KHz, please refer to the product datasheet */ | |||
#define GPIO_SPEED_FREQ_MEDIUM (0x00000001U) /*!< max: 1 MHz to 2 MHz, please refer to the product datasheet */ | |||
#define GPIO_SPEED_FREQ_HIGH (0x00000002U) /*!< max: 2 MHz to 10 MHz, please refer to the product datasheet */ | |||
#define GPIO_SPEED_FREQ_VERY_HIGH (0x00000003U) /*!< max: 8 MHz to 50 MHz, please refer to the product datasheet */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup GPIO_pull GPIO pull | |||
* @brief GPIO Pull-Up or Pull-Down Activation | |||
* @{ | |||
*/ | |||
#define GPIO_NOPULL (0x00000000U) /*!< No Pull-up or Pull-down activation */ | |||
#define GPIO_PULLUP (0x00000001U) /*!< Pull-up activation */ | |||
#define GPIO_PULLDOWN (0x00000002U) /*!< Pull-down activation */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/** @defgroup GPIO_Private_Constants GPIO Private Constants | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros --------------------------------------------------------*/ | |||
/** @defgroup GPIO_Private_Macros GPIO Private Macros | |||
* @{ | |||
*/ | |||
#define IS_GPIO_PIN_ACTION(ACTION) (((ACTION) == GPIO_PIN_RESET) || ((ACTION) == GPIO_PIN_SET)) | |||
#define IS_GPIO_PIN(__PIN__) ((((uint32_t)(__PIN__) & GPIO_PIN_MASK) != 0x00U) &&\ | |||
(((uint32_t)(__PIN__) & ~GPIO_PIN_MASK) == 0x00U)) | |||
#define IS_GPIO_PULL(PULL) (((PULL) == GPIO_NOPULL) || ((PULL) == GPIO_PULLUP) || \ | |||
((PULL) == GPIO_PULLDOWN)) | |||
#define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_SPEED_FREQ_LOW) || ((SPEED) == GPIO_SPEED_FREQ_MEDIUM) || \ | |||
((SPEED) == GPIO_SPEED_FREQ_HIGH) || ((SPEED) == GPIO_SPEED_FREQ_VERY_HIGH)) | |||
#define IS_GPIO_MODE(MODE) (((MODE) == GPIO_MODE_INPUT) ||\ | |||
((MODE) == GPIO_MODE_OUTPUT_PP) ||\ | |||
((MODE) == GPIO_MODE_OUTPUT_OD) ||\ | |||
((MODE) == GPIO_MODE_AF_PP) ||\ | |||
((MODE) == GPIO_MODE_AF_OD) ||\ | |||
((MODE) == GPIO_MODE_IT_RISING) ||\ | |||
((MODE) == GPIO_MODE_IT_FALLING) ||\ | |||
((MODE) == GPIO_MODE_IT_RISING_FALLING) ||\ | |||
((MODE) == GPIO_MODE_EVT_RISING) ||\ | |||
((MODE) == GPIO_MODE_EVT_FALLING) ||\ | |||
((MODE) == GPIO_MODE_EVT_RISING_FALLING) ||\ | |||
((MODE) == GPIO_MODE_ANALOG)) | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/** @defgroup GPIO_Exported_Macros GPIO Exported Macros | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Checks whether the specified EXTI line flag is set or not. | |||
* @param __EXTI_LINE__ specifies the EXTI line flag to check. | |||
* This parameter can be GPIO_PIN_x where x can be(0..15) | |||
* @retval The new state of __EXTI_LINE__ (SET or RESET). | |||
*/ | |||
#define __HAL_GPIO_EXTI_GET_FLAG(__EXTI_LINE__) (EXTI->PR & (__EXTI_LINE__)) | |||
/** | |||
* @brief Clears the EXTI's line pending flags. | |||
* @param __EXTI_LINE__ specifies the EXTI lines flags to clear. | |||
* This parameter can be any combination of GPIO_PIN_x where x can be (0..15) | |||
* @retval None | |||
*/ | |||
#define __HAL_GPIO_EXTI_CLEAR_FLAG(__EXTI_LINE__) (EXTI->PR = (__EXTI_LINE__)) | |||
/** | |||
* @brief Checks whether the specified EXTI line is asserted or not. | |||
* @param __EXTI_LINE__ specifies the EXTI line to check. | |||
* This parameter can be GPIO_PIN_x where x can be(0..15) | |||
* @retval The new state of __EXTI_LINE__ (SET or RESET). | |||
*/ | |||
#define __HAL_GPIO_EXTI_GET_IT(__EXTI_LINE__) (EXTI->PR & (__EXTI_LINE__)) | |||
/** | |||
* @brief Clears the EXTI's line pending bits. | |||
* @param __EXTI_LINE__ specifies the EXTI lines to clear. | |||
* This parameter can be any combination of GPIO_PIN_x where x can be (0..15) | |||
* @retval None | |||
*/ | |||
#define __HAL_GPIO_EXTI_CLEAR_IT(__EXTI_LINE__) (EXTI->PR = (__EXTI_LINE__)) | |||
/** | |||
* @brief Generates a Software interrupt on selected EXTI line. | |||
* @param __EXTI_LINE__ specifies the EXTI line to check. | |||
* This parameter can be GPIO_PIN_x where x can be(0..15) | |||
* @retval None | |||
*/ | |||
#define __HAL_GPIO_EXTI_GENERATE_SWIT(__EXTI_LINE__) (EXTI->SWIER |= (__EXTI_LINE__)) | |||
/** | |||
* @} | |||
*/ | |||
/* Include GPIO HAL Extension module */ | |||
#include "stm32l1xx_hal_gpio_ex.h" | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @defgroup GPIO_Exported_Functions GPIO Exported Functions | |||
* @brief GPIO Exported Functions | |||
* @{ | |||
*/ | |||
/** @defgroup GPIO_Exported_Functions_Group1 Initialization and Configuration functions | |||
* @brief Initialization and Configuration functions | |||
* @{ | |||
*/ | |||
/* Initialization and de-initialization functions *****************************/ | |||
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init); | |||
void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin); | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup GPIO_Exported_Functions_Group2 IO operation functions | |||
* @brief IO operation functions | |||
* @{ | |||
*/ | |||
/* IO operation functions *****************************************************/ | |||
GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); | |||
void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState); | |||
void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); | |||
HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); | |||
void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin); | |||
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32L1xx_HAL_GPIO_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | |||
@@ -0,0 +1,205 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_hal_gpio_ex.h | |||
* @author MCD Application Team | |||
* @brief Header file of GPIO HAL Extension module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32L1xx_HAL_GPIO_EX_H | |||
#define __STM32L1xx_HAL_GPIO_EX_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx_hal_def.h" | |||
/** @addtogroup STM32L1xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @defgroup GPIOEx GPIOEx | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup GPIOEx_Exported_Constants GPIOEx Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup GPIOEx_Alternate_function_selection GPIOEx Alternate function selection | |||
* @{ | |||
*/ | |||
/* AF 0 selection */ | |||
#define GPIO_AF0_MCO ((uint8_t)0x00) /*!< MCO Alternate Function mapping */ | |||
#define GPIO_AF0_TAMPER ((uint8_t)0x00) /*!< TAMPER Alternate Function mapping */ | |||
#define GPIO_AF0_SWJ ((uint8_t)0x00) /*!< SWJ (SWD and JTAG) Alternate Function mapping */ | |||
#define GPIO_AF0_TRACE ((uint8_t)0x00) /*!< TRACE Alternate Function mapping */ | |||
#define GPIO_AF0_RTC_50Hz ((uint8_t)0x00) /*!< RTC_OUT Alternate Function mapping */ | |||
/* AF 1 selection */ | |||
#define GPIO_AF1_TIM2 ((uint8_t)0x01) /*!< TIM2 Alternate Function mapping */ | |||
/* AF 2 selection */ | |||
#define GPIO_AF2_TIM3 ((uint8_t)0x02) /*!< TIM3 Alternate Function mapping */ | |||
#define GPIO_AF2_TIM4 ((uint8_t)0x02) /*!< TIM4 Alternate Function mapping */ | |||
#if defined (STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined (STM32L151xE) || defined (STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) || defined (STM32L162xC) || defined (STM32L152xC) || defined (STM32L151xC) | |||
#define GPIO_AF2_TIM5 ((uint8_t)0x02) /*!< TIM5 Alternate Function mapping */ | |||
#endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD ...STM32L151xC */ | |||
/* AF 3 selection */ | |||
#define GPIO_AF3_TIM9 ((uint8_t)0x03) /*!< TIM9 Alternate Function mapping */ | |||
#define GPIO_AF3_TIM10 ((uint8_t)0x03) /*!< TIM10 Alternate Function mapping */ | |||
#define GPIO_AF3_TIM11 ((uint8_t)0x03) /*!< TIM11 Alternate Function mapping */ | |||
/* AF 4 selection */ | |||
#define GPIO_AF4_I2C1 ((uint8_t)0x04) /*!< I2C1 Alternate Function mapping */ | |||
#define GPIO_AF4_I2C2 ((uint8_t)0x04) /*!< I2C2 Alternate Function mapping */ | |||
/* AF 5 selection */ | |||
#define GPIO_AF5_SPI1 ((uint8_t)0x05) /*!< SPI1/I2S1 Alternate Function mapping */ | |||
#define GPIO_AF5_SPI2 ((uint8_t)0x05) /*!< SPI2/I2S2 Alternate Function mapping */ | |||
/* AF 6 selection */ | |||
#if defined (STM32L100xC) || defined (STM32L151xC) || defined (STM32L151xCA) || defined (STM32L151xD) || defined (STM32L151xE) || defined (STM32L151xDX) ||\ | |||
defined (STM32L152xC) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L152xE) || defined (STM32L152xDX) ||\ | |||
defined (STM32L162xC) || defined (STM32L162xCA) || defined (STM32L162xD) || defined (STM32L162xE) || defined (STM32L162xDX) | |||
#define GPIO_AF6_SPI3 ((uint8_t)0x06) /*!< SPI3/I2S3 Alternate Function mapping */ | |||
#endif /* STM32L100xC || STM32L151xC || (...) || STM32L162xD || STM32L162xE || STM32L162xDX */ | |||
/* AF 7 selection */ | |||
#define GPIO_AF7_USART1 ((uint8_t)0x07) /*!< USART1 Alternate Function mapping */ | |||
#define GPIO_AF7_USART2 ((uint8_t)0x07) /*!< USART2 Alternate Function mapping */ | |||
#define GPIO_AF7_USART3 ((uint8_t)0x07) /*!< USART3 Alternate Function mapping */ | |||
/* AF 8 selection */ | |||
#if defined (STM32L151xD) || defined (STM32L151xE) || defined (STM32L151xDX) ||\ | |||
defined (STM32L152xD) || defined (STM32L152xE) || defined (STM32L152xDX) ||\ | |||
defined (STM32L162xD) || defined (STM32L162xE) || defined (STM32L162xDX) | |||
#define GPIO_AF8_UART4 ((uint8_t)0x08) /*!< UART4 Alternate Function mapping */ | |||
#define GPIO_AF8_UART5 ((uint8_t)0x08) /*!< UART5 Alternate Function mapping */ | |||
#endif /* STM32L151xD || STM32L151xE || STM32L151xDX || STM32L152xD || STM32L 152xE || STM32L162xD || STM32L162xE || STM32L162xDX */ | |||
/* AF 9 selection */ | |||
/* AF 10 selection */ | |||
/* AF 11 selection */ | |||
#if defined (STM32L100xB) || defined (STM32L100xBA) || defined (STM32L100xC) ||\ | |||
defined (STM32L152xB) || defined (STM32L152xBA) || defined (STM32L152xC) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L152xE) || defined (STM32L152xDX) ||\ | |||
defined (STM32L162xC) || defined (STM32L162xCA) || defined (STM32L162xD) || defined (STM32L162xE) || defined (STM32L162xDX) | |||
#define GPIO_AF11_LCD ((uint8_t)0x0B) /*!< LCD Alternate Function mapping */ | |||
#endif /* STM32L100xB || STM32L100xBA || STM32L100xC || (...) || STM32L162xCA || STM32L162xD || STM32L162xE || STM32L162xDX */ | |||
/* AF 12 selection */ | |||
#if defined (STM32L151xD) || defined (STM32L152xD) || defined (STM32L162xD) | |||
#define GPIO_AF12_FSMC ((uint8_t)0x0C) /*!< FSMC Alternate Function mapping */ | |||
#define GPIO_AF12_SDIO ((uint8_t)0x0C) /*!< SDIO Alternate Function mapping */ | |||
#endif /* STM32L151xD || STM32L152xD || STM32L162xD */ | |||
/* AF 13 selection */ | |||
/* AF 14 selection */ | |||
#define GPIO_AF14_TIM_IC1 ((uint8_t)0x0E) /*!< TIMER INPUT CAPTURE Alternate Function mapping */ | |||
#define GPIO_AF14_TIM_IC2 ((uint8_t)0x0E) /*!< TIMER INPUT CAPTURE Alternate Function mapping */ | |||
#define GPIO_AF14_TIM_IC3 ((uint8_t)0x0E) /*!< TIMER INPUT CAPTURE Alternate Function mapping */ | |||
#define GPIO_AF14_TIM_IC4 ((uint8_t)0x0E) /*!< TIMER INPUT CAPTURE Alternate Function mapping */ | |||
/* AF 15 selection */ | |||
#define GPIO_AF15_EVENTOUT ((uint8_t)0x0F) /*!< EVENTOUT Alternate Function mapping */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup GPIOEx_Private_Macros GPIOEx Private Macros | |||
* @{ | |||
*/ | |||
#define IS_GPIO_AF(AF) ((AF) <= (uint8_t)0x0F) | |||
#if defined (STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined (STM32L151xE) || defined (STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) | |||
#define GPIO_GET_INDEX(__GPIOx__) (((__GPIOx__) == (GPIOA))? 0U :\ | |||
((__GPIOx__) == (GPIOB))? 1U :\ | |||
((__GPIOx__) == (GPIOC))? 2U :\ | |||
((__GPIOx__) == (GPIOD))? 3U :\ | |||
((__GPIOx__) == (GPIOE))? 4U :\ | |||
((__GPIOx__) == (GPIOH))? 5U :\ | |||
((__GPIOx__) == (GPIOF))? 6U : 7U) | |||
#endif | |||
#if defined (STM32L151xB) || defined (STM32L151xBA) || defined (STM32L151xC) || defined (STM32L152xB) || defined (STM32L152xBA) || defined (STM32L152xC) || defined (STM32L162xC) | |||
#define GPIO_GET_INDEX(__GPIOx__) (((__GPIOx__) == (GPIOA))? 0U :\ | |||
((__GPIOx__) == (GPIOB))? 1U :\ | |||
((__GPIOx__) == (GPIOC))? 2U :\ | |||
((__GPIOx__) == (GPIOD))? 3U :\ | |||
((__GPIOx__) == (GPIOE))? 4U : 5U) | |||
#endif | |||
#if defined (STM32L100xB) || defined (STM32L100xBA) || defined (STM32L100xC) | |||
#define GPIO_GET_INDEX(__GPIOx__) (((__GPIOx__) == (GPIOA))? 0U :\ | |||
((__GPIOx__) == (GPIOB))? 1U :\ | |||
((__GPIOx__) == (GPIOC))? 2U :\ | |||
((__GPIOx__) == (GPIOD))? 3U : 5U) | |||
#endif | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32L1xx_HAL_GPIO_EX_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,246 @@ | |||
/* USER CODE BEGIN Header */ | |||
/** | |||
****************************************************************************** | |||
* File Name : stm32l1xx_hal_msp.c | |||
* Description : This file provides code for the MSP Initialization | |||
* and de-Initialization codes. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2020 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* 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 */ | |||
__HAL_RCC_COMP_CLK_ENABLE(); | |||
__HAL_RCC_SYSCFG_CLK_ENABLE(); | |||
__HAL_RCC_PWR_CLK_ENABLE(); | |||
/* System interrupt init*/ | |||
/* USER CODE BEGIN MspInit 1 */ | |||
/* USER CODE END MspInit 1 */ | |||
} | |||
/** | |||
* @brief RTC MSP Initialization | |||
* This function configures the hardware resources used in this example | |||
* @param hrtc: RTC handle pointer | |||
* @retval None | |||
*/ | |||
void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc) | |||
{ | |||
if(hrtc->Instance==RTC) | |||
{ | |||
/* USER CODE BEGIN RTC_MspInit 0 */ | |||
/* USER CODE END RTC_MspInit 0 */ | |||
/* Peripheral clock enable */ | |||
__HAL_RCC_RTC_ENABLE(); | |||
/* USER CODE BEGIN RTC_MspInit 1 */ | |||
/* USER CODE END RTC_MspInit 1 */ | |||
} | |||
} | |||
/** | |||
* @brief RTC MSP De-Initialization | |||
* This function freeze the hardware resources used in this example | |||
* @param hrtc: RTC handle pointer | |||
* @retval None | |||
*/ | |||
void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc) | |||
{ | |||
if(hrtc->Instance==RTC) | |||
{ | |||
/* USER CODE BEGIN RTC_MspDeInit 0 */ | |||
/* USER CODE END RTC_MspDeInit 0 */ | |||
/* Peripheral clock disable */ | |||
__HAL_RCC_RTC_DISABLE(); | |||
/* USER CODE BEGIN RTC_MspDeInit 1 */ | |||
/* USER CODE END RTC_MspDeInit 1 */ | |||
} | |||
} | |||
/** | |||
* @brief SPI MSP Initialization | |||
* This function configures the hardware resources used in this example | |||
* @param hspi: SPI handle pointer | |||
* @retval None | |||
*/ | |||
void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) | |||
{ | |||
GPIO_InitTypeDef GPIO_InitStruct = {0}; | |||
if(hspi->Instance==SPI1) | |||
{ | |||
/* USER CODE BEGIN SPI1_MspInit 0 */ | |||
/* USER CODE END SPI1_MspInit 0 */ | |||
/* Peripheral clock enable */ | |||
__HAL_RCC_SPI1_CLK_ENABLE(); | |||
__HAL_RCC_GPIOA_CLK_ENABLE(); | |||
/**SPI1 GPIO Configuration | |||
PA5 ------> SPI1_SCK | |||
PA6 ------> SPI1_MISO | |||
PA7 ------> SPI1_MOSI | |||
*/ | |||
GPIO_InitStruct.Pin = 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_AF5_SPI1; | |||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |||
/* USER CODE BEGIN SPI1_MspInit 1 */ | |||
/* USER CODE END SPI1_MspInit 1 */ | |||
} | |||
} | |||
/** | |||
* @brief SPI MSP De-Initialization | |||
* This function freeze the hardware resources used in this example | |||
* @param hspi: SPI handle pointer | |||
* @retval None | |||
*/ | |||
void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) | |||
{ | |||
if(hspi->Instance==SPI1) | |||
{ | |||
/* USER CODE BEGIN SPI1_MspDeInit 0 */ | |||
/* USER CODE END SPI1_MspDeInit 0 */ | |||
/* Peripheral clock disable */ | |||
__HAL_RCC_SPI1_CLK_DISABLE(); | |||
/**SPI1 GPIO Configuration | |||
PA5 ------> SPI1_SCK | |||
PA6 ------> SPI1_MISO | |||
PA7 ------> SPI1_MOSI | |||
*/ | |||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7); | |||
/* USER CODE BEGIN SPI1_MspDeInit 1 */ | |||
/* USER CODE END SPI1_MspDeInit 1 */ | |||
} | |||
} | |||
/** | |||
* @brief TIM_Base MSP Initialization | |||
* This function configures the hardware resources used in this example | |||
* @param htim_base: TIM_Base handle pointer | |||
* @retval None | |||
*/ | |||
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) | |||
{ | |||
if(htim_base->Instance==TIM4) | |||
{ | |||
/* USER CODE BEGIN TIM4_MspInit 0 */ | |||
/* USER CODE END TIM4_MspInit 0 */ | |||
/* Peripheral clock enable */ | |||
__HAL_RCC_TIM4_CLK_ENABLE(); | |||
/* TIM4 interrupt Init */ | |||
HAL_NVIC_SetPriority(TIM4_IRQn, 2, 0); | |||
HAL_NVIC_EnableIRQ(TIM4_IRQn); | |||
/* USER CODE BEGIN TIM4_MspInit 1 */ | |||
/* USER CODE END TIM4_MspInit 1 */ | |||
} | |||
} | |||
/** | |||
* @brief TIM_Base MSP De-Initialization | |||
* This function freeze the hardware resources used in this example | |||
* @param htim_base: TIM_Base handle pointer | |||
* @retval None | |||
*/ | |||
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base) | |||
{ | |||
if(htim_base->Instance==TIM4) | |||
{ | |||
/* USER CODE BEGIN TIM4_MspDeInit 0 */ | |||
/* USER CODE END TIM4_MspDeInit 0 */ | |||
/* Peripheral clock disable */ | |||
__HAL_RCC_TIM4_CLK_DISABLE(); | |||
/* TIM4 interrupt DeInit */ | |||
HAL_NVIC_DisableIRQ(TIM4_IRQn); | |||
/* USER CODE BEGIN TIM4_MspDeInit 1 */ | |||
/* USER CODE END TIM4_MspDeInit 1 */ | |||
} | |||
} | |||
/* USER CODE BEGIN 1 */ | |||
/* USER CODE END 1 */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,935 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_hal_pcd.h | |||
* @author MCD Application Team | |||
* @brief Header file of PCD HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2016 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef STM32L1xx_HAL_PCD_H | |||
#define STM32L1xx_HAL_PCD_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx_ll_usb.h" | |||
#if defined (USB) | |||
/** @addtogroup STM32L1xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup PCD | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup PCD_Exported_Types PCD Exported Types | |||
* @{ | |||
*/ | |||
/** | |||
* @brief PCD State structure definition | |||
*/ | |||
typedef enum | |||
{ | |||
HAL_PCD_STATE_RESET = 0x00, | |||
HAL_PCD_STATE_READY = 0x01, | |||
HAL_PCD_STATE_ERROR = 0x02, | |||
HAL_PCD_STATE_BUSY = 0x03, | |||
HAL_PCD_STATE_TIMEOUT = 0x04 | |||
} PCD_StateTypeDef; | |||
/* Device LPM suspend state */ | |||
typedef enum | |||
{ | |||
LPM_L0 = 0x00, /* on */ | |||
LPM_L1 = 0x01, /* LPM L1 sleep */ | |||
LPM_L2 = 0x02, /* suspend */ | |||
LPM_L3 = 0x03, /* off */ | |||
} PCD_LPM_StateTypeDef; | |||
typedef enum | |||
{ | |||
PCD_LPM_L0_ACTIVE = 0x00, /* on */ | |||
PCD_LPM_L1_ACTIVE = 0x01, /* LPM L1 sleep */ | |||
} PCD_LPM_MsgTypeDef; | |||
typedef enum | |||
{ | |||
PCD_BCD_ERROR = 0xFF, | |||
PCD_BCD_CONTACT_DETECTION = 0xFE, | |||
PCD_BCD_STD_DOWNSTREAM_PORT = 0xFD, | |||
PCD_BCD_CHARGING_DOWNSTREAM_PORT = 0xFC, | |||
PCD_BCD_DEDICATED_CHARGING_PORT = 0xFB, | |||
PCD_BCD_DISCOVERY_COMPLETED = 0x00, | |||
} PCD_BCD_MsgTypeDef; | |||
typedef USB_TypeDef PCD_TypeDef; | |||
typedef USB_CfgTypeDef PCD_InitTypeDef; | |||
typedef USB_EPTypeDef PCD_EPTypeDef; | |||
/** | |||
* @brief PCD Handle Structure definition | |||
*/ | |||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | |||
typedef struct __PCD_HandleTypeDef | |||
#else | |||
typedef struct | |||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | |||
{ | |||
PCD_TypeDef *Instance; /*!< Register base address */ | |||
PCD_InitTypeDef Init; /*!< PCD required parameters */ | |||
__IO uint8_t USB_Address; /*!< USB Address */ | |||
PCD_EPTypeDef IN_ep[8]; /*!< IN endpoint parameters */ | |||
PCD_EPTypeDef OUT_ep[8]; /*!< OUT endpoint parameters */ | |||
HAL_LockTypeDef Lock; /*!< PCD peripheral status */ | |||
__IO PCD_StateTypeDef State; /*!< PCD communication state */ | |||
__IO uint32_t ErrorCode; /*!< PCD Error code */ | |||
uint32_t Setup[12]; /*!< Setup packet buffer */ | |||
PCD_LPM_StateTypeDef LPM_State; /*!< LPM State */ | |||
uint32_t BESL; | |||
void *pData; /*!< Pointer to upper stack Handler */ | |||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | |||
void (* SOFCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD SOF callback */ | |||
void (* SetupStageCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Setup Stage callback */ | |||
void (* ResetCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Reset callback */ | |||
void (* SuspendCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Suspend callback */ | |||
void (* ResumeCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Resume callback */ | |||
void (* ConnectCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Connect callback */ | |||
void (* DisconnectCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Disconnect callback */ | |||
void (* DataOutStageCallback)(struct __PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< USB OTG PCD Data OUT Stage callback */ | |||
void (* DataInStageCallback)(struct __PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< USB OTG PCD Data IN Stage callback */ | |||
void (* ISOOUTIncompleteCallback)(struct __PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< USB OTG PCD ISO OUT Incomplete callback */ | |||
void (* ISOINIncompleteCallback)(struct __PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< USB OTG PCD ISO IN Incomplete callback */ | |||
void (* MspInitCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Msp Init callback */ | |||
void (* MspDeInitCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Msp DeInit callback */ | |||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | |||
} PCD_HandleTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/* Include PCD HAL Extended module */ | |||
#include "stm32l1xx_hal_pcd_ex.h" | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup PCD_Exported_Constants PCD Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup PCD_Speed PCD Speed | |||
* @{ | |||
*/ | |||
#define PCD_SPEED_FULL 2U | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PCD_PHY_Module PCD PHY Module | |||
* @{ | |||
*/ | |||
#define PCD_PHY_ULPI 1U | |||
#define PCD_PHY_EMBEDDED 2U | |||
#define PCD_PHY_UTMI 3U | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PCD_Error_Code_definition PCD Error Code definition | |||
* @brief PCD Error Code definition | |||
* @{ | |||
*/ | |||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | |||
#define HAL_PCD_ERROR_INVALID_CALLBACK (0x00000010U) /*!< Invalid Callback error */ | |||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macros -----------------------------------------------------------*/ | |||
/** @defgroup PCD_Exported_Macros PCD Exported Macros | |||
* @brief macros to handle interrupts and specific clock configurations | |||
* @{ | |||
*/ | |||
#define __HAL_PCD_ENABLE(__HANDLE__) (void)USB_EnableGlobalInt ((__HANDLE__)->Instance) | |||
#define __HAL_PCD_DISABLE(__HANDLE__) (void)USB_DisableGlobalInt ((__HANDLE__)->Instance) | |||
#define __HAL_PCD_GET_FLAG(__HANDLE__, __INTERRUPT__) ((USB_ReadInterrupts((__HANDLE__)->Instance) & (__INTERRUPT__)) == (__INTERRUPT__)) | |||
#define __HAL_PCD_CLEAR_FLAG(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->ISTR) &= ~(__INTERRUPT__)) | |||
#define __HAL_USB_WAKEUP_EXTI_ENABLE_IT() EXTI->IMR |= USB_WAKEUP_EXTI_LINE | |||
#define __HAL_USB_WAKEUP_EXTI_DISABLE_IT() EXTI->IMR &= ~(USB_WAKEUP_EXTI_LINE) | |||
#define __HAL_USB_WAKEUP_EXTI_GET_FLAG() EXTI->PR & (USB_WAKEUP_EXTI_LINE) | |||
#define __HAL_USB_WAKEUP_EXTI_CLEAR_FLAG() EXTI->PR = USB_WAKEUP_EXTI_LINE | |||
#define __HAL_USB_WAKEUP_EXTI_ENABLE_RISING_EDGE() \ | |||
do { \ | |||
EXTI->FTSR &= ~(USB_WAKEUP_EXTI_LINE); \ | |||
EXTI->RTSR |= USB_WAKEUP_EXTI_LINE; \ | |||
} while(0U) | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup PCD_Exported_Functions PCD Exported Functions | |||
* @{ | |||
*/ | |||
/* Initialization/de-initialization functions ********************************/ | |||
/** @addtogroup PCD_Exported_Functions_Group1 Initialization and de-initialization functions | |||
* @{ | |||
*/ | |||
HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd); | |||
HAL_StatusTypeDef HAL_PCD_DeInit(PCD_HandleTypeDef *hpcd); | |||
void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd); | |||
void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd); | |||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | |||
/** @defgroup HAL_PCD_Callback_ID_enumeration_definition HAL USB OTG PCD Callback ID enumeration definition | |||
* @brief HAL USB OTG PCD Callback ID enumeration definition | |||
* @{ | |||
*/ | |||
typedef enum | |||
{ | |||
HAL_PCD_SOF_CB_ID = 0x01, /*!< USB PCD SOF callback ID */ | |||
HAL_PCD_SETUPSTAGE_CB_ID = 0x02, /*!< USB PCD Setup Stage callback ID */ | |||
HAL_PCD_RESET_CB_ID = 0x03, /*!< USB PCD Reset callback ID */ | |||
HAL_PCD_SUSPEND_CB_ID = 0x04, /*!< USB PCD Suspend callback ID */ | |||
HAL_PCD_RESUME_CB_ID = 0x05, /*!< USB PCD Resume callback ID */ | |||
HAL_PCD_CONNECT_CB_ID = 0x06, /*!< USB PCD Connect callback ID */ | |||
HAL_PCD_DISCONNECT_CB_ID = 0x07, /*!< USB PCD Disconnect callback ID */ | |||
HAL_PCD_MSPINIT_CB_ID = 0x08, /*!< USB PCD MspInit callback ID */ | |||
HAL_PCD_MSPDEINIT_CB_ID = 0x09 /*!< USB PCD MspDeInit callback ID */ | |||
} HAL_PCD_CallbackIDTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup HAL_PCD_Callback_pointer_definition HAL USB OTG PCD Callback pointer definition | |||
* @brief HAL USB OTG PCD Callback pointer definition | |||
* @{ | |||
*/ | |||
typedef void (*pPCD_CallbackTypeDef)(PCD_HandleTypeDef *hpcd); /*!< pointer to a common USB OTG PCD callback function */ | |||
typedef void (*pPCD_DataOutStageCallbackTypeDef)(PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< pointer to USB OTG PCD Data OUT Stage callback */ | |||
typedef void (*pPCD_DataInStageCallbackTypeDef)(PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< pointer to USB OTG PCD Data IN Stage callback */ | |||
typedef void (*pPCD_IsoOutIncpltCallbackTypeDef)(PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< pointer to USB OTG PCD ISO OUT Incomplete callback */ | |||
typedef void (*pPCD_IsoInIncpltCallbackTypeDef)(PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< pointer to USB OTG PCD ISO IN Incomplete callback */ | |||
/** | |||
* @} | |||
*/ | |||
HAL_StatusTypeDef HAL_PCD_RegisterCallback(PCD_HandleTypeDef *hpcd, HAL_PCD_CallbackIDTypeDef CallbackID, pPCD_CallbackTypeDef pCallback); | |||
HAL_StatusTypeDef HAL_PCD_UnRegisterCallback(PCD_HandleTypeDef *hpcd, HAL_PCD_CallbackIDTypeDef CallbackID); | |||
HAL_StatusTypeDef HAL_PCD_RegisterDataOutStageCallback(PCD_HandleTypeDef *hpcd, pPCD_DataOutStageCallbackTypeDef pCallback); | |||
HAL_StatusTypeDef HAL_PCD_UnRegisterDataOutStageCallback(PCD_HandleTypeDef *hpcd); | |||
HAL_StatusTypeDef HAL_PCD_RegisterDataInStageCallback(PCD_HandleTypeDef *hpcd, pPCD_DataInStageCallbackTypeDef pCallback); | |||
HAL_StatusTypeDef HAL_PCD_UnRegisterDataInStageCallback(PCD_HandleTypeDef *hpcd); | |||
HAL_StatusTypeDef HAL_PCD_RegisterIsoOutIncpltCallback(PCD_HandleTypeDef *hpcd, pPCD_IsoOutIncpltCallbackTypeDef pCallback); | |||
HAL_StatusTypeDef HAL_PCD_UnRegisterIsoOutIncpltCallback(PCD_HandleTypeDef *hpcd); | |||
HAL_StatusTypeDef HAL_PCD_RegisterIsoInIncpltCallback(PCD_HandleTypeDef *hpcd, pPCD_IsoInIncpltCallbackTypeDef pCallback); | |||
HAL_StatusTypeDef HAL_PCD_UnRegisterIsoInIncpltCallback(PCD_HandleTypeDef *hpcd); | |||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | |||
/** | |||
* @} | |||
*/ | |||
/* I/O operation functions ***************************************************/ | |||
/* Non-Blocking mode: Interrupt */ | |||
/** @addtogroup PCD_Exported_Functions_Group2 Input and Output operation functions | |||
* @{ | |||
*/ | |||
HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd); | |||
HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd); | |||
void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd); | |||
void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd); | |||
void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd); | |||
void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd); | |||
void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd); | |||
void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd); | |||
void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd); | |||
void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd); | |||
void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum); | |||
void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum); | |||
void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum); | |||
void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum); | |||
/** | |||
* @} | |||
*/ | |||
/* Peripheral Control functions **********************************************/ | |||
/** @addtogroup PCD_Exported_Functions_Group3 Peripheral Control functions | |||
* @{ | |||
*/ | |||
HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd); | |||
HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd); | |||
HAL_StatusTypeDef HAL_PCD_SetAddress(PCD_HandleTypeDef *hpcd, uint8_t address); | |||
HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type); | |||
HAL_StatusTypeDef HAL_PCD_EP_Close(PCD_HandleTypeDef *hpcd, uint8_t ep_addr); | |||
HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len); | |||
HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len); | |||
uint32_t HAL_PCD_EP_GetRxCount(PCD_HandleTypeDef *hpcd, uint8_t ep_addr); | |||
HAL_StatusTypeDef HAL_PCD_EP_SetStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr); | |||
HAL_StatusTypeDef HAL_PCD_EP_ClrStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr); | |||
HAL_StatusTypeDef HAL_PCD_EP_Flush(PCD_HandleTypeDef *hpcd, uint8_t ep_addr); | |||
HAL_StatusTypeDef HAL_PCD_ActivateRemoteWakeup(PCD_HandleTypeDef *hpcd); | |||
HAL_StatusTypeDef HAL_PCD_DeActivateRemoteWakeup(PCD_HandleTypeDef *hpcd); | |||
/** | |||
* @} | |||
*/ | |||
/* Peripheral State functions ************************************************/ | |||
/** @addtogroup PCD_Exported_Functions_Group4 Peripheral State functions | |||
* @{ | |||
*/ | |||
PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef *hpcd); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/** @defgroup PCD_Private_Constants PCD Private Constants | |||
* @{ | |||
*/ | |||
/** @defgroup USB_EXTI_Line_Interrupt USB EXTI line interrupt | |||
* @{ | |||
*/ | |||
#define USB_WAKEUP_EXTI_LINE (0x1U << 18) /*!< USB FS EXTI Line WakeUp Interrupt */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PCD_EP0_MPS PCD EP0 MPS | |||
* @{ | |||
*/ | |||
#define PCD_EP0MPS_64 DEP0CTL_MPS_64 | |||
#define PCD_EP0MPS_32 DEP0CTL_MPS_32 | |||
#define PCD_EP0MPS_16 DEP0CTL_MPS_16 | |||
#define PCD_EP0MPS_08 DEP0CTL_MPS_8 | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PCD_ENDP PCD ENDP | |||
* @{ | |||
*/ | |||
#define PCD_ENDP0 0U | |||
#define PCD_ENDP1 1U | |||
#define PCD_ENDP2 2U | |||
#define PCD_ENDP3 3U | |||
#define PCD_ENDP4 4U | |||
#define PCD_ENDP5 5U | |||
#define PCD_ENDP6 6U | |||
#define PCD_ENDP7 7U | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PCD_ENDP_Kind PCD Endpoint Kind | |||
* @{ | |||
*/ | |||
#define PCD_SNG_BUF 0U | |||
#define PCD_DBL_BUF 1U | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/** @defgroup PCD_Private_Macros PCD Private Macros | |||
* @{ | |||
*/ | |||
/******************** Bit definition for USB_COUNTn_RX register *************/ | |||
#define USB_CNTRX_NBLK_MSK (0x1FU << 10) | |||
#define USB_CNTRX_BLSIZE (0x1U << 15) | |||
/* SetENDPOINT */ | |||
#define PCD_SET_ENDPOINT(USBx, bEpNum, wRegValue) (*(__IO uint16_t *)(&(USBx)->EP0R + ((bEpNum) * 2U)) = (uint16_t)(wRegValue)) | |||
/* GetENDPOINT */ | |||
#define PCD_GET_ENDPOINT(USBx, bEpNum) (*(__IO uint16_t *)(&(USBx)->EP0R + ((bEpNum) * 2U))) | |||
/* ENDPOINT transfer */ | |||
#define USB_EP0StartXfer USB_EPStartXfer | |||
/** | |||
* @brief sets the type in the endpoint register(bits EP_TYPE[1:0]) | |||
* @param USBx USB peripheral instance register address. | |||
* @param bEpNum Endpoint Number. | |||
* @param wType Endpoint Type. | |||
* @retval None | |||
*/ | |||
#define PCD_SET_EPTYPE(USBx, bEpNum, wType) (PCD_SET_ENDPOINT((USBx), (bEpNum), \ | |||
((PCD_GET_ENDPOINT((USBx), (bEpNum)) & USB_EP_T_MASK) | (wType) | USB_EP_CTR_TX | USB_EP_CTR_RX))) | |||
/** | |||
* @brief gets the type in the endpoint register(bits EP_TYPE[1:0]) | |||
* @param USBx USB peripheral instance register address. | |||
* @param bEpNum Endpoint Number. | |||
* @retval Endpoint Type | |||
*/ | |||
#define PCD_GET_EPTYPE(USBx, bEpNum) (PCD_GET_ENDPOINT((USBx), (bEpNum)) & USB_EP_T_FIELD) | |||
/** | |||
* @brief free buffer used from the application realizing it to the line | |||
* toggles bit SW_BUF in the double buffered endpoint register | |||
* @param USBx USB device. | |||
* @param bEpNum, bDir | |||
* @retval None | |||
*/ | |||
#define PCD_FreeUserBuffer(USBx, bEpNum, bDir) do { \ | |||
if ((bDir) == 0U) \ | |||
{ \ | |||
/* OUT double buffered endpoint */ \ | |||
PCD_TX_DTOG((USBx), (bEpNum)); \ | |||
} \ | |||
else if ((bDir) == 1U) \ | |||
{ \ | |||
/* IN double buffered endpoint */ \ | |||
PCD_RX_DTOG((USBx), (bEpNum)); \ | |||
} \ | |||
} while(0) | |||
/** | |||
* @brief sets the status for tx transfer (bits STAT_TX[1:0]). | |||
* @param USBx USB peripheral instance register address. | |||
* @param bEpNum Endpoint Number. | |||
* @param wState new state | |||
* @retval None | |||
*/ | |||
#define PCD_SET_EP_TX_STATUS(USBx, bEpNum, wState) do { \ | |||
register uint16_t _wRegVal; \ | |||
\ | |||
_wRegVal = PCD_GET_ENDPOINT((USBx), (bEpNum)) & USB_EPTX_DTOGMASK; \ | |||
/* toggle first bit ? */ \ | |||
if ((USB_EPTX_DTOG1 & (wState))!= 0U) \ | |||
{ \ | |||
_wRegVal ^= USB_EPTX_DTOG1; \ | |||
} \ | |||
/* toggle second bit ? */ \ | |||
if ((USB_EPTX_DTOG2 & (wState))!= 0U) \ | |||
{ \ | |||
_wRegVal ^= USB_EPTX_DTOG2; \ | |||
} \ | |||
PCD_SET_ENDPOINT((USBx), (bEpNum), (_wRegVal | USB_EP_CTR_RX | USB_EP_CTR_TX)); \ | |||
} while(0) /* PCD_SET_EP_TX_STATUS */ | |||
/** | |||
* @brief sets the status for rx transfer (bits STAT_TX[1:0]) | |||
* @param USBx USB peripheral instance register address. | |||
* @param bEpNum Endpoint Number. | |||
* @param wState new state | |||
* @retval None | |||
*/ | |||
#define PCD_SET_EP_RX_STATUS(USBx, bEpNum,wState) do { \ | |||
register uint16_t _wRegVal; \ | |||
\ | |||
_wRegVal = PCD_GET_ENDPOINT((USBx), (bEpNum)) & USB_EPRX_DTOGMASK; \ | |||
/* toggle first bit ? */ \ | |||
if ((USB_EPRX_DTOG1 & (wState))!= 0U) \ | |||
{ \ | |||
_wRegVal ^= USB_EPRX_DTOG1; \ | |||
} \ | |||
/* toggle second bit ? */ \ | |||
if ((USB_EPRX_DTOG2 & (wState))!= 0U) \ | |||
{ \ | |||
_wRegVal ^= USB_EPRX_DTOG2; \ | |||
} \ | |||
PCD_SET_ENDPOINT((USBx), (bEpNum), (_wRegVal | USB_EP_CTR_RX | USB_EP_CTR_TX)); \ | |||
} while(0) /* PCD_SET_EP_RX_STATUS */ | |||
/** | |||
* @brief sets the status for rx & tx (bits STAT_TX[1:0] & STAT_RX[1:0]) | |||
* @param USBx USB peripheral instance register address. | |||
* @param bEpNum Endpoint Number. | |||
* @param wStaterx new state. | |||
* @param wStatetx new state. | |||
* @retval None | |||
*/ | |||
#define PCD_SET_EP_TXRX_STATUS(USBx, bEpNum, wStaterx, wStatetx) do { \ | |||
register uint16_t _wRegVal; \ | |||
\ | |||
_wRegVal = PCD_GET_ENDPOINT((USBx), (bEpNum)) & (USB_EPRX_DTOGMASK | USB_EPTX_STAT); \ | |||
/* toggle first bit ? */ \ | |||
if ((USB_EPRX_DTOG1 & (wStaterx))!= 0U) \ | |||
{ \ | |||
_wRegVal ^= USB_EPRX_DTOG1; \ | |||
} \ | |||
/* toggle second bit ? */ \ | |||
if ((USB_EPRX_DTOG2 & (wStaterx))!= 0U) \ | |||
{ \ | |||
_wRegVal ^= USB_EPRX_DTOG2; \ | |||
} \ | |||
/* toggle first bit ? */ \ | |||
if ((USB_EPTX_DTOG1 & (wStatetx))!= 0U) \ | |||
{ \ | |||
_wRegVal ^= USB_EPTX_DTOG1; \ | |||
} \ | |||
/* toggle second bit ? */ \ | |||
if ((USB_EPTX_DTOG2 & (wStatetx))!= 0U) \ | |||
{ \ | |||
_wRegVal ^= USB_EPTX_DTOG2; \ | |||
} \ | |||
\ | |||
PCD_SET_ENDPOINT((USBx), (bEpNum), (_wRegVal | USB_EP_CTR_RX | USB_EP_CTR_TX)); \ | |||
} while(0) /* PCD_SET_EP_TXRX_STATUS */ | |||
/** | |||
* @brief gets the status for tx/rx transfer (bits STAT_TX[1:0] | |||
* /STAT_RX[1:0]) | |||
* @param USBx USB peripheral instance register address. | |||
* @param bEpNum Endpoint Number. | |||
* @retval status | |||
*/ | |||
#define PCD_GET_EP_TX_STATUS(USBx, bEpNum) ((uint16_t)PCD_GET_ENDPOINT((USBx), (bEpNum)) & USB_EPTX_STAT) | |||
#define PCD_GET_EP_RX_STATUS(USBx, bEpNum) ((uint16_t)PCD_GET_ENDPOINT((USBx), (bEpNum)) & USB_EPRX_STAT) | |||
/** | |||
* @brief sets directly the VALID tx/rx-status into the endpoint register | |||
* @param USBx USB peripheral instance register address. | |||
* @param bEpNum Endpoint Number. | |||
* @retval None | |||
*/ | |||
#define PCD_SET_EP_TX_VALID(USBx, bEpNum) (PCD_SET_EP_TX_STATUS((USBx), (bEpNum), USB_EP_TX_VALID)) | |||
#define PCD_SET_EP_RX_VALID(USBx, bEpNum) (PCD_SET_EP_RX_STATUS((USBx), (bEpNum), USB_EP_RX_VALID)) | |||
/** | |||
* @brief checks stall condition in an endpoint. | |||
* @param USBx USB peripheral instance register address. | |||
* @param bEpNum Endpoint Number. | |||
* @retval TRUE = endpoint in stall condition. | |||
*/ | |||
#define PCD_GET_EP_TX_STALL_STATUS(USBx, bEpNum) (PCD_GET_EP_TX_STATUS((USBx), (bEpNum)) \ | |||
== USB_EP_TX_STALL) | |||
#define PCD_GET_EP_RX_STALL_STATUS(USBx, bEpNum) (PCD_GET_EP_RX_STATUS((USBx), (bEpNum)) \ | |||
== USB_EP_RX_STALL) | |||
/** | |||
* @brief set & clear EP_KIND bit. | |||
* @param USBx USB peripheral instance register address. | |||
* @param bEpNum Endpoint Number. | |||
* @retval None | |||
*/ | |||
#define PCD_SET_EP_KIND(USBx, bEpNum) do { \ | |||
register uint16_t _wRegVal; \ | |||
\ | |||
_wRegVal = PCD_GET_ENDPOINT((USBx), (bEpNum)) & USB_EPREG_MASK; \ | |||
\ | |||
PCD_SET_ENDPOINT((USBx), (bEpNum), (_wRegVal | USB_EP_CTR_RX | USB_EP_CTR_TX | USB_EP_KIND)); \ | |||
} while(0) /* PCD_SET_EP_KIND */ | |||
#define PCD_CLEAR_EP_KIND(USBx, bEpNum) do { \ | |||
register uint16_t _wRegVal; \ | |||
\ | |||
_wRegVal = PCD_GET_ENDPOINT((USBx), (bEpNum)) & USB_EPKIND_MASK; \ | |||
\ | |||
PCD_SET_ENDPOINT((USBx), (bEpNum), (_wRegVal | USB_EP_CTR_RX | USB_EP_CTR_TX)); \ | |||
} while(0) /* PCD_CLEAR_EP_KIND */ | |||
/** | |||
* @brief Sets/clears directly STATUS_OUT bit in the endpoint register. | |||
* @param USBx USB peripheral instance register address. | |||
* @param bEpNum Endpoint Number. | |||
* @retval None | |||
*/ | |||
#define PCD_SET_OUT_STATUS(USBx, bEpNum) PCD_SET_EP_KIND((USBx), (bEpNum)) | |||
#define PCD_CLEAR_OUT_STATUS(USBx, bEpNum) PCD_CLEAR_EP_KIND((USBx), (bEpNum)) | |||
/** | |||
* @brief Sets/clears directly EP_KIND bit in the endpoint register. | |||
* @param USBx USB peripheral instance register address. | |||
* @param bEpNum Endpoint Number. | |||
* @retval None | |||
*/ | |||
#define PCD_SET_EP_DBUF(USBx, bEpNum) PCD_SET_EP_KIND((USBx), (bEpNum)) | |||
#define PCD_CLEAR_EP_DBUF(USBx, bEpNum) PCD_CLEAR_EP_KIND((USBx), (bEpNum)) | |||
/** | |||
* @brief Clears bit CTR_RX / CTR_TX in the endpoint register. | |||
* @param USBx USB peripheral instance register address. | |||
* @param bEpNum Endpoint Number. | |||
* @retval None | |||
*/ | |||
#define PCD_CLEAR_RX_EP_CTR(USBx, bEpNum) do { \ | |||
register uint16_t _wRegVal; \ | |||
\ | |||
_wRegVal = PCD_GET_ENDPOINT((USBx), (bEpNum)) & (0x7FFFU & USB_EPREG_MASK); \ | |||
\ | |||
PCD_SET_ENDPOINT((USBx), (bEpNum), (_wRegVal | USB_EP_CTR_TX)); \ | |||
} while(0) /* PCD_CLEAR_RX_EP_CTR */ | |||
#define PCD_CLEAR_TX_EP_CTR(USBx, bEpNum) do { \ | |||
register uint16_t _wRegVal; \ | |||
\ | |||
_wRegVal = PCD_GET_ENDPOINT((USBx), (bEpNum)) & (0xFF7FU & USB_EPREG_MASK); \ | |||
\ | |||
PCD_SET_ENDPOINT((USBx), (bEpNum), (_wRegVal | USB_EP_CTR_RX)); \ | |||
} while(0) /* PCD_CLEAR_TX_EP_CTR */ | |||
/** | |||
* @brief Toggles DTOG_RX / DTOG_TX bit in the endpoint register. | |||
* @param USBx USB peripheral instance register address. | |||
* @param bEpNum Endpoint Number. | |||
* @retval None | |||
*/ | |||
#define PCD_RX_DTOG(USBx, bEpNum) do { \ | |||
register uint16_t _wEPVal; \ | |||
\ | |||
_wEPVal = PCD_GET_ENDPOINT((USBx), (bEpNum)) & USB_EPREG_MASK; \ | |||
\ | |||
PCD_SET_ENDPOINT((USBx), (bEpNum), (_wEPVal | USB_EP_CTR_RX | USB_EP_CTR_TX | USB_EP_DTOG_RX)); \ | |||
} while(0) /* PCD_RX_DTOG */ | |||
#define PCD_TX_DTOG(USBx, bEpNum) do { \ | |||
register uint16_t _wEPVal; \ | |||
\ | |||
_wEPVal = PCD_GET_ENDPOINT((USBx), (bEpNum)) & USB_EPREG_MASK; \ | |||
\ | |||
PCD_SET_ENDPOINT((USBx), (bEpNum), (_wEPVal | USB_EP_CTR_RX | USB_EP_CTR_TX | USB_EP_DTOG_TX)); \ | |||
} while(0) /* PCD_TX_DTOG */ | |||
/** | |||
* @brief Clears DTOG_RX / DTOG_TX bit in the endpoint register. | |||
* @param USBx USB peripheral instance register address. | |||
* @param bEpNum Endpoint Number. | |||
* @retval None | |||
*/ | |||
#define PCD_CLEAR_RX_DTOG(USBx, bEpNum) do { \ | |||
register uint16_t _wRegVal; \ | |||
\ | |||
_wRegVal = PCD_GET_ENDPOINT((USBx), (bEpNum)); \ | |||
\ | |||
if ((_wRegVal & USB_EP_DTOG_RX) != 0U)\ | |||
{ \ | |||
PCD_RX_DTOG((USBx), (bEpNum)); \ | |||
} \ | |||
} while(0) /* PCD_CLEAR_RX_DTOG */ | |||
#define PCD_CLEAR_TX_DTOG(USBx, bEpNum) do { \ | |||
register uint16_t _wRegVal; \ | |||
\ | |||
_wRegVal = PCD_GET_ENDPOINT((USBx), (bEpNum)); \ | |||
\ | |||
if ((_wRegVal & USB_EP_DTOG_TX) != 0U)\ | |||
{ \ | |||
PCD_TX_DTOG((USBx), (bEpNum)); \ | |||
} \ | |||
} while(0) /* PCD_CLEAR_TX_DTOG */ | |||
/** | |||
* @brief Sets address in an endpoint register. | |||
* @param USBx USB peripheral instance register address. | |||
* @param bEpNum Endpoint Number. | |||
* @param bAddr Address. | |||
* @retval None | |||
*/ | |||
#define PCD_SET_EP_ADDRESS(USBx, bEpNum, bAddr) do { \ | |||
register uint16_t _wRegVal; \ | |||
\ | |||
_wRegVal = (PCD_GET_ENDPOINT((USBx), (bEpNum)) & USB_EPREG_MASK) | (bAddr); \ | |||
\ | |||
PCD_SET_ENDPOINT((USBx), (bEpNum), (_wRegVal | USB_EP_CTR_RX | USB_EP_CTR_TX)); \ | |||
} while(0) /* PCD_SET_EP_ADDRESS */ | |||
/** | |||
* @brief Gets address in an endpoint register. | |||
* @param USBx USB peripheral instance register address. | |||
* @param bEpNum Endpoint Number. | |||
* @retval None | |||
*/ | |||
#define PCD_GET_EP_ADDRESS(USBx, bEpNum) ((uint8_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)) & USB_EPADDR_FIELD)) | |||
#define PCD_EP_TX_CNT(USBx, bEpNum) ((uint16_t *)((((uint32_t)(USBx)->BTABLE + ((uint32_t)(bEpNum) * 8U) + 2U) * PMA_ACCESS) + ((uint32_t)(USBx) + 0x400U))) | |||
#define PCD_EP_RX_CNT(USBx, bEpNum) ((uint16_t *)((((uint32_t)(USBx)->BTABLE + ((uint32_t)(bEpNum) * 8U) + 6U) * PMA_ACCESS) + ((uint32_t)(USBx) + 0x400U))) | |||
/** | |||
* @brief sets address of the tx/rx buffer. | |||
* @param USBx USB peripheral instance register address. | |||
* @param bEpNum Endpoint Number. | |||
* @param wAddr address to be set (must be word aligned). | |||
* @retval None | |||
*/ | |||
#define PCD_SET_EP_TX_ADDRESS(USBx, bEpNum, wAddr) do { \ | |||
register uint16_t *_wRegVal; \ | |||
register uint32_t _wRegBase = (uint32_t)USBx; \ | |||
\ | |||
_wRegBase += (uint32_t)(USBx)->BTABLE; \ | |||
_wRegVal = (uint16_t *)(_wRegBase + 0x400U + (((uint32_t)(bEpNum) * 8U) * PMA_ACCESS)); \ | |||
*_wRegVal = ((wAddr) >> 1) << 1; \ | |||
} while(0) /* PCD_SET_EP_TX_ADDRESS */ | |||
#define PCD_SET_EP_RX_ADDRESS(USBx, bEpNum, wAddr) do { \ | |||
register uint16_t *_wRegVal; \ | |||
register uint32_t _wRegBase = (uint32_t)USBx; \ | |||
\ | |||
_wRegBase += (uint32_t)(USBx)->BTABLE; \ | |||
_wRegVal = (uint16_t *)(_wRegBase + 0x400U + ((((uint32_t)(bEpNum) * 8U) + 4U) * PMA_ACCESS)); \ | |||
*_wRegVal = ((wAddr) >> 1) << 1; \ | |||
} while(0) /* PCD_SET_EP_RX_ADDRESS */ | |||
/** | |||
* @brief Gets address of the tx/rx buffer. | |||
* @param USBx USB peripheral instance register address. | |||
* @param bEpNum Endpoint Number. | |||
* @retval address of the buffer. | |||
*/ | |||
#define PCD_GET_EP_TX_ADDRESS(USBx, bEpNum) ((uint16_t)*PCD_EP_TX_ADDRESS((USBx), (bEpNum))) | |||
#define PCD_GET_EP_RX_ADDRESS(USBx, bEpNum) ((uint16_t)*PCD_EP_RX_ADDRESS((USBx), (bEpNum))) | |||
/** | |||
* @brief Sets counter of rx buffer with no. of blocks. | |||
* @param pdwReg Register pointer | |||
* @param wCount Counter. | |||
* @param wNBlocks no. of Blocks. | |||
* @retval None | |||
*/ | |||
#define PCD_CALC_BLK32(pdwReg, wCount, wNBlocks) do { \ | |||
(wNBlocks) = (wCount) >> 5; \ | |||
*(pdwReg) = (uint16_t)(((wNBlocks) << 10) | USB_CNTRX_BLSIZE); \ | |||
} while(0) /* PCD_CALC_BLK32 */ | |||
#define PCD_CALC_BLK2(pdwReg, wCount, wNBlocks) do { \ | |||
(wNBlocks) = (wCount) >> 1; \ | |||
if (((wCount) & 0x1U) != 0U) \ | |||
{ \ | |||
(wNBlocks)++; \ | |||
} \ | |||
*(pdwReg) = (uint16_t)((wNBlocks) << 10); \ | |||
} while(0) /* PCD_CALC_BLK2 */ | |||
#define PCD_SET_EP_CNT_RX_REG(pdwReg, wCount) do { \ | |||
uint32_t wNBlocks; \ | |||
if ((wCount) == 0U) \ | |||
{ \ | |||
*(pdwReg) &= (uint16_t)~USB_CNTRX_NBLK_MSK; \ | |||
*(pdwReg) |= USB_CNTRX_BLSIZE; \ | |||
} \ | |||
else if((wCount) < 62U) \ | |||
{ \ | |||
PCD_CALC_BLK2((pdwReg), (wCount), wNBlocks); \ | |||
} \ | |||
else \ | |||
{ \ | |||
PCD_CALC_BLK32((pdwReg),(wCount), wNBlocks); \ | |||
} \ | |||
} while(0) /* PCD_SET_EP_CNT_RX_REG */ | |||
#define PCD_SET_EP_RX_DBUF0_CNT(USBx, bEpNum, wCount) do { \ | |||
register uint32_t _wRegBase = (uint32_t)(USBx); \ | |||
uint16_t *pdwReg; \ | |||
\ | |||
_wRegBase += (uint32_t)(USBx)->BTABLE; \ | |||
pdwReg = (uint16_t *)(_wRegBase + 0x400U + ((((uint32_t)(bEpNum) * 8U) + 2U) * PMA_ACCESS)); \ | |||
PCD_SET_EP_CNT_RX_REG(pdwReg, (wCount)); \ | |||
} while(0) | |||
/** | |||
* @brief sets counter for the tx/rx buffer. | |||
* @param USBx USB peripheral instance register address. | |||
* @param bEpNum Endpoint Number. | |||
* @param wCount Counter value. | |||
* @retval None | |||
*/ | |||
#define PCD_SET_EP_TX_CNT(USBx, bEpNum, wCount) do { \ | |||
register uint32_t _wRegBase = (uint32_t)(USBx); \ | |||
uint16_t *_wRegVal; \ | |||
\ | |||
_wRegBase += (uint32_t)(USBx)->BTABLE; \ | |||
_wRegVal = (uint16_t *)(_wRegBase + 0x400U + ((((uint32_t)(bEpNum) * 8U) + 2U) * PMA_ACCESS)); \ | |||
*_wRegVal = (uint16_t)(wCount); \ | |||
} while(0) | |||
#define PCD_SET_EP_RX_CNT(USBx, bEpNum, wCount) do { \ | |||
register uint32_t _wRegBase = (uint32_t)(USBx); \ | |||
uint16_t *_wRegVal; \ | |||
\ | |||
_wRegBase += (uint32_t)(USBx)->BTABLE; \ | |||
_wRegVal = (uint16_t *)(_wRegBase + 0x400U + ((((uint32_t)(bEpNum) * 8U) + 6U) * PMA_ACCESS)); \ | |||
PCD_SET_EP_CNT_RX_REG(_wRegVal, (wCount)); \ | |||
} while(0) | |||
/** | |||
* @brief gets counter of the tx buffer. | |||
* @param USBx USB peripheral instance register address. | |||
* @param bEpNum Endpoint Number. | |||
* @retval Counter value | |||
*/ | |||
#define PCD_GET_EP_TX_CNT(USBx, bEpNum) ((uint32_t)(*PCD_EP_TX_CNT((USBx), (bEpNum))) & 0x3ffU) | |||
#define PCD_GET_EP_RX_CNT(USBx, bEpNum) ((uint32_t)(*PCD_EP_RX_CNT((USBx), (bEpNum))) & 0x3ffU) | |||
/** | |||
* @brief Sets buffer 0/1 address in a double buffer endpoint. | |||
* @param USBx USB peripheral instance register address. | |||
* @param bEpNum Endpoint Number. | |||
* @param wBuf0Addr buffer 0 address. | |||
* @retval Counter value | |||
*/ | |||
#define PCD_SET_EP_DBUF0_ADDR(USBx, bEpNum, wBuf0Addr) do { \ | |||
PCD_SET_EP_TX_ADDRESS((USBx), (bEpNum), (wBuf0Addr)); \ | |||
} while(0) /* PCD_SET_EP_DBUF0_ADDR */ | |||
#define PCD_SET_EP_DBUF1_ADDR(USBx, bEpNum, wBuf1Addr) do { \ | |||
PCD_SET_EP_RX_ADDRESS((USBx), (bEpNum), (wBuf1Addr)); \ | |||
} while(0) /* PCD_SET_EP_DBUF1_ADDR */ | |||
/** | |||
* @brief Sets addresses in a double buffer endpoint. | |||
* @param USBx USB peripheral instance register address. | |||
* @param bEpNum Endpoint Number. | |||
* @param wBuf0Addr: buffer 0 address. | |||
* @param wBuf1Addr = buffer 1 address. | |||
* @retval None | |||
*/ | |||
#define PCD_SET_EP_DBUF_ADDR(USBx, bEpNum, wBuf0Addr, wBuf1Addr) do { \ | |||
PCD_SET_EP_DBUF0_ADDR((USBx), (bEpNum), (wBuf0Addr)); \ | |||
PCD_SET_EP_DBUF1_ADDR((USBx), (bEpNum), (wBuf1Addr)); \ | |||
} while(0) /* PCD_SET_EP_DBUF_ADDR */ | |||
/** | |||
* @brief Gets buffer 0/1 address of a double buffer endpoint. | |||
* @param USBx USB peripheral instance register address. | |||
* @param bEpNum Endpoint Number. | |||
* @retval None | |||
*/ | |||
#define PCD_GET_EP_DBUF0_ADDR(USBx, bEpNum) (PCD_GET_EP_TX_ADDRESS((USBx), (bEpNum))) | |||
#define PCD_GET_EP_DBUF1_ADDR(USBx, bEpNum) (PCD_GET_EP_RX_ADDRESS((USBx), (bEpNum))) | |||
/** | |||
* @brief Gets buffer 0/1 address of a double buffer endpoint. | |||
* @param USBx USB peripheral instance register address. | |||
* @param bEpNum Endpoint Number. | |||
* @param bDir endpoint dir EP_DBUF_OUT = OUT | |||
* EP_DBUF_IN = IN | |||
* @param wCount: Counter value | |||
* @retval None | |||
*/ | |||
#define PCD_SET_EP_DBUF0_CNT(USBx, bEpNum, bDir, wCount) do { \ | |||
if ((bDir) == 0U) \ | |||
/* OUT endpoint */ \ | |||
{ \ | |||
PCD_SET_EP_RX_DBUF0_CNT((USBx), (bEpNum), (wCount)); \ | |||
} \ | |||
else \ | |||
{ \ | |||
if ((bDir) == 1U) \ | |||
{ \ | |||
/* IN endpoint */ \ | |||
PCD_SET_EP_TX_CNT((USBx), (bEpNum), (wCount)); \ | |||
} \ | |||
} \ | |||
} while(0) /* SetEPDblBuf0Count*/ | |||
#define PCD_SET_EP_DBUF1_CNT(USBx, bEpNum, bDir, wCount) do { \ | |||
register uint32_t _wBase = (uint32_t)(USBx); \ | |||
uint16_t *_wEPRegVal; \ | |||
\ | |||
if ((bDir) == 0U) \ | |||
{ \ | |||
/* OUT endpoint */ \ | |||
PCD_SET_EP_RX_CNT((USBx), (bEpNum), (wCount)); \ | |||
} \ | |||
else \ | |||
{ \ | |||
if ((bDir) == 1U) \ | |||
{ \ | |||
/* IN endpoint */ \ | |||
_wBase += (uint32_t)(USBx)->BTABLE; \ | |||
_wEPRegVal = (uint16_t *)(_wBase + 0x400U + ((((uint32_t)(bEpNum) * 8U) + 6U) * PMA_ACCESS)); \ | |||
*_wEPRegVal = (uint16_t)(wCount); \ | |||
} \ | |||
} \ | |||
} while(0) /* SetEPDblBuf1Count */ | |||
#define PCD_SET_EP_DBUF_CNT(USBx, bEpNum, bDir, wCount) do { \ | |||
PCD_SET_EP_DBUF0_CNT((USBx), (bEpNum), (bDir), (wCount)); \ | |||
PCD_SET_EP_DBUF1_CNT((USBx), (bEpNum), (bDir), (wCount)); \ | |||
} while(0) /* PCD_SET_EP_DBUF_CNT */ | |||
/** | |||
* @brief Gets buffer 0/1 rx/tx counter for double buffering. | |||
* @param USBx USB peripheral instance register address. | |||
* @param bEpNum Endpoint Number. | |||
* @retval None | |||
*/ | |||
#define PCD_GET_EP_DBUF0_CNT(USBx, bEpNum) (PCD_GET_EP_TX_CNT((USBx), (bEpNum))) | |||
#define PCD_GET_EP_DBUF1_CNT(USBx, bEpNum) (PCD_GET_EP_RX_CNT((USBx), (bEpNum))) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#endif /* defined (USB) */ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* STM32L1xx_HAL_PCD_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,189 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_hal_pcd_ex.c | |||
* @author MCD Application Team | |||
* @brief PCD Extended HAL module driver. | |||
* This file provides firmware functions to manage the following | |||
* functionalities of the USB Peripheral Controller: | |||
* + Extended features functions | |||
* | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2016 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx_hal.h" | |||
/** @addtogroup STM32L1xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @defgroup PCDEx PCDEx | |||
* @brief PCD Extended HAL module driver | |||
* @{ | |||
*/ | |||
#ifdef HAL_PCD_MODULE_ENABLED | |||
#if defined (USB) | |||
/* Private types -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @defgroup PCDEx_Exported_Functions PCDEx Exported Functions | |||
* @{ | |||
*/ | |||
/** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions | |||
* @brief PCDEx control functions | |||
* | |||
@verbatim | |||
=============================================================================== | |||
##### Extended features functions ##### | |||
=============================================================================== | |||
[..] This section provides functions allowing to: | |||
(+) Update FIFO configuration | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Configure PMA for EP | |||
* @param hpcd Device instance | |||
* @param ep_addr endpoint address | |||
* @param ep_kind endpoint Kind | |||
* USB_SNG_BUF: Single Buffer used | |||
* USB_DBL_BUF: Double Buffer used | |||
* @param pmaadress: EP address in The PMA: In case of single buffer endpoint | |||
* this parameter is 16-bit value providing the address | |||
* in PMA allocated to endpoint. | |||
* In case of double buffer endpoint this parameter | |||
* is a 32-bit value providing the endpoint buffer 0 address | |||
* in the LSB part of 32-bit value and endpoint buffer 1 address | |||
* in the MSB part of 32-bit value. | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, | |||
uint16_t ep_addr, | |||
uint16_t ep_kind, | |||
uint32_t pmaadress) | |||
{ | |||
PCD_EPTypeDef *ep; | |||
/* initialize ep structure*/ | |||
if ((0x80U & ep_addr) == 0x80U) | |||
{ | |||
ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK]; | |||
} | |||
else | |||
{ | |||
ep = &hpcd->OUT_ep[ep_addr]; | |||
} | |||
/* Here we check if the endpoint is single or double Buffer*/ | |||
if (ep_kind == PCD_SNG_BUF) | |||
{ | |||
/* Single Buffer */ | |||
ep->doublebuffer = 0U; | |||
/* Configure the PMA */ | |||
ep->pmaadress = (uint16_t)pmaadress; | |||
} | |||
else /* USB_DBL_BUF */ | |||
{ | |||
/* Double Buffer Endpoint */ | |||
ep->doublebuffer = 1U; | |||
/* Configure the PMA */ | |||
ep->pmaaddr0 = (uint16_t)(pmaadress & 0xFFFFU); | |||
ep->pmaaddr1 = (uint16_t)((pmaadress & 0xFFFF0000U) >> 16); | |||
} | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Software Device Connection, | |||
* this function is not required by USB OTG FS peripheral, it is used | |||
* only by USB Device FS peripheral. | |||
* @param hpcd: PCD handle | |||
* @param state: connection state (0 : disconnected / 1: connected) | |||
* @retval None | |||
*/ | |||
__weak void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state) | |||
{ | |||
/* Prevent unused argument(s) compilation warning */ | |||
UNUSED(hpcd); | |||
UNUSED(state); | |||
/* NOTE : This function Should not be modified, when the callback is needed, | |||
the HAL_PCDEx_SetConnectionState could be implemented in the user file | |||
*/ | |||
} | |||
/** | |||
* @brief Send LPM message to user layer callback. | |||
* @param hpcd PCD handle | |||
* @param msg LPM message | |||
* @retval HAL status | |||
*/ | |||
__weak void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg) | |||
{ | |||
/* Prevent unused argument(s) compilation warning */ | |||
UNUSED(hpcd); | |||
UNUSED(msg); | |||
/* NOTE : This function should not be modified, when the callback is needed, | |||
the HAL_PCDEx_LPM_Callback could be implemented in the user file | |||
*/ | |||
} | |||
/** | |||
* @brief Send BatteryCharging message to user layer callback. | |||
* @param hpcd PCD handle | |||
* @param msg LPM message | |||
* @retval HAL status | |||
*/ | |||
__weak void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg) | |||
{ | |||
/* Prevent unused argument(s) compilation warning */ | |||
UNUSED(hpcd); | |||
UNUSED(msg); | |||
/* NOTE : This function should not be modified, when the callback is needed, | |||
the HAL_PCDEx_BCD_Callback could be implemented in the user file | |||
*/ | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#endif /* defined (USB) */ | |||
#endif /* HAL_PCD_MODULE_ENABLED */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,86 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_hal_pcd_ex.h | |||
* @author MCD Application Team | |||
* @brief Header file of PCD HAL Extension module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2016 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef STM32L1xx_HAL_PCD_EX_H | |||
#define STM32L1xx_HAL_PCD_EX_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx_hal_def.h" | |||
#if defined (USB) | |||
/** @addtogroup STM32L1xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup PCDEx | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/* Exported macros -----------------------------------------------------------*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup PCDEx_Exported_Functions PCDEx Exported Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup PCDEx_Exported_Functions_Group1 Peripheral Control functions | |||
* @{ | |||
*/ | |||
HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, | |||
uint16_t ep_addr, | |||
uint16_t ep_kind, | |||
uint32_t pmaadress); | |||
void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state); | |||
void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg); | |||
void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#endif /* defined (USB) */ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* STM32L1xx_HAL_PCD_EX_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,486 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_hal_pwr.h | |||
* @author MCD Application Team | |||
* @brief Header file of PWR HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32L1xx_HAL_PWR_H | |||
#define __STM32L1xx_HAL_PWR_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx_hal_def.h" | |||
/** @addtogroup STM32L1xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup PWR | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup PWR_Exported_Types PWR Exported Types | |||
* @{ | |||
*/ | |||
/** | |||
* @brief PWR PVD configuration structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t PVDLevel; /*!< PVDLevel: Specifies the PVD detection level. | |||
This parameter can be a value of @ref PWR_PVD_detection_level */ | |||
uint32_t Mode; /*!< Mode: Specifies the operating mode for the selected pins. | |||
This parameter can be a value of @ref PWR_PVD_Mode */ | |||
}PWR_PVDTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/* Internal constants --------------------------------------------------------*/ | |||
/** @addtogroup PWR_Private_Constants | |||
* @{ | |||
*/ | |||
#define PWR_EXTI_LINE_PVD (0x00010000U) /*!< External interrupt line 16 Connected to the PVD EXTI Line */ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup PWR_Exported_Constants PWR Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup PWR_register_alias_address PWR Register alias address | |||
* @{ | |||
*/ | |||
/* ------------- PWR registers bit address in the alias region ---------------*/ | |||
#define PWR_OFFSET (PWR_BASE - PERIPH_BASE) | |||
#define PWR_CR_OFFSET 0x00 | |||
#define PWR_CSR_OFFSET 0x04 | |||
#define PWR_CR_OFFSET_BB (PWR_OFFSET + PWR_CR_OFFSET) | |||
#define PWR_CSR_OFFSET_BB (PWR_OFFSET + PWR_CSR_OFFSET) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PWR_CR_register_alias PWR CR Register alias address | |||
* @{ | |||
*/ | |||
/* --- CR Register ---*/ | |||
/* Alias word address of LPSDSR bit */ | |||
#define LPSDSR_BIT_NUMBER POSITION_VAL(PWR_CR_LPSDSR) | |||
#define CR_LPSDSR_BB ((uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32) + (LPSDSR_BIT_NUMBER * 4))) | |||
/* Alias word address of DBP bit */ | |||
#define DBP_BIT_NUMBER POSITION_VAL(PWR_CR_DBP) | |||
#define CR_DBP_BB ((uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32) + (DBP_BIT_NUMBER * 4))) | |||
/* Alias word address of LPRUN bit */ | |||
#define LPRUN_BIT_NUMBER POSITION_VAL(PWR_CR_LPRUN) | |||
#define CR_LPRUN_BB ((uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32) + (LPRUN_BIT_NUMBER * 4))) | |||
/* Alias word address of PVDE bit */ | |||
#define PVDE_BIT_NUMBER POSITION_VAL(PWR_CR_PVDE) | |||
#define CR_PVDE_BB ((uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32) + (PVDE_BIT_NUMBER * 4))) | |||
/* Alias word address of FWU bit */ | |||
#define FWU_BIT_NUMBER POSITION_VAL(PWR_CR_FWU) | |||
#define CR_FWU_BB ((uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32) + (FWU_BIT_NUMBER * 4))) | |||
/* Alias word address of ULP bit */ | |||
#define ULP_BIT_NUMBER POSITION_VAL(PWR_CR_ULP) | |||
#define CR_ULP_BB ((uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32) + (ULP_BIT_NUMBER * 4))) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PWR_CSR_register_alias PWR CSR Register alias address | |||
* @{ | |||
*/ | |||
/* --- CSR Register ---*/ | |||
/* Alias word address of EWUP1, EWUP2 and EWUP3 bits */ | |||
#define CSR_EWUP_BB(VAL) ((uint32_t)(PERIPH_BB_BASE + (PWR_CSR_OFFSET_BB * 32) + (POSITION_VAL(VAL) * 4))) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PWR_PVD_detection_level PWR PVD detection level | |||
* @{ | |||
*/ | |||
#define PWR_PVDLEVEL_0 PWR_CR_PLS_LEV0 | |||
#define PWR_PVDLEVEL_1 PWR_CR_PLS_LEV1 | |||
#define PWR_PVDLEVEL_2 PWR_CR_PLS_LEV2 | |||
#define PWR_PVDLEVEL_3 PWR_CR_PLS_LEV3 | |||
#define PWR_PVDLEVEL_4 PWR_CR_PLS_LEV4 | |||
#define PWR_PVDLEVEL_5 PWR_CR_PLS_LEV5 | |||
#define PWR_PVDLEVEL_6 PWR_CR_PLS_LEV6 | |||
#define PWR_PVDLEVEL_7 PWR_CR_PLS_LEV7 /* External input analog voltage | |||
(Compare internally to VREFINT) */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PWR_PVD_Mode PWR PVD Mode | |||
* @{ | |||
*/ | |||
#define PWR_PVD_MODE_NORMAL (0x00000000U) /*!< basic mode is used */ | |||
#define PWR_PVD_MODE_IT_RISING (0x00010001U) /*!< External Interrupt Mode with Rising edge trigger detection */ | |||
#define PWR_PVD_MODE_IT_FALLING (0x00010002U) /*!< External Interrupt Mode with Falling edge trigger detection */ | |||
#define PWR_PVD_MODE_IT_RISING_FALLING (0x00010003U) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */ | |||
#define PWR_PVD_MODE_EVENT_RISING (0x00020001U) /*!< Event Mode with Rising edge trigger detection */ | |||
#define PWR_PVD_MODE_EVENT_FALLING (0x00020002U) /*!< Event Mode with Falling edge trigger detection */ | |||
#define PWR_PVD_MODE_EVENT_RISING_FALLING (0x00020003U) /*!< Event Mode with Rising/Falling edge trigger detection */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PWR_Regulator_state_in_SLEEP_STOP_mode PWR Regulator state in SLEEP/STOP mode | |||
* @{ | |||
*/ | |||
#define PWR_MAINREGULATOR_ON (0x00000000U) | |||
#define PWR_LOWPOWERREGULATOR_ON PWR_CR_LPSDSR | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PWR_SLEEP_mode_entry PWR SLEEP mode entry | |||
* @{ | |||
*/ | |||
#define PWR_SLEEPENTRY_WFI ((uint8_t)0x01) | |||
#define PWR_SLEEPENTRY_WFE ((uint8_t)0x02) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PWR_STOP_mode_entry PWR STOP mode entry | |||
* @{ | |||
*/ | |||
#define PWR_STOPENTRY_WFI ((uint8_t)0x01) | |||
#define PWR_STOPENTRY_WFE ((uint8_t)0x02) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PWR_Regulator_Voltage_Scale PWR Regulator Voltage Scale | |||
* @{ | |||
*/ | |||
#define PWR_REGULATOR_VOLTAGE_SCALE1 PWR_CR_VOS_0 | |||
#define PWR_REGULATOR_VOLTAGE_SCALE2 PWR_CR_VOS_1 | |||
#define PWR_REGULATOR_VOLTAGE_SCALE3 PWR_CR_VOS | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup PWR_Flag PWR Flag | |||
* @{ | |||
*/ | |||
#define PWR_FLAG_WU PWR_CSR_WUF | |||
#define PWR_FLAG_SB PWR_CSR_SBF | |||
#define PWR_FLAG_PVDO PWR_CSR_PVDO | |||
#define PWR_FLAG_VREFINTRDY PWR_CSR_VREFINTRDYF | |||
#define PWR_FLAG_VOS PWR_CSR_VOSF | |||
#define PWR_FLAG_REGLP PWR_CSR_REGLPF | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/** @defgroup PWR_Exported_Macros PWR Exported Macros | |||
* @{ | |||
*/ | |||
/** @brief macros configure the main internal regulator output voltage. | |||
* @param __REGULATOR__ specifies the regulator output voltage to achieve | |||
* a tradeoff between performance and power consumption when the device does | |||
* not operate at the maximum frequency (refer to the datasheets for more details). | |||
* This parameter can be one of the following values: | |||
* @arg PWR_REGULATOR_VOLTAGE_SCALE1: Regulator voltage output Scale 1 mode, | |||
* System frequency up to 32 MHz. | |||
* @arg PWR_REGULATOR_VOLTAGE_SCALE2: Regulator voltage output Scale 2 mode, | |||
* System frequency up to 16 MHz. | |||
* @arg PWR_REGULATOR_VOLTAGE_SCALE3: Regulator voltage output Scale 3 mode, | |||
* System frequency up to 4.2 MHz | |||
* @retval None | |||
*/ | |||
#define __HAL_PWR_VOLTAGESCALING_CONFIG(__REGULATOR__) (MODIFY_REG(PWR->CR, PWR_CR_VOS, (__REGULATOR__))) | |||
/** @brief Check PWR flag is set or not. | |||
* @param __FLAG__ specifies the flag to check. | |||
* This parameter can be one of the following values: | |||
* @arg PWR_FLAG_WU: Wake Up flag. This flag indicates that a wakeup event | |||
* was received from the WKUP pin or from the RTC alarm (Alarm B), | |||
* RTC Tamper event, RTC TimeStamp event or RTC Wakeup. | |||
* An additional wakeup event is detected if the WKUP pin is enabled | |||
* (by setting the EWUP bit) when the WKUP pin level is already high. | |||
* @arg PWR_FLAG_SB: StandBy flag. This flag indicates that the system was | |||
* resumed from StandBy mode. | |||
* @arg PWR_FLAG_PVDO: PVD Output. This flag is valid only if PVD is enabled | |||
* by the HAL_PWR_EnablePVD() function. The PVD is stopped by Standby mode | |||
* For this reason, this bit is equal to 0 after Standby or reset | |||
* until the PVDE bit is set. | |||
* @arg PWR_FLAG_VREFINTRDY: Internal voltage reference (VREFINT) ready flag. | |||
* This bit indicates the state of the internal voltage reference, VREFINT. | |||
* @arg PWR_FLAG_VOS: Voltage Scaling select flag. A delay is required for | |||
* the internal regulator to be ready after the voltage range is changed. | |||
* The VOSF bit indicates that the regulator has reached the voltage level | |||
* defined with bits VOS of PWR_CR register. | |||
* @arg PWR_FLAG_REGLP: Regulator LP flag. When the MCU exits from Low power run | |||
* mode, this bit stays at 1 until the regulator is ready in main mode. | |||
* A polling on this bit is recommended to wait for the regulator main mode. | |||
* This bit is reset by hardware when the regulator is ready. | |||
* @retval The new state of __FLAG__ (TRUE or FALSE). | |||
*/ | |||
#define __HAL_PWR_GET_FLAG(__FLAG__) ((PWR->CSR & (__FLAG__)) == (__FLAG__)) | |||
/** @brief Clear the PWR's pending flags. | |||
* @param __FLAG__ specifies the flag to clear. | |||
* This parameter can be one of the following values: | |||
* @arg PWR_FLAG_WU: Wake Up flag | |||
* @arg PWR_FLAG_SB: StandBy flag | |||
*/ | |||
#define __HAL_PWR_CLEAR_FLAG(__FLAG__) SET_BIT(PWR->CR, ((__FLAG__) << 2)) | |||
/** | |||
* @brief Enable interrupt on PVD Exti Line 16. | |||
* @retval None. | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR, PWR_EXTI_LINE_PVD) | |||
/** | |||
* @brief Disable interrupt on PVD Exti Line 16. | |||
* @retval None. | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR, PWR_EXTI_LINE_PVD) | |||
/** | |||
* @brief Enable event on PVD Exti Line 16. | |||
* @retval None. | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR, PWR_EXTI_LINE_PVD) | |||
/** | |||
* @brief Disable event on PVD Exti Line 16. | |||
* @retval None. | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR, PWR_EXTI_LINE_PVD) | |||
/** | |||
* @brief PVD EXTI line configuration: set falling edge trigger. | |||
* @retval None. | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR, PWR_EXTI_LINE_PVD) | |||
/** | |||
* @brief Disable the PVD Extended Interrupt Falling Trigger. | |||
* @retval None. | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR, PWR_EXTI_LINE_PVD) | |||
/** | |||
* @brief PVD EXTI line configuration: set rising edge trigger. | |||
* @retval None. | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR, PWR_EXTI_LINE_PVD) | |||
/** | |||
* @brief Disable the PVD Extended Interrupt Rising Trigger. | |||
* @retval None. | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR, PWR_EXTI_LINE_PVD) | |||
/** | |||
* @brief PVD EXTI line configuration: set rising & falling edge trigger. | |||
* @retval None. | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_ENABLE_RISING_FALLING_EDGE() \ | |||
do { \ | |||
__HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE(); \ | |||
__HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE(); \ | |||
} while(0) | |||
/** | |||
* @brief Disable the PVD Extended Interrupt Rising & Falling Trigger. | |||
* @retval None. | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_DISABLE_RISING_FALLING_EDGE() \ | |||
do { \ | |||
__HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE(); \ | |||
__HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE(); \ | |||
} while(0) | |||
/** | |||
* @brief Check whether the specified PVD EXTI interrupt flag is set or not. | |||
* @retval EXTI PVD Line Status. | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_GET_FLAG() (EXTI->PR & (PWR_EXTI_LINE_PVD)) | |||
/** | |||
* @brief Clear the PVD EXTI flag. | |||
* @retval None. | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_CLEAR_FLAG() (EXTI->PR = (PWR_EXTI_LINE_PVD)) | |||
/** | |||
* @brief Generate a Software interrupt on selected EXTI line. | |||
* @retval None. | |||
*/ | |||
#define __HAL_PWR_PVD_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER, PWR_EXTI_LINE_PVD) | |||
/** | |||
* @} | |||
*/ | |||
/* Private macro -------------------------------------------------------------*/ | |||
/** @defgroup PWR_Private_Macros PWR Private Macros | |||
* @{ | |||
*/ | |||
#define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLEVEL_0) || ((LEVEL) == PWR_PVDLEVEL_1)|| \ | |||
((LEVEL) == PWR_PVDLEVEL_2) || ((LEVEL) == PWR_PVDLEVEL_3)|| \ | |||
((LEVEL) == PWR_PVDLEVEL_4) || ((LEVEL) == PWR_PVDLEVEL_5)|| \ | |||
((LEVEL) == PWR_PVDLEVEL_6) || ((LEVEL) == PWR_PVDLEVEL_7)) | |||
#define IS_PWR_PVD_MODE(MODE) (((MODE) == PWR_PVD_MODE_IT_RISING)|| ((MODE) == PWR_PVD_MODE_IT_FALLING) || \ | |||
((MODE) == PWR_PVD_MODE_IT_RISING_FALLING) || ((MODE) == PWR_PVD_MODE_EVENT_RISING) || \ | |||
((MODE) == PWR_PVD_MODE_EVENT_FALLING) || ((MODE) == PWR_PVD_MODE_EVENT_RISING_FALLING) || \ | |||
((MODE) == PWR_PVD_MODE_NORMAL)) | |||
#define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) || \ | |||
((REGULATOR) == PWR_LOWPOWERREGULATOR_ON)) | |||
#define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) || ((ENTRY) == PWR_SLEEPENTRY_WFE)) | |||
#define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || ((ENTRY) == PWR_STOPENTRY_WFE) ) | |||
#define IS_PWR_VOLTAGE_SCALING_RANGE(RANGE) (((RANGE) == PWR_REGULATOR_VOLTAGE_SCALE1) || \ | |||
((RANGE) == PWR_REGULATOR_VOLTAGE_SCALE2) || \ | |||
((RANGE) == PWR_REGULATOR_VOLTAGE_SCALE3)) | |||
/** | |||
* @} | |||
*/ | |||
/* Include PWR HAL Extension module */ | |||
#include "stm32l1xx_hal_pwr_ex.h" | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup PWR_Exported_Functions PWR Exported Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions | |||
* @{ | |||
*/ | |||
/* Initialization and de-initialization functions *******************************/ | |||
void HAL_PWR_DeInit(void); | |||
void HAL_PWR_EnableBkUpAccess(void); | |||
void HAL_PWR_DisableBkUpAccess(void); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup PWR_Exported_Functions_Group2 Peripheral Control functions | |||
* @{ | |||
*/ | |||
/* Peripheral Control functions ************************************************/ | |||
void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD); | |||
void HAL_PWR_EnablePVD(void); | |||
void HAL_PWR_DisablePVD(void); | |||
/* WakeUp pins configuration functions ****************************************/ | |||
void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx); | |||
void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx); | |||
/* Low Power modes configuration functions ************************************/ | |||
void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry); | |||
void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry); | |||
void HAL_PWR_EnterSTANDBYMode(void); | |||
void HAL_PWR_EnableSleepOnExit(void); | |||
void HAL_PWR_DisableSleepOnExit(void); | |||
void HAL_PWR_EnableSEVOnPend(void); | |||
void HAL_PWR_DisableSEVOnPend(void); | |||
void HAL_PWR_PVD_IRQHandler(void); | |||
void HAL_PWR_PVDCallback(void); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32L1xx_HAL_PWR_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,118 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_hal_pwr_ex.h | |||
* @author MCD Application Team | |||
* @brief Header file of PWR HAL Extension module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32L1xx_HAL_PWR_EX_H | |||
#define __STM32L1xx_HAL_PWR_EX_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx_hal_def.h" | |||
/** @addtogroup STM32L1xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup PWREx | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup PWREx_Exported_Constants PWREx Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup PWREx_WakeUp_Pins PWREx Wakeup Pins | |||
* @{ | |||
*/ | |||
#if defined (STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined (STM32L151xE) || defined (STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) || defined (STM32L151xB) || defined (STM32L151xBA) || defined (STM32L151xC) || defined (STM32L152xB) || defined (STM32L152xBA) || defined (STM32L152xC) || defined (STM32L162xC) | |||
#define PWR_WAKEUP_PIN1 PWR_CSR_EWUP1 | |||
#define PWR_WAKEUP_PIN2 PWR_CSR_EWUP2 | |||
#define PWR_WAKEUP_PIN3 PWR_CSR_EWUP3 | |||
#define IS_PWR_WAKEUP_PIN(PIN) (((PIN) == PWR_WAKEUP_PIN1) || \ | |||
((PIN) == PWR_WAKEUP_PIN2) || \ | |||
((PIN) == PWR_WAKEUP_PIN3)) | |||
#else | |||
#define PWR_WAKEUP_PIN1 PWR_CSR_EWUP1 | |||
#define PWR_WAKEUP_PIN2 PWR_CSR_EWUP2 | |||
#define IS_PWR_WAKEUP_PIN(PIN) (((PIN) == PWR_WAKEUP_PIN1) || \ | |||
((PIN) == PWR_WAKEUP_PIN2)) | |||
#endif | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @defgroup PWREx_Exported_Functions PWREx Exported Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup PWREx_Exported_Functions_Group1 | |||
* @{ | |||
*/ | |||
/* Peripheral Control methods ************************************************/ | |||
uint32_t HAL_PWREx_GetVoltageRange(void); | |||
void HAL_PWREx_EnableFastWakeUp(void); | |||
void HAL_PWREx_DisableFastWakeUp(void); | |||
void HAL_PWREx_EnableUltraLowPower(void); | |||
void HAL_PWREx_DisableUltraLowPower(void); | |||
void HAL_PWREx_EnableLowPowerRunMode(void); | |||
HAL_StatusTypeDef HAL_PWREx_DisableLowPowerRunMode(void); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32L1xx_HAL_PWR_EX_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,440 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_hal_rcc_ex.c | |||
* @author MCD Application Team | |||
* @brief Extended RCC HAL module driver. | |||
* This file provides firmware functions to manage the following | |||
* functionalities RCC extension peripheral: | |||
* + Extended Peripheral Control functions | |||
* | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright(c) 2017 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx_hal.h" | |||
/** @addtogroup STM32L1xx_HAL_Driver | |||
* @{ | |||
*/ | |||
#ifdef HAL_RCC_MODULE_ENABLED | |||
/** @defgroup RCCEx RCCEx | |||
* @brief RCC Extension HAL module driver | |||
* @{ | |||
*/ | |||
/* Private typedef -----------------------------------------------------------*/ | |||
/* Private define ------------------------------------------------------------*/ | |||
/** @defgroup RCCEx_Private_Constants RCCEx Private Constants | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private macro -------------------------------------------------------------*/ | |||
/** @defgroup RCCEx_Private_Macros RCCEx Private Macros | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private function prototypes -----------------------------------------------*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** @defgroup RCCEx_Exported_Functions RCCEx Exported Functions | |||
* @{ | |||
*/ | |||
/** @defgroup RCCEx_Exported_Functions_Group1 Extended Peripheral Control functions | |||
* @brief Extended Peripheral Control functions | |||
* | |||
@verbatim | |||
=============================================================================== | |||
##### Extended Peripheral Control functions ##### | |||
=============================================================================== | |||
[..] | |||
This subsection provides a set of functions allowing to control the RCC Clocks | |||
frequencies. | |||
[..] | |||
(@) Important note: Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to | |||
select the RTC clock source; in this case the Backup domain will be reset in | |||
order to modify the RTC Clock source, as consequence RTC registers (including | |||
the backup registers) are set to their reset values. | |||
@endverbatim | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Initializes the RCC extended peripherals clocks according to the specified | |||
* parameters in the RCC_PeriphCLKInitTypeDef. | |||
* @param PeriphClkInit pointer to an RCC_PeriphCLKInitTypeDef structure that | |||
* contains the configuration information for the Extended Peripherals clocks(RTC/LCD clock). | |||
* @retval HAL status | |||
* @note If HAL_ERROR returned, first switch-OFF HSE clock oscillator with @ref HAL_RCC_OscConfig() | |||
* to possibly update HSE divider. | |||
*/ | |||
HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit) | |||
{ | |||
uint32_t tickstart; | |||
uint32_t temp_reg; | |||
/* Check the parameters */ | |||
assert_param(IS_RCC_PERIPHCLOCK(PeriphClkInit->PeriphClockSelection)); | |||
/*------------------------------- RTC/LCD Configuration ------------------------*/ | |||
if ((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC) | |||
#if defined(LCD) | |||
|| (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LCD) == RCC_PERIPHCLK_LCD) | |||
#endif /* LCD */ | |||
) | |||
{ | |||
/* check for RTC Parameters used to output RTCCLK */ | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC) | |||
{ | |||
assert_param(IS_RCC_RTCCLKSOURCE(PeriphClkInit->RTCClockSelection)); | |||
} | |||
#if defined(LCD) | |||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LCD) == RCC_PERIPHCLK_LCD) | |||
{ | |||
assert_param(IS_RCC_RTCCLKSOURCE(PeriphClkInit->LCDClockSelection)); | |||
} | |||
#endif /* LCD */ | |||
FlagStatus pwrclkchanged = RESET; | |||
/* As soon as function is called to change RTC clock source, activation of the | |||
power domain is done. */ | |||
/* Requires to enable write access to Backup Domain of necessary */ | |||
if(__HAL_RCC_PWR_IS_CLK_DISABLED()) | |||
{ | |||
__HAL_RCC_PWR_CLK_ENABLE(); | |||
pwrclkchanged = SET; | |||
} | |||
if(HAL_IS_BIT_CLR(PWR->CR, PWR_CR_DBP)) | |||
{ | |||
/* Enable write access to Backup domain */ | |||
SET_BIT(PWR->CR, PWR_CR_DBP); | |||
/* Wait for Backup domain Write protection disable */ | |||
tickstart = HAL_GetTick(); | |||
while(HAL_IS_BIT_CLR(PWR->CR, PWR_CR_DBP)) | |||
{ | |||
if((HAL_GetTick() - tickstart) > RCC_DBP_TIMEOUT_VALUE) | |||
{ | |||
return HAL_TIMEOUT; | |||
} | |||
} | |||
} | |||
/* Check if user wants to change HSE RTC prescaler whereas HSE is enabled */ | |||
temp_reg = (RCC->CR & RCC_CR_RTCPRE); | |||
if ((temp_reg != (PeriphClkInit->RTCClockSelection & RCC_CR_RTCPRE)) | |||
#if defined (LCD) | |||
|| (temp_reg != (PeriphClkInit->LCDClockSelection & RCC_CR_RTCPRE)) | |||
#endif /* LCD */ | |||
) | |||
{ /* Check HSE State */ | |||
if ((PeriphClkInit->RTCClockSelection & RCC_CSR_RTCSEL) == RCC_CSR_RTCSEL_HSE) | |||
{ | |||
if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY)) | |||
{ | |||
/* To update HSE divider, first switch-OFF HSE clock oscillator*/ | |||
return HAL_ERROR; | |||
} | |||
} | |||
} | |||
/* Reset the Backup domain only if the RTC Clock source selection is modified from reset value */ | |||
temp_reg = (RCC->CSR & RCC_CSR_RTCSEL); | |||
if((temp_reg != 0x00000000U) && (((temp_reg != (PeriphClkInit->RTCClockSelection & RCC_CSR_RTCSEL)) \ | |||
&& (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC)) | |||
#if defined(LCD) | |||
|| ((temp_reg != (PeriphClkInit->LCDClockSelection & RCC_CSR_RTCSEL)) \ | |||
&& (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LCD) == RCC_PERIPHCLK_LCD)) | |||
#endif /* LCD */ | |||
)) | |||
{ | |||
/* Store the content of CSR register before the reset of Backup Domain */ | |||
temp_reg = (RCC->CSR & ~(RCC_CSR_RTCSEL)); | |||
/* RTC Clock selection can be changed only if the Backup Domain is reset */ | |||
__HAL_RCC_BACKUPRESET_FORCE(); | |||
__HAL_RCC_BACKUPRESET_RELEASE(); | |||
/* Restore the Content of CSR register */ | |||
RCC->CSR = temp_reg; | |||
/* Wait for LSERDY if LSE was enabled */ | |||
if (HAL_IS_BIT_SET(temp_reg, RCC_CSR_LSEON)) | |||
{ | |||
/* Get Start Tick */ | |||
tickstart = HAL_GetTick(); | |||
/* Wait till LSE is ready */ | |||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == 0U) | |||
{ | |||
if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE) | |||
{ | |||
return HAL_TIMEOUT; | |||
} | |||
} | |||
} | |||
} | |||
__HAL_RCC_RTC_CONFIG(PeriphClkInit->RTCClockSelection); | |||
/* Require to disable power clock if necessary */ | |||
if(pwrclkchanged == SET) | |||
{ | |||
__HAL_RCC_PWR_CLK_DISABLE(); | |||
} | |||
} | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Get the PeriphClkInit according to the internal RCC configuration registers. | |||
* @param PeriphClkInit pointer to an RCC_PeriphCLKInitTypeDef structure that | |||
* returns the configuration information for the Extended Peripherals clocks(RTC/LCD clocks). | |||
* @retval None | |||
*/ | |||
void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit) | |||
{ | |||
uint32_t srcclk; | |||
/* Set all possible values for the extended clock type parameter------------*/ | |||
PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_RTC; | |||
#if defined(LCD) | |||
PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_LCD; | |||
#endif /* LCD */ | |||
/* Get the RTC/LCD configuration -----------------------------------------------*/ | |||
srcclk = __HAL_RCC_GET_RTC_SOURCE(); | |||
if (srcclk != RCC_RTCCLKSOURCE_HSE_DIV2) | |||
{ | |||
/* Source clock is LSE or LSI*/ | |||
PeriphClkInit->RTCClockSelection = srcclk; | |||
} | |||
else | |||
{ | |||
/* Source clock is HSE. Need to get the prescaler value*/ | |||
PeriphClkInit->RTCClockSelection = srcclk | (READ_BIT(RCC->CR, RCC_CR_RTCPRE)); | |||
} | |||
#if defined(LCD) | |||
PeriphClkInit->LCDClockSelection = PeriphClkInit->RTCClockSelection; | |||
#endif /* LCD */ | |||
} | |||
/** | |||
* @brief Return the peripheral clock frequency | |||
* @note Return 0 if peripheral clock is unknown | |||
* @param PeriphClk Peripheral clock identifier | |||
* This parameter can be one of the following values: | |||
* @arg @ref RCC_PERIPHCLK_RTC RTC peripheral clock | |||
* @arg @ref RCC_PERIPHCLK_LCD LCD peripheral clock (*) | |||
* @note (*) means that this peripheral is not present on all the devices | |||
* @retval Frequency in Hz (0: means that no available frequency for the peripheral) | |||
*/ | |||
uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk) | |||
{ | |||
uint32_t frequency = 0; | |||
uint32_t srcclk; | |||
/* Check the parameters */ | |||
assert_param(IS_RCC_PERIPHCLOCK(PeriphClk)); | |||
switch (PeriphClk) | |||
{ | |||
case RCC_PERIPHCLK_RTC: | |||
#if defined(LCD) | |||
case RCC_PERIPHCLK_LCD: | |||
#endif /* LCD */ | |||
{ | |||
/* Get the current RTC source */ | |||
srcclk = __HAL_RCC_GET_RTC_SOURCE(); | |||
/* Check if LSE is ready if RTC clock selection is LSE */ | |||
if (srcclk == RCC_RTCCLKSOURCE_LSE) | |||
{ | |||
if (HAL_IS_BIT_SET(RCC->CSR, RCC_CSR_LSERDY)) | |||
{ | |||
frequency = LSE_VALUE; | |||
} | |||
} | |||
/* Check if LSI is ready if RTC clock selection is LSI */ | |||
else if (srcclk == RCC_RTCCLKSOURCE_LSI) | |||
{ | |||
if (HAL_IS_BIT_SET(RCC->CSR, RCC_CSR_LSIRDY)) | |||
{ | |||
frequency = LSI_VALUE; | |||
} | |||
} | |||
/* Check if HSE is ready and if RTC clock selection is HSE */ | |||
else if (srcclk == RCC_RTCCLKSOURCE_HSE_DIVX) | |||
{ | |||
if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY)) | |||
{ | |||
/* Get the current HSE clock divider */ | |||
switch (__HAL_RCC_GET_RTC_HSE_PRESCALER()) | |||
{ | |||
case RCC_RTC_HSE_DIV_16: /* HSE DIV16 has been selected */ | |||
{ | |||
frequency = HSE_VALUE / 16U; | |||
break; | |||
} | |||
case RCC_RTC_HSE_DIV_8: /* HSE DIV8 has been selected */ | |||
{ | |||
frequency = HSE_VALUE / 8U; | |||
break; | |||
} | |||
case RCC_RTC_HSE_DIV_4: /* HSE DIV4 has been selected */ | |||
{ | |||
frequency = HSE_VALUE / 4U; | |||
break; | |||
} | |||
default: /* HSE DIV2 has been selected */ | |||
{ | |||
frequency = HSE_VALUE / 2U; | |||
break; | |||
} | |||
} | |||
} | |||
} | |||
else | |||
{ | |||
/* No clock source, frequency default init at 0 */ | |||
} | |||
break; | |||
} | |||
default: | |||
break; | |||
} | |||
return(frequency); | |||
} | |||
#if defined(RCC_LSECSS_SUPPORT) | |||
/** | |||
* @brief Enables the LSE Clock Security System. | |||
* @note If a failure is detected on the external 32 kHz oscillator, the LSE clock is no longer supplied | |||
* to the RTC but no hardware action is made to the registers. | |||
* In Standby mode a wakeup is generated. In other modes an interrupt can be sent to wakeup | |||
* the software (see Section 5.3.4: Clock interrupt register (RCC_CIR) on page 104). | |||
* The software MUST then disable the LSECSSON bit, stop the defective 32 kHz oscillator | |||
* (disabling LSEON), and can change the RTC clock source (no clock or LSI or HSE, with | |||
* RTCSEL), or take any required action to secure the application. | |||
* @note LSE CSS available only for high density and medium+ devices | |||
* @retval None | |||
*/ | |||
void HAL_RCCEx_EnableLSECSS(void) | |||
{ | |||
*(__IO uint32_t *) CSR_LSECSSON_BB = (uint32_t)ENABLE; | |||
} | |||
/** | |||
* @brief Disables the LSE Clock Security System. | |||
* @note Once enabled this bit cannot be disabled, except after an LSE failure detection | |||
* (LSECSSD=1). In that case the software MUST disable the LSECSSON bit. | |||
* Reset by power on reset and RTC software reset (RTCRST bit). | |||
* @note LSE CSS available only for high density and medium+ devices | |||
* @retval None | |||
*/ | |||
void HAL_RCCEx_DisableLSECSS(void) | |||
{ | |||
/* Disable LSE CSS */ | |||
*(__IO uint32_t *) CSR_LSECSSON_BB = (uint32_t)DISABLE; | |||
/* Disable LSE CSS IT */ | |||
__HAL_RCC_DISABLE_IT(RCC_IT_LSECSS); | |||
} | |||
/** | |||
* @brief Enable the LSE Clock Security System IT & corresponding EXTI line. | |||
* @note LSE Clock Security System IT is mapped on RTC EXTI line 19 | |||
* @retval None | |||
*/ | |||
void HAL_RCCEx_EnableLSECSS_IT(void) | |||
{ | |||
/* Enable LSE CSS */ | |||
*(__IO uint32_t *) CSR_LSECSSON_BB = (uint32_t)ENABLE; | |||
/* Enable LSE CSS IT */ | |||
__HAL_RCC_ENABLE_IT(RCC_IT_LSECSS); | |||
/* Enable IT on EXTI Line 19 */ | |||
__HAL_RCC_LSECSS_EXTI_ENABLE_IT(); | |||
__HAL_RCC_LSECSS_EXTI_ENABLE_RISING_EDGE(); | |||
} | |||
/** | |||
* @brief Handle the RCC LSE Clock Security System interrupt request. | |||
* @retval None | |||
*/ | |||
void HAL_RCCEx_LSECSS_IRQHandler(void) | |||
{ | |||
/* Check RCC LSE CSSF flag */ | |||
if(__HAL_RCC_GET_IT(RCC_IT_LSECSS)) | |||
{ | |||
/* RCC LSE Clock Security System interrupt user callback */ | |||
HAL_RCCEx_LSECSS_Callback(); | |||
/* Clear RCC LSE CSS pending bit */ | |||
__HAL_RCC_CLEAR_IT(RCC_IT_LSECSS); | |||
} | |||
} | |||
/** | |||
* @brief RCCEx LSE Clock Security System interrupt callback. | |||
* @retval none | |||
*/ | |||
__weak void HAL_RCCEx_LSECSS_Callback(void) | |||
{ | |||
/* NOTE : This function should not be modified, when the callback is needed, | |||
the @ref HAL_RCCEx_LSECSS_Callback should be implemented in the user file | |||
*/ | |||
} | |||
#endif /* RCC_LSECSS_SUPPORT */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#endif /* HAL_RCC_MODULE_ENABLED */ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,808 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_hal_rtc.h | |||
* @author MCD Application Team | |||
* @brief Header file of RTC HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2017 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32L1xx_HAL_RTC_H | |||
#define __STM32L1xx_HAL_RTC_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx_hal_def.h" | |||
/** @addtogroup STM32L1xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @defgroup RTC RTC | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup RTC_Exported_Types RTC Exported Types | |||
* @{ | |||
*/ | |||
/** | |||
* @brief HAL State structures definition | |||
*/ | |||
typedef enum | |||
{ | |||
HAL_RTC_STATE_RESET = 0x00U, /*!< RTC not yet initialized or disabled */ | |||
HAL_RTC_STATE_READY = 0x01U, /*!< RTC initialized and ready for use */ | |||
HAL_RTC_STATE_BUSY = 0x02U, /*!< RTC process is ongoing */ | |||
HAL_RTC_STATE_TIMEOUT = 0x03U, /*!< RTC timeout state */ | |||
HAL_RTC_STATE_ERROR = 0x04U /*!< RTC error state */ | |||
} HAL_RTCStateTypeDef; | |||
/** | |||
* @brief RTC Configuration Structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t HourFormat; /*!< Specifies the RTC Hour Format. | |||
This parameter can be a value of @ref RTC_Hour_Formats */ | |||
uint32_t AsynchPrediv; /*!< Specifies the RTC Asynchronous Predivider value. | |||
This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7F */ | |||
uint32_t SynchPrediv; /*!< Specifies the RTC Synchronous Predivider value. | |||
This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7FFF */ | |||
uint32_t OutPut; /*!< Specifies which signal will be routed to the RTC output. | |||
This parameter can be a value of @ref RTCEx_Output_selection_Definitions */ | |||
uint32_t OutPutPolarity; /*!< Specifies the polarity of the output signal. | |||
This parameter can be a value of @ref RTC_Output_Polarity_Definitions */ | |||
uint32_t OutPutType; /*!< Specifies the RTC Output Pin mode. | |||
This parameter can be a value of @ref RTC_Output_Type_ALARM_OUT */ | |||
} RTC_InitTypeDef; | |||
/** | |||
* @brief RTC Time structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint8_t Hours; /*!< Specifies the RTC Time Hour. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 12 if the RTC_HourFormat_12 is selected. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 23 if the RTC_HourFormat_24 is selected */ | |||
uint8_t Minutes; /*!< Specifies the RTC Time Minutes. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 59 */ | |||
uint8_t Seconds; /*!< Specifies the RTC Time Seconds. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 59 */ | |||
uint8_t TimeFormat; /*!< Specifies the RTC AM/PM Time. | |||
This parameter can be a value of @ref RTC_AM_PM_Definitions */ | |||
#if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) | |||
uint32_t SubSeconds; /*!< Specifies the RTC_SSR RTC Sub Second register content. | |||
This parameter corresponds to a time unit range between [0-1] Second | |||
with [1 Sec / SecondFraction +1] granularity */ | |||
uint32_t SecondFraction; /*!< Specifies the range or granularity of Sub Second register content | |||
corresponding to Synchronous pre-scaler factor value (PREDIV_S) | |||
This parameter corresponds to a time unit range between [0-1] Second | |||
with [1 Sec / SecondFraction +1] granularity. | |||
This field will be used only by HAL_RTC_GetTime function */ | |||
#endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ | |||
uint32_t DayLightSaving; /*!< Specifies RTC_DayLightSaveOperation: the value of hour adjustment. | |||
This parameter can be a value of @ref RTC_DayLightSaving_Definitions */ | |||
uint32_t StoreOperation; /*!< Specifies RTC_StoreOperation value to be written in the BCK bit | |||
in CR register to store the operation. | |||
This parameter can be a value of @ref RTC_StoreOperation_Definitions */ | |||
} RTC_TimeTypeDef; | |||
/** | |||
* @brief RTC Date structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint8_t WeekDay; /*!< Specifies the RTC Date WeekDay. | |||
This parameter can be a value of @ref RTC_WeekDay_Definitions */ | |||
uint8_t Month; /*!< Specifies the RTC Date Month (in BCD format). | |||
This parameter can be a value of @ref RTC_Month_Date_Definitions */ | |||
uint8_t Date; /*!< Specifies the RTC Date. | |||
This parameter must be a number between Min_Data = 1 and Max_Data = 31 */ | |||
uint8_t Year; /*!< Specifies the RTC Date Year. | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 99 */ | |||
} RTC_DateTypeDef; | |||
/** | |||
* @brief RTC Alarm structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
RTC_TimeTypeDef AlarmTime; /*!< Specifies the RTC Alarm Time members */ | |||
uint32_t AlarmMask; /*!< Specifies the RTC Alarm Masks. | |||
This parameter can be a value of @ref RTC_AlarmMask_Definitions */ | |||
#if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) | |||
uint32_t AlarmSubSecondMask; /*!< Specifies the RTC Alarm SubSeconds Masks. | |||
This parameter can be a value of @ref RTC_Alarm_Sub_Seconds_Masks_Definitions */ | |||
#endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ | |||
uint32_t AlarmDateWeekDaySel; /*!< Specifies the RTC Alarm is on Date or WeekDay. | |||
This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */ | |||
uint8_t AlarmDateWeekDay; /*!< Specifies the RTC Alarm Date/WeekDay. | |||
If the Alarm Date is selected, this parameter must be set to a value in the 1-31 range. | |||
If the Alarm WeekDay is selected, this parameter can be a value of @ref RTC_WeekDay_Definitions */ | |||
uint32_t Alarm; /*!< Specifies the alarm . | |||
This parameter can be a value of @ref RTC_Alarms_Definitions */ | |||
} RTC_AlarmTypeDef; | |||
/** | |||
* @brief RTC Handle Structure definition | |||
*/ | |||
#if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) | |||
typedef struct __RTC_HandleTypeDef | |||
#else | |||
typedef struct | |||
#endif | |||
{ | |||
RTC_TypeDef *Instance; /*!< Register base address */ | |||
RTC_InitTypeDef Init; /*!< RTC required parameters */ | |||
HAL_LockTypeDef Lock; /*!< RTC locking object */ | |||
__IO HAL_RTCStateTypeDef State; /*!< Time communication state */ | |||
#if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) | |||
void (* AlarmAEventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Alarm A Event callback */ | |||
void (* AlarmBEventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Alarm B Event callback */ | |||
void (* TimeStampEventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC TimeStamp Event callback */ | |||
void (* WakeUpTimerEventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC WakeUpTimer Event callback */ | |||
void (* Tamper1EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Tamper 1 Event callback */ | |||
#if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) | |||
void (* Tamper2EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Tamper 2 Event callback */ | |||
void (* Tamper3EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Tamper 3 Event callback */ | |||
#endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ | |||
void (* MspInitCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Msp Init callback */ | |||
void (* MspDeInitCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Msp DeInit callback */ | |||
#endif /* (USE_HAL_RTC_REGISTER_CALLBACKS) */ | |||
} RTC_HandleTypeDef; | |||
#if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) | |||
/** | |||
* @brief HAL LPTIM Callback ID enumeration definition | |||
*/ | |||
typedef enum | |||
{ | |||
HAL_RTC_ALARM_A_EVENT_CB_ID = 0x00U, /*!< RTC Alarm A Event Callback ID */ | |||
HAL_RTC_ALARM_B_EVENT_CB_ID = 0x01U, /*!< RTC Alarm B Event Callback ID */ | |||
HAL_RTC_TIMESTAMP_EVENT_CB_ID = 0x02U, /*!< RTC TimeStamp Event Callback ID */ | |||
HAL_RTC_WAKEUPTIMER_EVENT_CB_ID = 0x03U, /*!< RTC WakeUp Timer Event Callback ID */ | |||
HAL_RTC_TAMPER1_EVENT_CB_ID = 0x04U, /*!< RTC Tamper 1 Callback ID */ | |||
#if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) | |||
HAL_RTC_TAMPER2_EVENT_CB_ID = 0x05U, /*!< RTC Tamper 2 Callback ID */ | |||
HAL_RTC_TAMPER3_EVENT_CB_ID = 0x06U, /*!< RTC Tamper 3 Callback ID */ | |||
#endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ | |||
HAL_RTC_MSPINIT_CB_ID = 0x0EU, /*!< RTC Msp Init callback ID */ | |||
HAL_RTC_MSPDEINIT_CB_ID = 0x0FU /*!< RTC Msp DeInit callback ID */ | |||
} HAL_RTC_CallbackIDTypeDef; | |||
/** | |||
* @brief HAL RTC Callback pointer definition | |||
*/ | |||
typedef void (*pRTC_CallbackTypeDef)(RTC_HandleTypeDef *hrtc); /*!< pointer to an RTC callback function */ | |||
#endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup RTC_Exported_Constants RTC Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup RTC_Hour_Formats RTC Hour Formats | |||
* @{ | |||
*/ | |||
#define RTC_HOURFORMAT_24 (0x00000000U) | |||
#define RTC_HOURFORMAT_12 (0x00000040U) | |||
#define IS_RTC_HOUR_FORMAT(FORMAT) (((FORMAT) == RTC_HOURFORMAT_12) || \ | |||
((FORMAT) == RTC_HOURFORMAT_24)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_Output_Polarity_Definitions RTC Output Polarity Definitions | |||
* @{ | |||
*/ | |||
#define RTC_OUTPUT_POLARITY_HIGH (0x00000000U) | |||
#define RTC_OUTPUT_POLARITY_LOW (0x00100000U) | |||
#define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPUT_POLARITY_HIGH) || \ | |||
((POL) == RTC_OUTPUT_POLARITY_LOW)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_Output_Type_ALARM_OUT RTC Output Type ALARM OUT | |||
* @{ | |||
*/ | |||
#define RTC_OUTPUT_TYPE_OPENDRAIN (0x00000000U) | |||
#define RTC_OUTPUT_TYPE_PUSHPULL (0x00040000U) | |||
#define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_TYPE_OPENDRAIN) || \ | |||
((TYPE) == RTC_OUTPUT_TYPE_PUSHPULL)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_Asynchronous_Predivider Asynchronous Predivider | |||
* @{ | |||
*/ | |||
#define IS_RTC_ASYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7FU) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_Time_Definitions Time Definitions | |||
* @{ | |||
*/ | |||
#define IS_RTC_HOUR12(HOUR) (((HOUR) > 0U) && ((HOUR) <= 12U)) | |||
#define IS_RTC_HOUR24(HOUR) ((HOUR) <= 23U) | |||
#define IS_RTC_MINUTES(MINUTES) ((MINUTES) <= 59U) | |||
#define IS_RTC_SECONDS(SECONDS) ((SECONDS) <= 59U) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_AM_PM_Definitions AM PM Definitions | |||
* @{ | |||
*/ | |||
#define RTC_HOURFORMAT12_AM ((uint8_t)0x00) | |||
#define RTC_HOURFORMAT12_PM ((uint8_t)0x40) | |||
#define IS_RTC_HOURFORMAT12(PM) (((PM) == RTC_HOURFORMAT12_AM) || ((PM) == RTC_HOURFORMAT12_PM)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_DayLightSaving_Definitions DayLightSaving | |||
* @{ | |||
*/ | |||
#define RTC_DAYLIGHTSAVING_SUB1H (0x00020000U) | |||
#define RTC_DAYLIGHTSAVING_ADD1H (0x00010000U) | |||
#define RTC_DAYLIGHTSAVING_NONE (0x00000000U) | |||
#define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHTSAVING_SUB1H) || \ | |||
((SAVE) == RTC_DAYLIGHTSAVING_ADD1H) || \ | |||
((SAVE) == RTC_DAYLIGHTSAVING_NONE)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_StoreOperation_Definitions StoreOperation | |||
* @{ | |||
*/ | |||
#define RTC_STOREOPERATION_RESET (0x00000000U) | |||
#define RTC_STOREOPERATION_SET (0x00040000U) | |||
#define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_STOREOPERATION_RESET) || \ | |||
((OPERATION) == RTC_STOREOPERATION_SET)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_Input_parameter_format_definitions Input Parameter Format | |||
* @{ | |||
*/ | |||
#define RTC_FORMAT_BIN (0x000000000U) | |||
#define RTC_FORMAT_BCD (0x000000001U) | |||
#define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || ((FORMAT) == RTC_FORMAT_BCD)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_Year_Date_Definitions Year Definitions | |||
* @{ | |||
*/ | |||
#define IS_RTC_YEAR(YEAR) ((YEAR) <= 99U) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_Month_Date_Definitions Month Definitions | |||
* @{ | |||
*/ | |||
/* Coded in BCD format */ | |||
#define RTC_MONTH_JANUARY ((uint8_t)0x01) | |||
#define RTC_MONTH_FEBRUARY ((uint8_t)0x02) | |||
#define RTC_MONTH_MARCH ((uint8_t)0x03) | |||
#define RTC_MONTH_APRIL ((uint8_t)0x04) | |||
#define RTC_MONTH_MAY ((uint8_t)0x05) | |||
#define RTC_MONTH_JUNE ((uint8_t)0x06) | |||
#define RTC_MONTH_JULY ((uint8_t)0x07) | |||
#define RTC_MONTH_AUGUST ((uint8_t)0x08) | |||
#define RTC_MONTH_SEPTEMBER ((uint8_t)0x09) | |||
#define RTC_MONTH_OCTOBER ((uint8_t)0x10) | |||
#define RTC_MONTH_NOVEMBER ((uint8_t)0x11) | |||
#define RTC_MONTH_DECEMBER ((uint8_t)0x12) | |||
#define IS_RTC_MONTH(MONTH) (((MONTH) >= 1U) && ((MONTH) <= 12U)) | |||
#define IS_RTC_DATE(DATE) (((DATE) >= 1U) && ((DATE) <= 31U)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_WeekDay_Definitions WeekDay Definitions | |||
* @{ | |||
*/ | |||
#define RTC_WEEKDAY_MONDAY ((uint8_t)0x01) | |||
#define RTC_WEEKDAY_TUESDAY ((uint8_t)0x02) | |||
#define RTC_WEEKDAY_WEDNESDAY ((uint8_t)0x03) | |||
#define RTC_WEEKDAY_THURSDAY ((uint8_t)0x04) | |||
#define RTC_WEEKDAY_FRIDAY ((uint8_t)0x05) | |||
#define RTC_WEEKDAY_SATURDAY ((uint8_t)0x06) | |||
#define RTC_WEEKDAY_SUNDAY ((uint8_t)0x07) | |||
#define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \ | |||
((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \ | |||
((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \ | |||
((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \ | |||
((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \ | |||
((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \ | |||
((WEEKDAY) == RTC_WEEKDAY_SUNDAY)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_Alarm_Definitions Alarm Definitions | |||
* @{ | |||
*/ | |||
#define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) > 0U) && ((DATE) <= 31U)) | |||
#define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \ | |||
((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \ | |||
((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \ | |||
((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \ | |||
((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \ | |||
((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \ | |||
((WEEKDAY) == RTC_WEEKDAY_SUNDAY)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_AlarmDateWeekDay_Definitions AlarmDateWeekDay Definitions | |||
* @{ | |||
*/ | |||
#define RTC_ALARMDATEWEEKDAYSEL_DATE (0x00000000U) | |||
#define RTC_ALARMDATEWEEKDAYSEL_WEEKDAY (0x40000000U) | |||
#define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \ | |||
((SEL) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY)) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_AlarmMask_Definitions Alarm Mask Definitions | |||
* @{ | |||
*/ | |||
#define RTC_ALARMMASK_NONE (0x00000000U) | |||
#define RTC_ALARMMASK_DATEWEEKDAY RTC_ALRMAR_MSK4 | |||
#define RTC_ALARMMASK_HOURS RTC_ALRMAR_MSK3 | |||
#define RTC_ALARMMASK_MINUTES RTC_ALRMAR_MSK2 | |||
#define RTC_ALARMMASK_SECONDS RTC_ALRMAR_MSK1 | |||
#define RTC_ALARMMASK_ALL (0x80808080U) | |||
#define IS_RTC_ALARM_MASK(MASK) (((MASK) & 0x7F7F7F7F) == (uint32_t)RESET) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_Alarms_Definitions Alarms Definitions | |||
* @{ | |||
*/ | |||
#define RTC_ALARM_A RTC_CR_ALRAE | |||
#define RTC_ALARM_B RTC_CR_ALRBE | |||
#define IS_RTC_ALARM(ALARM) (((ALARM) == RTC_ALARM_A) || ((ALARM) == RTC_ALARM_B)) | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macros -----------------------------------------------------------*/ | |||
/** @defgroup RTC_Exported_macros RTC Exported Macros | |||
* @{ | |||
*/ | |||
/** @brief Reset RTC handle state | |||
* @param __HANDLE__ RTC handle. | |||
* @retval None | |||
*/ | |||
#if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) | |||
#define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) do{\ | |||
(__HANDLE__)->State = HAL_RTC_STATE_RESET;\ | |||
(__HANDLE__)->MspInitCallback = NULL;\ | |||
(__HANDLE__)->MspDeInitCallback = NULL;\ | |||
}while(0) | |||
#else | |||
#define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RTC_STATE_RESET) | |||
#endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ | |||
/** | |||
* @brief Disable the write protection for RTC registers. | |||
* @param __HANDLE__ specifies the RTC handle. | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__) \ | |||
do{ \ | |||
(__HANDLE__)->Instance->WPR = 0xCAU; \ | |||
(__HANDLE__)->Instance->WPR = 0x53U; \ | |||
} while(0U) | |||
/** | |||
* @brief Enable the write protection for RTC registers. | |||
* @param __HANDLE__ specifies the RTC handle. | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__) \ | |||
do{ \ | |||
(__HANDLE__)->Instance->WPR = 0xFFU; \ | |||
} while(0U) | |||
/** | |||
* @brief Enable the RTC ALARMA peripheral. | |||
* @param __HANDLE__ specifies the RTC handle. | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_ALARMA_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRAE)) | |||
/** | |||
* @brief Disable the RTC ALARMA peripheral. | |||
* @param __HANDLE__ specifies the RTC handle. | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_ALARMA_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRAE)) | |||
/** | |||
* @brief Enable the RTC ALARMB peripheral. | |||
* @param __HANDLE__ specifies the RTC handle. | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_ALARMB_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRBE)) | |||
/** | |||
* @brief Disable the RTC ALARMB peripheral. | |||
* @param __HANDLE__ specifies the RTC handle. | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_ALARMB_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRBE)) | |||
/** | |||
* @brief Enable the RTC Alarm interrupt. | |||
* @param __HANDLE__ specifies the RTC handle. | |||
* @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled. | |||
* This parameter can be any combination of the following values: | |||
* @arg RTC_IT_ALRA: Alarm A interrupt | |||
* @arg RTC_IT_ALRB: Alarm B interrupt | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_ALARM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR |= (__INTERRUPT__)) | |||
/** | |||
* @brief Disable the RTC Alarm interrupt. | |||
* @param __HANDLE__ specifies the RTC handle. | |||
* @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled. | |||
* This parameter can be any combination of the following values: | |||
* @arg RTC_IT_ALRA: Alarm A interrupt | |||
* @arg RTC_IT_ALRB: Alarm B interrupt | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_ALARM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__)) | |||
/** | |||
* @brief Check whether the specified RTC Alarm interrupt has occurred or not. | |||
* @param __HANDLE__ specifies the RTC handle. | |||
* @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to check. | |||
* This parameter can be: | |||
* @arg RTC_IT_ALRA: Alarm A interrupt | |||
* @arg RTC_IT_ALRB: Alarm B interrupt | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->ISR)& ((__INTERRUPT__)>> 4U)) != 0U)? 1U : 0U) | |||
/** | |||
* @brief Check whether the specified RTC Alarm interrupt has been enabled or not. | |||
* @param __HANDLE__ specifies the RTC handle. | |||
* @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to check. | |||
* This parameter can be: | |||
* @arg RTC_IT_ALRA: Alarm A interrupt | |||
* @arg RTC_IT_ALRB: Alarm B interrupt | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_ALARM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != 0U) ? 1U : 0U) | |||
/** | |||
* @brief Get the selected RTC Alarm's flag status. | |||
* @param __HANDLE__ specifies the RTC handle. | |||
* @param __FLAG__ specifies the RTC Alarm Flag sources to check. | |||
* This parameter can be: | |||
* @arg RTC_FLAG_ALRAF | |||
* @arg RTC_FLAG_ALRBF | |||
* @arg RTC_FLAG_ALRAWF | |||
* @arg RTC_FLAG_ALRBWF | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U)? 1U : 0U) | |||
/** | |||
* @brief Clear the RTC Alarm's pending flags. | |||
* @param __HANDLE__ specifies the RTC handle. | |||
* @param __FLAG__ specifies the RTC Alarm Flag sources to clear. | |||
* This parameter can be: | |||
* @arg RTC_FLAG_ALRAF | |||
* @arg RTC_FLAG_ALRBF | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT) | ((__HANDLE__)->Instance->ISR & RTC_ISR_INIT)) | |||
/** | |||
* @brief Enable interrupt on the RTC Alarm associated Exti line. | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_ENABLE_IT() (EXTI->IMR |= RTC_EXTI_LINE_ALARM_EVENT) | |||
/** | |||
* @brief Disable interrupt on the RTC Alarm associated Exti line. | |||
* @retval None | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_DISABLE_IT() (EXTI->IMR &= ~(RTC_EXTI_LINE_ALARM_EVENT)) | |||
/** | |||
* @brief Enable event on the RTC Alarm associated Exti line. | |||
* @retval None. | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_ENABLE_EVENT() (EXTI->EMR |= RTC_EXTI_LINE_ALARM_EVENT) | |||
/** | |||
* @brief Disable event on the RTC Alarm associated Exti line. | |||
* @retval None. | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_DISABLE_EVENT() (EXTI->EMR &= ~(RTC_EXTI_LINE_ALARM_EVENT)) | |||
/** | |||
* @brief Enable falling edge trigger on the RTC Alarm associated Exti line. | |||
* @retval None. | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE() (EXTI->FTSR |= RTC_EXTI_LINE_ALARM_EVENT) | |||
/** | |||
* @brief Disable falling edge trigger on the RTC Alarm associated Exti line. | |||
* @retval None. | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE() (EXTI->FTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT)) | |||
/** | |||
* @brief Enable rising edge trigger on the RTC Alarm associated Exti line. | |||
* @retval None. | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE() (EXTI->RTSR |= RTC_EXTI_LINE_ALARM_EVENT) | |||
/** | |||
* @brief Disable rising edge trigger on the RTC Alarm associated Exti line. | |||
* @retval None. | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE() (EXTI->RTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT)) | |||
/** | |||
* @brief Enable rising & falling edge trigger on the RTC Alarm associated Exti line. | |||
* @retval None. | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_FALLING_EDGE() do { \ | |||
__HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE(); \ | |||
__HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE(); \ | |||
} while(0U) | |||
/** | |||
* @brief Disable rising & falling edge trigger on the RTC Alarm associated Exti line. | |||
* @retval None. | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_FALLING_EDGE() do { \ | |||
__HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE(); \ | |||
__HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE(); \ | |||
} while(0U) | |||
/** | |||
* @brief Check whether the RTC Alarm associated Exti line interrupt flag is set or not. | |||
* @retval Line Status. | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_GET_FLAG() (EXTI->PR & RTC_EXTI_LINE_ALARM_EVENT) | |||
/** | |||
* @brief Clear the RTC Alarm associated Exti line flag. | |||
* @retval None. | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_CLEAR_FLAG() (EXTI->PR = RTC_EXTI_LINE_ALARM_EVENT) | |||
/** | |||
* @brief Generate a Software interrupt on RTC Alarm associated Exti line. | |||
* @retval None. | |||
*/ | |||
#define __HAL_RTC_ALARM_EXTI_GENERATE_SWIT() (EXTI->SWIER |= RTC_EXTI_LINE_ALARM_EVENT) | |||
/** | |||
* @} | |||
*/ | |||
/* Include RTC HAL Extended module */ | |||
#include "stm32l1xx_hal_rtc_ex.h" | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @defgroup RTC_Exported_Functions RTC Exported Functions | |||
* @{ | |||
*/ | |||
/** @defgroup RTC_Exported_Functions_Group1 Initialization and de-initialization functions | |||
* @{ | |||
*/ | |||
/* Initialization and de-initialization functions ****************************/ | |||
HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc); | |||
HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc); | |||
void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc); | |||
void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc); | |||
/* Callbacks Register/UnRegister functions ***********************************/ | |||
#if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) | |||
HAL_StatusTypeDef HAL_RTC_RegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID, pRTC_CallbackTypeDef pCallback); | |||
HAL_StatusTypeDef HAL_RTC_UnRegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID); | |||
#endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_Exported_Functions_Group2 RTC Time and Date functions | |||
* @{ | |||
*/ | |||
/* RTC Time and Date functions ************************************************/ | |||
HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format); | |||
HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format); | |||
HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format); | |||
HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format); | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_Exported_Functions_Group3 RTC Alarm functions | |||
* @{ | |||
*/ | |||
/* RTC Alarm functions ********************************************************/ | |||
HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format); | |||
HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format); | |||
HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm); | |||
HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format); | |||
void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc); | |||
HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout); | |||
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc); | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_Exported_Functions_Group4 Peripheral Control functions | |||
* @{ | |||
*/ | |||
/* Peripheral Control functions ***********************************************/ | |||
HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef *hrtc); | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup RTC_Exported_Functions_Group5 Peripheral State functions | |||
* @{ | |||
*/ | |||
/* Peripheral State functions *************************************************/ | |||
HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef *hrtc); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private types -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private constants ---------------------------------------------------------*/ | |||
/** @defgroup RTC_Private_Constants RTC Private Constants | |||
* @{ | |||
*/ | |||
#define RTC_TIMEOUT_VALUE 1000U | |||
#define RTC_EXTI_LINE_ALARM_EVENT ((uint32_t)EXTI_IMR_MR17) /*!< External interrupt line 17 Connected to the RTC Alarm event */ | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/** @defgroup RTC_Private_Macros RTC Private Macros | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Private functions -------------------------------------------------------------*/ | |||
/** @defgroup RTC_Private_Functions RTC Private Functions | |||
* @{ | |||
*/ | |||
HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef *hrtc); | |||
uint8_t RTC_ByteToBcd2(uint8_t Value); | |||
uint8_t RTC_Bcd2ToByte(uint8_t Value); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32L1xx_HAL_RTC_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,742 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_hal_spi.h | |||
* @author MCD Application Team | |||
* @brief Header file of SPI HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2016 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef STM32L1xx_HAL_SPI_H | |||
#define STM32L1xx_HAL_SPI_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx_hal_def.h" | |||
/** @addtogroup STM32L1xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup SPI | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup SPI_Exported_Types SPI Exported Types | |||
* @{ | |||
*/ | |||
/** | |||
* @brief SPI Configuration Structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t Mode; /*!< Specifies the SPI operating mode. | |||
This parameter can be a value of @ref SPI_Mode */ | |||
uint32_t Direction; /*!< Specifies the SPI bidirectional mode state. | |||
This parameter can be a value of @ref SPI_Direction */ | |||
uint32_t DataSize; /*!< Specifies the SPI data size. | |||
This parameter can be a value of @ref SPI_Data_Size */ | |||
uint32_t CLKPolarity; /*!< Specifies the serial clock steady state. | |||
This parameter can be a value of @ref SPI_Clock_Polarity */ | |||
uint32_t CLKPhase; /*!< Specifies the clock active edge for the bit capture. | |||
This parameter can be a value of @ref SPI_Clock_Phase */ | |||
uint32_t NSS; /*!< Specifies whether the NSS signal is managed by | |||
hardware (NSS pin) or by software using the SSI bit. | |||
This parameter can be a value of @ref SPI_Slave_Select_management */ | |||
uint32_t BaudRatePrescaler; /*!< Specifies the Baud Rate prescaler value which will be | |||
used to configure the transmit and receive SCK clock. | |||
This parameter can be a value of @ref SPI_BaudRate_Prescaler | |||
@note The communication clock is derived from the master | |||
clock. The slave clock does not need to be set. */ | |||
uint32_t FirstBit; /*!< Specifies whether data transfers start from MSB or LSB bit. | |||
This parameter can be a value of @ref SPI_MSB_LSB_transmission */ | |||
uint32_t TIMode; /*!< Specifies if the TI mode is enabled or not. | |||
This parameter can be a value of @ref SPI_TI_mode */ | |||
uint32_t CRCCalculation; /*!< Specifies if the CRC calculation is enabled or not. | |||
This parameter can be a value of @ref SPI_CRC_Calculation */ | |||
uint32_t CRCPolynomial; /*!< Specifies the polynomial used for the CRC calculation. | |||
This parameter must be an odd number between Min_Data = 1 and Max_Data = 65535 */ | |||
} SPI_InitTypeDef; | |||
/** | |||
* @brief HAL SPI State structure definition | |||
*/ | |||
typedef enum | |||
{ | |||
HAL_SPI_STATE_RESET = 0x00U, /*!< Peripheral not Initialized */ | |||
HAL_SPI_STATE_READY = 0x01U, /*!< Peripheral Initialized and ready for use */ | |||
HAL_SPI_STATE_BUSY = 0x02U, /*!< an internal process is ongoing */ | |||
HAL_SPI_STATE_BUSY_TX = 0x03U, /*!< Data Transmission process is ongoing */ | |||
HAL_SPI_STATE_BUSY_RX = 0x04U, /*!< Data Reception process is ongoing */ | |||
HAL_SPI_STATE_BUSY_TX_RX = 0x05U, /*!< Data Transmission and Reception process is ongoing */ | |||
HAL_SPI_STATE_ERROR = 0x06U, /*!< SPI error state */ | |||
HAL_SPI_STATE_ABORT = 0x07U /*!< SPI abort is ongoing */ | |||
} HAL_SPI_StateTypeDef; | |||
/** | |||
* @brief SPI handle Structure definition | |||
*/ | |||
typedef struct __SPI_HandleTypeDef | |||
{ | |||
SPI_TypeDef *Instance; /*!< SPI registers base address */ | |||
SPI_InitTypeDef Init; /*!< SPI communication parameters */ | |||
uint8_t *pTxBuffPtr; /*!< Pointer to SPI Tx transfer Buffer */ | |||
uint16_t TxXferSize; /*!< SPI Tx Transfer size */ | |||
__IO uint16_t TxXferCount; /*!< SPI Tx Transfer Counter */ | |||
uint8_t *pRxBuffPtr; /*!< Pointer to SPI Rx transfer Buffer */ | |||
uint16_t RxXferSize; /*!< SPI Rx Transfer size */ | |||
__IO uint16_t RxXferCount; /*!< SPI Rx Transfer Counter */ | |||
void (*RxISR)(struct __SPI_HandleTypeDef *hspi); /*!< function pointer on Rx ISR */ | |||
void (*TxISR)(struct __SPI_HandleTypeDef *hspi); /*!< function pointer on Tx ISR */ | |||
DMA_HandleTypeDef *hdmatx; /*!< SPI Tx DMA Handle parameters */ | |||
DMA_HandleTypeDef *hdmarx; /*!< SPI Rx DMA Handle parameters */ | |||
HAL_LockTypeDef Lock; /*!< Locking object */ | |||
__IO HAL_SPI_StateTypeDef State; /*!< SPI communication state */ | |||
__IO uint32_t ErrorCode; /*!< SPI Error code */ | |||
#if (USE_HAL_SPI_REGISTER_CALLBACKS == 1U) | |||
void (* TxCpltCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI Tx Completed callback */ | |||
void (* RxCpltCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI Rx Completed callback */ | |||
void (* TxRxCpltCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI TxRx Completed callback */ | |||
void (* TxHalfCpltCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI Tx Half Completed callback */ | |||
void (* RxHalfCpltCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI Rx Half Completed callback */ | |||
void (* TxRxHalfCpltCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI TxRx Half Completed callback */ | |||
void (* ErrorCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI Error callback */ | |||
void (* AbortCpltCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI Abort callback */ | |||
void (* MspInitCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI Msp Init callback */ | |||
void (* MspDeInitCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI Msp DeInit callback */ | |||
#endif /* USE_HAL_SPI_REGISTER_CALLBACKS */ | |||
} SPI_HandleTypeDef; | |||
#if (USE_HAL_SPI_REGISTER_CALLBACKS == 1U) | |||
/** | |||
* @brief HAL SPI Callback ID enumeration definition | |||
*/ | |||
typedef enum | |||
{ | |||
HAL_SPI_TX_COMPLETE_CB_ID = 0x00U, /*!< SPI Tx Completed callback ID */ | |||
HAL_SPI_RX_COMPLETE_CB_ID = 0x01U, /*!< SPI Rx Completed callback ID */ | |||
HAL_SPI_TX_RX_COMPLETE_CB_ID = 0x02U, /*!< SPI TxRx Completed callback ID */ | |||
HAL_SPI_TX_HALF_COMPLETE_CB_ID = 0x03U, /*!< SPI Tx Half Completed callback ID */ | |||
HAL_SPI_RX_HALF_COMPLETE_CB_ID = 0x04U, /*!< SPI Rx Half Completed callback ID */ | |||
HAL_SPI_TX_RX_HALF_COMPLETE_CB_ID = 0x05U, /*!< SPI TxRx Half Completed callback ID */ | |||
HAL_SPI_ERROR_CB_ID = 0x06U, /*!< SPI Error callback ID */ | |||
HAL_SPI_ABORT_CB_ID = 0x07U, /*!< SPI Abort callback ID */ | |||
HAL_SPI_MSPINIT_CB_ID = 0x08U, /*!< SPI Msp Init callback ID */ | |||
HAL_SPI_MSPDEINIT_CB_ID = 0x09U /*!< SPI Msp DeInit callback ID */ | |||
} HAL_SPI_CallbackIDTypeDef; | |||
/** | |||
* @brief HAL SPI Callback pointer definition | |||
*/ | |||
typedef void (*pSPI_CallbackTypeDef)(SPI_HandleTypeDef *hspi); /*!< pointer to an SPI callback function */ | |||
#endif /* USE_HAL_SPI_REGISTER_CALLBACKS */ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup SPI_Exported_Constants SPI Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup SPI_Error_Code SPI Error Code | |||
* @{ | |||
*/ | |||
#define HAL_SPI_ERROR_NONE (0x00000000U) /*!< No error */ | |||
#define HAL_SPI_ERROR_MODF (0x00000001U) /*!< MODF error */ | |||
#define HAL_SPI_ERROR_CRC (0x00000002U) /*!< CRC error */ | |||
#define HAL_SPI_ERROR_OVR (0x00000004U) /*!< OVR error */ | |||
#define HAL_SPI_ERROR_FRE (0x00000008U) /*!< FRE error */ | |||
#define HAL_SPI_ERROR_DMA (0x00000010U) /*!< DMA transfer error */ | |||
#define HAL_SPI_ERROR_FLAG (0x00000020U) /*!< Error on RXNE/TXE/BSY Flag */ | |||
#define HAL_SPI_ERROR_ABORT (0x00000040U) /*!< Error during SPI Abort procedure */ | |||
#if (USE_HAL_SPI_REGISTER_CALLBACKS == 1U) | |||
#define HAL_SPI_ERROR_INVALID_CALLBACK (0x00000080U) /*!< Invalid Callback error */ | |||
#endif /* USE_HAL_SPI_REGISTER_CALLBACKS */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_Mode SPI Mode | |||
* @{ | |||
*/ | |||
#define SPI_MODE_SLAVE (0x00000000U) | |||
#define SPI_MODE_MASTER (SPI_CR1_MSTR | SPI_CR1_SSI) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_Direction SPI Direction Mode | |||
* @{ | |||
*/ | |||
#define SPI_DIRECTION_2LINES (0x00000000U) | |||
#define SPI_DIRECTION_2LINES_RXONLY SPI_CR1_RXONLY | |||
#define SPI_DIRECTION_1LINE SPI_CR1_BIDIMODE | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_Data_Size SPI Data Size | |||
* @{ | |||
*/ | |||
#define SPI_DATASIZE_8BIT (0x00000000U) | |||
#define SPI_DATASIZE_16BIT SPI_CR1_DFF | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_Clock_Polarity SPI Clock Polarity | |||
* @{ | |||
*/ | |||
#define SPI_POLARITY_LOW (0x00000000U) | |||
#define SPI_POLARITY_HIGH SPI_CR1_CPOL | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_Clock_Phase SPI Clock Phase | |||
* @{ | |||
*/ | |||
#define SPI_PHASE_1EDGE (0x00000000U) | |||
#define SPI_PHASE_2EDGE SPI_CR1_CPHA | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_Slave_Select_management SPI Slave Select Management | |||
* @{ | |||
*/ | |||
#define SPI_NSS_SOFT SPI_CR1_SSM | |||
#define SPI_NSS_HARD_INPUT (0x00000000U) | |||
#define SPI_NSS_HARD_OUTPUT (SPI_CR2_SSOE << 16U) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_BaudRate_Prescaler SPI BaudRate Prescaler | |||
* @{ | |||
*/ | |||
#define SPI_BAUDRATEPRESCALER_2 (0x00000000U) | |||
#define SPI_BAUDRATEPRESCALER_4 (SPI_CR1_BR_0) | |||
#define SPI_BAUDRATEPRESCALER_8 (SPI_CR1_BR_1) | |||
#define SPI_BAUDRATEPRESCALER_16 (SPI_CR1_BR_1 | SPI_CR1_BR_0) | |||
#define SPI_BAUDRATEPRESCALER_32 (SPI_CR1_BR_2) | |||
#define SPI_BAUDRATEPRESCALER_64 (SPI_CR1_BR_2 | SPI_CR1_BR_0) | |||
#define SPI_BAUDRATEPRESCALER_128 (SPI_CR1_BR_2 | SPI_CR1_BR_1) | |||
#define SPI_BAUDRATEPRESCALER_256 (SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0) | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_MSB_LSB_transmission SPI MSB LSB Transmission | |||
* @{ | |||
*/ | |||
#define SPI_FIRSTBIT_MSB (0x00000000U) | |||
#define SPI_FIRSTBIT_LSB SPI_CR1_LSBFIRST | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_TI_mode SPI TI Mode | |||
* @brief SPI TI Mode not supported for Category 1 and 2 | |||
* @{ | |||
*/ | |||
#define SPI_TIMODE_DISABLE (0x00000000U) | |||
#if defined(SPI_CR2_FRF) | |||
#define SPI_TIMODE_ENABLE SPI_CR2_FRF | |||
#endif | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_CRC_Calculation SPI CRC Calculation | |||
* @{ | |||
*/ | |||
#define SPI_CRCCALCULATION_DISABLE (0x00000000U) | |||
#define SPI_CRCCALCULATION_ENABLE SPI_CR1_CRCEN | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_Interrupt_definition SPI Interrupt Definition | |||
* @{ | |||
*/ | |||
#define SPI_IT_TXE SPI_CR2_TXEIE | |||
#define SPI_IT_RXNE SPI_CR2_RXNEIE | |||
#define SPI_IT_ERR SPI_CR2_ERRIE | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup SPI_Flags_definition SPI Flags Definition | |||
* @{ | |||
*/ | |||
#define SPI_FLAG_RXNE SPI_SR_RXNE /* SPI status flag: Rx buffer not empty flag */ | |||
#define SPI_FLAG_TXE SPI_SR_TXE /* SPI status flag: Tx buffer empty flag */ | |||
#define SPI_FLAG_BSY SPI_SR_BSY /* SPI status flag: Busy flag */ | |||
#define SPI_FLAG_CRCERR SPI_SR_CRCERR /* SPI Error flag: CRC error flag */ | |||
#define SPI_FLAG_MODF SPI_SR_MODF /* SPI Error flag: Mode fault flag */ | |||
#define SPI_FLAG_OVR SPI_SR_OVR /* SPI Error flag: Overrun flag */ | |||
#if defined(SPI_CR2_FRF) | |||
#define SPI_FLAG_FRE SPI_SR_FRE /* SPI Error flag: TI mode frame format error flag */ | |||
#define SPI_FLAG_MASK (SPI_SR_RXNE | SPI_SR_TXE | SPI_SR_BSY | SPI_SR_CRCERR\ | |||
| SPI_SR_MODF | SPI_SR_OVR | SPI_SR_FRE) | |||
#else | |||
#define SPI_FLAG_MASK (SPI_SR_RXNE | SPI_SR_TXE | SPI_SR_BSY\ | |||
| SPI_SR_CRCERR | SPI_SR_MODF | SPI_SR_OVR) | |||
#endif | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macros -----------------------------------------------------------*/ | |||
/** @defgroup SPI_Exported_Macros SPI Exported Macros | |||
* @{ | |||
*/ | |||
/** @brief Reset SPI handle state. | |||
* @param __HANDLE__ specifies the SPI Handle. | |||
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. | |||
* @retval None | |||
*/ | |||
#if (USE_HAL_SPI_REGISTER_CALLBACKS == 1U) | |||
#define __HAL_SPI_RESET_HANDLE_STATE(__HANDLE__) do{ \ | |||
(__HANDLE__)->State = HAL_SPI_STATE_RESET; \ | |||
(__HANDLE__)->MspInitCallback = NULL; \ | |||
(__HANDLE__)->MspDeInitCallback = NULL; \ | |||
} while(0) | |||
#else | |||
#define __HAL_SPI_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SPI_STATE_RESET) | |||
#endif /* USE_HAL_SPI_REGISTER_CALLBACKS */ | |||
/** @brief Enable the specified SPI interrupts. | |||
* @param __HANDLE__ specifies the SPI Handle. | |||
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. | |||
* @param __INTERRUPT__ specifies the interrupt source to enable. | |||
* This parameter can be one of the following values: | |||
* @arg SPI_IT_TXE: Tx buffer empty interrupt enable | |||
* @arg SPI_IT_RXNE: RX buffer not empty interrupt enable | |||
* @arg SPI_IT_ERR: Error interrupt enable | |||
* @retval None | |||
*/ | |||
#define __HAL_SPI_ENABLE_IT(__HANDLE__, __INTERRUPT__) SET_BIT((__HANDLE__)->Instance->CR2, (__INTERRUPT__)) | |||
/** @brief Disable the specified SPI interrupts. | |||
* @param __HANDLE__ specifies the SPI handle. | |||
* This parameter can be SPIx where x: 1, 2, or 3 to select the SPI peripheral. | |||
* @param __INTERRUPT__ specifies the interrupt source to disable. | |||
* This parameter can be one of the following values: | |||
* @arg SPI_IT_TXE: Tx buffer empty interrupt enable | |||
* @arg SPI_IT_RXNE: RX buffer not empty interrupt enable | |||
* @arg SPI_IT_ERR: Error interrupt enable | |||
* @retval None | |||
*/ | |||
#define __HAL_SPI_DISABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BIT((__HANDLE__)->Instance->CR2, (__INTERRUPT__)) | |||
/** @brief Check whether the specified SPI interrupt source is enabled or not. | |||
* @param __HANDLE__ specifies the SPI Handle. | |||
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. | |||
* @param __INTERRUPT__ specifies the SPI interrupt source to check. | |||
* This parameter can be one of the following values: | |||
* @arg SPI_IT_TXE: Tx buffer empty interrupt enable | |||
* @arg SPI_IT_RXNE: RX buffer not empty interrupt enable | |||
* @arg SPI_IT_ERR: Error interrupt enable | |||
* @retval The new state of __IT__ (TRUE or FALSE). | |||
*/ | |||
#define __HAL_SPI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR2\ | |||
& (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET) | |||
/** @brief Check whether the specified SPI flag is set or not. | |||
* @param __HANDLE__ specifies the SPI Handle. | |||
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. | |||
* @param __FLAG__ specifies the flag to check. | |||
* This parameter can be one of the following values: | |||
* @arg SPI_FLAG_RXNE: Receive buffer not empty flag | |||
* @arg SPI_FLAG_TXE: Transmit buffer empty flag | |||
* @arg SPI_FLAG_CRCERR: CRC error flag | |||
* @arg SPI_FLAG_MODF: Mode fault flag | |||
* @arg SPI_FLAG_OVR: Overrun flag | |||
* @arg SPI_FLAG_BSY: Busy flag | |||
* @arg SPI_FLAG_FRE: Frame format error flag | |||
* @retval The new state of __FLAG__ (TRUE or FALSE). | |||
*/ | |||
#define __HAL_SPI_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__)) | |||
/** @brief Clear the SPI CRCERR pending flag. | |||
* @param __HANDLE__ specifies the SPI Handle. | |||
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. | |||
* @retval None | |||
*/ | |||
#define __HAL_SPI_CLEAR_CRCERRFLAG(__HANDLE__) ((__HANDLE__)->Instance->SR = (uint16_t)(~SPI_FLAG_CRCERR)) | |||
/** @brief Clear the SPI MODF pending flag. | |||
* @param __HANDLE__ specifies the SPI Handle. | |||
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. | |||
* @retval None | |||
*/ | |||
#define __HAL_SPI_CLEAR_MODFFLAG(__HANDLE__) \ | |||
do{ \ | |||
__IO uint32_t tmpreg_modf = 0x00U; \ | |||
tmpreg_modf = (__HANDLE__)->Instance->SR; \ | |||
CLEAR_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_SPE); \ | |||
UNUSED(tmpreg_modf); \ | |||
} while(0U) | |||
/** @brief Clear the SPI OVR pending flag. | |||
* @param __HANDLE__ specifies the SPI Handle. | |||
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. | |||
* @retval None | |||
*/ | |||
#define __HAL_SPI_CLEAR_OVRFLAG(__HANDLE__) \ | |||
do{ \ | |||
__IO uint32_t tmpreg_ovr = 0x00U; \ | |||
tmpreg_ovr = (__HANDLE__)->Instance->DR; \ | |||
tmpreg_ovr = (__HANDLE__)->Instance->SR; \ | |||
UNUSED(tmpreg_ovr); \ | |||
} while(0U) | |||
/** @brief Clear the SPI FRE pending flag. | |||
* @param __HANDLE__ specifies the SPI Handle. | |||
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. | |||
* @retval None | |||
*/ | |||
#define __HAL_SPI_CLEAR_FREFLAG(__HANDLE__) \ | |||
do{ \ | |||
__IO uint32_t tmpreg_fre = 0x00U; \ | |||
tmpreg_fre = (__HANDLE__)->Instance->SR; \ | |||
UNUSED(tmpreg_fre); \ | |||
}while(0U) | |||
/** @brief Enable the SPI peripheral. | |||
* @param __HANDLE__ specifies the SPI Handle. | |||
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. | |||
* @retval None | |||
*/ | |||
#define __HAL_SPI_ENABLE(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_SPE) | |||
/** @brief Disable the SPI peripheral. | |||
* @param __HANDLE__ specifies the SPI Handle. | |||
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. | |||
* @retval None | |||
*/ | |||
#define __HAL_SPI_DISABLE(__HANDLE__) CLEAR_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_SPE) | |||
/** | |||
* @} | |||
*/ | |||
/* Private macros ------------------------------------------------------------*/ | |||
/** @defgroup SPI_Private_Macros SPI Private Macros | |||
* @{ | |||
*/ | |||
/** @brief Set the SPI transmit-only mode. | |||
* @param __HANDLE__ specifies the SPI Handle. | |||
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. | |||
* @retval None | |||
*/ | |||
#define SPI_1LINE_TX(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_BIDIOE) | |||
/** @brief Set the SPI receive-only mode. | |||
* @param __HANDLE__ specifies the SPI Handle. | |||
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. | |||
* @retval None | |||
*/ | |||
#define SPI_1LINE_RX(__HANDLE__) CLEAR_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_BIDIOE) | |||
/** @brief Reset the CRC calculation of the SPI. | |||
* @param __HANDLE__ specifies the SPI Handle. | |||
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. | |||
* @retval None | |||
*/ | |||
#define SPI_RESET_CRC(__HANDLE__) do{CLEAR_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_CRCEN);\ | |||
SET_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_CRCEN);}while(0U) | |||
/** @brief Check whether the specified SPI flag is set or not. | |||
* @param __SR__ copy of SPI SR regsiter. | |||
* @param __FLAG__ specifies the flag to check. | |||
* This parameter can be one of the following values: | |||
* @arg SPI_FLAG_RXNE: Receive buffer not empty flag | |||
* @arg SPI_FLAG_TXE: Transmit buffer empty flag | |||
* @arg SPI_FLAG_CRCERR: CRC error flag | |||
* @arg SPI_FLAG_MODF: Mode fault flag | |||
* @arg SPI_FLAG_OVR: Overrun flag | |||
* @arg SPI_FLAG_BSY: Busy flag | |||
* @arg SPI_FLAG_FRE: Frame format error flag | |||
* @retval SET or RESET. | |||
*/ | |||
#define SPI_CHECK_FLAG(__SR__, __FLAG__) ((((__SR__) & ((__FLAG__) & SPI_FLAG_MASK)) == ((__FLAG__) & SPI_FLAG_MASK)) ? SET : RESET) | |||
/** @brief Check whether the specified SPI Interrupt is set or not. | |||
* @param __CR2__ copy of SPI CR2 regsiter. | |||
* @param __INTERRUPT__ specifies the SPI interrupt source to check. | |||
* This parameter can be one of the following values: | |||
* @arg SPI_IT_TXE: Tx buffer empty interrupt enable | |||
* @arg SPI_IT_RXNE: RX buffer not empty interrupt enable | |||
* @arg SPI_IT_ERR: Error interrupt enable | |||
* @retval SET or RESET. | |||
*/ | |||
#define SPI_CHECK_IT_SOURCE(__CR2__, __INTERRUPT__) ((((__CR2__) & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET) | |||
/** @brief Checks if SPI Mode parameter is in allowed range. | |||
* @param __MODE__ specifies the SPI Mode. | |||
* This parameter can be a value of @ref SPI_Mode | |||
* @retval None | |||
*/ | |||
#define IS_SPI_MODE(__MODE__) (((__MODE__) == SPI_MODE_SLAVE) || \ | |||
((__MODE__) == SPI_MODE_MASTER)) | |||
/** @brief Checks if SPI Direction Mode parameter is in allowed range. | |||
* @param __MODE__ specifies the SPI Direction Mode. | |||
* This parameter can be a value of @ref SPI_Direction | |||
* @retval None | |||
*/ | |||
#define IS_SPI_DIRECTION(__MODE__) (((__MODE__) == SPI_DIRECTION_2LINES) || \ | |||
((__MODE__) == SPI_DIRECTION_2LINES_RXONLY) || \ | |||
((__MODE__) == SPI_DIRECTION_1LINE)) | |||
/** @brief Checks if SPI Direction Mode parameter is 2 lines. | |||
* @param __MODE__ specifies the SPI Direction Mode. | |||
* @retval None | |||
*/ | |||
#define IS_SPI_DIRECTION_2LINES(__MODE__) ((__MODE__) == SPI_DIRECTION_2LINES) | |||
/** @brief Checks if SPI Direction Mode parameter is 1 or 2 lines. | |||
* @param __MODE__ specifies the SPI Direction Mode. | |||
* @retval None | |||
*/ | |||
#define IS_SPI_DIRECTION_2LINES_OR_1LINE(__MODE__) (((__MODE__) == SPI_DIRECTION_2LINES) || \ | |||
((__MODE__) == SPI_DIRECTION_1LINE)) | |||
/** @brief Checks if SPI Data Size parameter is in allowed range. | |||
* @param __DATASIZE__ specifies the SPI Data Size. | |||
* This parameter can be a value of @ref SPI_Data_Size | |||
* @retval None | |||
*/ | |||
#define IS_SPI_DATASIZE(__DATASIZE__) (((__DATASIZE__) == SPI_DATASIZE_16BIT) || \ | |||
((__DATASIZE__) == SPI_DATASIZE_8BIT)) | |||
/** @brief Checks if SPI Serial clock steady state parameter is in allowed range. | |||
* @param __CPOL__ specifies the SPI serial clock steady state. | |||
* This parameter can be a value of @ref SPI_Clock_Polarity | |||
* @retval None | |||
*/ | |||
#define IS_SPI_CPOL(__CPOL__) (((__CPOL__) == SPI_POLARITY_LOW) || \ | |||
((__CPOL__) == SPI_POLARITY_HIGH)) | |||
/** @brief Checks if SPI Clock Phase parameter is in allowed range. | |||
* @param __CPHA__ specifies the SPI Clock Phase. | |||
* This parameter can be a value of @ref SPI_Clock_Phase | |||
* @retval None | |||
*/ | |||
#define IS_SPI_CPHA(__CPHA__) (((__CPHA__) == SPI_PHASE_1EDGE) || \ | |||
((__CPHA__) == SPI_PHASE_2EDGE)) | |||
/** @brief Checks if SPI Slave Select parameter is in allowed range. | |||
* @param __NSS__ specifies the SPI Slave Select management parameter. | |||
* This parameter can be a value of @ref SPI_Slave_Select_management | |||
* @retval None | |||
*/ | |||
#define IS_SPI_NSS(__NSS__) (((__NSS__) == SPI_NSS_SOFT) || \ | |||
((__NSS__) == SPI_NSS_HARD_INPUT) || \ | |||
((__NSS__) == SPI_NSS_HARD_OUTPUT)) | |||
/** @brief Checks if SPI Baudrate prescaler parameter is in allowed range. | |||
* @param __PRESCALER__ specifies the SPI Baudrate prescaler. | |||
* This parameter can be a value of @ref SPI_BaudRate_Prescaler | |||
* @retval None | |||
*/ | |||
#define IS_SPI_BAUDRATE_PRESCALER(__PRESCALER__) (((__PRESCALER__) == SPI_BAUDRATEPRESCALER_2) || \ | |||
((__PRESCALER__) == SPI_BAUDRATEPRESCALER_4) || \ | |||
((__PRESCALER__) == SPI_BAUDRATEPRESCALER_8) || \ | |||
((__PRESCALER__) == SPI_BAUDRATEPRESCALER_16) || \ | |||
((__PRESCALER__) == SPI_BAUDRATEPRESCALER_32) || \ | |||
((__PRESCALER__) == SPI_BAUDRATEPRESCALER_64) || \ | |||
((__PRESCALER__) == SPI_BAUDRATEPRESCALER_128) || \ | |||
((__PRESCALER__) == SPI_BAUDRATEPRESCALER_256)) | |||
/** @brief Checks if SPI MSB LSB transmission parameter is in allowed range. | |||
* @param __BIT__ specifies the SPI MSB LSB transmission (whether data transfer starts from MSB or LSB bit). | |||
* This parameter can be a value of @ref SPI_MSB_LSB_transmission | |||
* @retval None | |||
*/ | |||
#define IS_SPI_FIRST_BIT(__BIT__) (((__BIT__) == SPI_FIRSTBIT_MSB) || \ | |||
((__BIT__) == SPI_FIRSTBIT_LSB)) | |||
#if defined(SPI_I2SCFGR_I2SMOD) | |||
/** @brief Checks if SPI TI mode parameter is in allowed range. | |||
* @param __MODE__ specifies the SPI TI mode. | |||
* This parameter can be a value of @ref SPI_TI_mode | |||
* @retval None | |||
*/ | |||
#define IS_SPI_TIMODE(__MODE__) (((__MODE__) == SPI_TIMODE_DISABLE) || \ | |||
((__MODE__) == SPI_TIMODE_ENABLE)) | |||
#else | |||
/** @defgroup SPI_TI_mode SPI TI mode disable | |||
* @brief SPI TI Mode not supported for Category 1 and 2 | |||
* @{ | |||
*/ | |||
#define IS_SPI_TIMODE(__MODE__) ((__MODE__) == SPI_TIMODE_DISABLE) | |||
#endif | |||
/** @brief Checks if SPI CRC calculation enabled state is in allowed range. | |||
* @param __CALCULATION__ specifies the SPI CRC calculation enable state. | |||
* This parameter can be a value of @ref SPI_CRC_Calculation | |||
* @retval None | |||
*/ | |||
#define IS_SPI_CRC_CALCULATION(__CALCULATION__) (((__CALCULATION__) == SPI_CRCCALCULATION_DISABLE) || \ | |||
((__CALCULATION__) == SPI_CRCCALCULATION_ENABLE)) | |||
/** @brief Checks if SPI polynomial value to be used for the CRC calculation, is in allowed range. | |||
* @param __POLYNOMIAL__ specifies the SPI polynomial value to be used for the CRC calculation. | |||
* This parameter must be a number between Min_Data = 0 and Max_Data = 65535 | |||
* @retval None | |||
*/ | |||
#define IS_SPI_CRC_POLYNOMIAL(__POLYNOMIAL__) (((__POLYNOMIAL__) >= 0x1U) && ((__POLYNOMIAL__) <= 0xFFFFU) && (((__POLYNOMIAL__)&0x1U) != 0U)) | |||
/** @brief Checks if DMA handle is valid. | |||
* @param __HANDLE__ specifies a DMA Handle. | |||
* @retval None | |||
*/ | |||
#define IS_SPI_DMA_HANDLE(__HANDLE__) ((__HANDLE__) != NULL) | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup SPI_Exported_Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup SPI_Exported_Functions_Group1 | |||
* @{ | |||
*/ | |||
/* Initialization/de-initialization functions ********************************/ | |||
HAL_StatusTypeDef HAL_SPI_Init(SPI_HandleTypeDef *hspi); | |||
HAL_StatusTypeDef HAL_SPI_DeInit(SPI_HandleTypeDef *hspi); | |||
void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi); | |||
void HAL_SPI_MspDeInit(SPI_HandleTypeDef *hspi); | |||
/* Callbacks Register/UnRegister functions ***********************************/ | |||
#if (USE_HAL_SPI_REGISTER_CALLBACKS == 1U) | |||
HAL_StatusTypeDef HAL_SPI_RegisterCallback(SPI_HandleTypeDef *hspi, HAL_SPI_CallbackIDTypeDef CallbackID, pSPI_CallbackTypeDef pCallback); | |||
HAL_StatusTypeDef HAL_SPI_UnRegisterCallback(SPI_HandleTypeDef *hspi, HAL_SPI_CallbackIDTypeDef CallbackID); | |||
#endif /* USE_HAL_SPI_REGISTER_CALLBACKS */ | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup SPI_Exported_Functions_Group2 | |||
* @{ | |||
*/ | |||
/* I/O operation functions ***************************************************/ | |||
HAL_StatusTypeDef HAL_SPI_Transmit(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout); | |||
HAL_StatusTypeDef HAL_SPI_Receive(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout); | |||
HAL_StatusTypeDef HAL_SPI_TransmitReceive(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, | |||
uint32_t Timeout); | |||
HAL_StatusTypeDef HAL_SPI_Transmit_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size); | |||
HAL_StatusTypeDef HAL_SPI_Receive_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size); | |||
HAL_StatusTypeDef HAL_SPI_TransmitReceive_IT(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, | |||
uint16_t Size); | |||
HAL_StatusTypeDef HAL_SPI_Transmit_DMA(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size); | |||
HAL_StatusTypeDef HAL_SPI_Receive_DMA(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size); | |||
HAL_StatusTypeDef HAL_SPI_TransmitReceive_DMA(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, | |||
uint16_t Size); | |||
HAL_StatusTypeDef HAL_SPI_DMAPause(SPI_HandleTypeDef *hspi); | |||
HAL_StatusTypeDef HAL_SPI_DMAResume(SPI_HandleTypeDef *hspi); | |||
HAL_StatusTypeDef HAL_SPI_DMAStop(SPI_HandleTypeDef *hspi); | |||
/* Transfer Abort functions */ | |||
HAL_StatusTypeDef HAL_SPI_Abort(SPI_HandleTypeDef *hspi); | |||
HAL_StatusTypeDef HAL_SPI_Abort_IT(SPI_HandleTypeDef *hspi); | |||
void HAL_SPI_IRQHandler(SPI_HandleTypeDef *hspi); | |||
void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi); | |||
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi); | |||
void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi); | |||
void HAL_SPI_TxHalfCpltCallback(SPI_HandleTypeDef *hspi); | |||
void HAL_SPI_RxHalfCpltCallback(SPI_HandleTypeDef *hspi); | |||
void HAL_SPI_TxRxHalfCpltCallback(SPI_HandleTypeDef *hspi); | |||
void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi); | |||
void HAL_SPI_AbortCpltCallback(SPI_HandleTypeDef *hspi); | |||
/** | |||
* @} | |||
*/ | |||
/** @addtogroup SPI_Exported_Functions_Group3 | |||
* @{ | |||
*/ | |||
/* Peripheral State and Error functions ***************************************/ | |||
HAL_SPI_StateTypeDef HAL_SPI_GetState(SPI_HandleTypeDef *hspi); | |||
uint32_t HAL_SPI_GetError(SPI_HandleTypeDef *hspi); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* STM32L1xx_HAL_SPI_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,181 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_hal_tim_ex.h | |||
* @author MCD Application Team | |||
* @brief Header file of TIM HAL Extended module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2016 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef STM32L1xx_HAL_TIM_EX_H | |||
#define STM32L1xx_HAL_TIM_EX_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx_hal_def.h" | |||
/** @addtogroup STM32L1xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup TIMEx | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** @defgroup TIMEx_Exported_Types TIM Extended Exported Types | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* End of exported types -----------------------------------------------------*/ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup TIMEx_Exported_Constants TIM Extended Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup TIMEx_Remap TIM Extended Remapping | |||
* @{ | |||
*/ | |||
/* @note STM32L1XX devices are organized in 6 categories: Cat.1, Cat.2, Cat.3, Cat.4, Cat.5, Cat.6. | |||
Remap capabilities depend on the device category. As the DMA2 controller is available only in | |||
Cat.3, Cat.4,Cat.5 and Cat.6 devices it is used to discriminate Cat.1 and Cat.2 devices v.s. | |||
Cat.3, Cat.4, Cat.5 and Cat.6 devices. */ | |||
#if defined(DMA2) | |||
#define TIM_TIM2_ITR1_TIM10_OC (0x00000000) /*!< TIM2 ITR1 input is connected to TIM10 OC */ | |||
#define TIM_TIM2_ITR1_TIM5_TGO TIM2_OR_ITR1_RMP /*!< TIM2 ITR1 input is connected to TIM5 TGO */ | |||
#endif /* DMA2 */ | |||
#if defined(DMA2) | |||
#define TIM_TIM3_ITR2_TIM11_OC (0x00000000) /*!< TIM3 ITR2 input is connected to TIM11 OC */ | |||
#define TIM_TIM3_ITR2_TIM5_TGO TIM2_OR_ITR1_RMP /*!< TIM3 ITR2 input is connected to TIM5 TGO */ | |||
#endif /* DMA2 */ | |||
#if defined(DMA2) | |||
#define TIM_TIM9_ITR1_TIM3_TGO (0x00000000) /*!< TIM9 ITR1 input is connected to TIM3 TGO */ | |||
#define TIM_TIM9_ITR1_TS TIM9_OR_ITR1_RMP /*!< TIM9 ITR1 input is connected to touch sensing I/O */ | |||
#endif /* DMA2 */ | |||
#define TIM_TIM9_GPIO (0x00000000) /*!< TIM9 Channel1 is connected to GPIO */ | |||
#define TIM_TIM9_LSE TIM_OR_TI1RMP_0 /*!< TIM9 Channel1 is connected to LSE internal clock */ | |||
#define TIM_TIM9_GPIO1 TIM_OR_TI1RMP_1 /*!< TIM9 Channel1 is connected to GPIO */ | |||
#define TIM_TIM9_GPIO2 TIM_OR_TI1RMP /*!< TIM9 Channel1 is connected to GPIO */ | |||
#if defined(DMA2) | |||
#define TIM_TIM10_TI1RMP (0x00000000) /*!< TIM10 Channel 1 depends on TI1_RMP */ | |||
#define TIM_TIM10_RI TIM_OR_TI1_RMP_RI /*!< TIM10 Channel 1 is connected to RI */ | |||
#define TIM_TIM10_ETR_LSE (0x00000000) /*!< TIM10 ETR input is connected to LSE clock */ | |||
#define TIM_TIM10_ETR_TIM9_TGO TIM_OR_ETR_RMP /*!< TIM10 ETR input is connected to TIM9 TGO */ | |||
#endif /* DMA2 */ | |||
#define TIM_TIM10_GPIO (0x00000000) /*!< TIM10 Channel1 is connected to GPIO */ | |||
#define TIM_TIM10_LSI TIM_OR_TI1RMP_0 /*!< TIM10 Channel1 is connected to LSI internal clock */ | |||
#define TIM_TIM10_LSE TIM_OR_TI1RMP_1 /*!< TIM10 Channel1 is connected to LSE internal clock */ | |||
#define TIM_TIM10_RTC TIM_OR_TI1RMP /*!< TIM10 Channel1 is connected to RTC wakeup interrupt */ | |||
#if defined(DMA2) | |||
#define TIM_TIM11_TI1RMP (0x00000000) /*!< TIM11 Channel 1 depends on TI1_RMP */ | |||
#define TIM_TIM11_RI TIM_OR_TI1_RMP_RI /*!< TIM11 Channel 1 is connected to RI */ | |||
#define TIM_TIM11_ETR_LSE (0x00000000) /*!< TIM11 ETR input is connected to LSE clock */ | |||
#define TIM_TIM11_ETR_TIM9_TGO TIM_OR_ETR_RMP /*!< TIM11 ETR input is connected to TIM9 TGO */ | |||
#endif /* DMA2 */ | |||
#define TIM_TIM11_GPIO (0x00000000) /*!< TIM11 Channel1 is connected to GPIO */ | |||
#define TIM_TIM11_MSI TIM_OR_TI1RMP_0 /*!< TIM11 Channel1 is connected to MSI internal clock */ | |||
#define TIM_TIM11_HSE_RTC TIM_OR_TI1RMP_1 /*!< TIM11 Channel1 is connected to HSE_RTC clock */ | |||
#define TIM_TIM11_GPIO1 TIM_OR_TI1RMP /*!< TIM11 Channel1 is connected to GPIO */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* End of exported constants -------------------------------------------------*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/** @defgroup TIMEx_Exported_Macros TIM Extended Exported Macros | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* End of exported macro -----------------------------------------------------*/ | |||
/* Private macro -------------------------------------------------------------*/ | |||
/** @defgroup TIMEx_Private_Macros TIM Extended Private Macros | |||
* @{ | |||
*/ | |||
#if defined(DMA2) | |||
#define IS_TIM_REMAP(INSTANCE, TIM_REMAP) \ | |||
( (((INSTANCE) == TIM2) && (((TIM_REMAP) == TIM_TIM2_ITR1_TIM10_OC) || ((TIM_REMAP) == TIM_TIM2_ITR1_TIM5_TGO))) || \ | |||
(((INSTANCE) == TIM3) && (((TIM_REMAP) == TIM_TIM3_ITR2_TIM11_OC) || ((TIM_REMAP) == TIM_TIM3_ITR2_TIM5_TGO))) || \ | |||
(((INSTANCE) == TIM9) && ((TIM_REMAP) <= (TIM_TIM9_ITR1_TS | TIM_TIM9_GPIO2))) || \ | |||
(((INSTANCE) == TIM10) && ((TIM_REMAP) <= (TIM_TIM10_RI | TIM_TIM10_ETR_TIM9_TGO | TIM_TIM10_RTC))) || \ | |||
(((INSTANCE) == TIM11) && ((TIM_REMAP) <= (TIM_TIM11_RI | TIM_TIM11_ETR_TIM9_TGO | TIM_TIM11_GPIO1))) \ | |||
) | |||
#else | |||
#define IS_TIM_REMAP(INSTANCE, TIM_REMAP) \ | |||
( (((INSTANCE) == TIM9) && (((TIM_REMAP) == TIM_TIM9_GPIO) || ((TIM_REMAP) == TIM_TIM9_LSE) || ((TIM_REMAP) == TIM_TIM9_GPIO1) || ((TIM_REMAP) == TIM_TIM9_GPIO2))) || \ | |||
(((INSTANCE) == TIM10) && (((TIM_REMAP) == TIM_TIM10_GPIO) || ((TIM_REMAP) == TIM_TIM10_LSI) || ((TIM_REMAP) == TIM_TIM10_LSE) || ((TIM_REMAP) == TIM_TIM10_RTC))) || \ | |||
(((INSTANCE) == TIM11) && (((TIM_REMAP) == TIM_TIM11_GPIO) || ((TIM_REMAP) == TIM_TIM11_MSI) || ((TIM_REMAP) == TIM_TIM11_HSE_RTC) || ((TIM_REMAP) == TIM_TIM11_GPIO1))) \ | |||
) | |||
#endif /* DMA2 */ | |||
/** | |||
* @} | |||
*/ | |||
/* End of private macro ------------------------------------------------------*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup TIMEx_Exported_Functions TIM Extended Exported Functions | |||
* @{ | |||
*/ | |||
/** @addtogroup TIMEx_Exported_Functions_Group5 Extended Peripheral Control functions | |||
* @brief Peripheral Control functions | |||
* @{ | |||
*/ | |||
/* Extended Control functions ************************************************/ | |||
HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim, TIM_MasterConfigTypeDef *sMasterConfig); | |||
HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/* End of exported functions -------------------------------------------------*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* STM32L1xx_HAL_TIM_EX_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,234 @@ | |||
/* USER CODE BEGIN Header */ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_it.c | |||
* @brief Interrupt Service Routines. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2020 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* USER CODE END Header */ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "main.h" | |||
#include "stm32l1xx_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 PCD_HandleTypeDef hpcd_USB_FS; | |||
extern TIM_HandleTypeDef htim4; | |||
/* USER CODE BEGIN EV */ | |||
/* USER CODE END EV */ | |||
/******************************************************************************/ | |||
/* Cortex-M3 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 */ | |||
/* 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 Pre-fetch 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 SVC_IRQn 0 */ | |||
/* USER CODE END SVC_IRQn 0 */ | |||
/* USER CODE BEGIN SVC_IRQn 1 */ | |||
/* USER CODE END SVC_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 */ | |||
HAL_IncTick(); | |||
/* USER CODE BEGIN SysTick_IRQn 1 */ | |||
/* USER CODE END SysTick_IRQn 1 */ | |||
} | |||
/******************************************************************************/ | |||
/* STM32L1xx 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_stm32l1xx.s). */ | |||
/******************************************************************************/ | |||
/** | |||
* @brief This function handles USB low priority interrupt. | |||
*/ | |||
void USB_LP_IRQHandler(void) | |||
{ | |||
/* USER CODE BEGIN USB_LP_IRQn 0 */ | |||
/* USER CODE END USB_LP_IRQn 0 */ | |||
HAL_PCD_IRQHandler(&hpcd_USB_FS); | |||
/* USER CODE BEGIN USB_LP_IRQn 1 */ | |||
/* USER CODE END USB_LP_IRQn 1 */ | |||
} | |||
/** | |||
* @brief This function handles TIM4 global interrupt. | |||
*/ | |||
void TIM4_IRQHandler(void) | |||
{ | |||
/* USER CODE BEGIN TIM4_IRQn 0 */ | |||
/* USER CODE END TIM4_IRQn 0 */ | |||
#if 0 | |||
HAL_TIM_IRQHandler(&htim4); | |||
#endif | |||
/* USER CODE BEGIN TIM4_IRQn 1 */ | |||
/* USER CODE END TIM4_IRQn 1 */ | |||
} | |||
/* USER CODE BEGIN 1 */ | |||
/* USER CODE END 1 */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,71 @@ | |||
/* USER CODE BEGIN Header */ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_it.h | |||
* @brief This file contains the headers of the interrupt handlers. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2020 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* USER CODE END Header */ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __STM32L1xx_IT_H | |||
#define __STM32L1xx_IT_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Private includes ----------------------------------------------------------*/ | |||
/* USER CODE BEGIN Includes */ | |||
/* USER CODE END Includes */ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/* USER CODE BEGIN ET */ | |||
/* USER CODE END ET */ | |||
/* Exported constants --------------------------------------------------------*/ | |||
/* USER CODE BEGIN EC */ | |||
/* USER CODE END EC */ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/* USER CODE BEGIN EM */ | |||
/* USER CODE END EM */ | |||
/* Exported functions prototypes ---------------------------------------------*/ | |||
void NMI_Handler(void); | |||
void HardFault_Handler(void); | |||
void MemManage_Handler(void); | |||
void BusFault_Handler(void); | |||
void UsageFault_Handler(void); | |||
void SVC_Handler(void); | |||
void DebugMon_Handler(void); | |||
void PendSV_Handler(void); | |||
void SysTick_Handler(void); | |||
void USB_LP_IRQHandler(void); | |||
void TIM4_IRQHandler(void); | |||
/* USER CODE BEGIN EFP */ | |||
/* USER CODE END EFP */ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __STM32L1xx_IT_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,886 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_ll_usb.c | |||
* @author MCD Application Team | |||
* @brief USB Low Layer HAL module driver. | |||
* | |||
* This file provides firmware functions to manage the following | |||
* functionalities of the USB Peripheral Controller: | |||
* + Initialization/de-initialization functions | |||
* + I/O operation functions | |||
* + Peripheral Control functions | |||
* + Peripheral State functions | |||
* | |||
@verbatim | |||
============================================================================== | |||
##### How to use this driver ##### | |||
============================================================================== | |||
[..] | |||
(#) Fill parameters of Init structure in USB_OTG_CfgTypeDef structure. | |||
(#) Call USB_CoreInit() API to initialize the USB Core peripheral. | |||
(#) The upper HAL HCD/PCD driver will call the right routines for its internal processes. | |||
@endverbatim | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2016 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx_hal.h" | |||
/** @addtogroup STM32L1xx_LL_USB_DRIVER | |||
* @{ | |||
*/ | |||
#if defined (HAL_PCD_MODULE_ENABLED) || defined (HAL_HCD_MODULE_ENABLED) | |||
#if defined (USB) | |||
/* Private typedef -----------------------------------------------------------*/ | |||
/* Private define ------------------------------------------------------------*/ | |||
/* Private macro -------------------------------------------------------------*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* Private function prototypes -----------------------------------------------*/ | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** | |||
* @brief Initializes the USB Core | |||
* @param USBx: USB Instance | |||
* @param cfg : pointer to a USB_CfgTypeDef structure that contains | |||
* the configuration information for the specified USBx peripheral. | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef USB_CoreInit(USB_TypeDef *USBx, USB_CfgTypeDef cfg) | |||
{ | |||
/* Prevent unused argument(s) compilation warning */ | |||
UNUSED(USBx); | |||
UNUSED(cfg); | |||
/* NOTE : - This function is not required by USB Device FS peripheral, it is used | |||
only by USB OTG FS peripheral. | |||
- This function is added to ensure compatibility across platforms. | |||
*/ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief USB_EnableGlobalInt | |||
* Enables the controller's Global Int in the AHB Config reg | |||
* @param USBx : Selected device | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef USB_EnableGlobalInt(USB_TypeDef *USBx) | |||
{ | |||
uint16_t winterruptmask; | |||
/* Set winterruptmask variable */ | |||
winterruptmask = USB_CNTR_CTRM | USB_CNTR_WKUPM | | |||
USB_CNTR_SUSPM | USB_CNTR_ERRM | | |||
USB_CNTR_SOFM | USB_CNTR_ESOFM | | |||
USB_CNTR_RESETM; | |||
/* Set interrupt mask */ | |||
USBx->CNTR |= winterruptmask; | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief USB_DisableGlobalInt | |||
* Disable the controller's Global Int in the AHB Config reg | |||
* @param USBx : Selected device | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef USB_DisableGlobalInt(USB_TypeDef *USBx) | |||
{ | |||
uint16_t winterruptmask; | |||
/* Set winterruptmask variable */ | |||
winterruptmask = USB_CNTR_CTRM | USB_CNTR_WKUPM | | |||
USB_CNTR_SUSPM | USB_CNTR_ERRM | | |||
USB_CNTR_SOFM | USB_CNTR_ESOFM | | |||
USB_CNTR_RESETM; | |||
/* Clear interrupt mask */ | |||
USBx->CNTR &= ~winterruptmask; | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief USB_SetCurrentMode : Set functional mode | |||
* @param USBx : Selected device | |||
* @param mode : current core mode | |||
* This parameter can be one of the these values: | |||
* @arg USB_DEVICE_MODE: Peripheral mode mode | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef USB_SetCurrentMode(USB_TypeDef *USBx, USB_ModeTypeDef mode) | |||
{ | |||
/* Prevent unused argument(s) compilation warning */ | |||
UNUSED(USBx); | |||
UNUSED(mode); | |||
/* NOTE : - This function is not required by USB Device FS peripheral, it is used | |||
only by USB OTG FS peripheral. | |||
- This function is added to ensure compatibility across platforms. | |||
*/ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief USB_DevInit : Initializes the USB controller registers | |||
* for device mode | |||
* @param USBx : Selected device | |||
* @param cfg : pointer to a USB_CfgTypeDef structure that contains | |||
* the configuration information for the specified USBx peripheral. | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef USB_DevInit(USB_TypeDef *USBx, USB_CfgTypeDef cfg) | |||
{ | |||
/* Prevent unused argument(s) compilation warning */ | |||
UNUSED(cfg); | |||
/* Init Device */ | |||
/*CNTR_FRES = 1*/ | |||
USBx->CNTR = USB_CNTR_FRES; | |||
/*CNTR_FRES = 0*/ | |||
USBx->CNTR = 0; | |||
/*Clear pending interrupts*/ | |||
USBx->ISTR = 0; | |||
/*Set Btable Address*/ | |||
USBx->BTABLE = BTABLE_ADDRESS; | |||
/* Enable USB Device Interrupt mask */ | |||
(void)USB_EnableGlobalInt(USBx); | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief USB_SetDevSpeed :Initializes the device speed | |||
* depending on the PHY type and the enumeration speed of the device. | |||
* @param USBx Selected device | |||
* @param speed device speed | |||
* @retval Hal status | |||
*/ | |||
HAL_StatusTypeDef USB_SetDevSpeed(USB_TypeDef *USBx, uint8_t speed) | |||
{ | |||
/* Prevent unused argument(s) compilation warning */ | |||
UNUSED(USBx); | |||
UNUSED(speed); | |||
/* NOTE : - This function is not required by USB Device FS peripheral, it is used | |||
only by USB OTG FS peripheral. | |||
- This function is added to ensure compatibility across platforms. | |||
*/ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief USB_FlushTxFifo : Flush a Tx FIFO | |||
* @param USBx : Selected device | |||
* @param num : FIFO number | |||
* This parameter can be a value from 1 to 15 | |||
15 means Flush all Tx FIFOs | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef USB_FlushTxFifo(USB_TypeDef *USBx, uint32_t num) | |||
{ | |||
/* Prevent unused argument(s) compilation warning */ | |||
UNUSED(USBx); | |||
UNUSED(num); | |||
/* NOTE : - This function is not required by USB Device FS peripheral, it is used | |||
only by USB OTG FS peripheral. | |||
- This function is added to ensure compatibility across platforms. | |||
*/ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief USB_FlushRxFifo : Flush Rx FIFO | |||
* @param USBx : Selected device | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef USB_FlushRxFifo(USB_TypeDef *USBx) | |||
{ | |||
/* Prevent unused argument(s) compilation warning */ | |||
UNUSED(USBx); | |||
/* NOTE : - This function is not required by USB Device FS peripheral, it is used | |||
only by USB OTG FS peripheral. | |||
- This function is added to ensure compatibility across platforms. | |||
*/ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Activate and configure an endpoint | |||
* @param USBx : Selected device | |||
* @param ep: pointer to endpoint structure | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef USB_ActivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep) | |||
{ | |||
HAL_StatusTypeDef ret = HAL_OK; | |||
uint16_t wEpRegVal; | |||
wEpRegVal = PCD_GET_ENDPOINT(USBx, ep->num) & USB_EP_T_MASK; | |||
/* initialize Endpoint */ | |||
switch (ep->type) | |||
{ | |||
case EP_TYPE_CTRL: | |||
wEpRegVal |= USB_EP_CONTROL; | |||
break; | |||
case EP_TYPE_BULK: | |||
wEpRegVal |= USB_EP_BULK; | |||
break; | |||
case EP_TYPE_INTR: | |||
wEpRegVal |= USB_EP_INTERRUPT; | |||
break; | |||
case EP_TYPE_ISOC: | |||
wEpRegVal |= USB_EP_ISOCHRONOUS; | |||
break; | |||
default: | |||
ret = HAL_ERROR; | |||
break; | |||
} | |||
PCD_SET_ENDPOINT(USBx, ep->num, wEpRegVal | USB_EP_CTR_RX | USB_EP_CTR_TX); | |||
PCD_SET_EP_ADDRESS(USBx, ep->num, ep->num); | |||
if (ep->doublebuffer == 0U) | |||
{ | |||
if (ep->is_in != 0U) | |||
{ | |||
/*Set the endpoint Transmit buffer address */ | |||
PCD_SET_EP_TX_ADDRESS(USBx, ep->num, ep->pmaadress); | |||
PCD_CLEAR_TX_DTOG(USBx, ep->num); | |||
if (ep->type != EP_TYPE_ISOC) | |||
{ | |||
/* Configure NAK status for the Endpoint */ | |||
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_NAK); | |||
} | |||
else | |||
{ | |||
/* Configure TX Endpoint to disabled state */ | |||
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS); | |||
} | |||
} | |||
else | |||
{ | |||
/*Set the endpoint Receive buffer address */ | |||
PCD_SET_EP_RX_ADDRESS(USBx, ep->num, ep->pmaadress); | |||
/*Set the endpoint Receive buffer counter*/ | |||
PCD_SET_EP_RX_CNT(USBx, ep->num, ep->maxpacket); | |||
PCD_CLEAR_RX_DTOG(USBx, ep->num); | |||
/* Configure VALID status for the Endpoint*/ | |||
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID); | |||
} | |||
} | |||
/*Double Buffer*/ | |||
else | |||
{ | |||
/* Set the endpoint as double buffered */ | |||
PCD_SET_EP_DBUF(USBx, ep->num); | |||
/* Set buffer address for double buffered mode */ | |||
PCD_SET_EP_DBUF_ADDR(USBx, ep->num, ep->pmaaddr0, ep->pmaaddr1); | |||
if (ep->is_in == 0U) | |||
{ | |||
/* Clear the data toggle bits for the endpoint IN/OUT */ | |||
PCD_CLEAR_RX_DTOG(USBx, ep->num); | |||
PCD_CLEAR_TX_DTOG(USBx, ep->num); | |||
/* Reset value of the data toggle bits for the endpoint out */ | |||
PCD_TX_DTOG(USBx, ep->num); | |||
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID); | |||
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS); | |||
} | |||
else | |||
{ | |||
/* Clear the data toggle bits for the endpoint IN/OUT */ | |||
PCD_CLEAR_RX_DTOG(USBx, ep->num); | |||
PCD_CLEAR_TX_DTOG(USBx, ep->num); | |||
PCD_RX_DTOG(USBx, ep->num); | |||
if (ep->type != EP_TYPE_ISOC) | |||
{ | |||
/* Configure NAK status for the Endpoint */ | |||
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_NAK); | |||
} | |||
else | |||
{ | |||
/* Configure TX Endpoint to disabled state */ | |||
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS); | |||
} | |||
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS); | |||
} | |||
} | |||
return ret; | |||
} | |||
/** | |||
* @brief De-activate and de-initialize an endpoint | |||
* @param USBx : Selected device | |||
* @param ep: pointer to endpoint structure | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef USB_DeactivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep) | |||
{ | |||
if (ep->doublebuffer == 0U) | |||
{ | |||
if (ep->is_in != 0U) | |||
{ | |||
PCD_CLEAR_TX_DTOG(USBx, ep->num); | |||
/* Configure DISABLE status for the Endpoint*/ | |||
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS); | |||
} | |||
else | |||
{ | |||
PCD_CLEAR_RX_DTOG(USBx, ep->num); | |||
/* Configure DISABLE status for the Endpoint*/ | |||
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS); | |||
} | |||
} | |||
/*Double Buffer*/ | |||
else | |||
{ | |||
if (ep->is_in == 0U) | |||
{ | |||
/* Clear the data toggle bits for the endpoint IN/OUT*/ | |||
PCD_CLEAR_RX_DTOG(USBx, ep->num); | |||
PCD_CLEAR_TX_DTOG(USBx, ep->num); | |||
/* Reset value of the data toggle bits for the endpoint out*/ | |||
PCD_TX_DTOG(USBx, ep->num); | |||
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS); | |||
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS); | |||
} | |||
else | |||
{ | |||
/* Clear the data toggle bits for the endpoint IN/OUT*/ | |||
PCD_CLEAR_RX_DTOG(USBx, ep->num); | |||
PCD_CLEAR_TX_DTOG(USBx, ep->num); | |||
PCD_RX_DTOG(USBx, ep->num); | |||
/* Configure DISABLE status for the Endpoint*/ | |||
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS); | |||
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS); | |||
} | |||
} | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief USB_EPStartXfer : setup and starts a transfer over an EP | |||
* @param USBx : Selected device | |||
* @param ep: pointer to endpoint structure | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef USB_EPStartXfer(USB_TypeDef *USBx, USB_EPTypeDef *ep) | |||
{ | |||
uint16_t pmabuffer; | |||
uint32_t len; | |||
/* IN endpoint */ | |||
if (ep->is_in == 1U) | |||
{ | |||
/*Multi packet transfer*/ | |||
if (ep->xfer_len > ep->maxpacket) | |||
{ | |||
len = ep->maxpacket; | |||
ep->xfer_len -= len; | |||
} | |||
else | |||
{ | |||
len = ep->xfer_len; | |||
ep->xfer_len = 0U; | |||
} | |||
/* configure and validate Tx endpoint */ | |||
if (ep->doublebuffer == 0U) | |||
{ | |||
USB_WritePMA(USBx, ep->xfer_buff, ep->pmaadress, (uint16_t)len); | |||
PCD_SET_EP_TX_CNT(USBx, ep->num, len); | |||
} | |||
else | |||
{ | |||
/* Write the data to the USB endpoint */ | |||
if ((PCD_GET_ENDPOINT(USBx, ep->num) & USB_EP_DTOG_TX) != 0U) | |||
{ | |||
/* Set the Double buffer counter for pmabuffer1 */ | |||
PCD_SET_EP_DBUF1_CNT(USBx, ep->num, ep->is_in, len); | |||
pmabuffer = ep->pmaaddr1; | |||
} | |||
else | |||
{ | |||
/* Set the Double buffer counter for pmabuffer0 */ | |||
PCD_SET_EP_DBUF0_CNT(USBx, ep->num, ep->is_in, len); | |||
pmabuffer = ep->pmaaddr0; | |||
} | |||
USB_WritePMA(USBx, ep->xfer_buff, pmabuffer, (uint16_t)len); | |||
PCD_FreeUserBuffer(USBx, ep->num, ep->is_in); | |||
} | |||
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_VALID); | |||
} | |||
else /* OUT endpoint */ | |||
{ | |||
/* Multi packet transfer*/ | |||
if (ep->xfer_len > ep->maxpacket) | |||
{ | |||
len = ep->maxpacket; | |||
ep->xfer_len -= len; | |||
} | |||
else | |||
{ | |||
len = ep->xfer_len; | |||
ep->xfer_len = 0U; | |||
} | |||
/* configure and validate Rx endpoint */ | |||
if (ep->doublebuffer == 0U) | |||
{ | |||
/*Set RX buffer count*/ | |||
PCD_SET_EP_RX_CNT(USBx, ep->num, len); | |||
} | |||
else | |||
{ | |||
/*Set the Double buffer counter*/ | |||
PCD_SET_EP_DBUF_CNT(USBx, ep->num, ep->is_in, len); | |||
} | |||
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID); | |||
} | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief USB_WritePacket : Writes a packet into the Tx FIFO associated | |||
* with the EP/channel | |||
* @param USBx : Selected device | |||
* @param src : pointer to source buffer | |||
* @param ch_ep_num : endpoint or host channel number | |||
* @param len : Number of bytes to write | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef USB_WritePacket(USB_TypeDef *USBx, uint8_t *src, uint8_t ch_ep_num, uint16_t len) | |||
{ | |||
/* Prevent unused argument(s) compilation warning */ | |||
UNUSED(USBx); | |||
UNUSED(src); | |||
UNUSED(ch_ep_num); | |||
UNUSED(len); | |||
/* NOTE : - This function is not required by USB Device FS peripheral, it is used | |||
only by USB OTG FS peripheral. | |||
- This function is added to ensure compatibility across platforms. | |||
*/ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief USB_ReadPacket : read a packet from the Tx FIFO associated | |||
* with the EP/channel | |||
* @param USBx : Selected device | |||
* @param dest : destination pointer | |||
* @param len : Number of bytes to read | |||
* @retval pointer to destination buffer | |||
*/ | |||
void *USB_ReadPacket(USB_TypeDef *USBx, uint8_t *dest, uint16_t len) | |||
{ | |||
/* Prevent unused argument(s) compilation warning */ | |||
UNUSED(USBx); | |||
UNUSED(dest); | |||
UNUSED(len); | |||
/* NOTE : - This function is not required by USB Device FS peripheral, it is used | |||
only by USB OTG FS peripheral. | |||
- This function is added to ensure compatibility across platforms. | |||
*/ | |||
return ((void *)NULL); | |||
} | |||
/** | |||
* @brief USB_EPSetStall : set a stall condition over an EP | |||
* @param USBx : Selected device | |||
* @param ep: pointer to endpoint structure | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef USB_EPSetStall(USB_TypeDef *USBx, USB_EPTypeDef *ep) | |||
{ | |||
if (ep->is_in != 0U) | |||
{ | |||
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_STALL); | |||
} | |||
else | |||
{ | |||
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_STALL); | |||
} | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief USB_EPClearStall : Clear a stall condition over an EP | |||
* @param USBx : Selected device | |||
* @param ep: pointer to endpoint structure | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef USB_EPClearStall(USB_TypeDef *USBx, USB_EPTypeDef *ep) | |||
{ | |||
if (ep->doublebuffer == 0U) | |||
{ | |||
if (ep->is_in != 0U) | |||
{ | |||
PCD_CLEAR_TX_DTOG(USBx, ep->num); | |||
if (ep->type != EP_TYPE_ISOC) | |||
{ | |||
/* Configure NAK status for the Endpoint */ | |||
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_NAK); | |||
} | |||
} | |||
else | |||
{ | |||
PCD_CLEAR_RX_DTOG(USBx, ep->num); | |||
/* Configure VALID status for the Endpoint*/ | |||
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID); | |||
} | |||
} | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief USB_StopDevice : Stop the usb device mode | |||
* @param USBx : Selected device | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef USB_StopDevice(USB_TypeDef *USBx) | |||
{ | |||
/* disable all interrupts and force USB reset */ | |||
USBx->CNTR = USB_CNTR_FRES; | |||
/* clear interrupt status register */ | |||
USBx->ISTR = 0; | |||
/* switch-off device */ | |||
USBx->CNTR = (USB_CNTR_FRES | USB_CNTR_PDWN); | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief USB_SetDevAddress : Stop the usb device mode | |||
* @param USBx : Selected device | |||
* @param address : new device address to be assigned | |||
* This parameter can be a value from 0 to 255 | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef USB_SetDevAddress(USB_TypeDef *USBx, uint8_t address) | |||
{ | |||
if (address == 0U) | |||
{ | |||
/* set device address and enable function */ | |||
USBx->DADDR = USB_DADDR_EF; | |||
} | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief USB_DevConnect : Connect the USB device by enabling the pull-up/pull-down | |||
* @param USBx : Selected device | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef USB_DevConnect(USB_TypeDef *USBx) | |||
{ | |||
/* Prevent unused argument(s) compilation warning */ | |||
UNUSED(USBx); | |||
/* NOTE : - This function is not required by USB Device FS peripheral, it is used | |||
only by USB OTG FS peripheral. | |||
- This function is added to ensure compatibility across platforms. | |||
*/ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief USB_DevDisconnect : Disconnect the USB device by disabling the pull-up/pull-down | |||
* @param USBx : Selected device | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef USB_DevDisconnect(USB_TypeDef *USBx) | |||
{ | |||
/* Prevent unused argument(s) compilation warning */ | |||
UNUSED(USBx); | |||
/* NOTE : - This function is not required by USB Device FS peripheral, it is used | |||
only by USB OTG FS peripheral. | |||
- This function is added to ensure compatibility across platforms. | |||
*/ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief USB_ReadInterrupts: return the global USB interrupt status | |||
* @param USBx : Selected device | |||
* @retval HAL status | |||
*/ | |||
uint32_t USB_ReadInterrupts(USB_TypeDef *USBx) | |||
{ | |||
uint32_t tmpreg; | |||
tmpreg = USBx->ISTR; | |||
return tmpreg; | |||
} | |||
/** | |||
* @brief USB_ReadDevAllOutEpInterrupt: return the USB device OUT endpoints interrupt status | |||
* @param USBx : Selected device | |||
* @retval HAL status | |||
*/ | |||
uint32_t USB_ReadDevAllOutEpInterrupt(USB_TypeDef *USBx) | |||
{ | |||
/* Prevent unused argument(s) compilation warning */ | |||
UNUSED(USBx); | |||
/* NOTE : - This function is not required by USB Device FS peripheral, it is used | |||
only by USB OTG FS peripheral. | |||
- This function is added to ensure compatibility across platforms. | |||
*/ | |||
return (0); | |||
} | |||
/** | |||
* @brief USB_ReadDevAllInEpInterrupt: return the USB device IN endpoints interrupt status | |||
* @param USBx : Selected device | |||
* @retval HAL status | |||
*/ | |||
uint32_t USB_ReadDevAllInEpInterrupt(USB_TypeDef *USBx) | |||
{ | |||
/* Prevent unused argument(s) compilation warning */ | |||
UNUSED(USBx); | |||
/* NOTE : - This function is not required by USB Device FS peripheral, it is used | |||
only by USB OTG FS peripheral. | |||
- This function is added to ensure compatibility across platforms. | |||
*/ | |||
return (0); | |||
} | |||
/** | |||
* @brief Returns Device OUT EP Interrupt register | |||
* @param USBx : Selected device | |||
* @param epnum : endpoint number | |||
* This parameter can be a value from 0 to 15 | |||
* @retval Device OUT EP Interrupt register | |||
*/ | |||
uint32_t USB_ReadDevOutEPInterrupt(USB_TypeDef *USBx, uint8_t epnum) | |||
{ | |||
/* Prevent unused argument(s) compilation warning */ | |||
UNUSED(USBx); | |||
UNUSED(epnum); | |||
/* NOTE : - This function is not required by USB Device FS peripheral, it is used | |||
only by USB OTG FS peripheral. | |||
- This function is added to ensure compatibility across platforms. | |||
*/ | |||
return (0); | |||
} | |||
/** | |||
* @brief Returns Device IN EP Interrupt register | |||
* @param USBx : Selected device | |||
* @param epnum : endpoint number | |||
* This parameter can be a value from 0 to 15 | |||
* @retval Device IN EP Interrupt register | |||
*/ | |||
uint32_t USB_ReadDevInEPInterrupt(USB_TypeDef *USBx, uint8_t epnum) | |||
{ | |||
/* Prevent unused argument(s) compilation warning */ | |||
UNUSED(USBx); | |||
UNUSED(epnum); | |||
/* NOTE : - This function is not required by USB Device FS peripheral, it is used | |||
only by USB OTG FS peripheral. | |||
- This function is added to ensure compatibility across platforms. | |||
*/ | |||
return (0); | |||
} | |||
/** | |||
* @brief USB_ClearInterrupts: clear a USB interrupt | |||
* @param USBx Selected device | |||
* @param interrupt interrupt flag | |||
* @retval None | |||
*/ | |||
void USB_ClearInterrupts(USB_TypeDef *USBx, uint32_t interrupt) | |||
{ | |||
/* Prevent unused argument(s) compilation warning */ | |||
UNUSED(USBx); | |||
UNUSED(interrupt); | |||
/* NOTE : - This function is not required by USB Device FS peripheral, it is used | |||
only by USB OTG FS peripheral. | |||
- This function is added to ensure compatibility across platforms. | |||
*/ | |||
} | |||
/** | |||
* @brief Prepare the EP0 to start the first control setup | |||
* @param USBx Selected device | |||
* @param psetup pointer to setup packet | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef USB_EP0_OutStart(USB_TypeDef *USBx, uint8_t *psetup) | |||
{ | |||
/* Prevent unused argument(s) compilation warning */ | |||
UNUSED(USBx); | |||
UNUSED(psetup); | |||
/* NOTE : - This function is not required by USB Device FS peripheral, it is used | |||
only by USB OTG FS peripheral. | |||
- This function is added to ensure compatibility across platforms. | |||
*/ | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief USB_ActivateRemoteWakeup : active remote wakeup signalling | |||
* @param USBx Selected device | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef USB_ActivateRemoteWakeup(USB_TypeDef *USBx) | |||
{ | |||
USBx->CNTR |= USB_CNTR_RESUME; | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief USB_DeActivateRemoteWakeup : de-active remote wakeup signalling | |||
* @param USBx Selected device | |||
* @retval HAL status | |||
*/ | |||
HAL_StatusTypeDef USB_DeActivateRemoteWakeup(USB_TypeDef *USBx) | |||
{ | |||
USBx->CNTR &= ~(USB_CNTR_RESUME); | |||
return HAL_OK; | |||
} | |||
/** | |||
* @brief Copy a buffer from user memory area to packet memory area (PMA) | |||
* @param USBx USB peripheral instance register address. | |||
* @param pbUsrBuf pointer to user memory area. | |||
* @param wPMABufAddr address into PMA. | |||
* @param wNBytes: no. of bytes to be copied. | |||
* @retval None | |||
*/ | |||
void USB_WritePMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes) | |||
{ | |||
uint32_t n = ((uint32_t)wNBytes + 1U) >> 1; | |||
uint32_t BaseAddr = (uint32_t)USBx; | |||
uint32_t i, temp1, temp2; | |||
uint16_t *pdwVal; | |||
uint8_t *pBuf = pbUsrBuf; | |||
pdwVal = (uint16_t *)(BaseAddr + 0x400U + ((uint32_t)wPMABufAddr * PMA_ACCESS)); | |||
for (i = n; i != 0U; i--) | |||
{ | |||
temp1 = (uint16_t) * pBuf; | |||
pBuf++; | |||
temp2 = temp1 | ((uint16_t)((uint16_t) * pBuf << 8)); | |||
*pdwVal = (uint16_t)temp2; | |||
pdwVal++; | |||
#if PMA_ACCESS > 1U | |||
pdwVal++; | |||
#endif | |||
pBuf++; | |||
} | |||
} | |||
/** | |||
* @brief Copy a buffer from user memory area to packet memory area (PMA) | |||
* @param USBx: USB peripheral instance register address. | |||
* @param pbUsrBuf pointer to user memory area. | |||
* @param wPMABufAddr address into PMA. | |||
* @param wNBytes: no. of bytes to be copied. | |||
* @retval None | |||
*/ | |||
void USB_ReadPMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes) | |||
{ | |||
uint32_t n = (uint32_t)wNBytes >> 1; | |||
uint32_t BaseAddr = (uint32_t)USBx; | |||
uint32_t i, temp; | |||
uint16_t *pdwVal; | |||
uint8_t *pBuf = pbUsrBuf; | |||
pdwVal = (uint16_t *)(BaseAddr + 0x400U + ((uint32_t)wPMABufAddr * PMA_ACCESS)); | |||
for (i = n; i != 0U; i--) | |||
{ | |||
temp = *pdwVal; | |||
pdwVal++; | |||
*pBuf = (uint8_t)((temp >> 0) & 0xFFU); | |||
pBuf++; | |||
*pBuf = (uint8_t)((temp >> 8) & 0xFFU); | |||
pBuf++; | |||
#if PMA_ACCESS > 1U | |||
pdwVal++; | |||
#endif | |||
} | |||
if ((wNBytes % 2U) != 0U) | |||
{ | |||
temp = *pdwVal; | |||
*pBuf = (uint8_t)((temp >> 0) & 0xFFU); | |||
} | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#endif /* defined (USB) */ | |||
#endif /* defined (HAL_PCD_MODULE_ENABLED) || defined (HAL_HCD_MODULE_ENABLED) */ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,229 @@ | |||
/** | |||
****************************************************************************** | |||
* @file stm32l1xx_ll_usb.h | |||
* @author MCD Application Team | |||
* @brief Header file of USB Low Layer HAL module. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2016 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under BSD 3-Clause license, | |||
* the "License"; You may not use this file except in compliance with the | |||
* License. You may obtain a copy of the License at: | |||
* opensource.org/licenses/BSD-3-Clause | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef STM32L1xx_LL_USB_H | |||
#define STM32L1xx_LL_USB_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx_hal_def.h" | |||
#if defined (USB) | |||
/** @addtogroup STM32L1xx_HAL_Driver | |||
* @{ | |||
*/ | |||
/** @addtogroup USB_LL | |||
* @{ | |||
*/ | |||
/* Exported types ------------------------------------------------------------*/ | |||
/** | |||
* @brief USB Mode definition | |||
*/ | |||
typedef enum | |||
{ | |||
USB_DEVICE_MODE = 0 | |||
} USB_ModeTypeDef; | |||
/** | |||
* @brief USB Initialization Structure definition | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t dev_endpoints; /*!< Device Endpoints number. | |||
This parameter depends on the used USB core. | |||
This parameter must be a number between Min_Data = 1 and Max_Data = 15 */ | |||
uint32_t speed; /*!< USB Core speed. | |||
This parameter can be any value of @ref USB_Core_Speed */ | |||
uint32_t ep0_mps; /*!< Set the Endpoint 0 Max Packet size. */ | |||
uint32_t phy_itface; /*!< Select the used PHY interface. | |||
This parameter can be any value of @ref USB_Core_PHY */ | |||
uint32_t Sof_enable; /*!< Enable or disable the output of the SOF signal. */ | |||
uint32_t low_power_enable; /*!< Enable or disable Low Power mode */ | |||
uint32_t lpm_enable; /*!< Enable or disable Battery charging. */ | |||
uint32_t battery_charging_enable; /*!< Enable or disable Battery charging. */ | |||
} USB_CfgTypeDef; | |||
typedef struct | |||
{ | |||
uint8_t num; /*!< Endpoint number | |||
This parameter must be a number between Min_Data = 1 and Max_Data = 15 */ | |||
uint8_t is_in; /*!< Endpoint direction | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ | |||
uint8_t is_stall; /*!< Endpoint stall condition | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ | |||
uint8_t type; /*!< Endpoint type | |||
This parameter can be any value of @ref USB_EP_Type */ | |||
uint8_t data_pid_start; /*!< Initial data PID | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ | |||
uint16_t pmaadress; /*!< PMA Address | |||
This parameter can be any value between Min_addr = 0 and Max_addr = 1K */ | |||
uint16_t pmaaddr0; /*!< PMA Address0 | |||
This parameter can be any value between Min_addr = 0 and Max_addr = 1K */ | |||
uint16_t pmaaddr1; /*!< PMA Address1 | |||
This parameter can be any value between Min_addr = 0 and Max_addr = 1K */ | |||
uint8_t doublebuffer; /*!< Double buffer enable | |||
This parameter can be 0 or 1 */ | |||
uint16_t tx_fifo_num; /*!< This parameter is not required by USB Device FS peripheral, it is used | |||
only by USB OTG FS peripheral | |||
This parameter is added to ensure compatibility across USB peripherals */ | |||
uint32_t maxpacket; /*!< Endpoint Max packet size | |||
This parameter must be a number between Min_Data = 0 and Max_Data = 64KB */ | |||
uint8_t *xfer_buff; /*!< Pointer to transfer buffer */ | |||
uint32_t xfer_len; /*!< Current transfer length */ | |||
uint32_t xfer_count; /*!< Partial transfer length in case of multi packet transfer */ | |||
} USB_EPTypeDef; | |||
/* Exported constants --------------------------------------------------------*/ | |||
/** @defgroup PCD_Exported_Constants PCD Exported Constants | |||
* @{ | |||
*/ | |||
/** @defgroup USB_LL_EP0_MPS USB Low Layer EP0 MPS | |||
* @{ | |||
*/ | |||
#define DEP0CTL_MPS_64 0U | |||
#define DEP0CTL_MPS_32 1U | |||
#define DEP0CTL_MPS_16 2U | |||
#define DEP0CTL_MPS_8 3U | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USB_LL_EP_Type USB Low Layer EP Type | |||
* @{ | |||
*/ | |||
#define EP_TYPE_CTRL 0U | |||
#define EP_TYPE_ISOC 1U | |||
#define EP_TYPE_BULK 2U | |||
#define EP_TYPE_INTR 3U | |||
#define EP_TYPE_MSK 3U | |||
/** | |||
* @} | |||
*/ | |||
#define BTABLE_ADDRESS 0x000U | |||
#define PMA_ACCESS 2U | |||
#define EP_ADDR_MSK 0x7U | |||
/** | |||
* @} | |||
*/ | |||
/* Exported macro ------------------------------------------------------------*/ | |||
/** | |||
* @} | |||
*/ | |||
/* Exported functions --------------------------------------------------------*/ | |||
/** @addtogroup USB_LL_Exported_Functions USB Low Layer Exported Functions | |||
* @{ | |||
*/ | |||
HAL_StatusTypeDef USB_CoreInit(USB_TypeDef *USBx, USB_CfgTypeDef cfg); | |||
HAL_StatusTypeDef USB_DevInit(USB_TypeDef *USBx, USB_CfgTypeDef cfg); | |||
HAL_StatusTypeDef USB_EnableGlobalInt(USB_TypeDef *USBx); | |||
HAL_StatusTypeDef USB_DisableGlobalInt(USB_TypeDef *USBx); | |||
HAL_StatusTypeDef USB_SetCurrentMode(USB_TypeDef *USBx, USB_ModeTypeDef mode); | |||
HAL_StatusTypeDef USB_SetDevSpeed(USB_TypeDef *USBx, uint8_t speed); | |||
HAL_StatusTypeDef USB_FlushRxFifo(USB_TypeDef *USBx); | |||
HAL_StatusTypeDef USB_FlushTxFifo(USB_TypeDef *USBx, uint32_t num); | |||
HAL_StatusTypeDef USB_ActivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep); | |||
HAL_StatusTypeDef USB_DeactivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep); | |||
HAL_StatusTypeDef USB_EPStartXfer(USB_TypeDef *USBx, USB_EPTypeDef *ep); | |||
HAL_StatusTypeDef USB_WritePacket(USB_TypeDef *USBx, uint8_t *src, uint8_t ch_ep_num, uint16_t len); | |||
void *USB_ReadPacket(USB_TypeDef *USBx, uint8_t *dest, uint16_t len); | |||
HAL_StatusTypeDef USB_EPSetStall(USB_TypeDef *USBx, USB_EPTypeDef *ep); | |||
HAL_StatusTypeDef USB_EPClearStall(USB_TypeDef *USBx, USB_EPTypeDef *ep); | |||
HAL_StatusTypeDef USB_SetDevAddress(USB_TypeDef *USBx, uint8_t address); | |||
HAL_StatusTypeDef USB_DevConnect(USB_TypeDef *USBx); | |||
HAL_StatusTypeDef USB_DevDisconnect(USB_TypeDef *USBx); | |||
HAL_StatusTypeDef USB_StopDevice(USB_TypeDef *USBx); | |||
HAL_StatusTypeDef USB_EP0_OutStart(USB_TypeDef *USBx, uint8_t *psetup); | |||
uint32_t USB_ReadInterrupts(USB_TypeDef *USBx); | |||
uint32_t USB_ReadDevAllOutEpInterrupt(USB_TypeDef *USBx); | |||
uint32_t USB_ReadDevOutEPInterrupt(USB_TypeDef *USBx, uint8_t epnum); | |||
uint32_t USB_ReadDevAllInEpInterrupt(USB_TypeDef *USBx); | |||
uint32_t USB_ReadDevInEPInterrupt(USB_TypeDef *USBx, uint8_t epnum); | |||
void USB_ClearInterrupts(USB_TypeDef *USBx, uint32_t interrupt); | |||
HAL_StatusTypeDef USB_ActivateRemoteWakeup(USB_TypeDef *USBx); | |||
HAL_StatusTypeDef USB_DeActivateRemoteWakeup(USB_TypeDef *USBx); | |||
void USB_WritePMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes); | |||
void USB_ReadPMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes); | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#endif /* defined (USB) */ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* STM32L1xx_LL_USB_H */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,102 @@ | |||
/* USER CODE BEGIN Header */ | |||
/** | |||
****************************************************************************** | |||
* @file : usb_device.c | |||
* @version : v2.0_Cube | |||
* @brief : This file implements the USB Device | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2020 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under Ultimate Liberty license | |||
* SLA0044, the "License"; You may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at: | |||
* www.st.com/SLA0044 | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* USER CODE END Header */ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "usb_device.h" | |||
#include "usbd_core.h" | |||
#include "usbd_desc.h" | |||
#include "usbd_cdc.h" | |||
#include "usbd_cdc_if.h" | |||
/* USER CODE BEGIN Includes */ | |||
/* USER CODE END Includes */ | |||
/* USER CODE BEGIN PV */ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* USER CODE END PV */ | |||
/* USER CODE BEGIN PFP */ | |||
/* Private function prototypes -----------------------------------------------*/ | |||
/* USER CODE END PFP */ | |||
/* USB Device Core handle declaration. */ | |||
USBD_HandleTypeDef hUsbDeviceFS; | |||
/* | |||
* -- Insert your variables declaration here -- | |||
*/ | |||
/* USER CODE BEGIN 0 */ | |||
/* USER CODE END 0 */ | |||
/* | |||
* -- Insert your external function declaration here -- | |||
*/ | |||
/* USER CODE BEGIN 1 */ | |||
/* USER CODE END 1 */ | |||
/** | |||
* Init USB device Library, add supported class and start the library | |||
* @retval None | |||
*/ | |||
void MX_USB_DEVICE_Init(void) | |||
{ | |||
/* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */ | |||
/* USER CODE END USB_DEVICE_Init_PreTreatment */ | |||
/* Init Device Library, add supported class and start the library. */ | |||
if (USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS) != USBD_OK) | |||
{ | |||
Error_Handler(); | |||
} | |||
if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK) | |||
{ | |||
Error_Handler(); | |||
} | |||
if (USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK) | |||
{ | |||
Error_Handler(); | |||
} | |||
if (USBD_Start(&hUsbDeviceFS) != USBD_OK) | |||
{ | |||
Error_Handler(); | |||
} | |||
/* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */ | |||
/* USER CODE END USB_DEVICE_Init_PostTreatment */ | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,107 @@ | |||
/* USER CODE BEGIN Header */ | |||
/** | |||
****************************************************************************** | |||
* @file : usb_device.h | |||
* @version : v2.0_Cube | |||
* @brief : Header for usb_device.c file. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2020 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under Ultimate Liberty license | |||
* SLA0044, the "License"; You may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at: | |||
* www.st.com/SLA0044 | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* USER CODE END Header */ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __USB_DEVICE__H__ | |||
#define __USB_DEVICE__H__ | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx.h" | |||
#include "stm32l1xx_hal.h" | |||
#include "usbd_def.h" | |||
/* USER CODE BEGIN INCLUDE */ | |||
extern USBD_HandleTypeDef hUsbDeviceFS; | |||
/* USER CODE END INCLUDE */ | |||
/** @addtogroup USBD_OTG_DRIVER | |||
* @{ | |||
*/ | |||
/** @defgroup USBD_DEVICE USBD_DEVICE | |||
* @brief Device file for Usb otg low level driver. | |||
* @{ | |||
*/ | |||
/** @defgroup USBD_DEVICE_Exported_Variables USBD_DEVICE_Exported_Variables | |||
* @brief Public variables. | |||
* @{ | |||
*/ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* USER CODE BEGIN PV */ | |||
/* USER CODE END PV */ | |||
/* Private function prototypes -----------------------------------------------*/ | |||
/* USER CODE BEGIN PFP */ | |||
/* USER CODE END PFP */ | |||
/* | |||
* -- Insert your variables declaration here -- | |||
*/ | |||
/* USER CODE BEGIN VARIABLES */ | |||
/* USER CODE END VARIABLES */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_DEVICE_Exported_FunctionsPrototype USBD_DEVICE_Exported_FunctionsPrototype | |||
* @brief Declaration of public functions for Usb device. | |||
* @{ | |||
*/ | |||
/** USB Device initialization function. */ | |||
void MX_USB_DEVICE_Init(void); | |||
/* | |||
* -- Insert functions declaration here -- | |||
*/ | |||
/* USER CODE BEGIN FD */ | |||
/* USER CODE END FD */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __USB_DEVICE__H__ */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,945 @@ | |||
/** | |||
****************************************************************************** | |||
* @file usbd_cdc.c | |||
* @author MCD Application Team | |||
* @brief This file provides the high layer firmware functions to manage the | |||
* following functionalities of the USB CDC Class: | |||
* - Initialization and Configuration of high and low layer | |||
* - Enumeration as CDC Device (and enumeration for each implemented memory interface) | |||
* - OUT/IN data transfer | |||
* - Command IN transfer (class requests management) | |||
* - Error management | |||
* | |||
* @verbatim | |||
* | |||
* =================================================================== | |||
* CDC Class Driver Description | |||
* =================================================================== | |||
* This driver manages the "Universal Serial Bus Class Definitions for Communications Devices | |||
* Revision 1.2 November 16, 2007" and the sub-protocol specification of "Universal Serial Bus | |||
* Communications Class Subclass Specification for PSTN Devices Revision 1.2 February 9, 2007" | |||
* This driver implements the following aspects of the specification: | |||
* - Device descriptor management | |||
* - Configuration descriptor management | |||
* - Enumeration as CDC device with 2 data endpoints (IN and OUT) and 1 command endpoint (IN) | |||
* - Requests management (as described in section 6.2 in specification) | |||
* - Abstract Control Model compliant | |||
* - Union Functional collection (using 1 IN endpoint for control) | |||
* - Data interface class | |||
* | |||
* These aspects may be enriched or modified for a specific user application. | |||
* | |||
* This driver doesn't implement the following aspects of the specification | |||
* (but it is possible to manage these features with some modifications on this driver): | |||
* - Any class-specific aspect relative to communication classes should be managed by user application. | |||
* - All communication classes other than PSTN are not managed | |||
* | |||
* @endverbatim | |||
* | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2015 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under Ultimate Liberty license | |||
* SLA0044, the "License"; You may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at: | |||
* http://www.st.com/SLA0044 | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* BSPDependencies | |||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" | |||
- "stm32xxxxx_{eval}{discovery}_io.c" | |||
EndBSPDependencies */ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "usbd_cdc.h" | |||
#include "usbd_ctlreq.h" | |||
/** @addtogroup STM32_USB_DEVICE_LIBRARY | |||
* @{ | |||
*/ | |||
/** @defgroup USBD_CDC | |||
* @brief usbd core module | |||
* @{ | |||
*/ | |||
/** @defgroup USBD_CDC_Private_TypesDefinitions | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CDC_Private_Defines | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CDC_Private_Macros | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CDC_Private_FunctionPrototypes | |||
* @{ | |||
*/ | |||
static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev, | |||
uint8_t cfgidx); | |||
static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev, | |||
uint8_t cfgidx); | |||
static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev, | |||
USBD_SetupReqTypedef *req); | |||
static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev, | |||
uint8_t epnum); | |||
static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, | |||
uint8_t epnum); | |||
static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev); | |||
static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length); | |||
static uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length); | |||
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length); | |||
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length); | |||
uint8_t *USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length); | |||
/* USB Standard Device Descriptor */ | |||
__ALIGN_BEGIN static uint8_t USBD_CDC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = | |||
{ | |||
USB_LEN_DEV_QUALIFIER_DESC, | |||
USB_DESC_TYPE_DEVICE_QUALIFIER, | |||
0x00, | |||
0x02, | |||
0x00, | |||
0x00, | |||
0x00, | |||
0x40, | |||
0x01, | |||
0x00, | |||
}; | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CDC_Private_Variables | |||
* @{ | |||
*/ | |||
/* CDC interface class callbacks structure */ | |||
USBD_ClassTypeDef USBD_CDC = | |||
{ | |||
USBD_CDC_Init, | |||
USBD_CDC_DeInit, | |||
USBD_CDC_Setup, | |||
NULL, /* EP0_TxSent, */ | |||
USBD_CDC_EP0_RxReady, | |||
USBD_CDC_DataIn, | |||
USBD_CDC_DataOut, | |||
NULL, | |||
NULL, | |||
NULL, | |||
USBD_CDC_GetHSCfgDesc, | |||
USBD_CDC_GetFSCfgDesc, | |||
USBD_CDC_GetOtherSpeedCfgDesc, | |||
USBD_CDC_GetDeviceQualifierDescriptor, | |||
}; | |||
/* USB CDC device Configuration Descriptor */ | |||
__ALIGN_BEGIN uint8_t USBD_CDC_CfgHSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = | |||
{ | |||
/*Configuration Descriptor*/ | |||
0x09, /* bLength: Configuration Descriptor size */ | |||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ | |||
USB_CDC_CONFIG_DESC_SIZ, /* wTotalLength:no of returned bytes */ | |||
0x00, | |||
0x02, /* bNumInterfaces: 2 interface */ | |||
0x01, /* bConfigurationValue: Configuration value */ | |||
0x00, /* iConfiguration: Index of string descriptor describing the configuration */ | |||
0xC0, /* bmAttributes: self powered */ | |||
0x32, /* MaxPower 0 mA */ | |||
/*---------------------------------------------------------------------------*/ | |||
/*Interface Descriptor */ | |||
0x09, /* bLength: Interface Descriptor size */ | |||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ | |||
/* Interface descriptor type */ | |||
0x00, /* bInterfaceNumber: Number of Interface */ | |||
0x00, /* bAlternateSetting: Alternate setting */ | |||
0x01, /* bNumEndpoints: One endpoints used */ | |||
0x02, /* bInterfaceClass: Communication Interface Class */ | |||
0x02, /* bInterfaceSubClass: Abstract Control Model */ | |||
0x01, /* bInterfaceProtocol: Common AT commands */ | |||
0x00, /* iInterface: */ | |||
/*Header Functional Descriptor*/ | |||
0x05, /* bLength: Endpoint Descriptor size */ | |||
0x24, /* bDescriptorType: CS_INTERFACE */ | |||
0x00, /* bDescriptorSubtype: Header Func Desc */ | |||
0x10, /* bcdCDC: spec release number */ | |||
0x01, | |||
/*Call Management Functional Descriptor*/ | |||
0x05, /* bFunctionLength */ | |||
0x24, /* bDescriptorType: CS_INTERFACE */ | |||
0x01, /* bDescriptorSubtype: Call Management Func Desc */ | |||
0x00, /* bmCapabilities: D0+D1 */ | |||
0x01, /* bDataInterface: 1 */ | |||
/*ACM Functional Descriptor*/ | |||
0x04, /* bFunctionLength */ | |||
0x24, /* bDescriptorType: CS_INTERFACE */ | |||
0x02, /* bDescriptorSubtype: Abstract Control Management desc */ | |||
0x02, /* bmCapabilities */ | |||
/*Union Functional Descriptor*/ | |||
0x05, /* bFunctionLength */ | |||
0x24, /* bDescriptorType: CS_INTERFACE */ | |||
0x06, /* bDescriptorSubtype: Union func desc */ | |||
0x00, /* bMasterInterface: Communication class interface */ | |||
0x01, /* bSlaveInterface0: Data Class Interface */ | |||
/*Endpoint 2 Descriptor*/ | |||
0x07, /* bLength: Endpoint Descriptor size */ | |||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ | |||
CDC_CMD_EP, /* bEndpointAddress */ | |||
0x03, /* bmAttributes: Interrupt */ | |||
LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ | |||
HIBYTE(CDC_CMD_PACKET_SIZE), | |||
CDC_HS_BINTERVAL, /* bInterval: */ | |||
/*---------------------------------------------------------------------------*/ | |||
/*Data class interface descriptor*/ | |||
0x09, /* bLength: Endpoint Descriptor size */ | |||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ | |||
0x01, /* bInterfaceNumber: Number of Interface */ | |||
0x00, /* bAlternateSetting: Alternate setting */ | |||
0x02, /* bNumEndpoints: Two endpoints used */ | |||
0x0A, /* bInterfaceClass: CDC */ | |||
0x00, /* bInterfaceSubClass: */ | |||
0x00, /* bInterfaceProtocol: */ | |||
0x00, /* iInterface: */ | |||
/*Endpoint OUT Descriptor*/ | |||
0x07, /* bLength: Endpoint Descriptor size */ | |||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ | |||
CDC_OUT_EP, /* bEndpointAddress */ | |||
0x02, /* bmAttributes: Bulk */ | |||
LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ | |||
HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), | |||
0x00, /* bInterval: ignore for Bulk transfer */ | |||
/*Endpoint IN Descriptor*/ | |||
0x07, /* bLength: Endpoint Descriptor size */ | |||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ | |||
CDC_IN_EP, /* bEndpointAddress */ | |||
0x02, /* bmAttributes: Bulk */ | |||
LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ | |||
HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), | |||
0x00 /* bInterval: ignore for Bulk transfer */ | |||
} ; | |||
/* USB CDC device Configuration Descriptor */ | |||
__ALIGN_BEGIN uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = | |||
{ | |||
/*Configuration Descriptor*/ | |||
0x09, /* bLength: Configuration Descriptor size */ | |||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ | |||
USB_CDC_CONFIG_DESC_SIZ, /* wTotalLength:no of returned bytes */ | |||
0x00, | |||
0x02, /* bNumInterfaces: 2 interface */ | |||
0x01, /* bConfigurationValue: Configuration value */ | |||
0x00, /* iConfiguration: Index of string descriptor describing the configuration */ | |||
0xC0, /* bmAttributes: self powered */ | |||
0x32, /* MaxPower 0 mA */ | |||
/*---------------------------------------------------------------------------*/ | |||
/*Interface Descriptor */ | |||
0x09, /* bLength: Interface Descriptor size */ | |||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ | |||
/* Interface descriptor type */ | |||
0x00, /* bInterfaceNumber: Number of Interface */ | |||
0x00, /* bAlternateSetting: Alternate setting */ | |||
0x01, /* bNumEndpoints: One endpoints used */ | |||
0x02, /* bInterfaceClass: Communication Interface Class */ | |||
0x02, /* bInterfaceSubClass: Abstract Control Model */ | |||
0x01, /* bInterfaceProtocol: Common AT commands */ | |||
0x00, /* iInterface: */ | |||
/*Header Functional Descriptor*/ | |||
0x05, /* bLength: Endpoint Descriptor size */ | |||
0x24, /* bDescriptorType: CS_INTERFACE */ | |||
0x00, /* bDescriptorSubtype: Header Func Desc */ | |||
0x10, /* bcdCDC: spec release number */ | |||
0x01, | |||
/*Call Management Functional Descriptor*/ | |||
0x05, /* bFunctionLength */ | |||
0x24, /* bDescriptorType: CS_INTERFACE */ | |||
0x01, /* bDescriptorSubtype: Call Management Func Desc */ | |||
0x00, /* bmCapabilities: D0+D1 */ | |||
0x01, /* bDataInterface: 1 */ | |||
/*ACM Functional Descriptor*/ | |||
0x04, /* bFunctionLength */ | |||
0x24, /* bDescriptorType: CS_INTERFACE */ | |||
0x02, /* bDescriptorSubtype: Abstract Control Management desc */ | |||
0x02, /* bmCapabilities */ | |||
/*Union Functional Descriptor*/ | |||
0x05, /* bFunctionLength */ | |||
0x24, /* bDescriptorType: CS_INTERFACE */ | |||
0x06, /* bDescriptorSubtype: Union func desc */ | |||
0x00, /* bMasterInterface: Communication class interface */ | |||
0x01, /* bSlaveInterface0: Data Class Interface */ | |||
/*Endpoint 2 Descriptor*/ | |||
0x07, /* bLength: Endpoint Descriptor size */ | |||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ | |||
CDC_CMD_EP, /* bEndpointAddress */ | |||
0x03, /* bmAttributes: Interrupt */ | |||
LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ | |||
HIBYTE(CDC_CMD_PACKET_SIZE), | |||
CDC_FS_BINTERVAL, /* bInterval: */ | |||
/*---------------------------------------------------------------------------*/ | |||
/*Data class interface descriptor*/ | |||
0x09, /* bLength: Endpoint Descriptor size */ | |||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ | |||
0x01, /* bInterfaceNumber: Number of Interface */ | |||
0x00, /* bAlternateSetting: Alternate setting */ | |||
0x02, /* bNumEndpoints: Two endpoints used */ | |||
0x0A, /* bInterfaceClass: CDC */ | |||
0x00, /* bInterfaceSubClass: */ | |||
0x00, /* bInterfaceProtocol: */ | |||
0x00, /* iInterface: */ | |||
/*Endpoint OUT Descriptor*/ | |||
0x07, /* bLength: Endpoint Descriptor size */ | |||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ | |||
CDC_OUT_EP, /* bEndpointAddress */ | |||
0x02, /* bmAttributes: Bulk */ | |||
LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ | |||
HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), | |||
0x00, /* bInterval: ignore for Bulk transfer */ | |||
/*Endpoint IN Descriptor*/ | |||
0x07, /* bLength: Endpoint Descriptor size */ | |||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ | |||
CDC_IN_EP, /* bEndpointAddress */ | |||
0x02, /* bmAttributes: Bulk */ | |||
LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ | |||
HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), | |||
0x00 /* bInterval: ignore for Bulk transfer */ | |||
} ; | |||
__ALIGN_BEGIN uint8_t USBD_CDC_OtherSpeedCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = | |||
{ | |||
0x09, /* bLength: Configuation Descriptor size */ | |||
USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, | |||
USB_CDC_CONFIG_DESC_SIZ, | |||
0x00, | |||
0x02, /* bNumInterfaces: 2 interfaces */ | |||
0x01, /* bConfigurationValue: */ | |||
0x04, /* iConfiguration: */ | |||
0xC0, /* bmAttributes: */ | |||
0x32, /* MaxPower 100 mA */ | |||
/*Interface Descriptor */ | |||
0x09, /* bLength: Interface Descriptor size */ | |||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ | |||
/* Interface descriptor type */ | |||
0x00, /* bInterfaceNumber: Number of Interface */ | |||
0x00, /* bAlternateSetting: Alternate setting */ | |||
0x01, /* bNumEndpoints: One endpoints used */ | |||
0x02, /* bInterfaceClass: Communication Interface Class */ | |||
0x02, /* bInterfaceSubClass: Abstract Control Model */ | |||
0x01, /* bInterfaceProtocol: Common AT commands */ | |||
0x00, /* iInterface: */ | |||
/*Header Functional Descriptor*/ | |||
0x05, /* bLength: Endpoint Descriptor size */ | |||
0x24, /* bDescriptorType: CS_INTERFACE */ | |||
0x00, /* bDescriptorSubtype: Header Func Desc */ | |||
0x10, /* bcdCDC: spec release number */ | |||
0x01, | |||
/*Call Management Functional Descriptor*/ | |||
0x05, /* bFunctionLength */ | |||
0x24, /* bDescriptorType: CS_INTERFACE */ | |||
0x01, /* bDescriptorSubtype: Call Management Func Desc */ | |||
0x00, /* bmCapabilities: D0+D1 */ | |||
0x01, /* bDataInterface: 1 */ | |||
/*ACM Functional Descriptor*/ | |||
0x04, /* bFunctionLength */ | |||
0x24, /* bDescriptorType: CS_INTERFACE */ | |||
0x02, /* bDescriptorSubtype: Abstract Control Management desc */ | |||
0x02, /* bmCapabilities */ | |||
/*Union Functional Descriptor*/ | |||
0x05, /* bFunctionLength */ | |||
0x24, /* bDescriptorType: CS_INTERFACE */ | |||
0x06, /* bDescriptorSubtype: Union func desc */ | |||
0x00, /* bMasterInterface: Communication class interface */ | |||
0x01, /* bSlaveInterface0: Data Class Interface */ | |||
/*Endpoint 2 Descriptor*/ | |||
0x07, /* bLength: Endpoint Descriptor size */ | |||
USB_DESC_TYPE_ENDPOINT , /* bDescriptorType: Endpoint */ | |||
CDC_CMD_EP, /* bEndpointAddress */ | |||
0x03, /* bmAttributes: Interrupt */ | |||
LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ | |||
HIBYTE(CDC_CMD_PACKET_SIZE), | |||
CDC_FS_BINTERVAL, /* bInterval: */ | |||
/*---------------------------------------------------------------------------*/ | |||
/*Data class interface descriptor*/ | |||
0x09, /* bLength: Endpoint Descriptor size */ | |||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ | |||
0x01, /* bInterfaceNumber: Number of Interface */ | |||
0x00, /* bAlternateSetting: Alternate setting */ | |||
0x02, /* bNumEndpoints: Two endpoints used */ | |||
0x0A, /* bInterfaceClass: CDC */ | |||
0x00, /* bInterfaceSubClass: */ | |||
0x00, /* bInterfaceProtocol: */ | |||
0x00, /* iInterface: */ | |||
/*Endpoint OUT Descriptor*/ | |||
0x07, /* bLength: Endpoint Descriptor size */ | |||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ | |||
CDC_OUT_EP, /* bEndpointAddress */ | |||
0x02, /* bmAttributes: Bulk */ | |||
0x40, /* wMaxPacketSize: */ | |||
0x00, | |||
0x00, /* bInterval: ignore for Bulk transfer */ | |||
/*Endpoint IN Descriptor*/ | |||
0x07, /* bLength: Endpoint Descriptor size */ | |||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ | |||
CDC_IN_EP, /* bEndpointAddress */ | |||
0x02, /* bmAttributes: Bulk */ | |||
0x40, /* wMaxPacketSize: */ | |||
0x00, | |||
0x00 /* bInterval */ | |||
}; | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CDC_Private_Functions | |||
* @{ | |||
*/ | |||
/** | |||
* @brief USBD_CDC_Init | |||
* Initialize the CDC interface | |||
* @param pdev: device instance | |||
* @param cfgidx: Configuration index | |||
* @retval status | |||
*/ | |||
static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) | |||
{ | |||
uint8_t ret = 0U; | |||
USBD_CDC_HandleTypeDef *hcdc; | |||
if(pdev->dev_speed == USBD_SPEED_HIGH) | |||
{ | |||
/* Open EP IN */ | |||
USBD_LL_OpenEP(pdev, CDC_IN_EP, USBD_EP_TYPE_BULK, | |||
CDC_DATA_HS_IN_PACKET_SIZE); | |||
pdev->ep_in[CDC_IN_EP & 0xFU].is_used = 1U; | |||
/* Open EP OUT */ | |||
USBD_LL_OpenEP(pdev, CDC_OUT_EP, USBD_EP_TYPE_BULK, | |||
CDC_DATA_HS_OUT_PACKET_SIZE); | |||
pdev->ep_out[CDC_OUT_EP & 0xFU].is_used = 1U; | |||
} | |||
else | |||
{ | |||
/* Open EP IN */ | |||
USBD_LL_OpenEP(pdev, CDC_IN_EP, USBD_EP_TYPE_BULK, | |||
CDC_DATA_FS_IN_PACKET_SIZE); | |||
pdev->ep_in[CDC_IN_EP & 0xFU].is_used = 1U; | |||
/* Open EP OUT */ | |||
USBD_LL_OpenEP(pdev, CDC_OUT_EP, USBD_EP_TYPE_BULK, | |||
CDC_DATA_FS_OUT_PACKET_SIZE); | |||
pdev->ep_out[CDC_OUT_EP & 0xFU].is_used = 1U; | |||
} | |||
/* Open Command IN EP */ | |||
USBD_LL_OpenEP(pdev, CDC_CMD_EP, USBD_EP_TYPE_INTR, CDC_CMD_PACKET_SIZE); | |||
pdev->ep_in[CDC_CMD_EP & 0xFU].is_used = 1U; | |||
pdev->pClassData = USBD_malloc(sizeof (USBD_CDC_HandleTypeDef)); | |||
if(pdev->pClassData == NULL) | |||
{ | |||
ret = 1U; | |||
} | |||
else | |||
{ | |||
hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; | |||
/* Init physical Interface components */ | |||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Init(); | |||
/* Init Xfer states */ | |||
hcdc->TxState = 0U; | |||
hcdc->RxState = 0U; | |||
if(pdev->dev_speed == USBD_SPEED_HIGH) | |||
{ | |||
/* Prepare Out endpoint to receive next packet */ | |||
USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, hcdc->RxBuffer, | |||
CDC_DATA_HS_OUT_PACKET_SIZE); | |||
} | |||
else | |||
{ | |||
/* Prepare Out endpoint to receive next packet */ | |||
USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, hcdc->RxBuffer, | |||
CDC_DATA_FS_OUT_PACKET_SIZE); | |||
} | |||
} | |||
return ret; | |||
} | |||
/** | |||
* @brief USBD_CDC_Init | |||
* DeInitialize the CDC layer | |||
* @param pdev: device instance | |||
* @param cfgidx: Configuration index | |||
* @retval status | |||
*/ | |||
static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx) | |||
{ | |||
uint8_t ret = 0U; | |||
/* Close EP IN */ | |||
USBD_LL_CloseEP(pdev, CDC_IN_EP); | |||
pdev->ep_in[CDC_IN_EP & 0xFU].is_used = 0U; | |||
/* Close EP OUT */ | |||
USBD_LL_CloseEP(pdev, CDC_OUT_EP); | |||
pdev->ep_out[CDC_OUT_EP & 0xFU].is_used = 0U; | |||
/* Close Command IN EP */ | |||
USBD_LL_CloseEP(pdev, CDC_CMD_EP); | |||
pdev->ep_in[CDC_CMD_EP & 0xFU].is_used = 0U; | |||
/* DeInit physical Interface components */ | |||
if(pdev->pClassData != NULL) | |||
{ | |||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->DeInit(); | |||
USBD_free(pdev->pClassData); | |||
pdev->pClassData = NULL; | |||
} | |||
return ret; | |||
} | |||
/** | |||
* @brief USBD_CDC_Setup | |||
* Handle the CDC specific requests | |||
* @param pdev: instance | |||
* @param req: usb requests | |||
* @retval status | |||
*/ | |||
static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev, | |||
USBD_SetupReqTypedef *req) | |||
{ | |||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; | |||
uint8_t ifalt = 0U; | |||
uint16_t status_info = 0U; | |||
uint8_t ret = USBD_OK; | |||
switch (req->bmRequest & USB_REQ_TYPE_MASK) | |||
{ | |||
case USB_REQ_TYPE_CLASS : | |||
if (req->wLength) | |||
{ | |||
if (req->bmRequest & 0x80U) | |||
{ | |||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest, | |||
(uint8_t *)(void *)hcdc->data, | |||
req->wLength); | |||
USBD_CtlSendData (pdev, (uint8_t *)(void *)hcdc->data, req->wLength); | |||
} | |||
else | |||
{ | |||
hcdc->CmdOpCode = req->bRequest; | |||
hcdc->CmdLength = (uint8_t)req->wLength; | |||
USBD_CtlPrepareRx (pdev, (uint8_t *)(void *)hcdc->data, req->wLength); | |||
} | |||
} | |||
else | |||
{ | |||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest, | |||
(uint8_t *)(void *)req, 0U); | |||
} | |||
break; | |||
case USB_REQ_TYPE_STANDARD: | |||
switch (req->bRequest) | |||
{ | |||
case USB_REQ_GET_STATUS: | |||
if (pdev->dev_state == USBD_STATE_CONFIGURED) | |||
{ | |||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&status_info, 2U); | |||
} | |||
else | |||
{ | |||
USBD_CtlError (pdev, req); | |||
ret = USBD_FAIL; | |||
} | |||
break; | |||
case USB_REQ_GET_INTERFACE: | |||
if (pdev->dev_state == USBD_STATE_CONFIGURED) | |||
{ | |||
USBD_CtlSendData (pdev, &ifalt, 1U); | |||
} | |||
else | |||
{ | |||
USBD_CtlError (pdev, req); | |||
ret = USBD_FAIL; | |||
} | |||
break; | |||
case USB_REQ_SET_INTERFACE: | |||
if (pdev->dev_state != USBD_STATE_CONFIGURED) | |||
{ | |||
USBD_CtlError (pdev, req); | |||
ret = USBD_FAIL; | |||
} | |||
break; | |||
default: | |||
USBD_CtlError (pdev, req); | |||
ret = USBD_FAIL; | |||
break; | |||
} | |||
break; | |||
default: | |||
USBD_CtlError (pdev, req); | |||
ret = USBD_FAIL; | |||
break; | |||
} | |||
return ret; | |||
} | |||
/** | |||
* @brief USBD_CDC_DataIn | |||
* Data sent on non-control IN endpoint | |||
* @param pdev: device instance | |||
* @param epnum: endpoint number | |||
* @retval status | |||
*/ | |||
static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum) | |||
{ | |||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)pdev->pClassData; | |||
PCD_HandleTypeDef *hpcd = pdev->pData; | |||
if(pdev->pClassData != NULL) | |||
{ | |||
if((pdev->ep_in[epnum].total_length > 0U) && ((pdev->ep_in[epnum].total_length % hpcd->IN_ep[epnum].maxpacket) == 0U)) | |||
{ | |||
/* Update the packet total length */ | |||
pdev->ep_in[epnum].total_length = 0U; | |||
/* Send ZLP */ | |||
USBD_LL_Transmit (pdev, epnum, NULL, 0U); | |||
} | |||
else | |||
{ | |||
hcdc->TxState = 0U; | |||
} | |||
return USBD_OK; | |||
} | |||
else | |||
{ | |||
return USBD_FAIL; | |||
} | |||
} | |||
/** | |||
* @brief USBD_CDC_DataOut | |||
* Data received on non-control Out endpoint | |||
* @param pdev: device instance | |||
* @param epnum: endpoint number | |||
* @retval status | |||
*/ | |||
static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum) | |||
{ | |||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; | |||
/* Get the received data length */ | |||
hcdc->RxLength = USBD_LL_GetRxDataSize (pdev, epnum); | |||
/* USB data will be immediately processed, this allow next USB traffic being | |||
NAKed till the end of the application Xfer */ | |||
if(pdev->pClassData != NULL) | |||
{ | |||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Receive(hcdc->RxBuffer, &hcdc->RxLength); | |||
return USBD_OK; | |||
} | |||
else | |||
{ | |||
return USBD_FAIL; | |||
} | |||
} | |||
/** | |||
* @brief USBD_CDC_EP0_RxReady | |||
* Handle EP0 Rx Ready event | |||
* @param pdev: device instance | |||
* @retval status | |||
*/ | |||
static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev) | |||
{ | |||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; | |||
if((pdev->pUserData != NULL) && (hcdc->CmdOpCode != 0xFFU)) | |||
{ | |||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(hcdc->CmdOpCode, | |||
(uint8_t *)(void *)hcdc->data, | |||
(uint16_t)hcdc->CmdLength); | |||
hcdc->CmdOpCode = 0xFFU; | |||
} | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_CDC_GetFSCfgDesc | |||
* Return configuration descriptor | |||
* @param speed : current device speed | |||
* @param length : pointer data length | |||
* @retval pointer to descriptor buffer | |||
*/ | |||
static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length) | |||
{ | |||
*length = sizeof (USBD_CDC_CfgFSDesc); | |||
return USBD_CDC_CfgFSDesc; | |||
} | |||
/** | |||
* @brief USBD_CDC_GetHSCfgDesc | |||
* Return configuration descriptor | |||
* @param speed : current device speed | |||
* @param length : pointer data length | |||
* @retval pointer to descriptor buffer | |||
*/ | |||
static uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length) | |||
{ | |||
*length = sizeof (USBD_CDC_CfgHSDesc); | |||
return USBD_CDC_CfgHSDesc; | |||
} | |||
/** | |||
* @brief USBD_CDC_GetCfgDesc | |||
* Return configuration descriptor | |||
* @param speed : current device speed | |||
* @param length : pointer data length | |||
* @retval pointer to descriptor buffer | |||
*/ | |||
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length) | |||
{ | |||
*length = sizeof (USBD_CDC_OtherSpeedCfgDesc); | |||
return USBD_CDC_OtherSpeedCfgDesc; | |||
} | |||
/** | |||
* @brief DeviceQualifierDescriptor | |||
* return Device Qualifier descriptor | |||
* @param length : pointer data length | |||
* @retval pointer to descriptor buffer | |||
*/ | |||
uint8_t *USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length) | |||
{ | |||
*length = sizeof (USBD_CDC_DeviceQualifierDesc); | |||
return USBD_CDC_DeviceQualifierDesc; | |||
} | |||
/** | |||
* @brief USBD_CDC_RegisterInterface | |||
* @param pdev: device instance | |||
* @param fops: CD Interface callback | |||
* @retval status | |||
*/ | |||
uint8_t USBD_CDC_RegisterInterface (USBD_HandleTypeDef *pdev, | |||
USBD_CDC_ItfTypeDef *fops) | |||
{ | |||
uint8_t ret = USBD_FAIL; | |||
if(fops != NULL) | |||
{ | |||
pdev->pUserData= fops; | |||
ret = USBD_OK; | |||
} | |||
return ret; | |||
} | |||
/** | |||
* @brief USBD_CDC_SetTxBuffer | |||
* @param pdev: device instance | |||
* @param pbuff: Tx Buffer | |||
* @retval status | |||
*/ | |||
uint8_t USBD_CDC_SetTxBuffer (USBD_HandleTypeDef *pdev, | |||
uint8_t *pbuff, | |||
uint16_t length) | |||
{ | |||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; | |||
hcdc->TxBuffer = pbuff; | |||
hcdc->TxLength = length; | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_CDC_SetRxBuffer | |||
* @param pdev: device instance | |||
* @param pbuff: Rx Buffer | |||
* @retval status | |||
*/ | |||
uint8_t USBD_CDC_SetRxBuffer (USBD_HandleTypeDef *pdev, | |||
uint8_t *pbuff) | |||
{ | |||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; | |||
hcdc->RxBuffer = pbuff; | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_CDC_TransmitPacket | |||
* Transmit packet on IN endpoint | |||
* @param pdev: device instance | |||
* @retval status | |||
*/ | |||
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev) | |||
{ | |||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; | |||
if(pdev->pClassData != NULL) | |||
{ | |||
if(hcdc->TxState == 0U) | |||
{ | |||
/* Tx Transfer in progress */ | |||
hcdc->TxState = 1U; | |||
/* Update the packet total length */ | |||
pdev->ep_in[CDC_IN_EP & 0xFU].total_length = hcdc->TxLength; | |||
/* Transmit next packet */ | |||
USBD_LL_Transmit(pdev, CDC_IN_EP, hcdc->TxBuffer, | |||
(uint16_t)hcdc->TxLength); | |||
return USBD_OK; | |||
} | |||
else | |||
{ | |||
return USBD_BUSY; | |||
} | |||
} | |||
else | |||
{ | |||
return USBD_FAIL; | |||
} | |||
} | |||
/** | |||
* @brief USBD_CDC_ReceivePacket | |||
* prepare OUT Endpoint for reception | |||
* @param pdev: device instance | |||
* @retval status | |||
*/ | |||
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev) | |||
{ | |||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; | |||
/* Suspend or Resume USB Out process */ | |||
if(pdev->pClassData != NULL) | |||
{ | |||
if(pdev->dev_speed == USBD_SPEED_HIGH ) | |||
{ | |||
/* Prepare Out endpoint to receive next packet */ | |||
USBD_LL_PrepareReceive(pdev, | |||
CDC_OUT_EP, | |||
hcdc->RxBuffer, | |||
CDC_DATA_HS_OUT_PACKET_SIZE); | |||
} | |||
else | |||
{ | |||
/* Prepare Out endpoint to receive next packet */ | |||
USBD_LL_PrepareReceive(pdev, | |||
CDC_OUT_EP, | |||
hcdc->RxBuffer, | |||
CDC_DATA_FS_OUT_PACKET_SIZE); | |||
} | |||
return USBD_OK; | |||
} | |||
else | |||
{ | |||
return USBD_FAIL; | |||
} | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,179 @@ | |||
/** | |||
****************************************************************************** | |||
* @file usbd_cdc.h | |||
* @author MCD Application Team | |||
* @brief header file for the usbd_cdc.c file. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2015 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under Ultimate Liberty license | |||
* SLA0044, the "License"; You may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at: | |||
* http://www.st.com/SLA0044 | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __USB_CDC_H | |||
#define __USB_CDC_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "usbd_ioreq.h" | |||
/** @addtogroup STM32_USB_DEVICE_LIBRARY | |||
* @{ | |||
*/ | |||
/** @defgroup usbd_cdc | |||
* @brief This file is the Header file for usbd_cdc.c | |||
* @{ | |||
*/ | |||
/** @defgroup usbd_cdc_Exported_Defines | |||
* @{ | |||
*/ | |||
#define CDC_IN_EP 0x81U /* EP1 for data IN */ | |||
#define CDC_OUT_EP 0x01U /* EP1 for data OUT */ | |||
#define CDC_CMD_EP 0x82U /* EP2 for CDC commands */ | |||
#ifndef CDC_HS_BINTERVAL | |||
#define CDC_HS_BINTERVAL 0x10U | |||
#endif /* CDC_HS_BINTERVAL */ | |||
#ifndef CDC_FS_BINTERVAL | |||
#define CDC_FS_BINTERVAL 0x10U | |||
#endif /* CDC_FS_BINTERVAL */ | |||
/* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */ | |||
#define CDC_DATA_HS_MAX_PACKET_SIZE 512U /* Endpoint IN & OUT Packet size */ | |||
#define CDC_DATA_FS_MAX_PACKET_SIZE 64U /* Endpoint IN & OUT Packet size */ | |||
#define CDC_CMD_PACKET_SIZE 8U /* Control Endpoint Packet size */ | |||
#define USB_CDC_CONFIG_DESC_SIZ 67U | |||
#define CDC_DATA_HS_IN_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE | |||
#define CDC_DATA_HS_OUT_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE | |||
#define CDC_DATA_FS_IN_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE | |||
#define CDC_DATA_FS_OUT_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE | |||
/*---------------------------------------------------------------------*/ | |||
/* CDC definitions */ | |||
/*---------------------------------------------------------------------*/ | |||
#define CDC_SEND_ENCAPSULATED_COMMAND 0x00U | |||
#define CDC_GET_ENCAPSULATED_RESPONSE 0x01U | |||
#define CDC_SET_COMM_FEATURE 0x02U | |||
#define CDC_GET_COMM_FEATURE 0x03U | |||
#define CDC_CLEAR_COMM_FEATURE 0x04U | |||
#define CDC_SET_LINE_CODING 0x20U | |||
#define CDC_GET_LINE_CODING 0x21U | |||
#define CDC_SET_CONTROL_LINE_STATE 0x22U | |||
#define CDC_SEND_BREAK 0x23U | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CORE_Exported_TypesDefinitions | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
typedef struct | |||
{ | |||
uint32_t bitrate; | |||
uint8_t format; | |||
uint8_t paritytype; | |||
uint8_t datatype; | |||
}USBD_CDC_LineCodingTypeDef; | |||
typedef struct _USBD_CDC_Itf | |||
{ | |||
int8_t (* Init) (void); | |||
int8_t (* DeInit) (void); | |||
int8_t (* Control) (uint8_t cmd, uint8_t* pbuf, uint16_t length); | |||
int8_t (* Receive) (uint8_t* Buf, uint32_t *Len); | |||
}USBD_CDC_ItfTypeDef; | |||
typedef struct | |||
{ | |||
uint32_t data[CDC_DATA_HS_MAX_PACKET_SIZE / 4U]; /* Force 32bits alignment */ | |||
uint8_t CmdOpCode; | |||
uint8_t CmdLength; | |||
uint8_t *RxBuffer; | |||
uint8_t *TxBuffer; | |||
uint32_t RxLength; | |||
uint32_t TxLength; | |||
__IO uint32_t TxState; | |||
__IO uint32_t RxState; | |||
} | |||
USBD_CDC_HandleTypeDef; | |||
/** @defgroup USBD_CORE_Exported_Macros | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CORE_Exported_Variables | |||
* @{ | |||
*/ | |||
extern USBD_ClassTypeDef USBD_CDC; | |||
#define USBD_CDC_CLASS &USBD_CDC | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USB_CORE_Exported_Functions | |||
* @{ | |||
*/ | |||
uint8_t USBD_CDC_RegisterInterface (USBD_HandleTypeDef *pdev, | |||
USBD_CDC_ItfTypeDef *fops); | |||
uint8_t USBD_CDC_SetTxBuffer (USBD_HandleTypeDef *pdev, | |||
uint8_t *pbuff, | |||
uint16_t length); | |||
uint8_t USBD_CDC_SetRxBuffer (USBD_HandleTypeDef *pdev, | |||
uint8_t *pbuff); | |||
uint8_t USBD_CDC_ReceivePacket (USBD_HandleTypeDef *pdev); | |||
uint8_t USBD_CDC_TransmitPacket (USBD_HandleTypeDef *pdev); | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __USB_CDC_H */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,330 @@ | |||
/* USER CODE BEGIN Header */ | |||
/** | |||
****************************************************************************** | |||
* @file : usbd_cdc_if.c | |||
* @version : v2.0_Cube | |||
* @brief : Usb device for Virtual Com Port. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2020 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under Ultimate Liberty license | |||
* SLA0044, the "License"; You may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at: | |||
* www.st.com/SLA0044 | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* USER CODE END Header */ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "usbd_cdc_if.h" | |||
/* USER CODE BEGIN INCLUDE */ | |||
uint8_t* CDC_RX_BUFFER = NULL ; | |||
/* USER CODE END INCLUDE */ | |||
/* Private typedef -----------------------------------------------------------*/ | |||
/* Private define ------------------------------------------------------------*/ | |||
/* Private macro -------------------------------------------------------------*/ | |||
/* USER CODE BEGIN PV */ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* USER CODE END PV */ | |||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY | |||
* @brief Usb device library. | |||
* @{ | |||
*/ | |||
/** @addtogroup USBD_CDC_IF | |||
* @{ | |||
*/ | |||
/** @defgroup USBD_CDC_IF_Private_TypesDefinitions USBD_CDC_IF_Private_TypesDefinitions | |||
* @brief Private types. | |||
* @{ | |||
*/ | |||
/* USER CODE BEGIN PRIVATE_TYPES */ | |||
/* USER CODE END PRIVATE_TYPES */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CDC_IF_Private_Defines USBD_CDC_IF_Private_Defines | |||
* @brief Private defines. | |||
* @{ | |||
*/ | |||
/* USER CODE BEGIN PRIVATE_DEFINES */ | |||
/* Define size for the receive and transmit buffer over CDC */ | |||
/* It's up to user to redefine and/or remove those define */ | |||
#define APP_RX_DATA_SIZE 1000 | |||
#define APP_TX_DATA_SIZE 1000 | |||
/* USER CODE END PRIVATE_DEFINES */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CDC_IF_Private_Macros USBD_CDC_IF_Private_Macros | |||
* @brief Private macros. | |||
* @{ | |||
*/ | |||
/* USER CODE BEGIN PRIVATE_MACRO */ | |||
/* USER CODE END PRIVATE_MACRO */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CDC_IF_Private_Variables USBD_CDC_IF_Private_Variables | |||
* @brief Private variables. | |||
* @{ | |||
*/ | |||
/* Create buffer for reception and transmission */ | |||
/* It's up to user to redefine and/or remove those define */ | |||
/** Received data over USB are stored in this buffer */ | |||
uint8_t UserRxBufferFS[APP_RX_DATA_SIZE]; | |||
/** Data to send over USB CDC are stored in this buffer */ | |||
uint8_t UserTxBufferFS[APP_TX_DATA_SIZE]; | |||
/* USER CODE BEGIN PRIVATE_VARIABLES */ | |||
/* USER CODE END PRIVATE_VARIABLES */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CDC_IF_Exported_Variables USBD_CDC_IF_Exported_Variables | |||
* @brief Public variables. | |||
* @{ | |||
*/ | |||
extern USBD_HandleTypeDef hUsbDeviceFS; | |||
/* USER CODE BEGIN EXPORTED_VARIABLES */ | |||
/* USER CODE END EXPORTED_VARIABLES */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CDC_IF_Private_FunctionPrototypes USBD_CDC_IF_Private_FunctionPrototypes | |||
* @brief Private functions declaration. | |||
* @{ | |||
*/ | |||
static int8_t CDC_Init_FS(void); | |||
static int8_t CDC_DeInit_FS(void); | |||
static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length); | |||
static int8_t CDC_Receive_FS(uint8_t* pbuf, uint32_t *Len); | |||
/* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */ | |||
/* USER CODE END PRIVATE_FUNCTIONS_DECLARATION */ | |||
/** | |||
* @} | |||
*/ | |||
USBD_CDC_ItfTypeDef USBD_Interface_fops_FS = | |||
{ | |||
CDC_Init_FS, | |||
CDC_DeInit_FS, | |||
CDC_Control_FS, | |||
CDC_Receive_FS | |||
}; | |||
/* Private functions ---------------------------------------------------------*/ | |||
/** | |||
* @brief Initializes the CDC media low layer over the FS USB IP | |||
* @retval USBD_OK if all operations are OK else USBD_FAIL | |||
*/ | |||
static int8_t CDC_Init_FS(void) | |||
{ | |||
/* USER CODE BEGIN 3 */ | |||
/* Set Application Buffers */ | |||
USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0); | |||
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS); | |||
return (USBD_OK); | |||
/* USER CODE END 3 */ | |||
} | |||
/** | |||
* @brief DeInitializes the CDC media low layer | |||
* @retval USBD_OK if all operations are OK else USBD_FAIL | |||
*/ | |||
static int8_t CDC_DeInit_FS(void) | |||
{ | |||
/* USER CODE BEGIN 4 */ | |||
return (USBD_OK); | |||
/* USER CODE END 4 */ | |||
} | |||
/** | |||
* @brief Manage the CDC class requests | |||
* @param cmd: Command code | |||
* @param pbuf: Buffer containing command data (request parameters) | |||
* @param length: Number of data to be sent (in bytes) | |||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL | |||
*/ | |||
static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length) | |||
{ | |||
/* USER CODE BEGIN 5 */ | |||
switch(cmd) | |||
{ | |||
case CDC_SEND_ENCAPSULATED_COMMAND: | |||
break; | |||
case CDC_GET_ENCAPSULATED_RESPONSE: | |||
break; | |||
case CDC_SET_COMM_FEATURE: | |||
break; | |||
case CDC_GET_COMM_FEATURE: | |||
break; | |||
case CDC_CLEAR_COMM_FEATURE: | |||
break; | |||
/*******************************************************************************/ | |||
/* Line Coding Structure */ | |||
/*-----------------------------------------------------------------------------*/ | |||
/* Offset | Field | Size | Value | Description */ | |||
/* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/ | |||
/* 4 | bCharFormat | 1 | Number | Stop bits */ | |||
/* 0 - 1 Stop bit */ | |||
/* 1 - 1.5 Stop bits */ | |||
/* 2 - 2 Stop bits */ | |||
/* 5 | bParityType | 1 | Number | Parity */ | |||
/* 0 - None */ | |||
/* 1 - Odd */ | |||
/* 2 - Even */ | |||
/* 3 - Mark */ | |||
/* 4 - Space */ | |||
/* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */ | |||
/*******************************************************************************/ | |||
case CDC_SET_LINE_CODING: | |||
break; | |||
case CDC_GET_LINE_CODING: | |||
break; | |||
case CDC_SET_CONTROL_LINE_STATE: | |||
break; | |||
case CDC_SEND_BREAK: | |||
break; | |||
default: | |||
break; | |||
} | |||
return (USBD_OK); | |||
/* USER CODE END 5 */ | |||
} | |||
/** | |||
* @brief Data received over USB OUT endpoint are sent over CDC interface | |||
* through this function. | |||
* | |||
* @note | |||
* This function will block any OUT packet reception on USB endpoint | |||
* untill exiting this function. If you exit this function before transfer | |||
* is complete on CDC interface (ie. using DMA controller) it will result | |||
* in receiving more data while previous ones are still not sent. | |||
* | |||
* @param Buf: Buffer of data to be received | |||
* @param Len: Number of data received (in bytes) | |||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL | |||
*/ | |||
static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len) | |||
{ | |||
/* USER CODE BEGIN 6 */ | |||
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]); | |||
USBD_CDC_ReceivePacket(&hUsbDeviceFS); | |||
CDC_RX_BUFFER = Buf; | |||
return (USBD_OK); | |||
/* USER CODE END 6 */ | |||
} | |||
/** | |||
* @brief CDC_Transmit_FS | |||
* Data to send over USB IN endpoint are sent over CDC interface | |||
* through this function. | |||
* @note | |||
* | |||
* | |||
* @param Buf: Buffer of data to be sent | |||
* @param Len: Number of data to be sent (in bytes) | |||
* @retval USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY | |||
*/ | |||
uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len) | |||
{ | |||
uint8_t result = USBD_OK; | |||
/* USER CODE BEGIN 7 */ | |||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData; | |||
if (hcdc->TxState != 0){ | |||
return USBD_BUSY; | |||
} | |||
USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len); | |||
result = USBD_CDC_TransmitPacket(&hUsbDeviceFS); | |||
/* USER CODE END 7 */ | |||
return result; | |||
} | |||
/* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */ | |||
#include <stdarg.h> | |||
uint16_t vcp_status( USBD_SetupReqTypedef *req){ | |||
if(req->bRequest ==CDC_SET_CONTROL_LINE_STATE){ | |||
if(req->wValue){ | |||
return 1; | |||
} | |||
} | |||
return 0; | |||
} | |||
void usb_printf(const char *format, ...) | |||
{ | |||
va_list args; | |||
uint32_t length; | |||
va_start(args, format); | |||
length = vsnprintf((char *)UserTxBufferFS, APP_TX_DATA_SIZE, (char *)format, args); | |||
va_end(args); | |||
CDC_Transmit_FS(UserTxBufferFS, length); | |||
} | |||
/* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,131 @@ | |||
/* USER CODE BEGIN Header */ | |||
/** | |||
****************************************************************************** | |||
* @file : usbd_cdc_if.h | |||
* @version : v2.0_Cube | |||
* @brief : Header for usbd_cdc_if.c file. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2020 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under Ultimate Liberty license | |||
* SLA0044, the "License"; You may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at: | |||
* www.st.com/SLA0044 | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* USER CODE END Header */ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __USBD_CDC_IF_H__ | |||
#define __USBD_CDC_IF_H__ | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "usbd_cdc.h" | |||
/* USER CODE BEGIN INCLUDE */ | |||
/* USER CODE END INCLUDE */ | |||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY | |||
* @brief For Usb device. | |||
* @{ | |||
*/ | |||
/** @defgroup USBD_CDC_IF USBD_CDC_IF | |||
* @brief Usb VCP device module | |||
* @{ | |||
*/ | |||
/** @defgroup USBD_CDC_IF_Exported_Defines USBD_CDC_IF_Exported_Defines | |||
* @brief Defines. | |||
* @{ | |||
*/ | |||
/* USER CODE BEGIN EXPORTED_DEFINES */ | |||
/* USER CODE END EXPORTED_DEFINES */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CDC_IF_Exported_Types USBD_CDC_IF_Exported_Types | |||
* @brief Types. | |||
* @{ | |||
*/ | |||
/* USER CODE BEGIN EXPORTED_TYPES */ | |||
/* USER CODE END EXPORTED_TYPES */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CDC_IF_Exported_Macros USBD_CDC_IF_Exported_Macros | |||
* @brief Aliases. | |||
* @{ | |||
*/ | |||
/* USER CODE BEGIN EXPORTED_MACRO */ | |||
/* USER CODE END EXPORTED_MACRO */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CDC_IF_Exported_Variables USBD_CDC_IF_Exported_Variables | |||
* @brief Public variables. | |||
* @{ | |||
*/ | |||
/** CDC Interface callback. */ | |||
extern USBD_CDC_ItfTypeDef USBD_Interface_fops_FS; | |||
/* USER CODE BEGIN EXPORTED_VARIABLES */ | |||
/* USER CODE END EXPORTED_VARIABLES */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CDC_IF_Exported_FunctionsPrototype USBD_CDC_IF_Exported_FunctionsPrototype | |||
* @brief Public functions declaration. | |||
* @{ | |||
*/ | |||
uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len); | |||
/* USER CODE BEGIN EXPORTED_FUNCTIONS */ | |||
void usb_printf(const char *format, ...); | |||
uint16_t vcp_status( USBD_SetupReqTypedef *req); | |||
/* USER CODE END EXPORTED_FUNCTIONS */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __USBD_CDC_IF_H__ */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,631 @@ | |||
/* USER CODE BEGIN Header */ | |||
/** | |||
****************************************************************************** | |||
* @file : Target/usbd_conf.c | |||
* @version : v2.0_Cube | |||
* @brief : This file implements the board support package for the USB device library | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2020 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under Ultimate Liberty license | |||
* SLA0044, the "License"; You may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at: | |||
* www.st.com/SLA0044 | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* USER CODE END Header */ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "stm32l1xx.h" | |||
#include "stm32l1xx_hal.h" | |||
#include "usbd_def.h" | |||
#include "usbd_core.h" | |||
#include "usbd_cdc.h" | |||
/* USER CODE BEGIN Includes */ | |||
/* USER CODE END Includes */ | |||
/* Private typedef -----------------------------------------------------------*/ | |||
/* Private define ------------------------------------------------------------*/ | |||
/* Private macro -------------------------------------------------------------*/ | |||
/* USER CODE BEGIN PV */ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* USER CODE END PV */ | |||
PCD_HandleTypeDef hpcd_USB_FS; | |||
void Error_Handler(void); | |||
/* USER CODE BEGIN 0 */ | |||
/* USER CODE END 0 */ | |||
/* USER CODE BEGIN PFP */ | |||
/* Private function prototypes -----------------------------------------------*/ | |||
/* USER CODE END PFP */ | |||
/* Private functions ---------------------------------------------------------*/ | |||
static USBD_StatusTypeDef USBD_Get_USB_Status(HAL_StatusTypeDef hal_status); | |||
/* USER CODE BEGIN 1 */ | |||
/* USER CODE END 1 */ | |||
/******************************************************************************* | |||
LL Driver Callbacks (PCD -> USB Device Library) | |||
*******************************************************************************/ | |||
/* MSP Init */ | |||
void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) | |||
{ | |||
if(pcdHandle->Instance==USB) | |||
{ | |||
/* USER CODE BEGIN USB_MspInit 0 */ | |||
/* USER CODE END USB_MspInit 0 */ | |||
/* Peripheral clock enable */ | |||
__HAL_RCC_USB_CLK_ENABLE(); | |||
/* Peripheral interrupt init */ | |||
HAL_NVIC_SetPriority(USB_LP_IRQn, 0, 0); | |||
HAL_NVIC_EnableIRQ(USB_LP_IRQn); | |||
/* USER CODE BEGIN USB_MspInit 1 */ | |||
/* USER CODE END USB_MspInit 1 */ | |||
} | |||
} | |||
void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) | |||
{ | |||
if(pcdHandle->Instance==USB) | |||
{ | |||
/* USER CODE BEGIN USB_MspDeInit 0 */ | |||
/* USER CODE END USB_MspDeInit 0 */ | |||
/* Peripheral clock disable */ | |||
__HAL_RCC_USB_CLK_DISABLE(); | |||
/* Peripheral interrupt Deinit*/ | |||
HAL_NVIC_DisableIRQ(USB_LP_IRQn); | |||
/* USER CODE BEGIN USB_MspDeInit 1 */ | |||
/* USER CODE END USB_MspDeInit 1 */ | |||
} | |||
} | |||
/** | |||
* @brief Setup stage callback | |||
* @param hpcd: PCD handle | |||
* @retval None | |||
*/ | |||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | |||
static void PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) | |||
#else | |||
void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) | |||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | |||
{ | |||
USBD_LL_SetupStage((USBD_HandleTypeDef*)hpcd->pData, (uint8_t *)hpcd->Setup); | |||
} | |||
/** | |||
* @brief Data Out stage callback. | |||
* @param hpcd: PCD handle | |||
* @param epnum: Endpoint number | |||
* @retval None | |||
*/ | |||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | |||
static void PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) | |||
#else | |||
void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) | |||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | |||
{ | |||
USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff); | |||
} | |||
/** | |||
* @brief Data In stage callback. | |||
* @param hpcd: PCD handle | |||
* @param epnum: Endpoint number | |||
* @retval None | |||
*/ | |||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | |||
static void PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) | |||
#else | |||
void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) | |||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | |||
{ | |||
USBD_LL_DataInStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff); | |||
} | |||
/** | |||
* @brief SOF callback. | |||
* @param hpcd: PCD handle | |||
* @retval None | |||
*/ | |||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | |||
static void PCD_SOFCallback(PCD_HandleTypeDef *hpcd) | |||
#else | |||
void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) | |||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | |||
{ | |||
USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData); | |||
} | |||
/** | |||
* @brief Reset callback. | |||
* @param hpcd: PCD handle | |||
* @retval None | |||
*/ | |||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | |||
static void PCD_ResetCallback(PCD_HandleTypeDef *hpcd) | |||
#else | |||
void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) | |||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | |||
{ | |||
USBD_SpeedTypeDef speed = USBD_SPEED_FULL; | |||
if ( hpcd->Init.speed != PCD_SPEED_FULL) | |||
{ | |||
Error_Handler(); | |||
} | |||
/* Set Speed. */ | |||
USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, speed); | |||
/* Reset Device. */ | |||
USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData); | |||
} | |||
/** | |||
* @brief Suspend callback. | |||
* When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) | |||
* @param hpcd: PCD handle | |||
* @retval None | |||
*/ | |||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | |||
static void PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) | |||
#else | |||
void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) | |||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | |||
{ | |||
/* Inform USB library that core enters in suspend Mode. */ | |||
USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData); | |||
/* Enter in STOP mode. */ | |||
/* USER CODE BEGIN 2 */ | |||
if (hpcd->Init.low_power_enable) | |||
{ | |||
/* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */ | |||
SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); | |||
} | |||
/* USER CODE END 2 */ | |||
} | |||
/** | |||
* @brief Resume callback. | |||
* When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) | |||
* @param hpcd: PCD handle | |||
* @retval None | |||
*/ | |||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | |||
static void PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) | |||
#else | |||
void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) | |||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | |||
{ | |||
/* USER CODE BEGIN 3 */ | |||
/* USER CODE END 3 */ | |||
USBD_LL_Resume((USBD_HandleTypeDef*)hpcd->pData); | |||
} | |||
/** | |||
* @brief ISOOUTIncomplete callback. | |||
* @param hpcd: PCD handle | |||
* @param epnum: Endpoint number | |||
* @retval None | |||
*/ | |||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | |||
static void PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) | |||
#else | |||
void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) | |||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | |||
{ | |||
USBD_LL_IsoOUTIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); | |||
} | |||
/** | |||
* @brief ISOINIncomplete callback. | |||
* @param hpcd: PCD handle | |||
* @param epnum: Endpoint number | |||
* @retval None | |||
*/ | |||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | |||
static void PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) | |||
#else | |||
void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) | |||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | |||
{ | |||
USBD_LL_IsoINIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); | |||
} | |||
/** | |||
* @brief Connect callback. | |||
* @param hpcd: PCD handle | |||
* @retval None | |||
*/ | |||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | |||
static void PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) | |||
#else | |||
void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) | |||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | |||
{ | |||
USBD_LL_DevConnected((USBD_HandleTypeDef*)hpcd->pData); | |||
} | |||
/** | |||
* @brief Disconnect callback. | |||
* @param hpcd: PCD handle | |||
* @retval None | |||
*/ | |||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | |||
static void PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) | |||
#else | |||
void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) | |||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | |||
{ | |||
USBD_LL_DevDisconnected((USBD_HandleTypeDef*)hpcd->pData); | |||
} | |||
/******************************************************************************* | |||
LL Driver Interface (USB Device Library --> PCD) | |||
*******************************************************************************/ | |||
/** | |||
* @brief Initializes the low level portion of the device driver. | |||
* @param pdev: Device handle | |||
* @retval USBD status | |||
*/ | |||
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev) | |||
{ | |||
/* Init USB Ip. */ | |||
/* Link the driver to the stack. */ | |||
hpcd_USB_FS.pData = pdev; | |||
pdev->pData = &hpcd_USB_FS; | |||
hpcd_USB_FS.Instance = USB; | |||
hpcd_USB_FS.Init.dev_endpoints = 8; | |||
hpcd_USB_FS.Init.speed = PCD_SPEED_FULL; | |||
hpcd_USB_FS.Init.phy_itface = PCD_PHY_EMBEDDED; | |||
hpcd_USB_FS.Init.low_power_enable = DISABLE; | |||
hpcd_USB_FS.Init.battery_charging_enable = DISABLE; | |||
if (HAL_PCD_Init(&hpcd_USB_FS) != HAL_OK) | |||
{ | |||
Error_Handler( ); | |||
} | |||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | |||
/* Register USB PCD CallBacks */ | |||
HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_SOF_CB_ID, PCD_SOFCallback); | |||
HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_SETUPSTAGE_CB_ID, PCD_SetupStageCallback); | |||
HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_RESET_CB_ID, PCD_ResetCallback); | |||
HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_SUSPEND_CB_ID, PCD_SuspendCallback); | |||
HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_RESUME_CB_ID, PCD_ResumeCallback); | |||
HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_CONNECT_CB_ID, PCD_ConnectCallback); | |||
HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_DISCONNECT_CB_ID, PCD_DisconnectCallback); | |||
HAL_PCD_RegisterDataOutStageCallback(&hpcd_USB_FS, PCD_DataOutStageCallback); | |||
HAL_PCD_RegisterDataInStageCallback(&hpcd_USB_FS, PCD_DataInStageCallback); | |||
HAL_PCD_RegisterIsoOutIncpltCallback(&hpcd_USB_FS, PCD_ISOOUTIncompleteCallback); | |||
HAL_PCD_RegisterIsoInIncpltCallback(&hpcd_USB_FS, PCD_ISOINIncompleteCallback); | |||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | |||
/* USER CODE BEGIN EndPoint_Configuration */ | |||
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x00 , PCD_SNG_BUF, 0x18); | |||
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x80 , PCD_SNG_BUF, 0x58); | |||
/* USER CODE END EndPoint_Configuration */ | |||
/* USER CODE BEGIN EndPoint_Configuration_CDC */ | |||
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x81 , PCD_SNG_BUF, 0xC0); | |||
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x01 , PCD_SNG_BUF, 0x110); | |||
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x82 , PCD_SNG_BUF, 0x100); | |||
/* USER CODE END EndPoint_Configuration_CDC */ | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief De-Initializes the low level portion of the device driver. | |||
* @param pdev: Device handle | |||
* @retval USBD status | |||
*/ | |||
USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev) | |||
{ | |||
HAL_StatusTypeDef hal_status = HAL_OK; | |||
USBD_StatusTypeDef usb_status = USBD_OK; | |||
hal_status = HAL_PCD_DeInit(pdev->pData); | |||
usb_status = USBD_Get_USB_Status(hal_status); | |||
return usb_status; | |||
} | |||
/** | |||
* @brief Starts the low level portion of the device driver. | |||
* @param pdev: Device handle | |||
* @retval USBD status | |||
*/ | |||
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev) | |||
{ | |||
HAL_StatusTypeDef hal_status = HAL_OK; | |||
USBD_StatusTypeDef usb_status = USBD_OK; | |||
hal_status = HAL_PCD_Start(pdev->pData); | |||
usb_status = USBD_Get_USB_Status(hal_status); | |||
return usb_status; | |||
} | |||
/** | |||
* @brief Stops the low level portion of the device driver. | |||
* @param pdev: Device handle | |||
* @retval USBD status | |||
*/ | |||
USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev) | |||
{ | |||
HAL_StatusTypeDef hal_status = HAL_OK; | |||
USBD_StatusTypeDef usb_status = USBD_OK; | |||
hal_status = HAL_PCD_Stop(pdev->pData); | |||
usb_status = USBD_Get_USB_Status(hal_status); | |||
return usb_status; | |||
} | |||
/** | |||
* @brief Opens an endpoint of the low level driver. | |||
* @param pdev: Device handle | |||
* @param ep_addr: Endpoint number | |||
* @param ep_type: Endpoint type | |||
* @param ep_mps: Endpoint max packet size | |||
* @retval USBD status | |||
*/ | |||
USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps) | |||
{ | |||
HAL_StatusTypeDef hal_status = HAL_OK; | |||
USBD_StatusTypeDef usb_status = USBD_OK; | |||
hal_status = HAL_PCD_EP_Open(pdev->pData, ep_addr, ep_mps, ep_type); | |||
usb_status = USBD_Get_USB_Status(hal_status); | |||
return usb_status; | |||
} | |||
/** | |||
* @brief Closes an endpoint of the low level driver. | |||
* @param pdev: Device handle | |||
* @param ep_addr: Endpoint number | |||
* @retval USBD status | |||
*/ | |||
USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) | |||
{ | |||
HAL_StatusTypeDef hal_status = HAL_OK; | |||
USBD_StatusTypeDef usb_status = USBD_OK; | |||
hal_status = HAL_PCD_EP_Close(pdev->pData, ep_addr); | |||
usb_status = USBD_Get_USB_Status(hal_status); | |||
return usb_status; | |||
} | |||
/** | |||
* @brief Flushes an endpoint of the Low Level Driver. | |||
* @param pdev: Device handle | |||
* @param ep_addr: Endpoint number | |||
* @retval USBD status | |||
*/ | |||
USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) | |||
{ | |||
HAL_StatusTypeDef hal_status = HAL_OK; | |||
USBD_StatusTypeDef usb_status = USBD_OK; | |||
hal_status = HAL_PCD_EP_Flush(pdev->pData, ep_addr); | |||
usb_status = USBD_Get_USB_Status(hal_status); | |||
return usb_status; | |||
} | |||
/** | |||
* @brief Sets a Stall condition on an endpoint of the Low Level Driver. | |||
* @param pdev: Device handle | |||
* @param ep_addr: Endpoint number | |||
* @retval USBD status | |||
*/ | |||
USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) | |||
{ | |||
HAL_StatusTypeDef hal_status = HAL_OK; | |||
USBD_StatusTypeDef usb_status = USBD_OK; | |||
hal_status = HAL_PCD_EP_SetStall(pdev->pData, ep_addr); | |||
usb_status = USBD_Get_USB_Status(hal_status); | |||
return usb_status; | |||
} | |||
/** | |||
* @brief Clears a Stall condition on an endpoint of the Low Level Driver. | |||
* @param pdev: Device handle | |||
* @param ep_addr: Endpoint number | |||
* @retval USBD status | |||
*/ | |||
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) | |||
{ | |||
HAL_StatusTypeDef hal_status = HAL_OK; | |||
USBD_StatusTypeDef usb_status = USBD_OK; | |||
hal_status = HAL_PCD_EP_ClrStall(pdev->pData, ep_addr); | |||
usb_status = USBD_Get_USB_Status(hal_status); | |||
return usb_status; | |||
} | |||
/** | |||
* @brief Returns Stall condition. | |||
* @param pdev: Device handle | |||
* @param ep_addr: Endpoint number | |||
* @retval Stall (1: Yes, 0: No) | |||
*/ | |||
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) | |||
{ | |||
PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData; | |||
if((ep_addr & 0x80) == 0x80) | |||
{ | |||
return hpcd->IN_ep[ep_addr & 0x7F].is_stall; | |||
} | |||
else | |||
{ | |||
return hpcd->OUT_ep[ep_addr & 0x7F].is_stall; | |||
} | |||
} | |||
/** | |||
* @brief Assigns a USB address to the device. | |||
* @param pdev: Device handle | |||
* @param dev_addr: Device address | |||
* @retval USBD status | |||
*/ | |||
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr) | |||
{ | |||
HAL_StatusTypeDef hal_status = HAL_OK; | |||
USBD_StatusTypeDef usb_status = USBD_OK; | |||
hal_status = HAL_PCD_SetAddress(pdev->pData, dev_addr); | |||
usb_status = USBD_Get_USB_Status(hal_status); | |||
return usb_status; | |||
} | |||
/** | |||
* @brief Transmits data over an endpoint. | |||
* @param pdev: Device handle | |||
* @param ep_addr: Endpoint number | |||
* @param pbuf: Pointer to data to be sent | |||
* @param size: Data size | |||
* @retval USBD status | |||
*/ | |||
USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size) | |||
{ | |||
HAL_StatusTypeDef hal_status = HAL_OK; | |||
USBD_StatusTypeDef usb_status = USBD_OK; | |||
hal_status = HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size); | |||
usb_status = USBD_Get_USB_Status(hal_status); | |||
return usb_status; | |||
} | |||
/** | |||
* @brief Prepares an endpoint for reception. | |||
* @param pdev: Device handle | |||
* @param ep_addr: Endpoint number | |||
* @param pbuf: Pointer to data to be received | |||
* @param size: Data size | |||
* @retval USBD status | |||
*/ | |||
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size) | |||
{ | |||
HAL_StatusTypeDef hal_status = HAL_OK; | |||
USBD_StatusTypeDef usb_status = USBD_OK; | |||
hal_status = HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size); | |||
usb_status = USBD_Get_USB_Status(hal_status); | |||
return usb_status; | |||
} | |||
/** | |||
* @brief Returns the last transfered packet size. | |||
* @param pdev: Device handle | |||
* @param ep_addr: Endpoint number | |||
* @retval Recived Data Size | |||
*/ | |||
uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr) | |||
{ | |||
return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*) pdev->pData, ep_addr); | |||
} | |||
/** | |||
* @brief Delays routine for the USB device library. | |||
* @param Delay: Delay in ms | |||
* @retval None | |||
*/ | |||
void USBD_LL_Delay(uint32_t Delay) | |||
{ | |||
HAL_Delay(Delay); | |||
} | |||
/** | |||
* @brief Static single allocation. | |||
* @param size: Size of allocated memory | |||
* @retval None | |||
*/ | |||
void *USBD_static_malloc(uint32_t size) | |||
{ | |||
static uint32_t mem[(sizeof(USBD_CDC_HandleTypeDef)/4)+1];/* On 32-bit boundary */ | |||
return mem; | |||
} | |||
/** | |||
* @brief Dummy memory free | |||
* @param p: Pointer to allocated memory address | |||
* @retval None | |||
*/ | |||
void USBD_static_free(void *p) | |||
{ | |||
} | |||
/** | |||
* @brief Retuns the USB status depending on the HAL status: | |||
* @param hal_status: HAL status | |||
* @retval USB status | |||
*/ | |||
USBD_StatusTypeDef USBD_Get_USB_Status(HAL_StatusTypeDef hal_status) | |||
{ | |||
USBD_StatusTypeDef usb_status = USBD_OK; | |||
switch (hal_status) | |||
{ | |||
case HAL_OK : | |||
usb_status = USBD_OK; | |||
break; | |||
case HAL_ERROR : | |||
usb_status = USBD_FAIL; | |||
break; | |||
case HAL_BUSY : | |||
usb_status = USBD_BUSY; | |||
break; | |||
case HAL_TIMEOUT : | |||
usb_status = USBD_FAIL; | |||
break; | |||
default : | |||
usb_status = USBD_FAIL; | |||
break; | |||
} | |||
return usb_status; | |||
} | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,175 @@ | |||
/* USER CODE BEGIN Header */ | |||
/** | |||
****************************************************************************** | |||
* @file : usbd_conf.h | |||
* @version : v2.0_Cube | |||
* @brief : Header for usbd_conf.c file. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2020 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under Ultimate Liberty license | |||
* SLA0044, the "License"; You may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at: | |||
* www.st.com/SLA0044 | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* USER CODE END Header */ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __USBD_CONF__H__ | |||
#define __USBD_CONF__H__ | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include <string.h> | |||
#include "main.h" | |||
#include "stm32l1xx.h" | |||
#include "stm32l1xx_hal.h" | |||
/* USER CODE BEGIN INCLUDE */ | |||
/* USER CODE END INCLUDE */ | |||
/** @addtogroup USBD_OTG_DRIVER | |||
* @{ | |||
*/ | |||
/** @defgroup USBD_CONF USBD_CONF | |||
* @brief Configuration file for Usb otg low level driver. | |||
* @{ | |||
*/ | |||
/** @defgroup USBD_CONF_Exported_Variables USBD_CONF_Exported_Variables | |||
* @brief Public variables. | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CONF_Exported_Defines USBD_CONF_Exported_Defines | |||
* @brief Defines for configuration of the Usb device. | |||
* @{ | |||
*/ | |||
/*---------- -----------*/ | |||
#define USBD_MAX_NUM_INTERFACES 1U | |||
/*---------- -----------*/ | |||
#define USBD_MAX_NUM_CONFIGURATION 1U | |||
/*---------- -----------*/ | |||
#define USBD_MAX_STR_DESC_SIZ 512U | |||
/*---------- -----------*/ | |||
#define USBD_DEBUG_LEVEL 0U | |||
/*---------- -----------*/ | |||
#define USBD_SELF_POWERED 1U | |||
/****************************************/ | |||
/* #define for FS and HS identification */ | |||
#define DEVICE_FS 0 | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CONF_Exported_Macros USBD_CONF_Exported_Macros | |||
* @brief Aliases. | |||
* @{ | |||
*/ | |||
/* Memory management macros */ | |||
/** Alias for memory allocation. */ | |||
#define USBD_malloc (uint32_t *)USBD_static_malloc | |||
/** Alias for memory release. */ | |||
#define USBD_free USBD_static_free | |||
/** Alias for memory set. */ | |||
#define USBD_memset /* Not used */ | |||
/** Alias for memory copy. */ | |||
#define USBD_memcpy /* Not used */ | |||
/** Alias for delay. */ | |||
#define USBD_Delay HAL_Delay | |||
/* For footprint reasons and since only one allocation is handled in the HID class | |||
driver, the malloc/free is changed into a static allocation method */ | |||
void *USBD_static_malloc(uint32_t size); | |||
void USBD_static_free(void *p); | |||
/* DEBUG macros */ | |||
#if (USBD_DEBUG_LEVEL > 0) | |||
#define USBD_UsrLog(...) printf(__VA_ARGS__);\ | |||
printf("\n"); | |||
#else | |||
#define USBD_UsrLog(...) | |||
#endif | |||
#if (USBD_DEBUG_LEVEL > 1) | |||
#define USBD_ErrLog(...) printf("ERROR: ") ;\ | |||
printf(__VA_ARGS__);\ | |||
printf("\n"); | |||
#else | |||
#define USBD_ErrLog(...) | |||
#endif | |||
#if (USBD_DEBUG_LEVEL > 2) | |||
#define USBD_DbgLog(...) printf("DEBUG : ") ;\ | |||
printf(__VA_ARGS__);\ | |||
printf("\n"); | |||
#else | |||
#define USBD_DbgLog(...) | |||
#endif | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CONF_Exported_Types USBD_CONF_Exported_Types | |||
* @brief Types. | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CONF_Exported_FunctionsPrototype USBD_CONF_Exported_FunctionsPrototype | |||
* @brief Declaration of public functions for Usb device. | |||
* @{ | |||
*/ | |||
/* Exported functions -------------------------------------------------------*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __USBD_CONF__H__ */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,598 @@ | |||
/** | |||
****************************************************************************** | |||
* @file usbd_core.c | |||
* @author MCD Application Team | |||
* @brief This file provides all the USBD core functions. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2015 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under Ultimate Liberty license | |||
* SLA0044, the "License"; You may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at: | |||
* http://www.st.com/SLA0044 | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "usbd_core.h" | |||
/** @addtogroup STM32_USBD_DEVICE_LIBRARY | |||
* @{ | |||
*/ | |||
/** @defgroup USBD_CORE | |||
* @brief usbd core module | |||
* @{ | |||
*/ | |||
/** @defgroup USBD_CORE_Private_TypesDefinitions | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CORE_Private_Defines | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CORE_Private_Macros | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CORE_Private_FunctionPrototypes | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CORE_Private_Variables | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CORE_Private_Functions | |||
* @{ | |||
*/ | |||
/** | |||
* @brief USBD_Init | |||
* Initializes the device stack and load the class driver | |||
* @param pdev: device instance | |||
* @param pdesc: Descriptor structure address | |||
* @param id: Low level core index | |||
* @retval None | |||
*/ | |||
USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id) | |||
{ | |||
/* Check whether the USB Host handle is valid */ | |||
if(pdev == NULL) | |||
{ | |||
#if (USBD_DEBUG_LEVEL > 1U) | |||
USBD_ErrLog("Invalid Device handle"); | |||
#endif | |||
return USBD_FAIL; | |||
} | |||
/* Unlink previous class*/ | |||
if(pdev->pClass != NULL) | |||
{ | |||
pdev->pClass = NULL; | |||
} | |||
/* Assign USBD Descriptors */ | |||
if(pdesc != NULL) | |||
{ | |||
pdev->pDesc = pdesc; | |||
} | |||
/* Set Device initial State */ | |||
pdev->dev_state = USBD_STATE_DEFAULT; | |||
pdev->id = id; | |||
/* Initialize low level driver */ | |||
USBD_LL_Init(pdev); | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_DeInit | |||
* Re-Initialize th device library | |||
* @param pdev: device instance | |||
* @retval status: status | |||
*/ | |||
USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev) | |||
{ | |||
/* Set Default State */ | |||
pdev->dev_state = USBD_STATE_DEFAULT; | |||
/* Free Class Resources */ | |||
pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config); | |||
/* Stop the low level driver */ | |||
USBD_LL_Stop(pdev); | |||
/* Initialize low level driver */ | |||
USBD_LL_DeInit(pdev); | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_RegisterClass | |||
* Link class driver to Device Core. | |||
* @param pDevice : Device Handle | |||
* @param pclass: Class handle | |||
* @retval USBD Status | |||
*/ | |||
USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass) | |||
{ | |||
USBD_StatusTypeDef status = USBD_OK; | |||
if(pclass != 0) | |||
{ | |||
/* link the class to the USB Device handle */ | |||
pdev->pClass = pclass; | |||
status = USBD_OK; | |||
} | |||
else | |||
{ | |||
#if (USBD_DEBUG_LEVEL > 1U) | |||
USBD_ErrLog("Invalid Class handle"); | |||
#endif | |||
status = USBD_FAIL; | |||
} | |||
return status; | |||
} | |||
/** | |||
* @brief USBD_Start | |||
* Start the USB Device Core. | |||
* @param pdev: Device Handle | |||
* @retval USBD Status | |||
*/ | |||
USBD_StatusTypeDef USBD_Start (USBD_HandleTypeDef *pdev) | |||
{ | |||
/* Start the low level driver */ | |||
USBD_LL_Start(pdev); | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_Stop | |||
* Stop the USB Device Core. | |||
* @param pdev: Device Handle | |||
* @retval USBD Status | |||
*/ | |||
USBD_StatusTypeDef USBD_Stop (USBD_HandleTypeDef *pdev) | |||
{ | |||
/* Free Class Resources */ | |||
pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config); | |||
/* Stop the low level driver */ | |||
USBD_LL_Stop(pdev); | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_RunTestMode | |||
* Launch test mode process | |||
* @param pdev: device instance | |||
* @retval status | |||
*/ | |||
USBD_StatusTypeDef USBD_RunTestMode (USBD_HandleTypeDef *pdev) | |||
{ | |||
/* Prevent unused argument compilation warning */ | |||
UNUSED(pdev); | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_SetClassConfig | |||
* Configure device and start the interface | |||
* @param pdev: device instance | |||
* @param cfgidx: configuration index | |||
* @retval status | |||
*/ | |||
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx) | |||
{ | |||
USBD_StatusTypeDef ret = USBD_FAIL; | |||
if(pdev->pClass != NULL) | |||
{ | |||
/* Set configuration and Start the Class*/ | |||
if(pdev->pClass->Init(pdev, cfgidx) == 0U) | |||
{ | |||
ret = USBD_OK; | |||
} | |||
} | |||
return ret; | |||
} | |||
/** | |||
* @brief USBD_ClrClassConfig | |||
* Clear current configuration | |||
* @param pdev: device instance | |||
* @param cfgidx: configuration index | |||
* @retval status: USBD_StatusTypeDef | |||
*/ | |||
USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx) | |||
{ | |||
/* Clear configuration and De-initialize the Class process*/ | |||
pdev->pClass->DeInit(pdev, cfgidx); | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_SetupStage | |||
* Handle the setup stage | |||
* @param pdev: device instance | |||
* @retval status | |||
*/ | |||
USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup) | |||
{ | |||
USBD_ParseSetupRequest(&pdev->request, psetup); | |||
pdev->ep0_state = USBD_EP0_SETUP; | |||
pdev->ep0_data_len = pdev->request.wLength; | |||
switch (pdev->request.bmRequest & 0x1FU) | |||
{ | |||
case USB_REQ_RECIPIENT_DEVICE: | |||
USBD_StdDevReq (pdev, &pdev->request); | |||
break; | |||
case USB_REQ_RECIPIENT_INTERFACE: | |||
USBD_StdItfReq(pdev, &pdev->request); | |||
break; | |||
case USB_REQ_RECIPIENT_ENDPOINT: | |||
USBD_StdEPReq(pdev, &pdev->request); | |||
break; | |||
default: | |||
USBD_LL_StallEP(pdev, (pdev->request.bmRequest & 0x80U)); | |||
break; | |||
} | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_DataOutStage | |||
* Handle data OUT stage | |||
* @param pdev: device instance | |||
* @param epnum: endpoint index | |||
* @retval status | |||
*/ | |||
USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev, | |||
uint8_t epnum, uint8_t *pdata) | |||
{ | |||
USBD_EndpointTypeDef *pep; | |||
if(epnum == 0U) | |||
{ | |||
pep = &pdev->ep_out[0]; | |||
if ( pdev->ep0_state == USBD_EP0_DATA_OUT) | |||
{ | |||
if(pep->rem_length > pep->maxpacket) | |||
{ | |||
pep->rem_length -= pep->maxpacket; | |||
USBD_CtlContinueRx (pdev, | |||
pdata, | |||
(uint16_t)MIN(pep->rem_length, pep->maxpacket)); | |||
} | |||
else | |||
{ | |||
if((pdev->pClass->EP0_RxReady != NULL)&& | |||
(pdev->dev_state == USBD_STATE_CONFIGURED)) | |||
{ | |||
pdev->pClass->EP0_RxReady(pdev); | |||
} | |||
USBD_CtlSendStatus(pdev); | |||
} | |||
} | |||
else | |||
{ | |||
if (pdev->ep0_state == USBD_EP0_STATUS_OUT) | |||
{ | |||
/* | |||
* STATUS PHASE completed, update ep0_state to idle | |||
*/ | |||
pdev->ep0_state = USBD_EP0_IDLE; | |||
USBD_LL_StallEP(pdev, 0U); | |||
} | |||
} | |||
} | |||
else if((pdev->pClass->DataOut != NULL) && | |||
(pdev->dev_state == USBD_STATE_CONFIGURED)) | |||
{ | |||
pdev->pClass->DataOut(pdev, epnum); | |||
} | |||
else | |||
{ | |||
/* should never be in this condition */ | |||
return USBD_FAIL; | |||
} | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_DataInStage | |||
* Handle data in stage | |||
* @param pdev: device instance | |||
* @param epnum: endpoint index | |||
* @retval status | |||
*/ | |||
USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum, | |||
uint8_t *pdata) | |||
{ | |||
USBD_EndpointTypeDef *pep; | |||
if(epnum == 0U) | |||
{ | |||
pep = &pdev->ep_in[0]; | |||
if ( pdev->ep0_state == USBD_EP0_DATA_IN) | |||
{ | |||
if(pep->rem_length > pep->maxpacket) | |||
{ | |||
pep->rem_length -= pep->maxpacket; | |||
USBD_CtlContinueSendData (pdev, pdata, (uint16_t)pep->rem_length); | |||
/* Prepare endpoint for premature end of transfer */ | |||
USBD_LL_PrepareReceive (pdev, 0U, NULL, 0U); | |||
} | |||
else | |||
{ /* last packet is MPS multiple, so send ZLP packet */ | |||
if((pep->total_length % pep->maxpacket == 0U) && | |||
(pep->total_length >= pep->maxpacket) && | |||
(pep->total_length < pdev->ep0_data_len)) | |||
{ | |||
USBD_CtlContinueSendData(pdev, NULL, 0U); | |||
pdev->ep0_data_len = 0U; | |||
/* Prepare endpoint for premature end of transfer */ | |||
USBD_LL_PrepareReceive (pdev, 0U, NULL, 0U); | |||
} | |||
else | |||
{ | |||
if((pdev->pClass->EP0_TxSent != NULL)&& | |||
(pdev->dev_state == USBD_STATE_CONFIGURED)) | |||
{ | |||
pdev->pClass->EP0_TxSent(pdev); | |||
} | |||
USBD_LL_StallEP(pdev, 0x80U); | |||
USBD_CtlReceiveStatus(pdev); | |||
} | |||
} | |||
} | |||
else | |||
{ | |||
if ((pdev->ep0_state == USBD_EP0_STATUS_IN) || | |||
(pdev->ep0_state == USBD_EP0_IDLE)) | |||
{ | |||
USBD_LL_StallEP(pdev, 0x80U); | |||
} | |||
} | |||
if (pdev->dev_test_mode == 1U) | |||
{ | |||
USBD_RunTestMode(pdev); | |||
pdev->dev_test_mode = 0U; | |||
} | |||
} | |||
else if((pdev->pClass->DataIn != NULL) && | |||
(pdev->dev_state == USBD_STATE_CONFIGURED)) | |||
{ | |||
pdev->pClass->DataIn(pdev, epnum); | |||
} | |||
else | |||
{ | |||
/* should never be in this condition */ | |||
return USBD_FAIL; | |||
} | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_LL_Reset | |||
* Handle Reset event | |||
* @param pdev: device instance | |||
* @retval status | |||
*/ | |||
USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev) | |||
{ | |||
/* Open EP0 OUT */ | |||
USBD_LL_OpenEP(pdev, 0x00U, USBD_EP_TYPE_CTRL, USB_MAX_EP0_SIZE); | |||
pdev->ep_out[0x00U & 0xFU].is_used = 1U; | |||
pdev->ep_out[0].maxpacket = USB_MAX_EP0_SIZE; | |||
/* Open EP0 IN */ | |||
USBD_LL_OpenEP(pdev, 0x80U, USBD_EP_TYPE_CTRL, USB_MAX_EP0_SIZE); | |||
pdev->ep_in[0x80U & 0xFU].is_used = 1U; | |||
pdev->ep_in[0].maxpacket = USB_MAX_EP0_SIZE; | |||
/* Upon Reset call user call back */ | |||
pdev->dev_state = USBD_STATE_DEFAULT; | |||
pdev->ep0_state = USBD_EP0_IDLE; | |||
pdev->dev_config= 0U; | |||
pdev->dev_remote_wakeup = 0U; | |||
if (pdev->pClassData) | |||
{ | |||
pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config); | |||
} | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_LL_Reset | |||
* Handle Reset event | |||
* @param pdev: device instance | |||
* @retval status | |||
*/ | |||
USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed) | |||
{ | |||
pdev->dev_speed = speed; | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_Suspend | |||
* Handle Suspend event | |||
* @param pdev: device instance | |||
* @retval status | |||
*/ | |||
USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev) | |||
{ | |||
pdev->dev_old_state = pdev->dev_state; | |||
pdev->dev_state = USBD_STATE_SUSPENDED; | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_Resume | |||
* Handle Resume event | |||
* @param pdev: device instance | |||
* @retval status | |||
*/ | |||
USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev) | |||
{ | |||
pdev->dev_state = pdev->dev_old_state; | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_SOF | |||
* Handle SOF event | |||
* @param pdev: device instance | |||
* @retval status | |||
*/ | |||
USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev) | |||
{ | |||
if(pdev->dev_state == USBD_STATE_CONFIGURED) | |||
{ | |||
if(pdev->pClass->SOF != NULL) | |||
{ | |||
pdev->pClass->SOF(pdev); | |||
} | |||
} | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_IsoINIncomplete | |||
* Handle iso in incomplete event | |||
* @param pdev: device instance | |||
* @retval status | |||
*/ | |||
USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum) | |||
{ | |||
/* Prevent unused arguments compilation warning */ | |||
UNUSED(pdev); | |||
UNUSED(epnum); | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_IsoOUTIncomplete | |||
* Handle iso out incomplete event | |||
* @param pdev: device instance | |||
* @retval status | |||
*/ | |||
USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum) | |||
{ | |||
/* Prevent unused arguments compilation warning */ | |||
UNUSED(pdev); | |||
UNUSED(epnum); | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_DevConnected | |||
* Handle device connection event | |||
* @param pdev: device instance | |||
* @retval status | |||
*/ | |||
USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev) | |||
{ | |||
/* Prevent unused argument compilation warning */ | |||
UNUSED(pdev); | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_DevDisconnected | |||
* Handle device disconnection event | |||
* @param pdev: device instance | |||
* @retval status | |||
*/ | |||
USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev) | |||
{ | |||
/* Free Class Resources */ | |||
pdev->dev_state = USBD_STATE_DEFAULT; | |||
pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config); | |||
return USBD_OK; | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | |||
@@ -0,0 +1,161 @@ | |||
/** | |||
****************************************************************************** | |||
* @file usbd_core.h | |||
* @author MCD Application Team | |||
* @brief Header file for usbd_core.c file | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2015 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under Ultimate Liberty license | |||
* SLA0044, the "License"; You may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at: | |||
* http://www.st.com/SLA0044 | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __USBD_CORE_H | |||
#define __USBD_CORE_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "usbd_conf.h" | |||
#include "usbd_def.h" | |||
#include "usbd_ioreq.h" | |||
#include "usbd_ctlreq.h" | |||
/** @addtogroup STM32_USB_DEVICE_LIBRARY | |||
* @{ | |||
*/ | |||
/** @defgroup USBD_CORE | |||
* @brief This file is the Header file for usbd_core.c file | |||
* @{ | |||
*/ | |||
/** @defgroup USBD_CORE_Exported_Defines | |||
* @{ | |||
*/ | |||
#ifndef USBD_DEBUG_LEVEL | |||
#define USBD_DEBUG_LEVEL 0U | |||
#endif /* USBD_DEBUG_LEVEL */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CORE_Exported_TypesDefinitions | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CORE_Exported_Macros | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CORE_Exported_Variables | |||
* @{ | |||
*/ | |||
#define USBD_SOF USBD_LL_SOF | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_CORE_Exported_FunctionsPrototype | |||
* @{ | |||
*/ | |||
USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id); | |||
USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev); | |||
USBD_StatusTypeDef USBD_Start (USBD_HandleTypeDef *pdev); | |||
USBD_StatusTypeDef USBD_Stop (USBD_HandleTypeDef *pdev); | |||
USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass); | |||
USBD_StatusTypeDef USBD_RunTestMode (USBD_HandleTypeDef *pdev); | |||
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); | |||
USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); | |||
USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup); | |||
USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev , uint8_t epnum, uint8_t *pdata); | |||
USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev , uint8_t epnum, uint8_t *pdata); | |||
USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev); | |||
USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed); | |||
USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev); | |||
USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev); | |||
USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev); | |||
USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); | |||
USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); | |||
USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev); | |||
USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev); | |||
/* USBD Low Level Driver */ | |||
USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev); | |||
USBD_StatusTypeDef USBD_LL_DeInit (USBD_HandleTypeDef *pdev); | |||
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev); | |||
USBD_StatusTypeDef USBD_LL_Stop (USBD_HandleTypeDef *pdev); | |||
USBD_StatusTypeDef USBD_LL_OpenEP (USBD_HandleTypeDef *pdev, | |||
uint8_t ep_addr, | |||
uint8_t ep_type, | |||
uint16_t ep_mps); | |||
USBD_StatusTypeDef USBD_LL_CloseEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); | |||
USBD_StatusTypeDef USBD_LL_FlushEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); | |||
USBD_StatusTypeDef USBD_LL_StallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); | |||
USBD_StatusTypeDef USBD_LL_ClearStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); | |||
uint8_t USBD_LL_IsStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); | |||
USBD_StatusTypeDef USBD_LL_SetUSBAddress (USBD_HandleTypeDef *pdev, uint8_t dev_addr); | |||
USBD_StatusTypeDef USBD_LL_Transmit (USBD_HandleTypeDef *pdev, | |||
uint8_t ep_addr, | |||
uint8_t *pbuf, | |||
uint16_t size); | |||
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, | |||
uint8_t ep_addr, | |||
uint8_t *pbuf, | |||
uint16_t size); | |||
uint32_t USBD_LL_GetRxDataSize (USBD_HandleTypeDef *pdev, uint8_t ep_addr); | |||
void USBD_LL_Delay (uint32_t Delay); | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __USBD_CORE_H */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | |||
@@ -0,0 +1,848 @@ | |||
/** | |||
****************************************************************************** | |||
* @file usbd_req.c | |||
* @author MCD Application Team | |||
* @brief This file provides the standard USB requests following chapter 9. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2015 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under Ultimate Liberty license | |||
* SLA0044, the "License"; You may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at: | |||
* http://www.st.com/SLA0044 | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "usbd_ctlreq.h" | |||
#include "usbd_ioreq.h" | |||
/** @addtogroup STM32_USBD_STATE_DEVICE_LIBRARY | |||
* @{ | |||
*/ | |||
/** @defgroup USBD_REQ | |||
* @brief USB standard requests module | |||
* @{ | |||
*/ | |||
/** @defgroup USBD_REQ_Private_TypesDefinitions | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_REQ_Private_Defines | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_REQ_Private_Macros | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_REQ_Private_Variables | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_REQ_Private_FunctionPrototypes | |||
* @{ | |||
*/ | |||
static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev , | |||
USBD_SetupReqTypedef *req); | |||
static void USBD_SetAddress(USBD_HandleTypeDef *pdev , | |||
USBD_SetupReqTypedef *req); | |||
static void USBD_SetConfig(USBD_HandleTypeDef *pdev , | |||
USBD_SetupReqTypedef *req); | |||
static void USBD_GetConfig(USBD_HandleTypeDef *pdev , | |||
USBD_SetupReqTypedef *req); | |||
static void USBD_GetStatus(USBD_HandleTypeDef *pdev , | |||
USBD_SetupReqTypedef *req); | |||
static void USBD_SetFeature(USBD_HandleTypeDef *pdev , | |||
USBD_SetupReqTypedef *req); | |||
static void USBD_ClrFeature(USBD_HandleTypeDef *pdev , | |||
USBD_SetupReqTypedef *req); | |||
static uint8_t USBD_GetLen(uint8_t *buf); | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_REQ_Private_Functions | |||
* @{ | |||
*/ | |||
/** | |||
* @brief USBD_StdDevReq | |||
* Handle standard usb device requests | |||
* @param pdev: device instance | |||
* @param req: usb request | |||
* @retval status | |||
*/ | |||
USBD_StatusTypeDef USBD_StdDevReq (USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) | |||
{ | |||
USBD_StatusTypeDef ret = USBD_OK; | |||
switch (req->bmRequest & USB_REQ_TYPE_MASK) | |||
{ | |||
case USB_REQ_TYPE_CLASS: | |||
case USB_REQ_TYPE_VENDOR: | |||
pdev->pClass->Setup(pdev, req); | |||
break; | |||
case USB_REQ_TYPE_STANDARD: | |||
switch (req->bRequest) | |||
{ | |||
case USB_REQ_GET_DESCRIPTOR: | |||
USBD_GetDescriptor (pdev, req); | |||
break; | |||
case USB_REQ_SET_ADDRESS: | |||
USBD_SetAddress (pdev, req); | |||
break; | |||
case USB_REQ_SET_CONFIGURATION: | |||
USBD_SetConfig (pdev, req); | |||
break; | |||
case USB_REQ_GET_CONFIGURATION: | |||
USBD_GetConfig (pdev, req); | |||
break; | |||
case USB_REQ_GET_STATUS: | |||
USBD_GetStatus (pdev, req); | |||
break; | |||
case USB_REQ_SET_FEATURE: | |||
USBD_SetFeature (pdev, req); | |||
break; | |||
case USB_REQ_CLEAR_FEATURE: | |||
USBD_ClrFeature (pdev, req); | |||
break; | |||
default: | |||
USBD_CtlError(pdev, req); | |||
break; | |||
} | |||
break; | |||
default: | |||
USBD_CtlError(pdev, req); | |||
break; | |||
} | |||
return ret; | |||
} | |||
/** | |||
* @brief USBD_StdItfReq | |||
* Handle standard usb interface requests | |||
* @param pdev: device instance | |||
* @param req: usb request | |||
* @retval status | |||
*/ | |||
USBD_StatusTypeDef USBD_StdItfReq (USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) | |||
{ | |||
USBD_StatusTypeDef ret = USBD_OK; | |||
switch (req->bmRequest & USB_REQ_TYPE_MASK) | |||
{ | |||
case USB_REQ_TYPE_CLASS: | |||
case USB_REQ_TYPE_VENDOR: | |||
case USB_REQ_TYPE_STANDARD: | |||
switch (pdev->dev_state) | |||
{ | |||
case USBD_STATE_DEFAULT: | |||
case USBD_STATE_ADDRESSED: | |||
case USBD_STATE_CONFIGURED: | |||
if (LOBYTE(req->wIndex) <= USBD_MAX_NUM_INTERFACES) | |||
{ | |||
ret = (USBD_StatusTypeDef)pdev->pClass->Setup (pdev, req); | |||
if ((req->wLength == 0U) && (ret == USBD_OK)) | |||
{ | |||
USBD_CtlSendStatus(pdev); | |||
} | |||
} | |||
else | |||
{ | |||
USBD_CtlError(pdev, req); | |||
} | |||
break; | |||
default: | |||
USBD_CtlError(pdev, req); | |||
break; | |||
} | |||
break; | |||
default: | |||
USBD_CtlError(pdev, req); | |||
break; | |||
} | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_StdEPReq | |||
* Handle standard usb endpoint requests | |||
* @param pdev: device instance | |||
* @param req: usb request | |||
* @retval status | |||
*/ | |||
USBD_StatusTypeDef USBD_StdEPReq (USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) | |||
{ | |||
uint8_t ep_addr; | |||
USBD_StatusTypeDef ret = USBD_OK; | |||
USBD_EndpointTypeDef *pep; | |||
ep_addr = LOBYTE(req->wIndex); | |||
switch (req->bmRequest & USB_REQ_TYPE_MASK) | |||
{ | |||
case USB_REQ_TYPE_CLASS: | |||
case USB_REQ_TYPE_VENDOR: | |||
pdev->pClass->Setup (pdev, req); | |||
break; | |||
case USB_REQ_TYPE_STANDARD: | |||
/* Check if it is a class request */ | |||
if ((req->bmRequest & 0x60U) == 0x20U) | |||
{ | |||
ret = (USBD_StatusTypeDef)pdev->pClass->Setup (pdev, req); | |||
return ret; | |||
} | |||
switch (req->bRequest) | |||
{ | |||
case USB_REQ_SET_FEATURE : | |||
switch (pdev->dev_state) | |||
{ | |||
case USBD_STATE_ADDRESSED: | |||
if ((ep_addr != 0x00U) && (ep_addr != 0x80U)) | |||
{ | |||
USBD_LL_StallEP(pdev, ep_addr); | |||
USBD_LL_StallEP(pdev, 0x80U); | |||
} | |||
else | |||
{ | |||
USBD_CtlError(pdev, req); | |||
} | |||
break; | |||
case USBD_STATE_CONFIGURED: | |||
if (req->wValue == USB_FEATURE_EP_HALT) | |||
{ | |||
if ((ep_addr != 0x00U) && (ep_addr != 0x80U) && (req->wLength == 0x00U)) | |||
{ | |||
USBD_LL_StallEP(pdev, ep_addr); | |||
} | |||
} | |||
USBD_CtlSendStatus(pdev); | |||
break; | |||
default: | |||
USBD_CtlError(pdev, req); | |||
break; | |||
} | |||
break; | |||
case USB_REQ_CLEAR_FEATURE : | |||
switch (pdev->dev_state) | |||
{ | |||
case USBD_STATE_ADDRESSED: | |||
if ((ep_addr != 0x00U) && (ep_addr != 0x80U)) | |||
{ | |||
USBD_LL_StallEP(pdev, ep_addr); | |||
USBD_LL_StallEP(pdev, 0x80U); | |||
} | |||
else | |||
{ | |||
USBD_CtlError(pdev, req); | |||
} | |||
break; | |||
case USBD_STATE_CONFIGURED: | |||
if (req->wValue == USB_FEATURE_EP_HALT) | |||
{ | |||
if ((ep_addr & 0x7FU) != 0x00U) | |||
{ | |||
USBD_LL_ClearStallEP(pdev, ep_addr); | |||
} | |||
USBD_CtlSendStatus(pdev); | |||
} | |||
break; | |||
default: | |||
USBD_CtlError(pdev, req); | |||
break; | |||
} | |||
break; | |||
case USB_REQ_GET_STATUS: | |||
switch (pdev->dev_state) | |||
{ | |||
case USBD_STATE_ADDRESSED: | |||
if ((ep_addr != 0x00U) && (ep_addr != 0x80U)) | |||
{ | |||
USBD_CtlError(pdev, req); | |||
break; | |||
} | |||
pep = ((ep_addr & 0x80U) == 0x80U) ? &pdev->ep_in[ep_addr & 0x7FU]:\ | |||
&pdev->ep_out[ep_addr & 0x7FU]; | |||
pep->status = 0x0000U; | |||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&pep->status, 2U); | |||
break; | |||
case USBD_STATE_CONFIGURED: | |||
if((ep_addr & 0x80U) == 0x80U) | |||
{ | |||
if (pdev->ep_in[ep_addr & 0xFU].is_used == 0U) | |||
{ | |||
USBD_CtlError(pdev, req); | |||
break; | |||
} | |||
} | |||
else | |||
{ | |||
if (pdev->ep_out[ep_addr & 0xFU].is_used == 0U) | |||
{ | |||
USBD_CtlError(pdev, req); | |||
break; | |||
} | |||
} | |||
pep = ((ep_addr & 0x80U) == 0x80U) ? &pdev->ep_in[ep_addr & 0x7FU]:\ | |||
&pdev->ep_out[ep_addr & 0x7FU]; | |||
if ((ep_addr == 0x00U) || (ep_addr == 0x80U)) | |||
{ | |||
pep->status = 0x0000U; | |||
} | |||
else if(USBD_LL_IsStallEP(pdev, ep_addr)) | |||
{ | |||
pep->status = 0x0001U; | |||
} | |||
else | |||
{ | |||
pep->status = 0x0000U; | |||
} | |||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&pep->status, 2U); | |||
break; | |||
default: | |||
USBD_CtlError(pdev, req); | |||
break; | |||
} | |||
break; | |||
default: | |||
USBD_CtlError(pdev, req); | |||
break; | |||
} | |||
break; | |||
default: | |||
USBD_CtlError(pdev, req); | |||
break; | |||
} | |||
return ret; | |||
} | |||
/** | |||
* @brief USBD_GetDescriptor | |||
* Handle Get Descriptor requests | |||
* @param pdev: device instance | |||
* @param req: usb request | |||
* @retval status | |||
*/ | |||
static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev , | |||
USBD_SetupReqTypedef *req) | |||
{ | |||
uint16_t len; | |||
uint8_t *pbuf; | |||
switch (req->wValue >> 8) | |||
{ | |||
#if (USBD_LPM_ENABLED == 1U) | |||
case USB_DESC_TYPE_BOS: | |||
pbuf = pdev->pDesc->GetBOSDescriptor(pdev->dev_speed, &len); | |||
break; | |||
#endif | |||
case USB_DESC_TYPE_DEVICE: | |||
pbuf = pdev->pDesc->GetDeviceDescriptor(pdev->dev_speed, &len); | |||
break; | |||
case USB_DESC_TYPE_CONFIGURATION: | |||
if(pdev->dev_speed == USBD_SPEED_HIGH ) | |||
{ | |||
pbuf = (uint8_t *)pdev->pClass->GetHSConfigDescriptor(&len); | |||
pbuf[1] = USB_DESC_TYPE_CONFIGURATION; | |||
} | |||
else | |||
{ | |||
pbuf = (uint8_t *)pdev->pClass->GetFSConfigDescriptor(&len); | |||
pbuf[1] = USB_DESC_TYPE_CONFIGURATION; | |||
} | |||
break; | |||
case USB_DESC_TYPE_STRING: | |||
switch ((uint8_t)(req->wValue)) | |||
{ | |||
case USBD_IDX_LANGID_STR: | |||
pbuf = pdev->pDesc->GetLangIDStrDescriptor(pdev->dev_speed, &len); | |||
break; | |||
case USBD_IDX_MFC_STR: | |||
pbuf = pdev->pDesc->GetManufacturerStrDescriptor(pdev->dev_speed, &len); | |||
break; | |||
case USBD_IDX_PRODUCT_STR: | |||
pbuf = pdev->pDesc->GetProductStrDescriptor(pdev->dev_speed, &len); | |||
break; | |||
case USBD_IDX_SERIAL_STR: | |||
pbuf = pdev->pDesc->GetSerialStrDescriptor(pdev->dev_speed, &len); | |||
break; | |||
case USBD_IDX_CONFIG_STR: | |||
pbuf = pdev->pDesc->GetConfigurationStrDescriptor(pdev->dev_speed, &len); | |||
break; | |||
case USBD_IDX_INTERFACE_STR: | |||
pbuf = pdev->pDesc->GetInterfaceStrDescriptor(pdev->dev_speed, &len); | |||
break; | |||
default: | |||
#if (USBD_SUPPORT_USER_STRING == 1U) | |||
pbuf = pdev->pClass->GetUsrStrDescriptor(pdev, (req->wValue) , &len); | |||
break; | |||
#else | |||
USBD_CtlError(pdev , req); | |||
return; | |||
#endif | |||
} | |||
break; | |||
case USB_DESC_TYPE_DEVICE_QUALIFIER: | |||
if(pdev->dev_speed == USBD_SPEED_HIGH) | |||
{ | |||
pbuf = (uint8_t *)pdev->pClass->GetDeviceQualifierDescriptor(&len); | |||
break; | |||
} | |||
else | |||
{ | |||
USBD_CtlError(pdev , req); | |||
return; | |||
} | |||
case USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION: | |||
if(pdev->dev_speed == USBD_SPEED_HIGH ) | |||
{ | |||
pbuf = (uint8_t *)pdev->pClass->GetOtherSpeedConfigDescriptor(&len); | |||
pbuf[1] = USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION; | |||
break; | |||
} | |||
else | |||
{ | |||
USBD_CtlError(pdev , req); | |||
return; | |||
} | |||
default: | |||
USBD_CtlError(pdev , req); | |||
return; | |||
} | |||
if((len != 0U) && (req->wLength != 0U)) | |||
{ | |||
len = MIN(len, req->wLength); | |||
USBD_CtlSendData (pdev, pbuf, len); | |||
} | |||
if(req->wLength == 0U) | |||
{ | |||
USBD_CtlSendStatus(pdev); | |||
} | |||
} | |||
/** | |||
* @brief USBD_SetAddress | |||
* Set device address | |||
* @param pdev: device instance | |||
* @param req: usb request | |||
* @retval status | |||
*/ | |||
static void USBD_SetAddress(USBD_HandleTypeDef *pdev , | |||
USBD_SetupReqTypedef *req) | |||
{ | |||
uint8_t dev_addr; | |||
if ((req->wIndex == 0U) && (req->wLength == 0U) && (req->wValue < 128U)) | |||
{ | |||
dev_addr = (uint8_t)(req->wValue) & 0x7FU; | |||
if (pdev->dev_state == USBD_STATE_CONFIGURED) | |||
{ | |||
USBD_CtlError(pdev , req); | |||
} | |||
else | |||
{ | |||
pdev->dev_address = dev_addr; | |||
USBD_LL_SetUSBAddress(pdev, dev_addr); | |||
USBD_CtlSendStatus(pdev); | |||
if (dev_addr != 0U) | |||
{ | |||
pdev->dev_state = USBD_STATE_ADDRESSED; | |||
} | |||
else | |||
{ | |||
pdev->dev_state = USBD_STATE_DEFAULT; | |||
} | |||
} | |||
} | |||
else | |||
{ | |||
USBD_CtlError(pdev, req); | |||
} | |||
} | |||
/** | |||
* @brief USBD_SetConfig | |||
* Handle Set device configuration request | |||
* @param pdev: device instance | |||
* @param req: usb request | |||
* @retval status | |||
*/ | |||
static void USBD_SetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) | |||
{ | |||
static uint8_t cfgidx; | |||
cfgidx = (uint8_t)(req->wValue); | |||
if (cfgidx > USBD_MAX_NUM_CONFIGURATION) | |||
{ | |||
USBD_CtlError(pdev, req); | |||
} | |||
else | |||
{ | |||
switch (pdev->dev_state) | |||
{ | |||
case USBD_STATE_ADDRESSED: | |||
if (cfgidx) | |||
{ | |||
pdev->dev_config = cfgidx; | |||
pdev->dev_state = USBD_STATE_CONFIGURED; | |||
if(USBD_SetClassConfig(pdev, cfgidx) == USBD_FAIL) | |||
{ | |||
USBD_CtlError(pdev, req); | |||
return; | |||
} | |||
USBD_CtlSendStatus(pdev); | |||
} | |||
else | |||
{ | |||
USBD_CtlSendStatus(pdev); | |||
} | |||
break; | |||
case USBD_STATE_CONFIGURED: | |||
if (cfgidx == 0U) | |||
{ | |||
pdev->dev_state = USBD_STATE_ADDRESSED; | |||
pdev->dev_config = cfgidx; | |||
USBD_ClrClassConfig(pdev, cfgidx); | |||
USBD_CtlSendStatus(pdev); | |||
} | |||
else if (cfgidx != pdev->dev_config) | |||
{ | |||
/* Clear old configuration */ | |||
USBD_ClrClassConfig(pdev, (uint8_t)pdev->dev_config); | |||
/* set new configuration */ | |||
pdev->dev_config = cfgidx; | |||
if(USBD_SetClassConfig(pdev, cfgidx) == USBD_FAIL) | |||
{ | |||
USBD_CtlError(pdev, req); | |||
return; | |||
} | |||
USBD_CtlSendStatus(pdev); | |||
} | |||
else | |||
{ | |||
USBD_CtlSendStatus(pdev); | |||
} | |||
break; | |||
default: | |||
USBD_CtlError(pdev, req); | |||
USBD_ClrClassConfig(pdev, cfgidx); | |||
break; | |||
} | |||
} | |||
} | |||
/** | |||
* @brief USBD_GetConfig | |||
* Handle Get device configuration request | |||
* @param pdev: device instance | |||
* @param req: usb request | |||
* @retval status | |||
*/ | |||
static void USBD_GetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) | |||
{ | |||
if (req->wLength != 1U) | |||
{ | |||
USBD_CtlError(pdev , req); | |||
} | |||
else | |||
{ | |||
switch (pdev->dev_state) | |||
{ | |||
case USBD_STATE_DEFAULT: | |||
case USBD_STATE_ADDRESSED: | |||
pdev->dev_default_config = 0U; | |||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&pdev->dev_default_config, 1U); | |||
break; | |||
case USBD_STATE_CONFIGURED: | |||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&pdev->dev_config, 1U); | |||
break; | |||
default: | |||
USBD_CtlError(pdev , req); | |||
break; | |||
} | |||
} | |||
} | |||
/** | |||
* @brief USBD_GetStatus | |||
* Handle Get Status request | |||
* @param pdev: device instance | |||
* @param req: usb request | |||
* @retval status | |||
*/ | |||
static void USBD_GetStatus(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) | |||
{ | |||
switch (pdev->dev_state) | |||
{ | |||
case USBD_STATE_DEFAULT: | |||
case USBD_STATE_ADDRESSED: | |||
case USBD_STATE_CONFIGURED: | |||
if(req->wLength != 0x2U) | |||
{ | |||
USBD_CtlError(pdev, req); | |||
break; | |||
} | |||
#if ( USBD_SELF_POWERED == 1U) | |||
pdev->dev_config_status = USB_CONFIG_SELF_POWERED; | |||
#else | |||
pdev->dev_config_status = 0U; | |||
#endif | |||
if (pdev->dev_remote_wakeup) | |||
{ | |||
pdev->dev_config_status |= USB_CONFIG_REMOTE_WAKEUP; | |||
} | |||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&pdev->dev_config_status, 2U); | |||
break; | |||
default : | |||
USBD_CtlError(pdev , req); | |||
break; | |||
} | |||
} | |||
/** | |||
* @brief USBD_SetFeature | |||
* Handle Set device feature request | |||
* @param pdev: device instance | |||
* @param req: usb request | |||
* @retval status | |||
*/ | |||
static void USBD_SetFeature(USBD_HandleTypeDef *pdev , | |||
USBD_SetupReqTypedef *req) | |||
{ | |||
if (req->wValue == USB_FEATURE_REMOTE_WAKEUP) | |||
{ | |||
pdev->dev_remote_wakeup = 1U; | |||
USBD_CtlSendStatus(pdev); | |||
} | |||
} | |||
/** | |||
* @brief USBD_ClrFeature | |||
* Handle clear device feature request | |||
* @param pdev: device instance | |||
* @param req: usb request | |||
* @retval status | |||
*/ | |||
static void USBD_ClrFeature(USBD_HandleTypeDef *pdev , | |||
USBD_SetupReqTypedef *req) | |||
{ | |||
switch (pdev->dev_state) | |||
{ | |||
case USBD_STATE_DEFAULT: | |||
case USBD_STATE_ADDRESSED: | |||
case USBD_STATE_CONFIGURED: | |||
if (req->wValue == USB_FEATURE_REMOTE_WAKEUP) | |||
{ | |||
pdev->dev_remote_wakeup = 0U; | |||
USBD_CtlSendStatus(pdev); | |||
} | |||
break; | |||
default : | |||
USBD_CtlError(pdev , req); | |||
break; | |||
} | |||
} | |||
/** | |||
* @brief USBD_ParseSetupRequest | |||
* Copy buffer into setup structure | |||
* @param pdev: device instance | |||
* @param req: usb request | |||
* @retval None | |||
*/ | |||
void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata) | |||
{ | |||
req->bmRequest = *(uint8_t *) (pdata); | |||
req->bRequest = *(uint8_t *) (pdata + 1); | |||
req->wValue = SWAPBYTE (pdata + 2); | |||
req->wIndex = SWAPBYTE (pdata + 4); | |||
req->wLength = SWAPBYTE (pdata + 6); | |||
} | |||
/** | |||
* @brief USBD_CtlError | |||
* Handle USB low level Error | |||
* @param pdev: device instance | |||
* @param req: usb request | |||
* @retval None | |||
*/ | |||
void USBD_CtlError( USBD_HandleTypeDef *pdev , | |||
USBD_SetupReqTypedef *req) | |||
{ | |||
USBD_LL_StallEP(pdev , 0x80U); | |||
USBD_LL_StallEP(pdev , 0U); | |||
} | |||
/** | |||
* @brief USBD_GetString | |||
* Convert Ascii string into unicode one | |||
* @param desc : descriptor buffer | |||
* @param unicode : Formatted string buffer (unicode) | |||
* @param len : descriptor length | |||
* @retval None | |||
*/ | |||
void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len) | |||
{ | |||
uint8_t idx = 0U; | |||
if (desc != NULL) | |||
{ | |||
*len = (uint16_t)USBD_GetLen(desc) * 2U + 2U; | |||
unicode[idx++] = *(uint8_t *)(void *)len; | |||
unicode[idx++] = USB_DESC_TYPE_STRING; | |||
while (*desc != '\0') | |||
{ | |||
unicode[idx++] = *desc++; | |||
unicode[idx++] = 0U; | |||
} | |||
} | |||
} | |||
/** | |||
* @brief USBD_GetLen | |||
* return the string length | |||
* @param buf : pointer to the ascii string buffer | |||
* @retval string length | |||
*/ | |||
static uint8_t USBD_GetLen(uint8_t *buf) | |||
{ | |||
uint8_t len = 0U; | |||
while (*buf != '\0') | |||
{ | |||
len++; | |||
buf++; | |||
} | |||
return len; | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,105 @@ | |||
/** | |||
****************************************************************************** | |||
* @file usbd_req.h | |||
* @author MCD Application Team | |||
* @brief Header file for the usbd_req.c file | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2015 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under Ultimate Liberty license | |||
* SLA0044, the "License"; You may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at: | |||
* http://www.st.com/SLA0044 | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __USB_REQUEST_H | |||
#define __USB_REQUEST_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "usbd_def.h" | |||
/** @addtogroup STM32_USB_DEVICE_LIBRARY | |||
* @{ | |||
*/ | |||
/** @defgroup USBD_REQ | |||
* @brief header file for the usbd_req.c file | |||
* @{ | |||
*/ | |||
/** @defgroup USBD_REQ_Exported_Defines | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_REQ_Exported_Types | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_REQ_Exported_Macros | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_REQ_Exported_Variables | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_REQ_Exported_FunctionsPrototype | |||
* @{ | |||
*/ | |||
USBD_StatusTypeDef USBD_StdDevReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); | |||
USBD_StatusTypeDef USBD_StdItfReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); | |||
USBD_StatusTypeDef USBD_StdEPReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); | |||
void USBD_CtlError (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); | |||
void USBD_ParseSetupRequest (USBD_SetupReqTypedef *req, uint8_t *pdata); | |||
void USBD_GetString (uint8_t *desc, uint8_t *unicode, uint16_t *len); | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __USB_REQUEST_H */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,342 @@ | |||
/** | |||
****************************************************************************** | |||
* @file usbd_def.h | |||
* @author MCD Application Team | |||
* @brief General defines for the usb device library | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2015 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under Ultimate Liberty license | |||
* SLA0044, the "License"; You may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at: | |||
* http://www.st.com/SLA0044 | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __USBD_DEF_H | |||
#define __USBD_DEF_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "usbd_conf.h" | |||
/** @addtogroup STM32_USBD_DEVICE_LIBRARY | |||
* @{ | |||
*/ | |||
/** @defgroup USB_DEF | |||
* @brief general defines for the usb device library file | |||
* @{ | |||
*/ | |||
/** @defgroup USB_DEF_Exported_Defines | |||
* @{ | |||
*/ | |||
#ifndef NULL | |||
#define NULL 0U | |||
#endif /* NULL */ | |||
#ifndef USBD_MAX_NUM_INTERFACES | |||
#define USBD_MAX_NUM_INTERFACES 1U | |||
#endif /* USBD_MAX_NUM_CONFIGURATION */ | |||
#ifndef USBD_MAX_NUM_CONFIGURATION | |||
#define USBD_MAX_NUM_CONFIGURATION 1U | |||
#endif /* USBD_MAX_NUM_CONFIGURATION */ | |||
#ifndef USBD_LPM_ENABLED | |||
#define USBD_LPM_ENABLED 0U | |||
#endif /* USBD_LPM_ENABLED */ | |||
#ifndef USBD_SELF_POWERED | |||
#define USBD_SELF_POWERED 1U | |||
#endif /*USBD_SELF_POWERED */ | |||
#ifndef USBD_SUPPORT_USER_STRING | |||
#define USBD_SUPPORT_USER_STRING 0U | |||
#endif /* USBD_SUPPORT_USER_STRING */ | |||
#define USB_LEN_DEV_QUALIFIER_DESC 0x0AU | |||
#define USB_LEN_DEV_DESC 0x12U | |||
#define USB_LEN_CFG_DESC 0x09U | |||
#define USB_LEN_IF_DESC 0x09U | |||
#define USB_LEN_EP_DESC 0x07U | |||
#define USB_LEN_OTG_DESC 0x03U | |||
#define USB_LEN_LANGID_STR_DESC 0x04U | |||
#define USB_LEN_OTHER_SPEED_DESC_SIZ 0x09U | |||
#define USBD_IDX_LANGID_STR 0x00U | |||
#define USBD_IDX_MFC_STR 0x01U | |||
#define USBD_IDX_PRODUCT_STR 0x02U | |||
#define USBD_IDX_SERIAL_STR 0x03U | |||
#define USBD_IDX_CONFIG_STR 0x04U | |||
#define USBD_IDX_INTERFACE_STR 0x05U | |||
#define USB_REQ_TYPE_STANDARD 0x00U | |||
#define USB_REQ_TYPE_CLASS 0x20U | |||
#define USB_REQ_TYPE_VENDOR 0x40U | |||
#define USB_REQ_TYPE_MASK 0x60U | |||
#define USB_REQ_RECIPIENT_DEVICE 0x00U | |||
#define USB_REQ_RECIPIENT_INTERFACE 0x01U | |||
#define USB_REQ_RECIPIENT_ENDPOINT 0x02U | |||
#define USB_REQ_RECIPIENT_MASK 0x03U | |||
#define USB_REQ_GET_STATUS 0x00U | |||
#define USB_REQ_CLEAR_FEATURE 0x01U | |||
#define USB_REQ_SET_FEATURE 0x03U | |||
#define USB_REQ_SET_ADDRESS 0x05U | |||
#define USB_REQ_GET_DESCRIPTOR 0x06U | |||
#define USB_REQ_SET_DESCRIPTOR 0x07U | |||
#define USB_REQ_GET_CONFIGURATION 0x08U | |||
#define USB_REQ_SET_CONFIGURATION 0x09U | |||
#define USB_REQ_GET_INTERFACE 0x0AU | |||
#define USB_REQ_SET_INTERFACE 0x0BU | |||
#define USB_REQ_SYNCH_FRAME 0x0CU | |||
#define USB_DESC_TYPE_DEVICE 0x01U | |||
#define USB_DESC_TYPE_CONFIGURATION 0x02U | |||
#define USB_DESC_TYPE_STRING 0x03U | |||
#define USB_DESC_TYPE_INTERFACE 0x04U | |||
#define USB_DESC_TYPE_ENDPOINT 0x05U | |||
#define USB_DESC_TYPE_DEVICE_QUALIFIER 0x06U | |||
#define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 0x07U | |||
#define USB_DESC_TYPE_BOS 0x0FU | |||
#define USB_CONFIG_REMOTE_WAKEUP 0x02U | |||
#define USB_CONFIG_SELF_POWERED 0x01U | |||
#define USB_FEATURE_EP_HALT 0x00U | |||
#define USB_FEATURE_REMOTE_WAKEUP 0x01U | |||
#define USB_FEATURE_TEST_MODE 0x02U | |||
#define USB_DEVICE_CAPABITY_TYPE 0x10U | |||
#define USB_HS_MAX_PACKET_SIZE 512U | |||
#define USB_FS_MAX_PACKET_SIZE 64U | |||
#define USB_MAX_EP0_SIZE 64U | |||
/* Device Status */ | |||
#define USBD_STATE_DEFAULT 0x01U | |||
#define USBD_STATE_ADDRESSED 0x02U | |||
#define USBD_STATE_CONFIGURED 0x03U | |||
#define USBD_STATE_SUSPENDED 0x04U | |||
/* EP0 State */ | |||
#define USBD_EP0_IDLE 0x00U | |||
#define USBD_EP0_SETUP 0x01U | |||
#define USBD_EP0_DATA_IN 0x02U | |||
#define USBD_EP0_DATA_OUT 0x03U | |||
#define USBD_EP0_STATUS_IN 0x04U | |||
#define USBD_EP0_STATUS_OUT 0x05U | |||
#define USBD_EP0_STALL 0x06U | |||
#define USBD_EP_TYPE_CTRL 0x00U | |||
#define USBD_EP_TYPE_ISOC 0x01U | |||
#define USBD_EP_TYPE_BULK 0x02U | |||
#define USBD_EP_TYPE_INTR 0x03U | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_DEF_Exported_TypesDefinitions | |||
* @{ | |||
*/ | |||
typedef struct usb_setup_req | |||
{ | |||
uint8_t bmRequest; | |||
uint8_t bRequest; | |||
uint16_t wValue; | |||
uint16_t wIndex; | |||
uint16_t wLength; | |||
}USBD_SetupReqTypedef; | |||
struct _USBD_HandleTypeDef; | |||
typedef struct _Device_cb | |||
{ | |||
uint8_t (*Init) (struct _USBD_HandleTypeDef *pdev , uint8_t cfgidx); | |||
uint8_t (*DeInit) (struct _USBD_HandleTypeDef *pdev , uint8_t cfgidx); | |||
/* Control Endpoints*/ | |||
uint8_t (*Setup) (struct _USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req); | |||
uint8_t (*EP0_TxSent) (struct _USBD_HandleTypeDef *pdev ); | |||
uint8_t (*EP0_RxReady) (struct _USBD_HandleTypeDef *pdev ); | |||
/* Class Specific Endpoints*/ | |||
uint8_t (*DataIn) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum); | |||
uint8_t (*DataOut) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum); | |||
uint8_t (*SOF) (struct _USBD_HandleTypeDef *pdev); | |||
uint8_t (*IsoINIncomplete) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum); | |||
uint8_t (*IsoOUTIncomplete) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum); | |||
uint8_t *(*GetHSConfigDescriptor)(uint16_t *length); | |||
uint8_t *(*GetFSConfigDescriptor)(uint16_t *length); | |||
uint8_t *(*GetOtherSpeedConfigDescriptor)(uint16_t *length); | |||
uint8_t *(*GetDeviceQualifierDescriptor)(uint16_t *length); | |||
#if (USBD_SUPPORT_USER_STRING == 1U) | |||
uint8_t *(*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef *pdev ,uint8_t index, uint16_t *length); | |||
#endif | |||
} USBD_ClassTypeDef; | |||
/* Following USB Device Speed */ | |||
typedef enum | |||
{ | |||
USBD_SPEED_HIGH = 0U, | |||
USBD_SPEED_FULL = 1U, | |||
USBD_SPEED_LOW = 2U, | |||
}USBD_SpeedTypeDef; | |||
/* Following USB Device status */ | |||
typedef enum { | |||
USBD_OK = 0U, | |||
USBD_BUSY, | |||
USBD_FAIL, | |||
}USBD_StatusTypeDef; | |||
/* USB Device descriptors structure */ | |||
typedef struct | |||
{ | |||
uint8_t *(*GetDeviceDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); | |||
uint8_t *(*GetLangIDStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); | |||
uint8_t *(*GetManufacturerStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); | |||
uint8_t *(*GetProductStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); | |||
uint8_t *(*GetSerialStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); | |||
uint8_t *(*GetConfigurationStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); | |||
uint8_t *(*GetInterfaceStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); | |||
#if (USBD_LPM_ENABLED == 1U) | |||
uint8_t *(*GetBOSDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); | |||
#endif | |||
} USBD_DescriptorsTypeDef; | |||
/* USB Device handle structure */ | |||
typedef struct | |||
{ | |||
uint32_t status; | |||
uint32_t is_used; | |||
uint32_t total_length; | |||
uint32_t rem_length; | |||
uint32_t maxpacket; | |||
} USBD_EndpointTypeDef; | |||
/* USB Device handle structure */ | |||
typedef struct _USBD_HandleTypeDef | |||
{ | |||
uint8_t id; | |||
uint32_t dev_config; | |||
uint32_t dev_default_config; | |||
uint32_t dev_config_status; | |||
USBD_SpeedTypeDef dev_speed; | |||
USBD_EndpointTypeDef ep_in[15]; | |||
USBD_EndpointTypeDef ep_out[15]; | |||
uint32_t ep0_state; | |||
uint32_t ep0_data_len; | |||
uint8_t dev_state; | |||
uint8_t dev_old_state; | |||
uint8_t dev_address; | |||
uint8_t dev_connection_status; | |||
uint8_t dev_test_mode; | |||
uint32_t dev_remote_wakeup; | |||
USBD_SetupReqTypedef request; | |||
USBD_DescriptorsTypeDef *pDesc; | |||
USBD_ClassTypeDef *pClass; | |||
void *pClassData; | |||
void *pUserData; | |||
void *pData; | |||
} USBD_HandleTypeDef; | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_DEF_Exported_Macros | |||
* @{ | |||
*/ | |||
#define SWAPBYTE(addr) (((uint16_t)(*((uint8_t *)(addr)))) + \ | |||
(((uint16_t)(*(((uint8_t *)(addr)) + 1U))) << 8U)) | |||
#define LOBYTE(x) ((uint8_t)(x & 0x00FFU)) | |||
#define HIBYTE(x) ((uint8_t)((x & 0xFF00U) >> 8U)) | |||
#define MIN(a, b) (((a) < (b)) ? (a) : (b)) | |||
#define MAX(a, b) (((a) > (b)) ? (a) : (b)) | |||
#if defined ( __GNUC__ ) | |||
#ifndef __weak | |||
#define __weak __attribute__((weak)) | |||
#endif /* __weak */ | |||
#ifndef __packed | |||
#define __packed __attribute__((__packed__)) | |||
#endif /* __packed */ | |||
#endif /* __GNUC__ */ | |||
/* In HS mode and when the DMA is used, all variables and data structures dealing | |||
with the DMA during the transaction process should be 4-bytes aligned */ | |||
#if defined (__GNUC__) /* GNU Compiler */ | |||
#define __ALIGN_END __attribute__ ((aligned (4))) | |||
#define __ALIGN_BEGIN | |||
#else | |||
#define __ALIGN_END | |||
#if defined (__CC_ARM) /* ARM Compiler */ | |||
#define __ALIGN_BEGIN __align(4) | |||
#elif defined (__ICCARM__) /* IAR Compiler */ | |||
#define __ALIGN_BEGIN | |||
#elif defined (__TASKING__) /* TASKING Compiler */ | |||
#define __ALIGN_BEGIN __align(4) | |||
#endif /* __CC_ARM */ | |||
#endif /* __GNUC__ */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_DEF_Exported_Variables | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_DEF_Exported_FunctionsPrototype | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __USBD_DEF_H */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,395 @@ | |||
/* USER CODE BEGIN Header */ | |||
/** | |||
****************************************************************************** | |||
* @file : App/usbd_desc.c | |||
* @version : v2.0_Cube | |||
* @brief : This file implements the USB device descriptors. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2020 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under Ultimate Liberty license | |||
* SLA0044, the "License"; You may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at: | |||
* www.st.com/SLA0044 | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* USER CODE END Header */ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "usbd_core.h" | |||
#include "usbd_desc.h" | |||
#include "usbd_conf.h" | |||
/* USER CODE BEGIN INCLUDE */ | |||
/* USER CODE END INCLUDE */ | |||
/* Private typedef -----------------------------------------------------------*/ | |||
/* Private define ------------------------------------------------------------*/ | |||
/* Private macro -------------------------------------------------------------*/ | |||
/* USER CODE BEGIN PV */ | |||
/* Private variables ---------------------------------------------------------*/ | |||
/* USER CODE END PV */ | |||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY | |||
* @{ | |||
*/ | |||
/** @addtogroup USBD_DESC | |||
* @{ | |||
*/ | |||
/** @defgroup USBD_DESC_Private_TypesDefinitions USBD_DESC_Private_TypesDefinitions | |||
* @brief Private types. | |||
* @{ | |||
*/ | |||
/* USER CODE BEGIN PRIVATE_TYPES */ | |||
/* USER CODE END PRIVATE_TYPES */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_DESC_Private_Defines USBD_DESC_Private_Defines | |||
* @brief Private defines. | |||
* @{ | |||
*/ | |||
#define USBD_VID 1155 | |||
#define USBD_LANGID_STRING 1033 | |||
#define USBD_MANUFACTURER_STRING "STMicroelectronics" | |||
#define USBD_PID_FS 22336 | |||
#define USBD_PRODUCT_STRING_FS "STM32 Virtual ComPort" | |||
#define USBD_CONFIGURATION_STRING_FS "CDC Config" | |||
#define USBD_INTERFACE_STRING_FS "CDC Interface" | |||
/* USER CODE BEGIN PRIVATE_DEFINES */ | |||
/* USER CODE END PRIVATE_DEFINES */ | |||
/** | |||
* @} | |||
*/ | |||
/* USER CODE BEGIN 0 */ | |||
/* USER CODE END 0 */ | |||
/** @defgroup USBD_DESC_Private_Macros USBD_DESC_Private_Macros | |||
* @brief Private macros. | |||
* @{ | |||
*/ | |||
/* USER CODE BEGIN PRIVATE_MACRO */ | |||
/* USER CODE END PRIVATE_MACRO */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes | |||
* @brief Private functions declaration. | |||
* @{ | |||
*/ | |||
static void Get_SerialNum(void); | |||
static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len); | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes | |||
* @brief Private functions declaration for FS. | |||
* @{ | |||
*/ | |||
uint8_t * USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | |||
uint8_t * USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | |||
uint8_t * USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | |||
uint8_t * USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | |||
uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | |||
uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | |||
uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables | |||
* @brief Private variables. | |||
* @{ | |||
*/ | |||
USBD_DescriptorsTypeDef FS_Desc = | |||
{ | |||
USBD_FS_DeviceDescriptor | |||
, USBD_FS_LangIDStrDescriptor | |||
, USBD_FS_ManufacturerStrDescriptor | |||
, USBD_FS_ProductStrDescriptor | |||
, USBD_FS_SerialStrDescriptor | |||
, USBD_FS_ConfigStrDescriptor | |||
, USBD_FS_InterfaceStrDescriptor | |||
}; | |||
#if defined ( __ICCARM__ ) /* IAR Compiler */ | |||
#pragma data_alignment=4 | |||
#endif /* defined ( __ICCARM__ ) */ | |||
/** USB standard device descriptor. */ | |||
__ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = | |||
{ | |||
0x12, /*bLength */ | |||
USB_DESC_TYPE_DEVICE, /*bDescriptorType*/ | |||
0x00, /*bcdUSB */ | |||
0x02, | |||
0x02, /*bDeviceClass*/ | |||
0x02, /*bDeviceSubClass*/ | |||
0x00, /*bDeviceProtocol*/ | |||
USB_MAX_EP0_SIZE, /*bMaxPacketSize*/ | |||
LOBYTE(USBD_VID), /*idVendor*/ | |||
HIBYTE(USBD_VID), /*idVendor*/ | |||
LOBYTE(USBD_PID_FS), /*idProduct*/ | |||
HIBYTE(USBD_PID_FS), /*idProduct*/ | |||
0x00, /*bcdDevice rel. 2.00*/ | |||
0x02, | |||
USBD_IDX_MFC_STR, /*Index of manufacturer string*/ | |||
USBD_IDX_PRODUCT_STR, /*Index of product string*/ | |||
USBD_IDX_SERIAL_STR, /*Index of serial number string*/ | |||
USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/ | |||
}; | |||
/* USB_DeviceDescriptor */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables | |||
* @brief Private variables. | |||
* @{ | |||
*/ | |||
#if defined ( __ICCARM__ ) /* IAR Compiler */ | |||
#pragma data_alignment=4 | |||
#endif /* defined ( __ICCARM__ ) */ | |||
/** USB lang indentifier descriptor. */ | |||
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = | |||
{ | |||
USB_LEN_LANGID_STR_DESC, | |||
USB_DESC_TYPE_STRING, | |||
LOBYTE(USBD_LANGID_STRING), | |||
HIBYTE(USBD_LANGID_STRING) | |||
}; | |||
#if defined ( __ICCARM__ ) /* IAR Compiler */ | |||
#pragma data_alignment=4 | |||
#endif /* defined ( __ICCARM__ ) */ | |||
/* Internal string descriptor. */ | |||
__ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END; | |||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */ | |||
#pragma data_alignment=4 | |||
#endif | |||
__ALIGN_BEGIN uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] __ALIGN_END = { | |||
USB_SIZ_STRING_SERIAL, | |||
USB_DESC_TYPE_STRING, | |||
}; | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_DESC_Private_Functions USBD_DESC_Private_Functions | |||
* @brief Private functions. | |||
* @{ | |||
*/ | |||
/** | |||
* @brief Return the device descriptor | |||
* @param speed : Current device speed | |||
* @param length : Pointer to data length variable | |||
* @retval Pointer to descriptor buffer | |||
*/ | |||
uint8_t * USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) | |||
{ | |||
UNUSED(speed); | |||
*length = sizeof(USBD_FS_DeviceDesc); | |||
return USBD_FS_DeviceDesc; | |||
} | |||
/** | |||
* @brief Return the LangID string descriptor | |||
* @param speed : Current device speed | |||
* @param length : Pointer to data length variable | |||
* @retval Pointer to descriptor buffer | |||
*/ | |||
uint8_t * USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) | |||
{ | |||
UNUSED(speed); | |||
*length = sizeof(USBD_LangIDDesc); | |||
return USBD_LangIDDesc; | |||
} | |||
/** | |||
* @brief Return the product string descriptor | |||
* @param speed : Current device speed | |||
* @param length : Pointer to data length variable | |||
* @retval Pointer to descriptor buffer | |||
*/ | |||
uint8_t * USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) | |||
{ | |||
if(speed == 0) | |||
{ | |||
USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length); | |||
} | |||
else | |||
{ | |||
USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length); | |||
} | |||
return USBD_StrDesc; | |||
} | |||
/** | |||
* @brief Return the manufacturer string descriptor | |||
* @param speed : Current device speed | |||
* @param length : Pointer to data length variable | |||
* @retval Pointer to descriptor buffer | |||
*/ | |||
uint8_t * USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) | |||
{ | |||
UNUSED(speed); | |||
USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length); | |||
return USBD_StrDesc; | |||
} | |||
/** | |||
* @brief Return the serial number string descriptor | |||
* @param speed : Current device speed | |||
* @param length : Pointer to data length variable | |||
* @retval Pointer to descriptor buffer | |||
*/ | |||
uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) | |||
{ | |||
UNUSED(speed); | |||
*length = USB_SIZ_STRING_SERIAL; | |||
/* Update the serial number string descriptor with the data from the unique | |||
* ID */ | |||
Get_SerialNum(); | |||
/* USER CODE BEGIN USBD_FS_SerialStrDescriptor */ | |||
/* USER CODE END USBD_FS_SerialStrDescriptor */ | |||
return (uint8_t *) USBD_StringSerial; | |||
} | |||
/** | |||
* @brief Return the configuration string descriptor | |||
* @param speed : Current device speed | |||
* @param length : Pointer to data length variable | |||
* @retval Pointer to descriptor buffer | |||
*/ | |||
uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) | |||
{ | |||
if(speed == USBD_SPEED_HIGH) | |||
{ | |||
USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length); | |||
} | |||
else | |||
{ | |||
USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length); | |||
} | |||
return USBD_StrDesc; | |||
} | |||
/** | |||
* @brief Return the interface string descriptor | |||
* @param speed : Current device speed | |||
* @param length : Pointer to data length variable | |||
* @retval Pointer to descriptor buffer | |||
*/ | |||
uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) | |||
{ | |||
if(speed == 0) | |||
{ | |||
USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length); | |||
} | |||
else | |||
{ | |||
USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length); | |||
} | |||
return USBD_StrDesc; | |||
} | |||
/** | |||
* @brief Create the serial number string descriptor | |||
* @param None | |||
* @retval None | |||
*/ | |||
static void Get_SerialNum(void) | |||
{ | |||
uint32_t deviceserial0, deviceserial1, deviceserial2; | |||
deviceserial0 = *(uint32_t *) DEVICE_ID1; | |||
deviceserial1 = *(uint32_t *) DEVICE_ID2; | |||
deviceserial2 = *(uint32_t *) DEVICE_ID3; | |||
deviceserial0 += deviceserial2; | |||
if (deviceserial0 != 0) | |||
{ | |||
IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8); | |||
IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4); | |||
} | |||
} | |||
/** | |||
* @brief Convert Hex 32Bits value into char | |||
* @param value: value to convert | |||
* @param pbuf: pointer to the buffer | |||
* @param len: buffer length | |||
* @retval None | |||
*/ | |||
static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len) | |||
{ | |||
uint8_t idx = 0; | |||
for (idx = 0; idx < len; idx++) | |||
{ | |||
if (((value >> 28)) < 0xA) | |||
{ | |||
pbuf[2 * idx] = (value >> 28) + '0'; | |||
} | |||
else | |||
{ | |||
pbuf[2 * idx] = (value >> 28) + 'A' - 10; | |||
} | |||
value = value << 4; | |||
pbuf[2 * idx + 1] = 0; | |||
} | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,145 @@ | |||
/* USER CODE BEGIN Header */ | |||
/** | |||
****************************************************************************** | |||
* @file : usbd_desc.c | |||
* @version : v2.0_Cube | |||
* @brief : Header for usbd_conf.c file. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2020 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under Ultimate Liberty license | |||
* SLA0044, the "License"; You may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at: | |||
* www.st.com/SLA0044 | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* USER CODE END Header */ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __USBD_DESC__C__ | |||
#define __USBD_DESC__C__ | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "usbd_def.h" | |||
/* USER CODE BEGIN INCLUDE */ | |||
/* USER CODE END INCLUDE */ | |||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY | |||
* @{ | |||
*/ | |||
/** @defgroup USBD_DESC USBD_DESC | |||
* @brief Usb device descriptors module. | |||
* @{ | |||
*/ | |||
/** @defgroup USBD_DESC_Exported_Constants USBD_DESC_Exported_Constants | |||
* @brief Constants. | |||
* @{ | |||
*/ | |||
#define DEVICE_ID1 (UID_BASE) | |||
#define DEVICE_ID2 (UID_BASE + 0x4) | |||
#define DEVICE_ID3 (UID_BASE + 0x8) | |||
#define USB_SIZ_STRING_SERIAL 0x1A | |||
/* USER CODE BEGIN EXPORTED_CONSTANTS */ | |||
/* USER CODE END EXPORTED_CONSTANTS */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_DESC_Exported_Defines USBD_DESC_Exported_Defines | |||
* @brief Defines. | |||
* @{ | |||
*/ | |||
/* USER CODE BEGIN EXPORTED_DEFINES */ | |||
/* USER CODE END EXPORTED_DEFINES */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_DESC_Exported_TypesDefinitions USBD_DESC_Exported_TypesDefinitions | |||
* @brief Types. | |||
* @{ | |||
*/ | |||
/* USER CODE BEGIN EXPORTED_TYPES */ | |||
/* USER CODE END EXPORTED_TYPES */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_DESC_Exported_Macros USBD_DESC_Exported_Macros | |||
* @brief Aliases. | |||
* @{ | |||
*/ | |||
/* USER CODE BEGIN EXPORTED_MACRO */ | |||
/* USER CODE END EXPORTED_MACRO */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_DESC_Exported_Variables USBD_DESC_Exported_Variables | |||
* @brief Public variables. | |||
* @{ | |||
*/ | |||
/** Descriptor for the Usb device. */ | |||
extern USBD_DescriptorsTypeDef FS_Desc; | |||
/* USER CODE BEGIN EXPORTED_VARIABLES */ | |||
/* USER CODE END EXPORTED_VARIABLES */ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_DESC_Exported_FunctionsPrototype USBD_DESC_Exported_FunctionsPrototype | |||
* @brief Public functions declaration. | |||
* @{ | |||
*/ | |||
/* USER CODE BEGIN EXPORTED_FUNCTIONS */ | |||
/* USER CODE END EXPORTED_FUNCTIONS */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __USBD_DESC__C__ */ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,216 @@ | |||
/** | |||
****************************************************************************** | |||
* @file usbd_ioreq.c | |||
* @author MCD Application Team | |||
* @brief This file provides the IO requests APIs for control endpoints. | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2015 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under Ultimate Liberty license | |||
* SLA0044, the "License"; You may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at: | |||
* http://www.st.com/SLA0044 | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "usbd_ioreq.h" | |||
/** @addtogroup STM32_USB_DEVICE_LIBRARY | |||
* @{ | |||
*/ | |||
/** @defgroup USBD_IOREQ | |||
* @brief control I/O requests module | |||
* @{ | |||
*/ | |||
/** @defgroup USBD_IOREQ_Private_TypesDefinitions | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_IOREQ_Private_Defines | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_IOREQ_Private_Macros | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_IOREQ_Private_Variables | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_IOREQ_Private_FunctionPrototypes | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_IOREQ_Private_Functions | |||
* @{ | |||
*/ | |||
/** | |||
* @brief USBD_CtlSendData | |||
* send data on the ctl pipe | |||
* @param pdev: device instance | |||
* @param buff: pointer to data buffer | |||
* @param len: length of data to be sent | |||
* @retval status | |||
*/ | |||
USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev, uint8_t *pbuf, | |||
uint16_t len) | |||
{ | |||
/* Set EP0 State */ | |||
pdev->ep0_state = USBD_EP0_DATA_IN; | |||
pdev->ep_in[0].total_length = len; | |||
pdev->ep_in[0].rem_length = len; | |||
/* Start the transfer */ | |||
USBD_LL_Transmit (pdev, 0x00U, pbuf, len); | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_CtlContinueSendData | |||
* continue sending data on the ctl pipe | |||
* @param pdev: device instance | |||
* @param buff: pointer to data buffer | |||
* @param len: length of data to be sent | |||
* @retval status | |||
*/ | |||
USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev, | |||
uint8_t *pbuf, uint16_t len) | |||
{ | |||
/* Start the next transfer */ | |||
USBD_LL_Transmit (pdev, 0x00U, pbuf, len); | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_CtlPrepareRx | |||
* receive data on the ctl pipe | |||
* @param pdev: device instance | |||
* @param buff: pointer to data buffer | |||
* @param len: length of data to be received | |||
* @retval status | |||
*/ | |||
USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev, uint8_t *pbuf, | |||
uint16_t len) | |||
{ | |||
/* Set EP0 State */ | |||
pdev->ep0_state = USBD_EP0_DATA_OUT; | |||
pdev->ep_out[0].total_length = len; | |||
pdev->ep_out[0].rem_length = len; | |||
/* Start the transfer */ | |||
USBD_LL_PrepareReceive (pdev, 0U, pbuf, len); | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_CtlContinueRx | |||
* continue receive data on the ctl pipe | |||
* @param pdev: device instance | |||
* @param buff: pointer to data buffer | |||
* @param len: length of data to be received | |||
* @retval status | |||
*/ | |||
USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev, uint8_t *pbuf, | |||
uint16_t len) | |||
{ | |||
USBD_LL_PrepareReceive(pdev, 0U, pbuf, len); | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_CtlSendStatus | |||
* send zero lzngth packet on the ctl pipe | |||
* @param pdev: device instance | |||
* @retval status | |||
*/ | |||
USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev) | |||
{ | |||
/* Set EP0 State */ | |||
pdev->ep0_state = USBD_EP0_STATUS_IN; | |||
/* Start the transfer */ | |||
USBD_LL_Transmit(pdev, 0x00U, NULL, 0U); | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_CtlReceiveStatus | |||
* receive zero lzngth packet on the ctl pipe | |||
* @param pdev: device instance | |||
* @retval status | |||
*/ | |||
USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev) | |||
{ | |||
/* Set EP0 State */ | |||
pdev->ep0_state = USBD_EP0_STATUS_OUT; | |||
/* Start the transfer */ | |||
USBD_LL_PrepareReceive (pdev, 0U, NULL, 0U); | |||
return USBD_OK; | |||
} | |||
/** | |||
* @brief USBD_GetRxCount | |||
* returns the received data length | |||
* @param pdev: device instance | |||
* @param ep_addr: endpoint address | |||
* @retval Rx Data blength | |||
*/ | |||
uint32_t USBD_GetRxCount (USBD_HandleTypeDef *pdev, uint8_t ep_addr) | |||
{ | |||
return USBD_LL_GetRxDataSize(pdev, ep_addr); | |||
} | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@@ -0,0 +1,119 @@ | |||
/** | |||
****************************************************************************** | |||
* @file usbd_ioreq.h | |||
* @author MCD Application Team | |||
* @brief Header file for the usbd_ioreq.c file | |||
****************************************************************************** | |||
* @attention | |||
* | |||
* <h2><center>© Copyright (c) 2015 STMicroelectronics. | |||
* All rights reserved.</center></h2> | |||
* | |||
* This software component is licensed by ST under Ultimate Liberty license | |||
* SLA0044, the "License"; You may not use this file except in compliance with | |||
* the License. You may obtain a copy of the License at: | |||
* http://www.st.com/SLA0044 | |||
* | |||
****************************************************************************** | |||
*/ | |||
/* Define to prevent recursive inclusion -------------------------------------*/ | |||
#ifndef __USBD_IOREQ_H | |||
#define __USBD_IOREQ_H | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/* Includes ------------------------------------------------------------------*/ | |||
#include "usbd_def.h" | |||
#include "usbd_core.h" | |||
/** @addtogroup STM32_USB_DEVICE_LIBRARY | |||
* @{ | |||
*/ | |||
/** @defgroup USBD_IOREQ | |||
* @brief header file for the usbd_ioreq.c file | |||
* @{ | |||
*/ | |||
/** @defgroup USBD_IOREQ_Exported_Defines | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_IOREQ_Exported_Types | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_IOREQ_Exported_Macros | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_IOREQ_Exported_Variables | |||
* @{ | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/** @defgroup USBD_IOREQ_Exported_FunctionsPrototype | |||
* @{ | |||
*/ | |||
USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev, | |||
uint8_t *pbuf, | |||
uint16_t len); | |||
USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev, | |||
uint8_t *pbuf, | |||
uint16_t len); | |||
USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev, | |||
uint8_t *pbuf, | |||
uint16_t len); | |||
USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev, | |||
uint8_t *pbuf, | |||
uint16_t len); | |||
USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev); | |||
USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev); | |||
uint32_t USBD_GetRxCount (USBD_HandleTypeDef *pdev, uint8_t ep_addr); | |||
/** | |||
* @} | |||
*/ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __USBD_IOREQ_H */ | |||
/** | |||
* @} | |||
*/ | |||
/** | |||
* @} | |||
*/ | |||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |