aboutsummaryrefslogtreecommitdiff
path: root/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Projects/Mass_Storage/src
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2017-01-25 22:23:13 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2017-01-25 22:23:17 +0100
commit2fff65aed2477a503c72629d27e2a330d30c02d1 (patch)
tree96fd9f2f8151e266c0cf8563a714d7bab8aa7cb0 /thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Projects/Mass_Storage/src
parent41fdd2b1f35bcb4224fdb8fee2b959e09d1f5916 (diff)
downloadstm32f103-playground-2fff65aed2477a503c72629d27e2a330d30c02d1.tar.gz
stm32f103-playground-2fff65aed2477a503c72629d27e2a330d30c02d1.tar.bz2
stm32f103-playground-2fff65aed2477a503c72629d27e2a330d30c02d1.tar.xz
stm32f103-playground-2fff65aed2477a503c72629d27e2a330d30c02d1.zip
o Seemingly working Mutexes.
o Dropping the privileged/unprivileged split for now.
Diffstat (limited to 'thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Projects/Mass_Storage/src')
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Projects/Mass_Storage/src/hw_config.c460
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Projects/Mass_Storage/src/system_stm32f30x.c382
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Projects/Mass_Storage/src/usb_istr.c185
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Projects/Mass_Storage/src/usb_pwr.c318
4 files changed, 1345 insertions, 0 deletions
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Projects/Mass_Storage/src/hw_config.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Projects/Mass_Storage/src/hw_config.c
new file mode 100644
index 0000000..b3976ba
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Projects/Mass_Storage/src/hw_config.c
@@ -0,0 +1,460 @@
+/**
+ ******************************************************************************
+ * @file hw_config.c
+ * @author MCD Application Team
+ * @version V4.0.0
+ * @date 21-January-2013
+ * @brief Hardware Configuration & Setup
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (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/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+
+/* Includes ------------------------------------------------------------------*/
+
+#include "hw_config.h"
+#include "stm32_it.h"
+#include "mass_mal.h"
+#include "usb_desc.h"
+#include "usb_pwr.h"
+#include "usb_lib.h"
+
+
+/* Private typedef -----------------------------------------------------------*/
+/* Private define ------------------------------------------------------------*/
+/* Private macro -------------------------------------------------------------*/
+/* Private variables ---------------------------------------------------------*/
+ErrorStatus HSEStartUpStatus;
+EXTI_InitTypeDef EXTI_InitStructure;
+
+/* Extern variables ----------------------------------------------------------*/
+/* Private function prototypes -----------------------------------------------*/
+static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len);
+
+/* Private functions ---------------------------------------------------------*/
+
+/*******************************************************************************
+* Function Name : Set_System
+* Description : Configures Main system clocks & power
+* Input : None.
+* Return : None.
+*******************************************************************************/
+void Set_System(void)
+{
+#if defined (STM32F37X) || defined (STM32F30X)
+ GPIO_InitTypeDef GPIO_InitStructure;
+#endif /*STM32L1XX_XD */
+
+#if defined(USB_USE_EXTERNAL_PULLUP)
+ GPIO_InitTypeDef GPIO_InitStructure;
+#endif /* USB_USE_EXTERNAL_PULLUP */
+
+ /*!< At this stage the microcontroller clock setting is already configured,
+ this is done through SystemInit() function which is called from startup
+ file (startup_stm32xxx.s) before to branch to application main.
+ To reconfigure the default setting of SystemInit() function, refer to
+ system_stm32xxx.c file
+ */
+#if defined(STM32L1XX_MD) || defined(STM32L1XX_HD)|| defined(STM32L1XX_MD_PLUS) || defined(STM32F37X) || defined(STM32F30X)
+ /* Enable the SYSCFG module clock */
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
+#endif /* STM32L1XX_XD */
+
+#if !defined (USE_STM32L152_EVAL)
+ /* Enable and Disconnect Line GPIO clock */
+ USB_Disconnect_Config();
+#endif /* USE_STM32L152_EVAL */
+
+#if defined (STM32F37X) || defined(STM32F30X)
+
+ /* Enable the USB disconnect GPIO clock */
+ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIO_DISCONNECT, ENABLE);
+
+ /*Set PA11,12 as IN - USB_DM,DP*/
+
+ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(GPIOA, &GPIO_InitStructure);
+
+ /*SET PA11,12 for USB: USB_DM,DP*/
+ GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_14);
+ GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_14);
+
+ /* USB_DISCONNECT used as USB pull-up */
+ GPIO_InitStructure.GPIO_Pin = USB_DISCONNECT_PIN;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(USB_DISCONNECT, &GPIO_InitStructure);
+#endif /* STM32F37X && STM32F30X */
+
+#if defined(USB_USE_EXTERNAL_PULLUP)
+ /* Enable the USB disconnect GPIO clock */
+ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIO_DISCONNECT, ENABLE);
+
+ /* USB_DISCONNECT used as USB pull-up */
+ GPIO_InitStructure.GPIO_Pin = USB_DISCONNECT_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(USB_DISCONNECT, &GPIO_InitStructure);
+#endif /* USB_USE_EXTERNAL_PULLUP */
+
+ /* Configure the EXTI line 18 connected internally to the USB IP */
+ EXTI_ClearITPendingBit(EXTI_Line18);
+ EXTI_InitStructure.EXTI_Line = EXTI_Line18;
+ EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
+ EXTI_InitStructure.EXTI_LineCmd = ENABLE;
+ EXTI_Init(&EXTI_InitStructure);
+
+ /* MAL configuration */
+ MAL_Config();
+}
+
+/*******************************************************************************
+* Function Name : Set_USBClock
+* Description : Configures USB Clock input (48MHz)
+* Input : None.
+* Return : None.
+*******************************************************************************/
+void Set_USBClock(void)
+{
+#if defined(STM32L1XX_MD) || defined(STM32L1XX_HD)|| defined(STM32L1XX_MD_PLUS)
+ /* Enable USB clock */
+ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);
+
+#else
+ /* Select USBCLK source */
+ RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
+
+ /* Enable the USB clock */
+ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);
+#endif /* STM32L1XX_XD */
+}
+
+/*******************************************************************************
+* Function Name : Enter_LowPowerMode
+* Description : Power-off system clocks and power while entering suspend mode
+* Input : None.
+* Return : None.
+*******************************************************************************/
+void Enter_LowPowerMode(void)
+{
+ /* Set the device state to suspend */
+ bDeviceState = SUSPENDED;
+}
+
+/*******************************************************************************
+* Function Name : Leave_LowPowerMode
+* Description : Restores system clocks and power while exiting suspend mode
+* Input : None.
+* Return : None.
+*******************************************************************************/
+void Leave_LowPowerMode(void)
+{
+ DEVICE_INFO *pInfo = &Device_Info;
+
+ /* Set the device state to the correct state */
+ if (pInfo->Current_Configuration != 0)
+ {
+ /* Device configured */
+ bDeviceState = CONFIGURED;
+ }
+ else
+ {
+ bDeviceState = ATTACHED;
+ }
+ /*Enable SystemCoreClock*/
+ SystemInit();
+}
+
+/*******************************************************************************
+* Function Name : USB_Interrupts_Config
+* Description : Configures the USB interrupts
+* Input : None.
+* Return : None.
+*******************************************************************************/
+void USB_Interrupts_Config(void)
+{
+ NVIC_InitTypeDef NVIC_InitStructure;
+
+ /* 2 bit for pre-emption priority, 2 bits for subpriority */
+ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
+
+#if defined(STM32L1XX_MD) || defined(STM32L1XX_HD)|| defined(STM32L1XX_MD_PLUS)
+ NVIC_InitStructure.NVIC_IRQChannel = USB_LP_IRQn;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+ NVIC_Init(&NVIC_InitStructure);
+
+ /* Enable the USB Wake-up interrupt */
+ NVIC_InitStructure.NVIC_IRQChannel = USB_FS_WKUP_IRQn;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+ NVIC_Init(&NVIC_InitStructure);
+
+#elif defined(STM32F37X)
+ /* Enable the USB interrupt */
+ NVIC_InitStructure.NVIC_IRQChannel = USB_LP_IRQn;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+ NVIC_Init(&NVIC_InitStructure);
+
+ /* Enable the USB Wake-up interrupt */
+ NVIC_InitStructure.NVIC_IRQChannel = USBWakeUp_IRQn;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+ NVIC_Init(&NVIC_InitStructure);
+
+#else
+ NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+ NVIC_Init(&NVIC_InitStructure);
+
+ /* Enable the USB Wake-up interrupt */
+ NVIC_InitStructure.NVIC_IRQChannel = USBWakeUp_IRQn;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
+ NVIC_Init(&NVIC_InitStructure);
+#endif /* STM32L1XX_XD */
+
+
+#if defined(STM32F10X_HD) || defined(STM32F10X_XL) || defined(STM32L1XX_HD)|| defined(STM32L1XX_MD_PLUS)
+ NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
+ NVIC_Init(&NVIC_InitStructure);
+ NVIC_InitStructure.NVIC_IRQChannel = SD_SDIO_DMA_IRQn;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
+ NVIC_Init(&NVIC_InitStructure);
+#endif /* STM32L1XX_MD */
+
+}
+
+/*******************************************************************************
+* Function Name : Led_Config
+* Description : configure the Read/Write LEDs.
+* Input : None.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void Led_Config(void)
+{
+ /* Configure the LEDs */
+ STM_EVAL_LEDInit(LED1);
+ STM_EVAL_LEDInit(LED2);
+ STM_EVAL_LEDInit(LED3);
+ STM_EVAL_LEDInit(LED4);
+}
+
+/*******************************************************************************
+* Function Name : Led_RW_ON
+* Description : Turn ON the Read/Write LEDs.
+* Input : None.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void Led_RW_ON(void)
+{
+ STM_EVAL_LEDOn(LED3);
+}
+
+/*******************************************************************************
+* Function Name : Led_RW_OFF
+* Description : Turn off the Read/Write LEDs.
+* Input : None.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void Led_RW_OFF(void)
+{
+ STM_EVAL_LEDOff(LED3);
+}
+/*******************************************************************************
+* Function Name : USB_Configured_LED
+* Description : Turn ON the Read/Write LEDs.
+* Input : None.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void USB_Configured_LED(void)
+{
+ STM_EVAL_LEDOn(LED1);
+}
+
+/*******************************************************************************
+* Function Name : USB_NotConfigured_LED
+* Description : Turn off the Read/Write LEDs.
+* Input : None.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void USB_NotConfigured_LED(void)
+{
+ STM_EVAL_LEDOff(LED1);
+}
+
+/*******************************************************************************
+* Function Name : USB_Cable_Config
+* Description : Software Connection/Disconnection of USB Cable.
+* Input : None.
+* Return : Status
+*******************************************************************************/
+void USB_Cable_Config (FunctionalState NewState)
+{
+
+#if defined(STM32L1XX_MD)
+ if (NewState != DISABLE)
+ {
+ STM32L15_USB_CONNECT;
+ }
+ else
+ {
+ STM32L15_USB_DISCONNECT;
+ }
+
+#elif defined(STM32L1XX_HD) || defined(STM32L1XX_MD_PLUS)
+ if (NewState != DISABLE)
+ {
+ GPIO_ResetBits(USB_DISCONNECT, USB_DISCONNECT_PIN);
+ SYSCFG_USBPuCmd(ENABLE);
+ }
+ else
+ {
+ GPIO_SetBits(USB_DISCONNECT, USB_DISCONNECT_PIN);
+ SYSCFG_USBPuCmd(DISABLE);
+ }
+#endif /* STM32L1XX_MD */
+}
+
+/*******************************************************************************
+* Function Name : Get_SerialNum.
+* Description : Create the serial number string descriptor.
+* Input : None.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void Get_SerialNum(void)
+{
+ uint32_t Device_Serial0, Device_Serial1, Device_Serial2;
+
+ Device_Serial0 = *(uint32_t*)ID1;
+ Device_Serial1 = *(uint32_t*)ID2;
+ Device_Serial2 = *(uint32_t*)ID3;
+
+ Device_Serial0 += Device_Serial2;
+
+ if (Device_Serial0 != 0)
+ {
+ IntToUnicode (Device_Serial0, &MASS_StringSerial[2] , 8);
+ IntToUnicode (Device_Serial1, &MASS_StringSerial[18], 4);
+ }
+}
+
+/*******************************************************************************
+* Function Name : HexToChar.
+* Description : Convert Hex 32Bits value into char.
+* Input : None.
+* Output : None.
+* Return : 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;
+ }
+}
+
+/*******************************************************************************
+* Function Name : MAL_Config
+* Description : MAL_layer configuration
+* Input : None.
+* Return : None.
+*******************************************************************************/
+void MAL_Config(void)
+{
+ MAL_Init(0);
+
+#if defined(STM32F10X_HD) || defined(STM32F10X_XL)
+ /* Enable the FSMC Clock */
+ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
+ MAL_Init(1);
+#endif /* STM32F10X_HD | STM32F10X_XL */
+}
+
+#if !defined (USE_STM32L152_EVAL)
+/*******************************************************************************
+* Function Name : USB_Disconnect_Config
+* Description : Disconnect pin configuration
+* Input : None.
+* Return : None.
+*******************************************************************************/
+void USB_Disconnect_Config(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+#if defined (USE_STM3210B_EVAL) || defined (USE_STM3210E_EVAL)
+ /* Enable USB_DISCONNECT GPIO clock */
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_DISCONNECT, ENABLE);
+
+ /* USB_DISCONNECT_PIN used as USB pull-up */
+ GPIO_InitStructure.GPIO_Pin = USB_DISCONNECT_PIN;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
+#else
+ /* Enable the USB disconnect GPIO clock */
+ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIO_DISCONNECT, ENABLE);
+ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ALLGPIO, ENABLE);
+
+ /* USB_DISCONNECT used as USB pull-up */
+ GPIO_InitStructure.GPIO_Pin = USB_DISCONNECT_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+
+#endif
+ GPIO_Init(USB_DISCONNECT, &GPIO_InitStructure);
+}
+#endif /* USE_STM3210B_EVAL or USE_STM3210E_EVAL */
+
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Projects/Mass_Storage/src/system_stm32f30x.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Projects/Mass_Storage/src/system_stm32f30x.c
new file mode 100644
index 0000000..31faf5c
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Projects/Mass_Storage/src/system_stm32f30x.c
@@ -0,0 +1,382 @@
+/**
+ ******************************************************************************
+ * @file system_stm32f30x.c
+ * @author MCD Application Team
+ * @version V4.0.0
+ * @date 21-January-2013
+ * @brief CMSIS Cortex-M4 Device Peripheral Access Layer System Source File.
+ * This file contains the system clock configuration for STM32F30x devices,
+ * and is generated by the clock configuration tool
+ * stm32f30x_Clock_Configuration_V1.0.0.xls
+ *
+ * 1. This file provides two functions and one global variable to be called from
+ * user application:
+ * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier
+ * and Divider factors, AHB/APBx prescalers and Flash settings),
+ * depending on the configuration made in the clock xls tool.
+ * This function is called at startup just after reset and
+ * before branch to main program. This call is made inside
+ * the "startup_stm32f30x.s" file.
+ *
+ * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
+ * by the user application to setup the SysTick
+ * timer or configure other parameters.
+ *
+ * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
+ * be called whenever the core clock is changed
+ * during program execution.
+ *
+ * 2. After each device reset the HSI (8 MHz) is used as system clock source.
+ * Then SystemInit() function is called, in "startup_stm32f30x.s" file, to
+ * configure the system clock before to branch to main program.
+ *
+ * 3. If the system clock source selected by user fails to startup, the SystemInit()
+ * function will do nothing and HSI still used as system clock source. User can
+ * add some code to deal with this issue inside the SetSysClock() function.
+ *
+ * 4. The default value of HSE crystal is set to 8MHz, refer to "HSE_VALUE" define
+ * in "stm32f30x.h" file. When HSE is used as system clock source, directly or
+ * through PLL, and you are using different crystal you have to adapt the HSE
+ * value to your own configuration.
+ *
+ * 5. This file configures the system clock as follows:
+ *=============================================================================
+ * Supported STM32F30x device
+ *-----------------------------------------------------------------------------
+ * System Clock source | PLL (HSE)
+ *-----------------------------------------------------------------------------
+ * SYSCLK(Hz) | 72000000
+ *-----------------------------------------------------------------------------
+ * HCLK(Hz) | 72000000
+ *-----------------------------------------------------------------------------
+ * AHB Prescaler | 1
+ *-----------------------------------------------------------------------------
+ * APB2 Prescaler | 1
+ *-----------------------------------------------------------------------------
+ * APB1 Prescaler | 2
+ *-----------------------------------------------------------------------------
+ * HSE Frequency(Hz) | 8000000
+ *----------------------------------------------------------------------------
+ * PLLMUL | 9
+ *-----------------------------------------------------------------------------
+ * PREDIV | 1
+ *-----------------------------------------------------------------------------
+ * USB Clock | ENABLE
+ *-----------------------------------------------------------------------------
+ * Flash Latency(WS) | 2
+ *-----------------------------------------------------------------------------
+ * Prefetch Buffer | ON
+ *-----------------------------------------------------------------------------
+ *=============================================================================
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (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/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+/** @addtogroup CMSIS
+ * @{
+ */
+
+/** @addtogroup stm32f30x_system
+ * @{
+ */
+
+/** @addtogroup STM32F30x_System_Private_Includes
+ * @{
+ */
+
+#include "stm32f30x.h"
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32F30x_System_Private_TypesDefinitions
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32F30x_System_Private_Defines
+ * @{
+ */
+/*!< Uncomment the following line if you need to relocate your vector Table in
+ Internal SRAM. */
+/* #define VECT_TAB_SRAM */
+#define VECT_TAB_OFFSET 0x0 /*!< Vector Table base offset field.
+ This value must be a multiple of 0x200. */
+/**
+ * @}
+ */
+
+/** @addtogroup STM32F30x_System_Private_Macros
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32F30x_System_Private_Variables
+ * @{
+ */
+
+ uint32_t SystemCoreClock = 72000000;
+
+ __I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32F30x_System_Private_FunctionPrototypes
+ * @{
+ */
+
+static void SetSysClock(void);
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32F30x_System_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief Setup the microcontroller system
+ * Initialize the Embedded Flash Interface, the PLL and update the
+ * SystemFrequency variable.
+ * @param None
+ * @retval None
+ */
+void SystemInit(void)
+{
+ /* FPU settings ------------------------------------------------------------*/
+ #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
+ SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
+ #endif
+
+ /* Reset the RCC clock configuration to the default reset state ------------*/
+ /* Set HSION bit */
+ RCC->CR |= (uint32_t)0x00000001;
+
+ /* Reset CFGR register */
+ RCC->CFGR &= 0xF87FC00C;
+
+ /* Reset HSEON, CSSON and PLLON bits */
+ RCC->CR &= (uint32_t)0xFEF6FFFF;
+
+ /* Reset HSEBYP bit */
+ RCC->CR &= (uint32_t)0xFFFBFFFF;
+
+ /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE bits */
+ RCC->CFGR &= (uint32_t)0xFF80FFFF;
+
+ /* Reset PREDIV1[3:0] bits */
+ RCC->CFGR2 &= (uint32_t)0xFFFFFFF0;
+
+ /* Reset USARTSW[1:0], I2CSW and TIMs bits */
+ RCC->CFGR3 &= (uint32_t)0xFF00FCCC;
+
+ /* Disable all interrupts */
+ RCC->CIR = 0x00000000;
+
+ /* Configure the System clock source, PLL Multiplier and Divider factors,
+ AHB/APBx prescalers and Flash settings ----------------------------------*/
+ SetSysClock();
+
+#ifdef VECT_TAB_SRAM
+ SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
+#else
+ SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
+#endif
+}
+
+/**
+ * @brief Update SystemCoreClock variable according to Clock Register Values.
+ * The SystemCoreClock variable contains the core clock (HCLK), it can
+ * be used by the user application to setup the SysTick timer or configure
+ * other parameters.
+ *
+ * @note Each time the core clock (HCLK) changes, this function must be called
+ * to update SystemCoreClock variable value. Otherwise, any configuration
+ * based on this variable will be incorrect.
+ *
+ * @note - The system frequency computed by this function is not the real
+ * frequency in the chip. It is calculated based on the predefined
+ * constant and the selected clock source:
+ *
+ * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
+ *
+ * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
+ *
+ * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**)
+ * or HSI_VALUE(*) multiplied/divided by the PLL factors.
+ *
+ * (*) HSI_VALUE is a constant defined in stm32f30x.h file (default value
+ * 8 MHz) but the real value may vary depending on the variations
+ * in voltage and temperature.
+ *
+ * (**) HSE_VALUE is a constant defined in stm32f30x.h file (default value
+ * 8 MHz), user has to ensure that HSE_VALUE is same as the real
+ * frequency of the crystal used. Otherwise, this function may
+ * have wrong result.
+ *
+ * - The result of this function could be not correct when using fractional
+ * value for HSE crystal.
+ *
+ * @param None
+ * @retval None
+ */
+void SystemCoreClockUpdate (void)
+{
+ uint32_t tmp = 0, pllmull = 0, pllsource = 0, prediv1factor = 0;
+
+ /* Get SYSCLK source -------------------------------------------------------*/
+ tmp = RCC->CFGR & RCC_CFGR_SWS;
+
+ switch (tmp)
+ {
+ case 0x00: /* HSI used as system clock */
+ SystemCoreClock = HSI_VALUE;
+ break;
+ case 0x04: /* HSE used as system clock */
+ SystemCoreClock = HSE_VALUE;
+ break;
+ case 0x08: /* PLL used as system clock */
+ /* Get PLL clock source and multiplication factor ----------------------*/
+ pllmull = RCC->CFGR & RCC_CFGR_PLLMULL;
+ pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;
+ pllmull = ( pllmull >> 18) + 2;
+
+ if (pllsource == 0x00)
+ {
+ /* HSI oscillator clock divided by 2 selected as PLL clock entry */
+ SystemCoreClock = (HSI_VALUE >> 1) * pllmull;
+ }
+ else
+ {
+ prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1;
+ /* HSE oscillator clock selected as PREDIV1 clock entry */
+ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
+ }
+ break;
+ default: /* HSI used as system clock */
+ SystemCoreClock = HSI_VALUE;
+ break;
+ }
+ /* Compute HCLK clock frequency ----------------*/
+ /* Get HCLK prescaler */
+ tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
+ /* HCLK clock frequency */
+ SystemCoreClock >>= tmp;
+}
+
+/**
+ * @brief Configures the System clock source, PLL Multiplier and Divider factors,
+ * AHB/APBx prescalers and Flash settings
+ * @note This function should be called only once the RCC clock configuration
+ * is reset to the default reset state (done in SystemInit() function).
+ * @param None
+ * @retval None
+ */
+static void SetSysClock(void)
+{
+ __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
+
+/******************************************************************************/
+/* PLL (clocked by HSE) used as System clock source */
+/******************************************************************************/
+
+ /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------*/
+ /* Enable HSE */
+ RCC->CR |= ((uint32_t)RCC_CR_HSEON);
+
+ /* Wait till HSE is ready and if Time out is reached exit */
+ do
+ {
+ HSEStatus = RCC->CR & RCC_CR_HSERDY;
+ StartUpCounter++;
+ } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
+
+ if ((RCC->CR & RCC_CR_HSERDY) != RESET)
+ {
+ HSEStatus = (uint32_t)0x01;
+ }
+ else
+ {
+ HSEStatus = (uint32_t)0x00;
+ }
+
+ if (HSEStatus == (uint32_t)0x01)
+ {
+ /* Enable Prefetch Buffer and set Flash Latency */
+ FLASH->ACR = FLASH_ACR_PRFTBE | (uint32_t)FLASH_ACR_LATENCY_1;
+
+ /* HCLK = SYSCLK / 1 */
+ RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
+
+ /* PCLK2 = HCLK / 1 */
+ RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;
+
+ /* PCLK1 = HCLK / 2 */
+ RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV2;
+
+ /* PLL configuration */
+ RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));
+ RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_PREDIV1 | RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLMULL9);
+
+ /* Enable PLL */
+ RCC->CR |= RCC_CR_PLLON;
+
+ /* Wait till PLL is ready */
+ while((RCC->CR & RCC_CR_PLLRDY) == 0)
+ {
+ }
+
+ /* Select PLL as system clock source */
+ RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
+ RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;
+
+ /* Wait till PLL is used as system clock source */
+ while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)RCC_CFGR_SWS_PLL)
+ {
+ }
+ }
+ else
+ { /* If HSE fails to start-up, the application will have wrong clock
+ configuration. User can add here some code to deal with this error */
+ }
+}
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Projects/Mass_Storage/src/usb_istr.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Projects/Mass_Storage/src/usb_istr.c
new file mode 100644
index 0000000..90e0061
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Projects/Mass_Storage/src/usb_istr.c
@@ -0,0 +1,185 @@
+/**
+ ******************************************************************************
+ * @file usb_istr.c
+ * @author MCD Application Team
+ * @version V4.0.0
+ * @date 21-January-2013
+ * @brief ISTR events interrupt service routines
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (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/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+
+/* Includes ------------------------------------------------------------------*/
+#include "hw_config.h"
+#include "usb_type.h"
+#include "usb_regs.h"
+#include "usb_pwr.h"
+#include "usb_istr.h"
+#include "usb_init.h"
+#include "usb_int.h"
+#include "usb_lib.h"
+
+/* Private typedef -----------------------------------------------------------*/
+/* Private define ------------------------------------------------------------*/
+/* Private macro -------------------------------------------------------------*/
+/* Private variables ---------------------------------------------------------*/
+__IO uint16_t wIstr; /* ISTR register last read value */
+__IO uint8_t bIntPackSOF = 0; /* SOFs received between 2 consecutive packets */
+
+/* Extern variables ----------------------------------------------------------*/
+/* Private function prototypes -----------------------------------------------*/
+/* Private functions ---------------------------------------------------------*/
+/* function pointers to non-control endpoints service routines */
+void (*pEpInt_IN[7])(void) =
+ {
+ EP1_IN_Callback,
+ EP2_IN_Callback,
+ EP3_IN_Callback,
+ EP4_IN_Callback,
+ EP5_IN_Callback,
+ EP6_IN_Callback,
+ EP7_IN_Callback,
+ };
+
+void (*pEpInt_OUT[7])(void) =
+ {
+ EP1_OUT_Callback,
+ EP2_OUT_Callback,
+ EP3_OUT_Callback,
+ EP4_OUT_Callback,
+ EP5_OUT_Callback,
+ EP6_OUT_Callback,
+ EP7_OUT_Callback,
+ };
+
+/*******************************************************************************
+* Function Name : USB_Istr
+* Description : ISTR events interrupt service routine
+* Input : None.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void USB_Istr(void)
+{
+ wIstr = _GetISTR();
+
+#if (IMR_MSK & ISTR_CTR)
+ if (wIstr & ISTR_CTR & wInterrupt_Mask)
+ {
+ /* servicing of the endpoint correct transfer interrupt */
+ /* clear of the CTR flag into the sub */
+ CTR_LP();
+#ifdef CTR_CALLBACK
+ CTR_Callback();
+#endif
+ }
+#endif
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
+#if (IMR_MSK & ISTR_RESET)
+ if (wIstr & ISTR_RESET & wInterrupt_Mask)
+ {
+ _SetISTR((uint16_t)CLR_RESET);
+ Device_Property.Reset();
+#ifdef RESET_CALLBACK
+ RESET_Callback();
+#endif
+ }
+#endif
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
+#if (IMR_MSK & ISTR_DOVR)
+ if (wIstr & ISTR_DOVR & wInterrupt_Mask)
+ {
+ _SetISTR((uint16_t)CLR_DOVR);
+#ifdef DOVR_CALLBACK
+ DOVR_Callback();
+#endif
+ }
+#endif
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
+#if (IMR_MSK & ISTR_ERR)
+ if (wIstr & ISTR_ERR & wInterrupt_Mask)
+ {
+ _SetISTR((uint16_t)CLR_ERR);
+#ifdef ERR_CALLBACK
+ ERR_Callback();
+#endif
+ }
+#endif
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
+#if (IMR_MSK & ISTR_WKUP)
+ if (wIstr & ISTR_WKUP & wInterrupt_Mask)
+ {
+ _SetISTR((uint16_t)CLR_WKUP);
+ Resume(RESUME_EXTERNAL);
+#ifdef WKUP_CALLBACK
+ WKUP_Callback();
+#endif
+ }
+#endif
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
+#if (IMR_MSK & ISTR_SUSP)
+ if (wIstr & ISTR_SUSP & wInterrupt_Mask)
+ {
+
+ /* check if SUSPEND is possible */
+ if (fSuspendEnabled)
+ {
+ Suspend();
+ }
+ else
+ {
+ /* if not possible then resume after xx ms */
+ Resume(RESUME_LATER);
+ }
+ /* clear of the ISTR bit must be done after setting of CNTR_FSUSP */
+ _SetISTR((uint16_t)CLR_SUSP);
+#ifdef SUSP_CALLBACK
+ SUSP_Callback();
+#endif
+ }
+#endif
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
+#if (IMR_MSK & ISTR_SOF)
+ if (wIstr & ISTR_SOF & wInterrupt_Mask)
+ {
+ _SetISTR((uint16_t)CLR_SOF);
+ bIntPackSOF++;
+
+#ifdef SOF_CALLBACK
+ SOF_Callback();
+#endif
+ }
+#endif
+ /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
+#if (IMR_MSK & ISTR_ESOF)
+ if (wIstr & ISTR_ESOF & wInterrupt_Mask)
+ {
+ _SetISTR((uint16_t)CLR_ESOF);
+ /* resume handling timing is made with ESOFs */
+ Resume(RESUME_ESOF); /* request without change of the machine state */
+
+#ifdef ESOF_CALLBACK
+ ESOF_Callback();
+#endif
+ }
+#endif
+} /* USB_Istr */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Projects/Mass_Storage/src/usb_pwr.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Projects/Mass_Storage/src/usb_pwr.c
new file mode 100644
index 0000000..04673bd
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Projects/Mass_Storage/src/usb_pwr.c
@@ -0,0 +1,318 @@
+/**
+ ******************************************************************************
+ * @file usb_pwr.c
+ * @author MCD Application Team
+ * @version V4.0.0
+ * @date 21-January-2013
+ * @brief Connection/disconnection & power management
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (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/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+
+/* Includes ------------------------------------------------------------------*/
+#include "usb_lib.h"
+#include "usb_conf.h"
+#include "usb_pwr.h"
+#include "hw_config.h"
+
+/* Private typedef -----------------------------------------------------------*/
+/* Private define ------------------------------------------------------------*/
+/* Private macro -------------------------------------------------------------*/
+/* Private variables ---------------------------------------------------------*/
+__IO uint32_t bDeviceState = UNCONNECTED; /* USB device status */
+__IO bool fSuspendEnabled = TRUE; /* true when suspend is possible */
+__IO uint32_t EP[8];
+
+struct
+{
+ __IO RESUME_STATE eState;
+ __IO uint8_t bESOFcnt;
+}
+ResumeS;
+
+__IO uint32_t remotewakeupon=0;
+
+/* Extern variables ----------------------------------------------------------*/
+/* Private function prototypes -----------------------------------------------*/
+/* Extern function prototypes ------------------------------------------------*/
+/* Private functions ---------------------------------------------------------*/
+
+/*******************************************************************************
+* Function Name : PowerOn
+* Description :
+* Input : None.
+* Output : None.
+* Return : USB_SUCCESS.
+*******************************************************************************/
+RESULT PowerOn(void)
+{
+ uint16_t wRegVal;
+
+ /*** cable plugged-in ? ***/
+ USB_Cable_Config(ENABLE);
+
+ /*** CNTR_PWDN = 0 ***/
+ wRegVal = CNTR_FRES;
+ _SetCNTR(wRegVal);
+
+ /*** CNTR_FRES = 0 ***/
+ wInterrupt_Mask = 0;
+ _SetCNTR(wInterrupt_Mask);
+ /*** Clear pending interrupts ***/
+ _SetISTR(0);
+ /*** Set interrupt mask ***/
+ wInterrupt_Mask = CNTR_RESETM | CNTR_SUSPM | CNTR_WKUPM;
+ _SetCNTR(wInterrupt_Mask);
+
+ return USB_SUCCESS;
+}
+
+/*******************************************************************************
+* Function Name : PowerOff
+* Description : handles switch-off conditions
+* Input : None.
+* Output : None.
+* Return : USB_SUCCESS.
+*******************************************************************************/
+RESULT PowerOff()
+{
+ /* disable all interrupts and force USB reset */
+ _SetCNTR(CNTR_FRES);
+ /* clear interrupt status register */
+ _SetISTR(0);
+ /* Disable the Pull-Up*/
+ USB_Cable_Config(DISABLE);
+ /* switch-off device */
+ _SetCNTR(CNTR_FRES + CNTR_PDWN);
+ /* sw variables reset */
+ /* ... */
+
+ return USB_SUCCESS;
+}
+
+/*******************************************************************************
+* Function Name : Suspend
+* Description : sets suspend mode operating conditions
+* Input : None.
+* Output : None.
+* Return : USB_SUCCESS.
+*******************************************************************************/
+void Suspend(void)
+{
+ uint32_t i =0;
+ uint16_t wCNTR;
+ uint32_t tmpreg = 0;
+ __IO uint32_t savePWR_CR=0;
+ /* suspend preparation */
+ /* ... */
+
+ /*Store CNTR value */
+ wCNTR = _GetCNTR();
+
+ /* This a sequence to apply a force RESET to handle a robustness case */
+
+ /*Store endpoints registers status */
+ for (i=0;i<8;i++) EP[i] = _GetENDPOINT(i);
+
+ /* unmask RESET flag */
+ wCNTR|=CNTR_RESETM;
+ _SetCNTR(wCNTR);
+
+ /*apply FRES */
+ wCNTR|=CNTR_FRES;
+ _SetCNTR(wCNTR);
+
+ /*clear FRES*/
+ wCNTR&=~CNTR_FRES;
+ _SetCNTR(wCNTR);
+
+ /*poll for RESET flag in ISTR*/
+ while((_GetISTR()&ISTR_RESET) == 0);
+
+ /* clear RESET flag in ISTR */
+ _SetISTR((uint16_t)CLR_RESET);
+
+ /*restore Enpoints*/
+ for (i=0;i<8;i++)
+ _SetENDPOINT(i, EP[i]);
+
+ /* Now it is safe to enter macrocell in suspend mode */
+ wCNTR |= CNTR_FSUSP;
+ _SetCNTR(wCNTR);
+
+ /* force low-power mode in the macrocell */
+ wCNTR = _GetCNTR();
+ wCNTR |= CNTR_LPMODE;
+ _SetCNTR(wCNTR);
+
+ /*prepare entry in low power mode (STOP mode)*/
+ /* Select the regulator state in STOP mode*/
+ savePWR_CR = PWR->CR;
+ tmpreg = PWR->CR;
+ /* Clear PDDS and LPDS bits */
+ tmpreg &= ((uint32_t)0xFFFFFFFC);
+ /* Set LPDS bit according to PWR_Regulator value */
+ tmpreg |= PWR_Regulator_LowPower;
+ /* Store the new value */
+ PWR->CR = tmpreg;
+ /* Set SLEEPDEEP bit of Cortex System Control Register */
+#if defined (STM32F30X) || defined (STM32F37X)
+ SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
+#else
+ SCB->SCR |= SCB_SCR_SLEEPDEEP;
+#endif
+
+ /* enter system in STOP mode, only when wakeup flag in not set */
+ if((_GetISTR()&ISTR_WKUP)==0)
+ {
+ __WFI();
+ /* Reset SLEEPDEEP bit of Cortex System Control Register */
+#if defined (STM32F30X) || defined (STM32F37X)
+ SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
+#else
+ SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP);
+#endif
+ }
+ else
+ {
+ /* Clear Wakeup flag */
+ _SetISTR(CLR_WKUP);
+ /* clear FSUSP to abort entry in suspend mode */
+ wCNTR = _GetCNTR();
+ wCNTR&=~CNTR_FSUSP;
+ _SetCNTR(wCNTR);
+
+ /*restore sleep mode configuration */
+ /* restore Power regulator config in sleep mode*/
+ PWR->CR = savePWR_CR;
+
+ /* Reset SLEEPDEEP bit of Cortex System Control Register */
+#if defined (STM32F30X) || defined (STM32F37X)
+ SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
+#else
+ SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP);
+#endif
+ }
+}
+
+/*******************************************************************************
+* Function Name : Resume_Init
+* Description : Handles wake-up restoring normal operations
+* Input : None.
+* Output : None.
+* Return : USB_SUCCESS.
+*******************************************************************************/
+void Resume_Init(void)
+{
+ uint16_t wCNTR;
+
+ /* ------------------ ONLY WITH BUS-POWERED DEVICES ---------------------- */
+ /* restart the clocks */
+ /* ... */
+
+ /* CNTR_LPMODE = 0 */
+ wCNTR = _GetCNTR();
+ wCNTR &= (~CNTR_LPMODE);
+ _SetCNTR(wCNTR);
+
+ /* restore full power */
+ /* ... on connected devices */
+ Leave_LowPowerMode();
+
+ /* reset FSUSP bit */
+ _SetCNTR(IMR_MSK);
+
+ /* reverse suspend preparation */
+ /* ... */
+
+}
+
+/*******************************************************************************
+* Function Name : Resume
+* Description : This is the state machine handling resume operations and
+* timing sequence. The control is based on the Resume structure
+* variables and on the ESOF interrupt calling this subroutine
+* without changing machine state.
+* Input : a state machine value (RESUME_STATE)
+* RESUME_ESOF doesn't change ResumeS.eState allowing
+* decrementing of the ESOF counter in different states.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void Resume(RESUME_STATE eResumeSetVal)
+{
+ uint16_t wCNTR;
+
+ if (eResumeSetVal != RESUME_ESOF)
+ ResumeS.eState = eResumeSetVal;
+ switch (ResumeS.eState)
+ {
+ case RESUME_EXTERNAL:
+ if (remotewakeupon ==0)
+ {
+ Resume_Init();
+ ResumeS.eState = RESUME_OFF;
+ }
+ else /* RESUME detected during the RemoteWAkeup signalling => keep RemoteWakeup handling*/
+ {
+ ResumeS.eState = RESUME_ON;
+ }
+ break;
+ case RESUME_INTERNAL:
+ Resume_Init();
+ ResumeS.eState = RESUME_START;
+ remotewakeupon = 1;
+ break;
+ case RESUME_LATER:
+ ResumeS.bESOFcnt = 2;
+ ResumeS.eState = RESUME_WAIT;
+ break;
+ case RESUME_WAIT:
+ ResumeS.bESOFcnt--;
+ if (ResumeS.bESOFcnt == 0)
+ ResumeS.eState = RESUME_START;
+ break;
+ case RESUME_START:
+ wCNTR = _GetCNTR();
+ wCNTR |= CNTR_RESUME;
+ _SetCNTR(wCNTR);
+ ResumeS.eState = RESUME_ON;
+ ResumeS.bESOFcnt = 10;
+ break;
+ case RESUME_ON:
+ ResumeS.bESOFcnt--;
+ if (ResumeS.bESOFcnt == 0)
+ {
+ wCNTR = _GetCNTR();
+ wCNTR &= (~CNTR_RESUME);
+ _SetCNTR(wCNTR);
+ ResumeS.eState = RESUME_OFF;
+ remotewakeupon = 0;
+ }
+ break;
+ case RESUME_OFF:
+ case RESUME_ESOF:
+ default:
+ ResumeS.eState = RESUME_OFF;
+ break;
+ }
+}
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/