summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <git@jaseg.net>2017-07-30 16:10:36 +0200
committerjaseg <git@jaseg.net>2017-07-30 16:10:36 +0200
commit6482cf2a698d1108510680f95ac0373ac21b92ce (patch)
tree31762ea41fcf60b22d24aaa4a0bc5d35bcaa26de
parentb9535e1b089f14f7123d0865a06b985d2285dabf (diff)
downloadsecure-hid-6482cf2a698d1108510680f95ac0373ac21b92ce.tar.gz
secure-hid-6482cf2a698d1108510680f95ac0373ac21b92ce.tar.bz2
secure-hid-6482cf2a698d1108510680f95ac0373ac21b92ce.zip
USB HID host code import
-rw-r--r--base.c20
-rw-r--r--keyboard.c73
-rw-r--r--main.c296
-rw-r--r--main.h92
-rw-r--r--menu.c110
-rw-r--r--stm32f4xx_hal_conf.h147
-rw-r--r--stm32f4xx_it.c72
-rw-r--r--stm32f4xx_it.h44
-rw-r--r--system_stm32f4xx.c310
-rw-r--r--usbh_conf.c434
-rw-r--r--usbh_conf.h114
11 files changed, 1388 insertions, 324 deletions
diff --git a/base.c b/base.c
deleted file mode 100644
index 8c9de6f..0000000
--- a/base.c
+++ /dev/null
@@ -1,20 +0,0 @@
-
-#include <unistd.h>
-
-int __errno = 0;
-void *_impure_ptr = NULL;
-
-void __sinit(void) {
-}
-
-void memset(void *s, int c, size_t n) {
- char *end = (char *)s + n;
- for (char *p = (char *)s; p < end; p++)
- *p = (char)c;
-}
-
-size_t strlen(const char *s) {
- const char *start = s;
- while (*s++);
- return s - start - 1;
-}
diff --git a/keyboard.c b/keyboard.c
new file mode 100644
index 0000000..6a3f44a
--- /dev/null
+++ b/keyboard.c
@@ -0,0 +1,73 @@
+/**
+ ******************************************************************************
+ * @file USB_Host/HID_Standalone/Src/keyboard.c
+ * @author MCD Application Team
+ * @version V1.1.0
+ * @date 17-February-2017
+ * @brief This file implements the HID keyboard functions
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics International N.V.
+ * All rights reserved.</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted, provided that the following conditions are met:
+ *
+ * 1. Redistribution 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 other
+ * contributors to this software may be used to endorse or promote products
+ * derived from this software without specific written permission.
+ * 4. This software, including modifications and/or derivative works of this
+ * software, must execute solely and exclusively on microcontroller or
+ * microprocessor devices manufactured by or for STMicroelectronics.
+ * 5. Redistribution and use of this software other than as permitted under
+ * this license is void and will automatically terminate your rights under
+ * this license.
+ *
+ * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
+ * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
+ * SHALL STMICROELECTRONICS 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.
+ *
+ ******************************************************************************
+ */
+#include "main.h"
+
+#define KYBRD_FIRST_COLUMN (uint16_t)7
+#define KYBRD_LAST_COLUMN (uint16_t)479
+#define KYBRD_FIRST_LINE (uint8_t)90
+#define SMALL_FONT_COLUMN_WIDTH 8
+#define SMALL_FONT_LINE_WIDTH 15
+#define KYBRD_LAST_LINE (uint16_t)200
+
+extern HID_DEMO_StateMachine hid_demo;
+uint8_t KeybrdCharXpos = 0;
+uint16_t KeybrdCharYpos = 0;
+
+static void USR_KEYBRD_Init(void);
+
+void HID_KeyboardMenuProcess(void) { USR_KEYBRD_Init(); }
+
+static void USR_KEYBRD_Init(void)
+{
+ uart_print("Keyboard initialized\n");
+}
+
+void USR_KEYBRD_ProcessData(uint8_t data)
+{
+ uart_putc(data);
+}
+
diff --git a/main.c b/main.c
index eb093c4..f0141f0 100644
--- a/main.c
+++ b/main.c
@@ -1,82 +1,214 @@
-
-#include <stm32f407xx.h>
-#include <stdint.h>
-#include <system_stm32f4xx.h>
-#include <stm32f4xx_ll_utils.h>
-#include <stm32f4xx_ll_spi.h>
-#include <string.h>
-#include <unistd.h>
-/*
- * Part number: STM32F030F4C6
- */
-
-void _init(void) {}
-
-void tick(void) {
- for(int i=0; i<50; i++)
- __asm__("nop");
-}
-
-int main(void) {
- /*
- RCC->CR |= RCC_CR_HSEON;
- while (!(RCC->CR&RCC_CR_HSERDY));
- RCC->CFGR &= ~RCC_CFGR_PLLMUL_Msk & ~RCC_CFGR_SW_Msk;
- RCC->CFGR |= (2<<RCC_CFGR_PLLMUL_Pos) | RCC_CFGR_PLLSRC_HSE_PREDIV;
- RCC->CFGR2 &= ~RCC_CFGR2_PREDIV_Msk;
- RCC->CFGR2 |= RCC_CFGR2_PREDIV_DIV2;
- RCC->CR |= RCC_CR_PLLON;
- while (!(RCC->CR&RCC_CR_PLLRDY));
- RCC->CFGR |= (2<<RCC_CFGR_SW_Pos);
- SystemCoreClockUpdate();
- */
-
- LL_Init1msTick(SystemCoreClock);
-
- RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
-
- GPIOA->MODER |=
- (1<<GPIO_MODER_MODER5_Pos)|
- (1<<GPIO_MODER_MODER6_Pos)|
- (1<<GPIO_MODER_MODER7_Pos);
-
- /* Set shift register IO GPIO output speed */
- GPIOA->OSPEEDR |=
- (2<<GPIO_OSPEEDR_OSPEED5_Pos)|
- (2<<GPIO_OSPEEDR_OSPEED6_Pos)|
- (2<<GPIO_OSPEEDR_OSPEED7_Pos);
-
- GPIOA->BSRR = GPIO_BSRR_BR_5;
- GPIOA->BSRR = GPIO_BSRR_BR_6;
- GPIOA->BSRR = GPIO_BSRR_BR_7;
- while (42) {
- for (int i=0; i<10000; i++)
- tick();
- GPIOA->BSRR = GPIO_BSRR_BS_5;
- GPIOA->BSRR = GPIO_BSRR_BS_6;
- GPIOA->BSRR = GPIO_BSRR_BS_7;
- for (int i=0; i<10000; i++)
- tick();
- GPIOA->BSRR = GPIO_BSRR_BR_5;
- GPIOA->BSRR = GPIO_BSRR_BR_6;
- GPIOA->BSRR = GPIO_BSRR_BR_7;
- }
-}
-
-void NMI_Handler(void) {
-}
-
-void HardFault_Handler(void) {
- for(;;);
-}
-
-void SVC_Handler(void) {
-}
-
-
-void PendSV_Handler(void) {
-}
-
-void SysTick_Handler(void) {
-}
-
+/**
+ ******************************************************************************
+ * @file USB_Host/HID_Standalone/Src/main.c
+ * @author MCD Application Team
+ * @version V1.1.0
+ * @date 17-February-2017
+ * @brief USB host HID Mouse and Keyboard demo main file
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics International N.V.
+ * All rights reserved.</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted, provided that the following conditions are met:
+ *
+ * 1. Redistribution 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 other
+ * contributors to this software may be used to endorse or promote products
+ * derived from this software without specific written permission.
+ * 4. This software, including modifications and/or derivative works of this
+ * software, must execute solely and exclusively on microcontroller or
+ * microprocessor devices manufactured by or for STMicroelectronics.
+ * 5. Redistribution and use of this software other than as permitted under
+ * this license is void and will automatically terminate your rights under
+ * this license.
+ *
+ * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
+ * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
+ * SHALL STMICROELECTRONICS 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.
+ *
+ ******************************************************************************
+ */
+#include "main.h"
+
+USBH_HandleTypeDef hUSBHost;
+HID_ApplicationTypeDef Appli_state = APPLICATION_IDLE;
+
+static void SystemClock_Config(void);
+static void USBH_UserProcess(USBH_HandleTypeDef* phost, uint8_t id);
+static void HID_InitApplication(void);
+static void Error_Handler(void);
+
+int main(void)
+{
+ HAL_Init();
+ SystemClock_Config();
+ HID_InitApplication();
+ USBH_Init(&hUSBHost, USBH_UserProcess, 0);
+ USBH_RegisterClass(&hUSBHost, USBH_HID_CLASS);
+ USBH_Start(&hUSBHost);
+
+ while (1) {
+ USBH_Process(&hUSBHost);
+ HID_MenuProcess();
+ }
+}
+
+static void HID_InitApplication(void)
+{
+ BSP_LED_Init(LED1);
+ BSP_LED_Init(LED2);
+ BSP_LED_Init(LED3);
+ BSP_LED_Init(LED4);
+
+ BSP_PB_Init(BUTTON_WAKEUP, BUTTON_MODE_GPIO);
+
+ HID_MenuInit();
+}
+
+static void USBH_UserProcess(USBH_HandleTypeDef* phost, uint8_t id)
+{
+ switch (id) {
+ case HOST_USER_SELECT_CONFIGURATION:
+ break;
+
+ case HOST_USER_DISCONNECTION:
+ Appli_state = APPLICATION_DISCONNECT;
+ break;
+
+ case HOST_USER_CLASS_ACTIVE:
+ Appli_state = APPLICATION_READY;
+ break;
+
+ case HOST_USER_CONNECTION:
+ Appli_state = APPLICATION_START;
+ break;
+
+ default:
+ break;
+ }
+}
+
+void Toggle_Leds(void)
+{
+ static uint32_t ticks;
+
+ if (ticks++ == 100) {
+ BSP_LED_Toggle(LED1);
+ BSP_LED_Toggle(LED2);
+ BSP_LED_Toggle(LED3);
+ BSP_LED_Toggle(LED4);
+ ticks = 0;
+ }
+}
+
+/**
+ * @brief System Clock Configuration
+ * The system Clock is configured as follow :
+ * System Clock source = PLL (HSE)
+ * SYSCLK(Hz) = 180000000
+ * HCLK(Hz) = 180000000
+ * AHB Prescaler = 1
+ * APB1 Prescaler = 4
+ * APB2 Prescaler = 2
+ * HSE Frequency(Hz) = 8000000
+ * PLL_M = 8
+ * PLL_N = 360
+ * PLL_P = 2
+ * PLL_Q = 7
+ * PLL_R = 2
+ * VDD(V) = 3.3
+ * Main regulator output voltage = Scale1 mode
+ * Flash Latency(WS) = 5
+ * The USB clock configuration from PLLSAI:
+ * PLLSAIM = 8
+ * PLLSAIN = 384
+ * PLLSAIP = 8
+ * @param None
+ * @retval None
+ */
+static void SystemClock_Config(void)
+{
+ RCC_ClkInitTypeDef RCC_ClkInitStruct;
+ RCC_OscInitTypeDef RCC_OscInitStruct;
+ RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
+
+ /* Enable Power Control clock */
+ __HAL_RCC_PWR_CLK_ENABLE();
+
+ /* The voltage scaling allows optimizing the power consumption when the device
+ is
+ clocked below the maximum system frequency, to update the voltage scaling
+ value
+ regarding system frequency refer to product datasheet. */
+ __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
+
+ /* Enable HSE Oscillator and activate PLL with HSE as source */
+ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
+ RCC_OscInitStruct.HSEState = RCC_HSE_ON;
+ RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
+ RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
+#if defined(USE_STM32469I_DISCO_REVA)
+ RCC_OscInitStruct.PLL.PLLM = 25;
+#else
+ RCC_OscInitStruct.PLL.PLLM = 8;
+#endif /* USE_STM32469I_DISCO_REVA */
+ RCC_OscInitStruct.PLL.PLLN = 360;
+ RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
+ RCC_OscInitStruct.PLL.PLLQ = 7;
+ RCC_OscInitStruct.PLL.PLLR = 2;
+ if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
+ Error_Handler();
+
+ /* Enable the OverDrive to reach the 180 Mhz Frequency */
+ if (HAL_PWREx_EnableOverDrive() != HAL_OK)
+ Error_Handler();
+
+ /* Select PLLSAI output as USB clock source */
+ PeriphClkInitStruct.PLLSAI.PLLSAIQ = 7;
+ PeriphClkInitStruct.PLLSAI.PLLSAIN = 384;
+ PeriphClkInitStruct.PLLSAI.PLLSAIP = RCC_PLLSAIP_DIV8;
+ PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_CK48;
+ PeriphClkInitStruct.Clk48ClockSelection = RCC_CK48CLKSOURCE_PLLSAIP;
+ HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
+
+ /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
+ clocks dividers */
+ RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
+ RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
+ RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
+ RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
+ RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
+ if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
+ Error_Handler();
+}
+
+void HAL_Delay(__IO uint32_t Delay)
+{
+ while (Delay) {
+ if (SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk)
+ Delay--;
+ }
+}
+
+static void Error_Handler(void)
+{
+ while (1)
+ ;
+}
+
diff --git a/main.h b/main.h
new file mode 100644
index 0000000..948652a
--- /dev/null
+++ b/main.h
@@ -0,0 +1,92 @@
+/**
+ ******************************************************************************
+ * @file USB_Host/HID_Standalone/Inc/main.h
+ * @author MCD Application Team
+ * @version V1.1.0
+ * @date 17-February-2017
+ * @brief Header for main.c module
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics International N.V.
+ * All rights reserved.</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted, provided that the following conditions are met:
+ *
+ * 1. Redistribution 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 other
+ * contributors to this software may be used to endorse or promote products
+ * derived from this software without specific written permission.
+ * 4. This software, including modifications and/or derivative works of this
+ * software, must execute solely and exclusively on microcontroller or
+ * microprocessor devices manufactured by or for STMicroelectronics.
+ * 5. Redistribution and use of this software other than as permitted under
+ * this license is void and will automatically terminate your rights under
+ * this license.
+ *
+ * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
+ * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
+ * SHALL STMICROELECTRONICS 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.
+ *
+ ******************************************************************************
+ */
+#ifndef __MAIN_H
+#define __MAIN_H
+
+#include "stdio.h"
+#include "usbh_core.h"
+#include "usbh_hid.h"
+#include "usbh_hid_parser.h"
+
+typedef enum {
+ HID_DEMO_START = 0,
+ HID_DEMO_KEYBOARD,
+} HID_Demo_State;
+
+typedef enum {
+ HID_KEYBOARD_IDLE = 0,
+ HID_KEYBOARD_WAIT,
+ HID_KEYBOARD_START,
+} HID_keyboard_State;
+
+typedef struct _DemoStateMachine {
+ __IO HID_Demo_State state;
+ __IO HID_keyboard_State keyboard_state;
+ __IO uint8_t select;
+ __IO uint8_t lock;
+} HID_DEMO_StateMachine;
+
+typedef enum {
+ APPLICATION_IDLE = 0,
+ APPLICATION_DISCONNECT,
+ APPLICATION_START,
+ APPLICATION_READY,
+ APPLICATION_RUNNING,
+} HID_ApplicationTypeDef;
+
+extern USBH_HandleTypeDef hUSBHost;
+extern HID_ApplicationTypeDef Appli_state;
+extern HID_DEMO_StateMachine hid_demo;
+
+void Toggle_Leds(void);
+void HID_SelectItem(uint8_t** menu, uint8_t item);
+void HID_MenuInit(void);
+void HID_MenuProcess(void);
+void HID_KeyboardMenuProcess(void);
+void USR_KEYBRD_ProcessData(uint8_t data);
+
+#endif
diff --git a/menu.c b/menu.c
new file mode 100644
index 0000000..60a59e9
--- /dev/null
+++ b/menu.c
@@ -0,0 +1,110 @@
+/**
+ ******************************************************************************
+ * @file USB_Host/HID_Standalone/Src/menu.c
+ * @author MCD Application Team
+ * @version V1.1.0
+ * @date 17-February-2017
+ * @brief This file implements Menu Functions
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics International N.V.
+ * All rights reserved.</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted, provided that the following conditions are met:
+ *
+ * 1. Redistribution 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 other
+ * contributors to this software may be used to endorse or promote products
+ * derived from this software without specific written permission.
+ * 4. This software, including modifications and/or derivative works of this
+ * software, must execute solely and exclusively on microcontroller or
+ * microprocessor devices manufactured by or for STMicroelectronics.
+ * 5. Redistribution and use of this software other than as permitted under
+ * this license is void and will automatically terminate your rights under
+ * this license.
+ *
+ * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
+ * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
+ * SHALL STMICROELECTRONICS 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.
+ *
+ ******************************************************************************
+ */
+/* Includes ------------------------------------------------------------------*/
+#include "main.h"
+
+HID_DEMO_StateMachine hid_demo;
+
+static void USBH_KeybdDemo(USBH_HandleTypeDef* phost);
+
+void HID_MenuInit(void)
+{
+ uart_print("Starting HID Demo");
+ hid_demo.state = HID_DEMO_START;
+ HID_MenuProcess();
+}
+
+void HID_MenuProcess(void)
+{
+ switch (hid_demo.state) {
+ case HID_DEMO_START:
+ if (Appli_state == APPLICATION_READY) {
+ if (USBH_HID_GetDeviceType(&hUSBHost) == HID_KEYBOARD) {
+ hid_demo.keyboard_state = HID_KEYBOARD_IDLE;
+ hid_demo.state = HID_DEMO_KEYBOARD;
+
+ uart_print("HID initialized");
+
+ HID_KeyboardMenuProcess();
+ } else {
+ uart_print("Unsupported HID device!\n");
+ hid_demo.state = HID_DEMO_START;
+ }
+ }
+ break;
+
+ case HID_DEMO_KEYBOARD:
+ if (Appli_state == APPLICATION_READY) {
+ USBH_KeybdDemo(&hUSBHost);
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ if (Appli_state == APPLICATION_DISCONNECT) {
+ Appli_state = APPLICATION_IDLE;
+ uart_print("HID device disconnected\n");
+ hid_demo.state = HID_DEMO_START;
+ hid_demo.select = 0;
+ }
+}
+
+static void USBH_KeybdDemo(USBH_HandleTypeDef* phost)
+{
+ HID_KEYBD_Info_TypeDef* k_pinfo;
+ char c;
+ k_pinfo = USBH_HID_GetKeybdInfo(phost);
+
+ if (k_pinfo != NULL) {
+ c = USBH_HID_GetASCIICode(k_pinfo);
+ if (c != 0) {
+ USR_KEYBRD_ProcessData(c);
+ }
+ }
+}
diff --git a/stm32f4xx_hal_conf.h b/stm32f4xx_hal_conf.h
new file mode 100644
index 0000000..00c13ab
--- /dev/null
+++ b/stm32f4xx_hal_conf.h
@@ -0,0 +1,147 @@
+/**
+ ******************************************************************************
+ * @file USB_Host/HID_Standalone/Inc/stm32f4xx_hal_conf.h
+ * @author MCD Application Team
+ * @version V1.1.0
+ * @date 17-February-2017
+ * @brief HAL configuration file.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT(c) 2017 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.
+ *
+ ******************************************************************************
+ */
+
+#ifndef __STM32F4xx_HAL_CONF_H
+#define __STM32F4xx_HAL_CONF_H
+
+#define HAL_MODULE_ENABLED
+
+#define HAL_DMA_MODULE_ENABLED
+#include "stm32f4xx_hal_dma.h"
+
+#define HAL_DMA2D_MODULE_ENABLED
+#include "stm32f4xx_hal_dma2d.h"
+
+#define HAL_FLASH_MODULE_ENABLED
+#include "stm32f4xx_hal_flash.h"
+
+#define HAL_SRAM_MODULE_ENABLED
+#include "stm32f4xx_hal_sram.h"
+
+#define HAL_SDRAM_MODULE_ENABLED
+#include "stm32f4xx_hal_sdram.h"
+
+#define HAL_GPIO_MODULE_ENABLED
+#include "stm32f4xx_hal_gpio.h"
+
+#define HAL_I2C_MODULE_ENABLED
+#include "stm32f4xx_hal_i2c.h"
+
+#define HAL_LTDC_MODULE_ENABLED
+#include "stm32f4xx_hal_ltdc.h"
+
+#define HAL_DSI_MODULE_ENABLED
+#include "stm32f4xx_hal_dsi.h"
+
+#define HAL_PWR_MODULE_ENABLED
+#include "stm32f4xx_hal_pwr.h"
+
+#define HAL_RCC_MODULE_ENABLED
+#include "stm32f4xx_hal_rcc.h"
+
+#define HAL_UART_MODULE_ENABLED
+#include "stm32f4xx_hal_uart.h"
+
+#define HAL_CORTEX_MODULE_ENABLED
+#include "stm32f4xx_hal_cortex.h"
+
+#define HAL_HCD_MODULE_ENABLED
+#include "stm32f4xx_hal_hcd.h"
+
+#define HAL_FMPI2C_MODULE_ENABLED
+#include "stm32f4xx_hal_fmpi2c.h"
+
+#if !defined(HSE_VALUE)
+#if defined(USE_STM32469I_DISCO_REVA)
+#define HSE_VALUE \
+ 25000000U /*!< Default value of the External oscillator in Hz */
+#else
+#define HSE_VALUE \
+ 8000000U /*!< Default value of the External oscillator in Hz */
+#endif /* USE_STM32469I_DISCO_REVA */
+#endif /* HSE_VALUE */
+
+#if !defined(HSE_STARTUP_TIMEOUT)
+#define HSE_STARTUP_TIMEOUT 100U /*!< Time out for HSE start up, in ms */
+#endif
+
+/* 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 16000000U
+#endif
+
+/* Internal Low Speed oscillator (LSI) value. */
+#if !defined(LSI_VALUE)
+#define LSI_VALUE 32000U
+#endif
+
+/* External Low Speed oscillator (LSE) value. */
+#if !defined(LSE_VALUE)
+#define LSE_VALUE 32768U
+#endif
+
+#if !defined(LSE_STARTUP_TIMEOUT)
+#define LSE_STARTUP_TIMEOUT 5000U
+#endif
+
+/* External clock source for I2S peripheral This value is used by the I2S HAL module to compute the I2S clock source
+ * frequency, this source is inserted directly through I2S_CKIN pad. */
+#if !defined(EXTERNAL_CLOCK_VALUE)
+#define EXTERNAL_CLOCK_VALUE 12288000U
+#endif
+
+/* For the HAL */
+#define VDD_VALUE 3300U
+#define TICK_INT_PRIORITY 0x00U
+#define USE_RTOS 0
+#define PREFETCH_ENABLE 1
+#define INSTRUCTION_CACHE_ENABLE 1
+#define DATA_CACHE_ENABLE 1
+
+#define USE_SPI_CRC 1U
+
+#define assert_param(expr) ((void)0U)
+
+#endif
diff --git a/stm32f4xx_it.c b/stm32f4xx_it.c
new file mode 100644
index 0000000..cbbc7fd
--- /dev/null
+++ b/stm32f4xx_it.c
@@ -0,0 +1,72 @@
+/**
+ ******************************************************************************
+ * @file USB_Host/HID_Standalone/Src/stm32f4xx_it.c
+ * @author MCD Application Team
+ * @version V1.1.0
+ * @date 17-February-2017
+ * @brief Main Interrupt Service Routines.
+ * This file provides template for all exceptions handler and
+ * peripherals interrupt service routine.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT(c) 2017 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.
+ *
+ ******************************************************************************
+ */
+
+#include "stm32f4xx_it.h"
+
+extern HCD_HandleTypeDef hhcd;
+
+void NMI_Handler(void) {}
+
+void HardFault_Handler(void)
+{
+ while (1)
+ ;
+}
+
+void MemManage_Handler(void)
+{
+ while (1)
+ ;
+}
+
+void BusFault_Handler(void)
+{
+ while (1)
+ ;
+}
+
+void UsageFault_Handler(void)
+{
+ while (1)
+ ;
+}
+
+void SVC_Handler(void) {}
+
+void DebugMon_Handler(void) {}
+
+void PendSV_Handler(void) {}
+
+void SysTick_Handler(void) {
+ HAL_IncTick();
+}
+
+void OTG_FS_IRQHandler(void) {
+ HAL_HCD_IRQHandler(&hhcd);
+}
diff --git a/stm32f4xx_it.h b/stm32f4xx_it.h
new file mode 100644
index 0000000..eec1994
--- /dev/null
+++ b/stm32f4xx_it.h
@@ -0,0 +1,44 @@
+/**
+ ******************************************************************************
+ * @file USB_Host/HID_Standalone/Inc/stm32f4xx_it.h
+ * @author MCD Application Team
+ * @version V1.1.0
+ * @date 17-February-2017
+ * @brief This file contains the headers of the interrupt handlers.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT(c) 2017 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.
+ *
+ ******************************************************************************
+ */
+
+#ifndef __STM32F4xx_IT_H
+#define __STM32F4xx_IT_H
+
+#include "main.h"
+
+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 OTG_FS_IRQHandler(void);
+
+#endif
diff --git a/system_stm32f4xx.c b/system_stm32f4xx.c
index 854bc35..d00e5aa 100644
--- a/system_stm32f4xx.c
+++ b/system_stm32f4xx.c
@@ -1,22 +1,25 @@
/**
******************************************************************************
- * @file Demonstrations/Src/system_stm32f4xx.c
+ * @file system_stm32f4xx.c
* @author MCD Application Team
- * @version V1.4.4
+ * @version V1.1.0
* @date 17-February-2017
* @brief CMSIS Cortex-M4 Device Peripheral Access Layer System Source File.
*
- * This file provides two functions and one global variable to be called from
+ * This file provides two functions and one global variable to be called from
* user application:
- * - SystemInit(): This function is called at startup just after reset and
+ * - SystemInit(): This function is called at startup just after reset and
* before branch to main program. This call is made inside
* the "startup_stm32f4xx.s" file.
*
- * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
- * by the user application to setup the SysTick
+ * - 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
+ *
+ * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and
+ *must
* be called whenever the core clock is changed
* during program execution.
*
@@ -24,255 +27,118 @@
******************************************************************************
* @attention
*
- * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
+ * <h2><center>&copy; COPYRIGHT 2017 STMicroelectronics</center></h2>
*
- * Redistribution and use in source and binary forms, with or without modification,
+ * 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
+ * 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
+ * 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
+ * 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
+ * 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.
*
******************************************************************************
*/
-/** @addtogroup CMSIS
- * @{
- */
-
-/** @addtogroup stm32f4xx_system
- * @{
- */
-
-/** @addtogroup STM32F4xx_System_Private_Includes
- * @{
- */
-
#include "stm32f4xx.h"
-#if !defined (HSE_VALUE)
- #define HSE_VALUE ((uint32_t)8000000) /*!< Default value of the External oscillator in Hz */
+#if !defined(HSE_VALUE)
+#if defined(USE_STM32469I_DISCO_REVA)
+#define HSE_VALUE \
+ ((uint32_t)25000000) /*!< Default value of the External oscillator in Hz */
+#else
+#define HSE_VALUE \
+ ((uint32_t)8000000) /*!< Default value of the External oscillator in Hz */
+#endif /* USE_STM32469I_DISCO_REVA */
#endif /* HSE_VALUE */
-#if !defined (HSI_VALUE)
- #define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/
+#if !defined(HSI_VALUE)
+#define HSI_VALUE \
+ ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI_VALUE */
-/**
- * @}
- */
-
-/** @addtogroup STM32F4xx_System_Private_TypesDefinitions
- * @{
- */
-
-/**
- * @}
- */
-
-/** @addtogroup STM32F4xx_System_Private_Defines
- * @{
- */
-
-/************************* Miscellaneous Configuration ************************/
-
-/*!< Uncomment the following line if you need to relocate your vector Table in
- Internal SRAM. */
-/* #define VECT_TAB_SRAM */
-#define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field.
- This value must be a multiple of 0x200. */
-/******************************************************************************/
-
-/**
- * @}
- */
-
-/** @addtogroup STM32F4xx_System_Private_Macros
- * @{
- */
-
-/**
- * @}
- */
+#define VECT_TAB_OFFSET 0x00 /* This value must be a multiple of 0x200. */
-/** @addtogroup STM32F4xx_System_Private_Variables
- * @{
- */
- /* This variable is updated in three ways:
- 1) by calling CMSIS function SystemCoreClockUpdate()
- 2) by calling HAL API function HAL_RCC_GetHCLKFreq()
- 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
- Note: If you use this function to configure the system clock; then there
- is no need to call the 2 first functions listed above, since SystemCoreClock
- variable is updated automatically.
- */
+/* The following variable is updated in three ways:
+ 1) by calling CMSIS function SystemCoreClockUpdate()
+ 2) by calling HAL API function HAL_RCC_GetHCLKFreq()
+ 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
+ Note: If you use this function to configure the system clock; then there is no need to call the 2 first functions
+ listed above, since the SystemCoreClock variable is updated automatically. */
uint32_t SystemCoreClock = 16000000;
-const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
-const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4};
-/**
- * @}
- */
-
-/** @addtogroup STM32F4xx_System_Private_FunctionPrototypes
- * @{
- */
-
-/**
- * @}
- */
-
-/** @addtogroup STM32F4xx_System_Private_Functions
- * @{
- */
+const uint8_t AHBPrescTable[16] = { 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 2, 3, 4, 6, 7, 8, 9 };
+const uint8_t APBPrescTable[8] = { 0, 0, 0, 0, 1, 2, 3, 4 };
-/**
- * @brief Setup the microcontroller system
- * Initialize the FPU setting, vector table location and External memory
- * configuration.
- * @param None
- * @retval None
- */
+/* Setup the microcontroller system: Initialize the FPU setting, vector table location and External memory configuration. */
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 = 0x00000000;
-
- /* Reset HSEON, CSSON and PLLON bits */
- RCC->CR &= (uint32_t)0xFEF6FFFF;
-
- /* Reset PLLCFGR register */
- RCC->PLLCFGR = 0x24003010;
-
- /* Reset HSEBYP bit */
- RCC->CR &= (uint32_t)0xFFFBFFFF;
-
- /* Disable all interrupts */
- RCC->CIR = 0x00000000;
-
- /* Configure the Vector Table location add offset address ------------------*/
-#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 */
+#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 */
+ RCC->CR |= (uint32_t)0x00000001; /* Set HSION bit */
+ RCC->CFGR = 0x00000000; /* Reset CFGR register */
+ RCC->CR &= (uint32_t)0xFEF6FFFF; /* Reset HSEON, CSSON and PLLON bits */
+ RCC->PLLCFGR = 0x24003010; /* Reset PLLCFGR register */
+ RCC->CR &= (uint32_t)0xFFFBFFFF; /* Reset HSEBYP bit */
+ RCC->CIR = 0x00000000; /* Disable all interrupts */
+
+ SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
}
-/**
- * @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 stm32f4xx_hal_conf.h file (default value
- * 16 MHz) but the real value may vary depending on the variations
- * in voltage and temperature.
- *
- * (**) HSE_VALUE is a constant defined in stm32f4xx_hal_conf.h file (its value
- * depends on the application requirements), 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
- */
+/* 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. */
void SystemCoreClockUpdate(void)
{
- uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2;
-
- /* Get SYSCLK source -------------------------------------------------------*/
- tmp = RCC->CFGR & RCC_CFGR_SWS;
-
- switch (tmp)
- {
- case 0x00: /* HSI used as system clock source */
- SystemCoreClock = HSI_VALUE;
- break;
- case 0x04: /* HSE used as system clock source */
- SystemCoreClock = HSE_VALUE;
- break;
- case 0x08: /* PLL used as system clock source */
-
- /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N
- SYSCLK = PLL_VCO / PLL_P
- */
- pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
- pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
-
- if (pllsource != 0)
- {
- /* HSE used as PLL clock source */
- pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
- }
- else
- {
- /* HSI used as PLL clock source */
- pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
- }
-
- pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2;
- SystemCoreClock = pllvco/pllp;
- break;
+ switch (RCC->CFGR & RCC_CFGR_SWS) {
+ case 0x00: /* HSI */
+ SystemCoreClock = HSI_VALUE;
+ break;
+ case 0x04: /* HSE */
+ SystemCoreClock = HSE_VALUE;
+ break;
+ case 0x08: /* PLL */
+ /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N
+ SYSCLK = PLL_VCO / PLL_P */
+ uint32_t pllvco;
+ uint32_t pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
+ uint32_t pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
+ if (pllsource != 0) /* HSE */
+ pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
+ else /* HSI */
+ pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
+
+ uint32_t pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >> 16) + 1) * 2;
+ SystemCoreClock = pllvco / pllp;
+ break;
default:
- SystemCoreClock = HSI_VALUE;
- break;
- }
- /* Compute HCLK frequency --------------------------------------------------*/
- /* Get HCLK prescaler */
- tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
- /* HCLK frequency */
- SystemCoreClock >>= tmp;
+ SystemCoreClock = HSI_VALUE;
+ break;
+ }
+ /* Compute HCLK frequency */
+ tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
+ SystemCoreClock >>= tmp;
}
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/usbh_conf.c b/usbh_conf.c
new file mode 100644
index 0000000..851c4ff
--- /dev/null
+++ b/usbh_conf.c
@@ -0,0 +1,434 @@
+/**
+ ******************************************************************************
+ * @file USB_Host/HID_Standalone/Src/usbh_conf.c
+ * @author MCD Application Team
+ * @version V1.1.0
+ * @date 17-February-2017
+ * @brief USB Host configuration file.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics International N.V.
+ * All rights reserved.</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted, provided that the following conditions are met:
+ *
+ * 1. Redistribution 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 other
+ * contributors to this software may be used to endorse or promote products
+ * derived from this software without specific written permission.
+ * 4. This software, including modifications and/or derivative works of this
+ * software, must execute solely and exclusively on microcontroller or
+ * microprocessor devices manufactured by or for STMicroelectronics.
+ * 5. Redistribution and use of this software other than as permitted under
+ * this license is void and will automatically terminate your rights under
+ * this license.
+ *
+ * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
+ * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
+ * SHALL STMICROELECTRONICS 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.
+ *
+ ******************************************************************************
+ */
+/* Includes ------------------------------------------------------------------*/
+#include "stm32f4xx_hal.h"
+#include "usbh_core.h"
+
+HCD_HandleTypeDef hhcd;
+
+/*******************************************************************************
+ HCD BSP Routines
+*******************************************************************************/
+/**
+ * @brief Initializes the HCD MSP.
+ * @param hhcd: HCD handle
+ * @retval None
+ */
+void HAL_HCD_MspInit(HCD_HandleTypeDef* hhcd)
+{
+ GPIO_InitTypeDef GPIO_InitStruct;
+
+ /* Configure USB FS GPIOs */
+ __HAL_RCC_GPIOA_CLK_ENABLE();
+
+ GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
+ GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
+ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+
+ GPIO_InitStruct.Pin = GPIO_PIN_10;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
+ GPIO_InitStruct.Pull = GPIO_PULLUP;
+ GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
+ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+
+ /* Configure POWER_SWITCH IO pin */
+ __HAL_RCC_GPIOB_CLK_ENABLE();
+ GPIO_InitStruct.Pin = GPIO_PIN_2;
+ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+
+ /* Enable USB FS Clocks */
+ __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
+
+ /* Set USBFS Interrupt priority */
+ HAL_NVIC_SetPriority(OTG_FS_IRQn, 6, 0);
+
+ /* Enable USBFS Interrupt */
+ HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
+}
+
+/**
+ * @brief DeInitializes the HCD MSP.
+ * @param hhcd: HCD handle
+ * @retval None
+ */
+void HAL_HCD_MspDeInit(HCD_HandleTypeDef* hhcd)
+{
+ /* Disable USB FS Clocks */
+ __HAL_RCC_USB_OTG_FS_CLK_DISABLE();
+}
+
+/*******************************************************************************
+ LL Driver Callbacks (HCD -> USB Host Library)
+*******************************************************************************/
+
+/**
+ * @brief SOF callback.
+ * @param hhcd: HCD handle
+ * @retval None
+ */
+void HAL_HCD_SOF_Callback(HCD_HandleTypeDef* hhcd)
+{
+ USBH_LL_IncTimer(hhcd->pData);
+}
+
+/**
+ * @brief Connect callback.
+ * @param hhcd: HCD handle
+ * @retval None
+ */
+void HAL_HCD_Connect_Callback(HCD_HandleTypeDef* hhcd)
+{
+ USBH_LL_Connect(hhcd->pData);
+}
+
+/**
+ * @brief Disconnect callback.
+ * @param hhcd: HCD handle
+ * @retval None
+ */
+void HAL_HCD_Disconnect_Callback(HCD_HandleTypeDef* hhcd)
+{
+ USBH_LL_Disconnect(hhcd->pData);
+}
+
+/**
+ * @brief Notify URB state change callback.
+ * @param hhcd: HCD handle
+ * @param chnum: Channel number
+ * @param urb_state: URB State
+ * @retval None
+ */
+void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef* hhcd, uint8_t chnum,
+ HCD_URBStateTypeDef urb_state)
+{
+ /* To be used with OS to sync URB state with the global state machine */
+}
+
+/*******************************************************************************
+ LL Driver Interface (USB Host Library --> HCD)
+*******************************************************************************/
+/**
+ * @brief USBH_LL_Init
+ * Initialize the Low Level portion of the Host driver.
+ * @param phost: Host handle
+ * @retval USBH Status
+ */
+USBH_StatusTypeDef USBH_LL_Init(USBH_HandleTypeDef* phost)
+{
+ /* Set the LL Driver parameters */
+ hhcd.Instance = USB_OTG_FS;
+ hhcd.Init.Host_channels = 11;
+ hhcd.Init.dma_enable = 0;
+ hhcd.Init.low_power_enable = 0;
+ hhcd.Init.phy_itface = HCD_PHY_EMBEDDED;
+ hhcd.Init.Sof_enable = 0;
+ hhcd.Init.speed = HCD_SPEED_FULL;
+ hhcd.Init.vbus_sensing_enable = 0;
+ hhcd.Init.lpm_enable = 0;
+
+ /* Link the driver to the stack */
+ hhcd.pData = phost;
+ phost->pData = &hhcd;
+
+ /* Initialize the LL Driver */
+ HAL_HCD_Init(&hhcd);
+
+ USBH_LL_SetTimer(phost, HAL_HCD_GetCurrentFrame(&hhcd));
+
+ return USBH_OK;
+}
+
+/**
+ * @brief De-Initializes the Low Level portion of the Host driver.
+ * @param phost: Host handle
+ * @retval USBH Status
+ */
+USBH_StatusTypeDef USBH_LL_DeInit(USBH_HandleTypeDef* phost)
+{
+ HAL_HCD_DeInit(phost->pData);
+ return USBH_OK;
+}
+
+/**
+ * @brief Starts the Low Level portion of the Host driver.
+ * @param phost: Host handle
+ * @retval USBH Status
+ */
+USBH_StatusTypeDef USBH_LL_Start(USBH_HandleTypeDef* phost)
+{
+ HAL_HCD_Start(phost->pData);
+ return USBH_OK;
+}
+
+/**
+ * @brief Stops the Low Level portion of the Host driver.
+ * @param phost: Host handle
+ * @retval USBH Status
+ */
+USBH_StatusTypeDef USBH_LL_Stop(USBH_HandleTypeDef* phost)
+{
+ HAL_HCD_Stop(phost->pData);
+ return USBH_OK;
+}
+
+/**
+ * @brief Returns the USB Host Speed from the Low Level Driver.
+ * @param phost: Host handle
+ * @retval USBH Speeds
+ */
+USBH_SpeedTypeDef USBH_LL_GetSpeed(USBH_HandleTypeDef* phost)
+{
+ USBH_SpeedTypeDef speed = USBH_SPEED_FULL;
+
+ switch (HAL_HCD_GetCurrentSpeed(phost->pData)) {
+ case 0:
+ speed = USBH_SPEED_HIGH;
+ break;
+
+ case 1:
+ speed = USBH_SPEED_FULL;
+ break;
+
+ case 2:
+ speed = USBH_SPEED_LOW;
+ break;
+
+ default:
+ speed = USBH_SPEED_FULL;
+ break;
+ }
+ return speed;
+}
+
+/**
+ * @brief Resets the Host Port of the Low Level Driver.
+ * @param phost: Host handle
+ * @retval USBH Status
+ */
+USBH_StatusTypeDef USBH_LL_ResetPort(USBH_HandleTypeDef* phost)
+{
+ HAL_HCD_ResetPort(phost->pData);
+ return USBH_OK;
+}
+
+/**
+ * @brief Returns the last transferred packet size.
+ * @param phost: Host handle
+ * @param pipe: Pipe index
+ * @retval Packet Size
+ */
+uint32_t USBH_LL_GetLastXferSize(USBH_HandleTypeDef* phost, uint8_t pipe)
+{
+ return HAL_HCD_HC_GetXferCount(phost->pData, pipe);
+}
+
+/**
+ * @brief Opens a pipe of the Low Level Driver.
+ * @param phost: Host handle
+ * @param pipe: Pipe index
+ * @param epnum: Endpoint Number
+ * @param dev_address: Device USB address
+ * @param speed: Device Speed
+ * @param ep_type: Endpoint Type
+ * @param mps: Endpoint Max Packet Size
+ * @retval USBH Status
+ */
+USBH_StatusTypeDef USBH_LL_OpenPipe(USBH_HandleTypeDef* phost, uint8_t pipe,
+ uint8_t epnum, uint8_t dev_address,
+ uint8_t speed, uint8_t ep_type,
+ uint16_t mps)
+{
+ HAL_HCD_HC_Init(phost->pData, pipe, epnum, dev_address, speed, ep_type, mps);
+ return USBH_OK;
+}
+
+/**
+ * @brief Closes a pipe of the Low Level Driver.
+ * @param phost: Host handle
+ * @param pipe: Pipe index
+ * @retval USBH Status
+ */
+USBH_StatusTypeDef USBH_LL_ClosePipe(USBH_HandleTypeDef* phost, uint8_t pipe)
+{
+ HAL_HCD_HC_Halt(phost->pData, pipe);
+ return USBH_OK;
+}
+
+/**
+ * @brief Submits a new URB to the low level driver.
+ * @param phost: Host handle
+ * @param pipe: Pipe index
+ * This parameter can be a value from 1 to 15
+ * @param direction: Channel number
+ * This parameter can be one of these values:
+ * 0: Output
+ * 1: Input
+ * @param ep_type: Endpoint Type
+ * This parameter can be one of these values:
+ * @arg EP_TYPE_CTRL: Control type
+ * @arg EP_TYPE_ISOC: Isochronous type
+ * @arg EP_TYPE_BULK: Bulk type
+ * @arg EP_TYPE_INTR: Interrupt type
+ * @param token: Endpoint Type
+ * This parameter can be one of these values:
+ * @arg 0: PID_SETUP
+ * @arg 1: PID_DATA
+ * @param pbuff: pointer to URB data
+ * @param length: length of URB data
+ * @param do_ping: activate do ping protocol (for high speed only)
+ * This parameter can be one of these values:
+ * 0: do ping inactive
+ * 1: do ping active
+ * @retval USBH Status
+ */
+USBH_StatusTypeDef USBH_LL_SubmitURB(USBH_HandleTypeDef* phost, uint8_t pipe,
+ uint8_t direction, uint8_t ep_type,
+ uint8_t token, uint8_t* pbuff,
+ uint16_t length, uint8_t do_ping)
+{
+ HAL_HCD_HC_SubmitRequest(phost->pData, pipe, direction, ep_type, token, pbuff,
+ length, do_ping);
+ return USBH_OK;
+}
+
+/**
+ * @brief Gets a URB state from the low level driver.
+ * @param phost: Host handle
+ * @param pipe: Pipe index
+ * This parameter can be a value from 1 to 15
+ * @retval URB state
+ * This parameter can be one of these values:
+ * @arg URB_IDLE
+ * @arg URB_DONE
+ * @arg URB_NOTREADY
+ * @arg URB_NYET
+ * @arg URB_ERROR
+ * @arg URB_STALL
+ */
+USBH_URBStateTypeDef USBH_LL_GetURBState(USBH_HandleTypeDef* phost,
+ uint8_t pipe)
+{
+ return (USBH_URBStateTypeDef)HAL_HCD_HC_GetURBState(phost->pData, pipe);
+}
+
+/**
+ * @brief Drives VBUS.
+ * @param phost: Host handle
+ * @param state: VBUS state
+ * This parameter can be one of these values:
+ * 0: VBUS Active
+ * 1: VBUS Inactive
+ * @retval USBH Status
+ */
+USBH_StatusTypeDef USBH_LL_DriverVBUS(USBH_HandleTypeDef* phost,
+ uint8_t state)
+{
+ if (state == 0) {
+ HAL_GPIO_WritePin(GPIOB, GPIO_PIN_2, GPIO_PIN_RESET);
+ } else {
+ HAL_GPIO_WritePin(GPIOB, GPIO_PIN_2, GPIO_PIN_SET);
+ }
+ HAL_Delay(200);
+ return USBH_OK;
+}
+
+/**
+ * @brief Sets toggle for a pipe.
+ * @param phost: Host handle
+ * @param pipe: Pipe index
+ * @param toggle: toggle (0/1)
+ * @retval USBH Status
+ */
+USBH_StatusTypeDef USBH_LL_SetToggle(USBH_HandleTypeDef* phost, uint8_t pipe,
+ uint8_t toggle)
+{
+ if (hhcd.hc[pipe].ep_is_in) {
+ hhcd.hc[pipe].toggle_in = toggle;
+ } else {
+ hhcd.hc[pipe].toggle_out = toggle;
+ }
+ return USBH_OK;
+}
+
+/**
+ * @brief Returns the current toggle of a pipe.
+ * @param phost: Host handle
+ * @param pipe: Pipe index
+ * @retval toggle (0/1)
+ */
+uint8_t USBH_LL_GetToggle(USBH_HandleTypeDef* phost, uint8_t pipe)
+{
+ uint8_t toggle = 0;
+
+ if (hhcd.hc[pipe].ep_is_in) {
+ toggle = hhcd.hc[pipe].toggle_in;
+ } else {
+ toggle = hhcd.hc[pipe].toggle_out;
+ }
+ return toggle;
+}
+
+/**
+ * @brief Delay routine for the USB Host Library
+ * @param Delay: Delay in ms
+ * @retval None
+ */
+void USBH_Delay(uint32_t Delay)
+{
+#if (USBH_USE_OS == 1)
+ osDelay(Delay);
+#else
+ HAL_Delay(Delay);
+#endif
+}
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/usbh_conf.h b/usbh_conf.h
new file mode 100644
index 0000000..da91b6e
--- /dev/null
+++ b/usbh_conf.h
@@ -0,0 +1,114 @@
+/**
+ ******************************************************************************
+ * @file USB_Host/HID_Standalone/Inc/usbh_conf.h
+ * @author MCD Application Team
+ * @version V1.1.0
+ * @date 17-February-2017
+ * @brief General low level driver configuration
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics International N.V.
+ * All rights reserved.</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted, provided that the following conditions are met:
+ *
+ * 1. Redistribution 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 other
+ * contributors to this software may be used to endorse or promote products
+ * derived from this software without specific written permission.
+ * 4. This software, including modifications and/or derivative works of this
+ * software, must execute solely and exclusively on microcontroller or
+ * microprocessor devices manufactured by or for STMicroelectronics.
+ * 5. Redistribution and use of this software other than as permitted under
+ * this license is void and will automatically terminate your rights under
+ * this license.
+ *
+ * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
+ * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
+ * SHALL STMICROELECTRONICS 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 __USBH_CONF_H
+#define __USBH_CONF_H
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32f4xx_hal.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* Exported types ------------------------------------------------------------*/
+#define USBH_MAX_NUM_ENDPOINTS 2
+#define USBH_MAX_NUM_INTERFACES 2
+#define USBH_MAX_NUM_CONFIGURATION 1
+#define USBH_MAX_NUM_SUPPORTED_CLASS 1
+#define USBH_KEEP_CFG_DESCRIPTOR 0
+#define USBH_MAX_SIZE_CONFIGURATION 0x200
+#define USBH_MAX_DATA_BUFFER 0x200
+#define USBH_DEBUG_LEVEL 2
+#define USBH_USE_OS 0
+
+/* Exported constants --------------------------------------------------------*/
+/* Exported macro ------------------------------------------------------------*/
+/* CMSIS OS macros */
+#if (USBH_USE_OS == 1)
+#include "cmsis_os.h"
+#define USBH_PROCESS_PRIO osPriorityNormal
+#endif
+
+/* Memory management macros */
+#define USBH_malloc malloc
+#define USBH_free free
+#define USBH_memset memset
+#define USBH_memcpy memcpy
+
+/* DEBUG macros */
+#if (USBH_DEBUG_LEVEL > 0)
+#define USBH_UsrLog(...) \
+ printf(__VA_ARGS__); \
+ printf("\n");
+#else
+#define USBH_UsrLog(...)
+#endif
+
+#if (USBH_DEBUG_LEVEL > 1)
+
+#define USBH_ErrLog(...) \
+ printf("ERROR: "); \
+ printf(__VA_ARGS__); \
+ printf("\n");
+#else
+#define USBH_ErrLog(...)
+#endif
+
+#if (USBH_DEBUG_LEVEL > 2)
+#define USBH_DbgLog(...) \
+ printf("DEBUG : "); \
+ printf(__VA_ARGS__); \
+ printf("\n");
+#else
+#define USBH_DbgLog(...)
+#endif
+
+/* Exported functions ------------------------------------------------------- */
+
+#endif /* __USBH_CONF_H */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/