F6: USB glue cleanup and fixes (#666)
* USB-CDC: accepting the next data packet only if we process previous data * USB-CDC: use USB FS packet size * HAL-console: puts method * Check: print assertion data * FuriHal: rx stream free space aware CDC confirmation. * Bootloader: pull down USB lines, leave the rest to the firmware or bootloader * F6: cleanup and move USB code to usb-glue folder, add USB suspend/resume events to VCP, cleanup target.mk, fix missing motd message in cli when using minicom. * F5: cleanup the rest of USB glue code, adjust LPM and Power info data in descriptor. Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
		
							parent
							
								
									6966ca8f8f
								
							
						
					
					
						commit
						153666f73f
					
				| @ -300,6 +300,7 @@ void cli_process_input(Cli* cli) { | ||||
|     if(c == CliSymbolAsciiTab) { | ||||
|         cli_handle_autocomplete(cli); | ||||
|     } else if(c == CliSymbolAsciiSOH) { | ||||
|         osDelay(33); // We are too fast, Minicom is not ready yet
 | ||||
|         cli_motd(); | ||||
|         cli_prompt(cli); | ||||
|     } else if(c == CliSymbolAsciiETX) { | ||||
|  | ||||
| @ -138,8 +138,6 @@ void target_version_save(void) { | ||||
| 
 | ||||
| void target_usb_wire_reset() { | ||||
|     LL_GPIO_ResetOutputPin(BOOT_USB_PORT, BOOT_USB_PIN); | ||||
|     LL_mDelay(10); | ||||
|     LL_GPIO_SetOutputPin(BOOT_USB_PORT, BOOT_USB_PIN); | ||||
| } | ||||
| 
 | ||||
| void target_display_init() { | ||||
|  | ||||
| @ -1,37 +1,30 @@ | ||||
| #include "check.h" | ||||
| #include "furi-hal-task.h" | ||||
| #include <furi-hal-console.h> | ||||
| #include <stdio.h> | ||||
| 
 | ||||
| void __furi_abort(void); | ||||
| 
 | ||||
| // TODO printf doesnt work in ISR context
 | ||||
| void __furi_check(void) { | ||||
|     printf("assertion failed in release mode, switch to debug mode to see full assert info"); | ||||
|     __furi_abort(); | ||||
| } | ||||
| 
 | ||||
| // TODO printf doesnt work in ISR context
 | ||||
| void __furi_check_debug(const char* file, int line, const char* function, const char* condition) { | ||||
|     printf( | ||||
|         "assertion \"%s\" failed: file \"%s\", line %d%s%s", | ||||
|         condition, | ||||
|         file, | ||||
|         line, | ||||
|         function ? ", function: " : "", | ||||
|         function ? function : ""); | ||||
| 
 | ||||
| void __furi_print_name(void) { | ||||
|     furi_hal_console_puts("\r\n\033[0;31m[E]"); | ||||
|     if(task_is_isr_context()) { | ||||
|         printf(" in [ISR] context"); | ||||
|         furi_hal_console_puts("[ISR] "); | ||||
|     } else { | ||||
|         // FuriApp* app = find_task(xTaskGetCurrentTaskHandle());
 | ||||
| 
 | ||||
|         // if(app == NULL) {
 | ||||
|         //     printf(", in [main] context");
 | ||||
|         // } else {
 | ||||
|         //     printf(", in [%s] app context", app->name);
 | ||||
|         // }
 | ||||
|         const char* name = osThreadGetName(osThreadGetId()); | ||||
|         if(name == NULL) { | ||||
|             furi_hal_console_puts("[main] "); | ||||
|         } else { | ||||
|             furi_hal_console_puts("["); | ||||
|             furi_hal_console_puts(name); | ||||
|             furi_hal_console_puts("] "); | ||||
|         } | ||||
|     } | ||||
|     furi_hal_console_puts("\033[0m"); | ||||
| } | ||||
| 
 | ||||
| void __furi_check(void) { | ||||
|     __furi_print_name(); | ||||
|     furi_hal_console_puts("assertion failed\r\n"); | ||||
|     __furi_abort(); | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -38,7 +38,6 @@ extern "C" { | ||||
| // !NDEBUG
 | ||||
| 
 | ||||
| void __furi_check(void); | ||||
| void __furi_check_debug(const char* file, int line, const char* function, const char* condition); | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
|  | ||||
| @ -1,105 +0,0 @@ | ||||
| /* USER CODE BEGIN Header */ | ||||
| /**
 | ||||
|   ****************************************************************************** | ||||
|   * @file           : usb_device.h | ||||
|   * @version        : v3.0_Cube | ||||
|   * @brief          : Header for usb_device.c file. | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2020 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
| /* USER CODE END Header */ | ||||
| 
 | ||||
| /* Define to prevent recursive inclusion -------------------------------------*/ | ||||
| #ifndef __USB_DEVICE__H__ | ||||
| #define __USB_DEVICE__H__ | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
|  extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "stm32wbxx.h" | ||||
| #include "stm32wbxx_hal.h" | ||||
| #include "usbd_def.h" | ||||
| 
 | ||||
| /* USER CODE BEGIN INCLUDE */ | ||||
| 
 | ||||
| /* USER CODE END INCLUDE */ | ||||
| 
 | ||||
| /** @addtogroup USBD_OTG_DRIVER
 | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_DEVICE USBD_DEVICE
 | ||||
|   * @brief Device file for Usb otg low level driver. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_DEVICE_Exported_Variables USBD_DEVICE_Exported_Variables
 | ||||
|   * @brief Public variables. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /* Private variables ---------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN PV */ | ||||
| 
 | ||||
| /* USER CODE END PV */ | ||||
| 
 | ||||
| /* Private function prototypes -----------------------------------------------*/ | ||||
| /* USER CODE BEGIN PFP */ | ||||
| 
 | ||||
| /* USER CODE END PFP */ | ||||
| 
 | ||||
| /*
 | ||||
|  * -- Insert your variables declaration here -- | ||||
|  */ | ||||
| /* USER CODE BEGIN VARIABLES */ | ||||
| 
 | ||||
| /* USER CODE END VARIABLES */ | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_DEVICE_Exported_FunctionsPrototype USBD_DEVICE_Exported_FunctionsPrototype
 | ||||
|   * @brief Declaration of public functions for Usb device. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /** USB Device initialization function. */ | ||||
| void MX_USB_Device_Init(void); | ||||
| 
 | ||||
| /*
 | ||||
|  * -- Insert functions declaration here -- | ||||
|  */ | ||||
| /* USER CODE BEGIN FD */ | ||||
| 
 | ||||
| /* USER CODE END FD */ | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif /* __USB_DEVICE__H__ */ | ||||
| 
 | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
| @ -1,134 +0,0 @@ | ||||
| /* USER CODE BEGIN Header */ | ||||
| /**
 | ||||
|   ****************************************************************************** | ||||
|   * @file           : usbd_cdc_if.h | ||||
|   * @version        : v3.0_Cube | ||||
|   * @brief          : Header for usbd_cdc_if.c file. | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2020 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
| /* USER CODE END Header */ | ||||
| 
 | ||||
| /* Define to prevent recursive inclusion -------------------------------------*/ | ||||
| #ifndef __USBD_CDC_IF_H__ | ||||
| #define __USBD_CDC_IF_H__ | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
|  extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "usbd_cdc.h" | ||||
| 
 | ||||
| /* USER CODE BEGIN INCLUDE */ | ||||
| 
 | ||||
| /* USER CODE END INCLUDE */ | ||||
| 
 | ||||
| /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
 | ||||
|   * @brief For Usb device. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_CDC_IF USBD_CDC_IF
 | ||||
|   * @brief Usb VCP device module | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_CDC_IF_Exported_Defines USBD_CDC_IF_Exported_Defines
 | ||||
|   * @brief Defines. | ||||
|   * @{ | ||||
|   */ | ||||
| /* USER CODE BEGIN EXPORTED_DEFINES */ | ||||
| /* Define size for the receive and transmit buffer over CDC */ | ||||
| /* It's up to user to redefine and/or remove those define */ | ||||
| #define APP_RX_DATA_SIZE  CDC_DATA_HS_MAX_PACKET_SIZE | ||||
| #define APP_TX_DATA_SIZE  CDC_DATA_HS_MAX_PACKET_SIZE | ||||
| 
 | ||||
| /* USER CODE END EXPORTED_DEFINES */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_CDC_IF_Exported_Types USBD_CDC_IF_Exported_Types
 | ||||
|   * @brief Types. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /* USER CODE BEGIN EXPORTED_TYPES */ | ||||
| 
 | ||||
| /* USER CODE END EXPORTED_TYPES */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_CDC_IF_Exported_Macros USBD_CDC_IF_Exported_Macros
 | ||||
|   * @brief Aliases. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /* USER CODE BEGIN EXPORTED_MACRO */ | ||||
| 
 | ||||
| /* USER CODE END EXPORTED_MACRO */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_CDC_IF_Exported_Variables USBD_CDC_IF_Exported_Variables
 | ||||
|   * @brief Public variables. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /** CDC Interface callback. */ | ||||
| extern USBD_CDC_ItfTypeDef USBD_Interface_fops_FS; | ||||
| 
 | ||||
| /* USER CODE BEGIN EXPORTED_VARIABLES */ | ||||
| 
 | ||||
| /* USER CODE END EXPORTED_VARIABLES */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_CDC_IF_Exported_FunctionsPrototype USBD_CDC_IF_Exported_FunctionsPrototype
 | ||||
|   * @brief Public functions declaration. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len); | ||||
| 
 | ||||
| /* USER CODE BEGIN EXPORTED_FUNCTIONS */ | ||||
| 
 | ||||
| /* USER CODE END EXPORTED_FUNCTIONS */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif /* __USBD_CDC_IF_H__ */ | ||||
| 
 | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
| @ -1,176 +0,0 @@ | ||||
| /* USER CODE BEGIN Header */ | ||||
| /**
 | ||||
|   ****************************************************************************** | ||||
|   * @file           : usbd_conf.h | ||||
|   * @version        : v3.0_Cube | ||||
|   * @brief          : Header for usbd_conf.c file. | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2020 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
| /* USER CODE END Header */ | ||||
| 
 | ||||
| /* Define to prevent recursive inclusion -------------------------------------*/ | ||||
| #ifndef __USBD_CONF__H__ | ||||
| #define __USBD_CONF__H__ | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
|  extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include <stdio.h> | ||||
| #include <stdlib.h> | ||||
| #include <string.h> | ||||
| #include "stm32wbxx.h" | ||||
| #include "stm32wbxx_hal.h" | ||||
| 
 | ||||
| /* USER CODE BEGIN INCLUDE */ | ||||
| 
 | ||||
| /* USER CODE END INCLUDE */ | ||||
| 
 | ||||
| /** @addtogroup USBD_OTG_DRIVER
 | ||||
|   * @brief Driver for Usb device. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_CONF USBD_CONF
 | ||||
|   * @brief Configuration file for Usb otg low level driver. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_CONF_Exported_Variables USBD_CONF_Exported_Variables
 | ||||
|   * @brief Public variables. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /* Private variables ---------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN PV */ | ||||
| /* USER CODE END PV */ | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_CONF_Exported_Defines USBD_CONF_Exported_Defines
 | ||||
|   * @brief Defines for configuration of the Usb device. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /*---------- -----------*/ | ||||
| #define USBD_MAX_NUM_INTERFACES     1U | ||||
| /*---------- -----------*/ | ||||
| #define USBD_MAX_NUM_CONFIGURATION     1U | ||||
| /*---------- -----------*/ | ||||
| #define USBD_MAX_STR_DESC_SIZ     512U | ||||
| /*---------- -----------*/ | ||||
| #define USBD_DEBUG_LEVEL     0U | ||||
| /*---------- -----------*/ | ||||
| #define USBD_LPM_ENABLED     1U | ||||
| /*---------- -----------*/ | ||||
| #define USBD_SELF_POWERED     1U | ||||
| 
 | ||||
| /****************************************/ | ||||
| /* #define for FS and HS identification */ | ||||
| #define DEVICE_FS 		0 | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_CONF_Exported_Macros USBD_CONF_Exported_Macros
 | ||||
|   * @brief Aliases. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /* Memory management macros */ | ||||
| 
 | ||||
| /** Alias for memory allocation. */ | ||||
| #define USBD_malloc         (void *)USBD_static_malloc | ||||
| 
 | ||||
| /** Alias for memory release. */ | ||||
| #define USBD_free           USBD_static_free | ||||
| 
 | ||||
| /** Alias for memory set. */ | ||||
| #define USBD_memset         memset | ||||
| 
 | ||||
| /** Alias for memory copy. */ | ||||
| #define USBD_memcpy         memcpy | ||||
| 
 | ||||
| /** Alias for delay. */ | ||||
| #define USBD_Delay          HAL_Delay | ||||
| /* DEBUG macros */ | ||||
| 
 | ||||
| #if (USBD_DEBUG_LEVEL > 0) | ||||
| #define USBD_UsrLog(...)    printf(__VA_ARGS__);\ | ||||
|                             printf("\n"); | ||||
| #else | ||||
| #define USBD_UsrLog(...) | ||||
| #endif | ||||
| 
 | ||||
| #if (USBD_DEBUG_LEVEL > 1) | ||||
| 
 | ||||
| #define USBD_ErrLog(...)    printf("ERROR: ") ;\ | ||||
|                             printf(__VA_ARGS__);\ | ||||
|                             printf("\n"); | ||||
| #else | ||||
| #define USBD_ErrLog(...) | ||||
| #endif | ||||
| 
 | ||||
| #if (USBD_DEBUG_LEVEL > 2) | ||||
| #define USBD_DbgLog(...)    printf("DEBUG : ") ;\ | ||||
|                             printf(__VA_ARGS__);\ | ||||
|                             printf("\n"); | ||||
| #else | ||||
| #define USBD_DbgLog(...) | ||||
| #endif | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_CONF_Exported_Types USBD_CONF_Exported_Types
 | ||||
|   * @brief Types. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_CONF_Exported_FunctionsPrototype USBD_CONF_Exported_FunctionsPrototype
 | ||||
|   * @brief Declaration of public functions for Usb device. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /* Exported functions -------------------------------------------------------*/ | ||||
| void *USBD_static_malloc(uint32_t size); | ||||
| void USBD_static_free(void *p); | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif /* __USBD_CONF__H__ */ | ||||
| 
 | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
| @ -1,145 +0,0 @@ | ||||
| /* USER CODE BEGIN Header */ | ||||
| /**
 | ||||
|   ****************************************************************************** | ||||
|   * @file           : usbd_desc.c | ||||
|   * @version        : v3.0_Cube | ||||
|   * @brief          : Header for usbd_conf.c file. | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2020 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
| /* USER CODE END Header */ | ||||
| 
 | ||||
| /* Define to prevent recursive inclusion -------------------------------------*/ | ||||
| #ifndef __USBD_DESC__C__ | ||||
| #define __USBD_DESC__C__ | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
|  extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "usbd_def.h" | ||||
| 
 | ||||
| /* USER CODE BEGIN INCLUDE */ | ||||
| 
 | ||||
| /* USER CODE END INCLUDE */ | ||||
| 
 | ||||
| /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
 | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_DESC USBD_DESC
 | ||||
|   * @brief Usb device descriptors module. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_DESC_Exported_Constants USBD_DESC_Exported_Constants
 | ||||
|   * @brief Constants. | ||||
|   * @{ | ||||
|   */ | ||||
| #define         DEVICE_ID1          (UID_BASE) | ||||
| #define         DEVICE_ID2          (UID_BASE + 0x4) | ||||
| #define         DEVICE_ID3          (UID_BASE + 0x8) | ||||
| 
 | ||||
| #define         USB_SIZ_STRING_SERIAL       0x1E | ||||
| 
 | ||||
| /* USER CODE BEGIN EXPORTED_CONSTANTS */ | ||||
| 
 | ||||
| /* USER CODE END EXPORTED_CONSTANTS */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_DESC_Exported_Defines USBD_DESC_Exported_Defines
 | ||||
|   * @brief Defines. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /* USER CODE BEGIN EXPORTED_DEFINES */ | ||||
| 
 | ||||
| /* USER CODE END EXPORTED_DEFINES */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_DESC_Exported_TypesDefinitions USBD_DESC_Exported_TypesDefinitions
 | ||||
|   * @brief Types. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /* USER CODE BEGIN EXPORTED_TYPES */ | ||||
| 
 | ||||
| /* USER CODE END EXPORTED_TYPES */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_DESC_Exported_Macros USBD_DESC_Exported_Macros
 | ||||
|   * @brief Aliases. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /* USER CODE BEGIN EXPORTED_MACRO */ | ||||
| 
 | ||||
| /* USER CODE END EXPORTED_MACRO */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_DESC_Exported_Variables USBD_DESC_Exported_Variables
 | ||||
|   * @brief Public variables. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| extern USBD_DescriptorsTypeDef     CDC_Desc; | ||||
| 
 | ||||
| /* USER CODE BEGIN EXPORTED_VARIABLES */ | ||||
| 
 | ||||
| /* USER CODE END EXPORTED_VARIABLES */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_DESC_Exported_FunctionsPrototype USBD_DESC_Exported_FunctionsPrototype
 | ||||
|   * @brief Public functions declaration. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /* USER CODE BEGIN EXPORTED_FUNCTIONS */ | ||||
| 
 | ||||
| /* USER CODE END EXPORTED_FUNCTIONS */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif /* __USBD_DESC__C__ */ | ||||
| 
 | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
| @ -1,99 +0,0 @@ | ||||
| /* USER CODE BEGIN Header */ | ||||
| /**
 | ||||
|   ****************************************************************************** | ||||
|   * @file           : usb_device.c | ||||
|   * @version        : v3.0_Cube | ||||
|   * @brief          : This file implements the USB Device | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2020 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
| /* USER CODE END Header */ | ||||
| 
 | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| 
 | ||||
| #include "usb_device.h" | ||||
| #include "usbd_core.h" | ||||
| #include "usbd_desc.h" | ||||
| #include "usbd_cdc.h" | ||||
| #include "usbd_cdc_if.h" | ||||
| 
 | ||||
| /* USER CODE BEGIN Includes */ | ||||
| 
 | ||||
| /* USER CODE END Includes */ | ||||
| 
 | ||||
| /* USER CODE BEGIN PV */ | ||||
| /* Private variables ---------------------------------------------------------*/ | ||||
| 
 | ||||
| /* USER CODE END PV */ | ||||
| 
 | ||||
| /* USER CODE BEGIN PFP */ | ||||
| /* Private function prototypes -----------------------------------------------*/ | ||||
| 
 | ||||
| /* USER CODE END PFP */ | ||||
| 
 | ||||
| extern void Error_Handler(void); | ||||
| /* USB Device Core handle declaration. */ | ||||
| USBD_HandleTypeDef hUsbDeviceFS; | ||||
| extern USBD_DescriptorsTypeDef CDC_Desc; | ||||
| 
 | ||||
| /*
 | ||||
|  * -- Insert your variables declaration here -- | ||||
|  */ | ||||
| /* USER CODE BEGIN 0 */ | ||||
| 
 | ||||
| /* USER CODE END 0 */ | ||||
| 
 | ||||
| /*
 | ||||
|  * -- Insert your external function declaration here -- | ||||
|  */ | ||||
| /* USER CODE BEGIN 1 */ | ||||
| 
 | ||||
| /* USER CODE END 1 */ | ||||
| 
 | ||||
| /**
 | ||||
|   * Init USB device Library, add supported class and start the library | ||||
|   * @retval None | ||||
|   */ | ||||
| void MX_USB_Device_Init(void) | ||||
| { | ||||
|   /* USER CODE BEGIN USB_Device_Init_PreTreatment */ | ||||
| 
 | ||||
|   /* USER CODE END USB_Device_Init_PreTreatment */ | ||||
| 
 | ||||
|   /* Init Device Library, add supported class and start the library. */ | ||||
|   if (USBD_Init(&hUsbDeviceFS, &CDC_Desc, DEVICE_FS) != USBD_OK) { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK) { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   if (USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK) { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   if (USBD_Start(&hUsbDeviceFS) != USBD_OK) { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|   /* USER CODE BEGIN USB_Device_Init_PostTreatment */ | ||||
| 
 | ||||
|   /* USER CODE END USB_Device_Init_PostTreatment */ | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
| @ -1,313 +0,0 @@ | ||||
| /* USER CODE BEGIN Header */ | ||||
| /**
 | ||||
|   ****************************************************************************** | ||||
|   * @file           : usbd_cdc_if.c | ||||
|   * @version        : v3.0_Cube | ||||
|   * @brief          : Usb device for Virtual Com Port. | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2020 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
| /* USER CODE END Header */ | ||||
| 
 | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "usbd_cdc_if.h" | ||||
| 
 | ||||
| /* USER CODE BEGIN INCLUDE */ | ||||
| 
 | ||||
| /* USER CODE END INCLUDE */ | ||||
| 
 | ||||
| /* Private typedef -----------------------------------------------------------*/ | ||||
| /* Private define ------------------------------------------------------------*/ | ||||
| /* Private macro -------------------------------------------------------------*/ | ||||
| 
 | ||||
| /* USER CODE BEGIN PV */ | ||||
| /* Private variables ---------------------------------------------------------*/ | ||||
| 
 | ||||
| /* USER CODE END PV */ | ||||
| 
 | ||||
| /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
 | ||||
|   * @brief Usb device library. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /** @addtogroup USBD_CDC_IF
 | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_CDC_IF_Private_TypesDefinitions USBD_CDC_IF_Private_TypesDefinitions
 | ||||
|   * @brief Private types. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /* USER CODE BEGIN PRIVATE_TYPES */ | ||||
| 
 | ||||
| extern void _furi_hal_vcp_init(); | ||||
| extern void _furi_hal_vcp_deinit(); | ||||
| extern void _furi_hal_vcp_control_line(uint8_t state); | ||||
| extern void _furi_hal_vcp_rx_callback(char* buffer, size_t size); | ||||
| extern void _furi_hal_vcp_tx_complete(size_t size); | ||||
| 
 | ||||
| /* USER CODE END PRIVATE_TYPES */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_CDC_IF_Private_Defines USBD_CDC_IF_Private_Defines
 | ||||
|   * @brief Private defines. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /* USER CODE BEGIN PRIVATE_DEFINES */ | ||||
| /* USER CODE END PRIVATE_DEFINES */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_CDC_IF_Private_Macros USBD_CDC_IF_Private_Macros
 | ||||
|   * @brief Private macros. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /* USER CODE BEGIN PRIVATE_MACRO */ | ||||
| 
 | ||||
| /* USER CODE END PRIVATE_MACRO */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_CDC_IF_Private_Variables USBD_CDC_IF_Private_Variables
 | ||||
|   * @brief Private variables. | ||||
|   * @{ | ||||
|   */ | ||||
| /* Create buffer for reception and transmission           */ | ||||
| /* It's up to user to redefine and/or remove those define */ | ||||
| /** Received data over USB are stored in this buffer      */ | ||||
| uint8_t UserRxBufferFS[APP_RX_DATA_SIZE]; | ||||
| 
 | ||||
| /** Data to send over USB CDC are stored in this buffer   */ | ||||
| uint8_t UserTxBufferFS[APP_TX_DATA_SIZE]; | ||||
| 
 | ||||
| /* USER CODE BEGIN PRIVATE_VARIABLES */ | ||||
| 
 | ||||
| /* USER CODE END PRIVATE_VARIABLES */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_CDC_IF_Exported_Variables USBD_CDC_IF_Exported_Variables
 | ||||
|   * @brief Public variables. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| extern USBD_HandleTypeDef hUsbDeviceFS; | ||||
| 
 | ||||
| /* USER CODE BEGIN EXPORTED_VARIABLES */ | ||||
| 
 | ||||
| /* USER CODE END EXPORTED_VARIABLES */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_CDC_IF_Private_FunctionPrototypes USBD_CDC_IF_Private_FunctionPrototypes
 | ||||
|   * @brief Private functions declaration. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| static int8_t CDC_Init_FS(void); | ||||
| static int8_t CDC_DeInit_FS(void); | ||||
| static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length); | ||||
| static int8_t CDC_Receive_FS(uint8_t* pbuf, uint32_t *Len); | ||||
| static int8_t CDC_TransmitCplt_FS(uint8_t *pbuf, uint32_t *Len, uint8_t epnum); | ||||
| 
 | ||||
| /* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */ | ||||
| 
 | ||||
| /* USER CODE END PRIVATE_FUNCTIONS_DECLARATION */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| USBD_CDC_ItfTypeDef USBD_Interface_fops_FS = | ||||
| { | ||||
|   CDC_Init_FS, | ||||
|   CDC_DeInit_FS, | ||||
|   CDC_Control_FS, | ||||
|   CDC_Receive_FS, | ||||
|   CDC_TransmitCplt_FS | ||||
| }; | ||||
| 
 | ||||
| /* Private functions ---------------------------------------------------------*/ | ||||
| /**
 | ||||
|   * @brief  Initializes the CDC media low layer over the FS USB IP | ||||
|   * @retval USBD_OK if all operations are OK else USBD_FAIL | ||||
|   */ | ||||
| static int8_t CDC_Init_FS(void) | ||||
| { | ||||
|   /* USER CODE BEGIN 3 */ | ||||
|   /* Set Application Buffers */ | ||||
|   USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0); | ||||
|   USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS); | ||||
|   _furi_hal_vcp_init(); | ||||
|   return (USBD_OK); | ||||
|   /* USER CODE END 3 */ | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  DeInitializes the CDC media low layer | ||||
|   * @retval USBD_OK if all operations are OK else USBD_FAIL | ||||
|   */ | ||||
| static int8_t CDC_DeInit_FS(void) | ||||
| { | ||||
|   /* USER CODE BEGIN 4 */ | ||||
|   _furi_hal_vcp_deinit(); | ||||
|   return (USBD_OK); | ||||
|   /* USER CODE END 4 */ | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Manage the CDC class requests | ||||
|   * @param  cmd: Command code | ||||
|   * @param  pbuf: Buffer containing command data (request parameters) | ||||
|   * @param  length: Number of data to be sent (in bytes) | ||||
|   * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL | ||||
|   */ | ||||
| static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length) | ||||
| { | ||||
|   /* USER CODE BEGIN 5 */ | ||||
|   if (cmd == CDC_SEND_ENCAPSULATED_COMMAND) { | ||||
|   } else if (cmd == CDC_GET_ENCAPSULATED_RESPONSE) { | ||||
|   } else if (cmd == CDC_SET_COMM_FEATURE) { | ||||
|   } else if (cmd == CDC_GET_COMM_FEATURE) { | ||||
|   } else if (cmd == CDC_CLEAR_COMM_FEATURE) { | ||||
|   } else if (cmd == CDC_SET_LINE_CODING) { | ||||
|       /*******************************************************************************/ | ||||
|       /* Line Coding Structure                                                       */ | ||||
|       /*-----------------------------------------------------------------------------*/ | ||||
|       /* Offset | Field       | Size | Value  | Description                          */ | ||||
|       /* 0      | dwDTERate   |   4  | Number |Data terminal rate, in bits per second*/ | ||||
|       /* 4      | bCharFormat |   1  | Number | Stop bits                            */ | ||||
|       /*                                        0 - 1 Stop bit                       */ | ||||
|       /*                                        1 - 1.5 Stop bits                    */ | ||||
|       /*                                        2 - 2 Stop bits                      */ | ||||
|       /* 5      | bParityType |  1   | Number | Parity                               */ | ||||
|       /*                                        0 - None                             */ | ||||
|       /*                                        1 - Odd                              */ | ||||
|       /*                                        2 - Even                             */ | ||||
|       /*                                        3 - Mark                             */ | ||||
|       /*                                        4 - Space                            */ | ||||
|       /* 6      | bDataBits  |   1   | Number Data bits (5, 6, 7, 8 or 16).          */ | ||||
|       /*******************************************************************************/ | ||||
|   } else if (cmd == CDC_GET_LINE_CODING) { | ||||
|   } else if (cmd == CDC_SET_CONTROL_LINE_STATE) { | ||||
|     _furi_hal_vcp_control_line(((USBD_SetupReqTypedef*)pbuf)->wValue); | ||||
|   } else if (cmd == CDC_SEND_BREAK) { | ||||
|   } else { | ||||
|   } | ||||
| 
 | ||||
|   return (USBD_OK); | ||||
|   /* USER CODE END 5 */ | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Data received over USB OUT endpoint are sent over CDC interface | ||||
|   *         through this function. | ||||
|   * | ||||
|   *         @note | ||||
|   *         This function will issue a NAK packet on any OUT packet received on | ||||
|   *         USB endpoint until exiting this function. If you exit this function | ||||
|   *         before transfer is complete on CDC interface (ie. using DMA controller) | ||||
|   *         it will result in receiving more data while previous ones are still | ||||
|   *         not sent. | ||||
|   * | ||||
|   * @param  Buf: Buffer of data to be received | ||||
|   * @param  Len: Number of data received (in bytes) | ||||
|   * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL | ||||
|   */ | ||||
| static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len) | ||||
| { | ||||
|   /* USER CODE BEGIN 6 */ | ||||
|   if (*Len) { | ||||
|     _furi_hal_vcp_rx_callback((char*)Buf, *Len); | ||||
|   } | ||||
|   USBD_CDC_ReceivePacket(&hUsbDeviceFS); | ||||
|   return (USBD_OK); | ||||
|   /* USER CODE END 6 */ | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  CDC_Transmit_FS | ||||
|   *         Data to send over USB IN endpoint are sent over CDC interface | ||||
|   *         through this function. | ||||
|   *         @note | ||||
|   * | ||||
|   * | ||||
|   * @param  Buf: Buffer of data to be sent | ||||
|   * @param  Len: Number of data to be sent (in bytes) | ||||
|   * @retval USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY | ||||
|   */ | ||||
| uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len) | ||||
| { | ||||
|   uint8_t result = USBD_OK; | ||||
|   /* USER CODE BEGIN 7 */ | ||||
|   USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData; | ||||
|   if (hcdc->TxState != 0){ | ||||
|     return USBD_BUSY; | ||||
|   } | ||||
|   memcpy(UserTxBufferFS, Buf, Len); | ||||
|   USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, Len); | ||||
|   result = USBD_CDC_TransmitPacket(&hUsbDeviceFS); | ||||
|   /* USER CODE END 7 */ | ||||
|   return result; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  CDC_TransmitCplt_FS | ||||
|   *         Data transmited callback | ||||
|   * | ||||
|   *         @note | ||||
|   *         This function is IN transfer complete callback used to inform user that | ||||
|   *         the submitted Data is successfully sent over USB. | ||||
|   * | ||||
|   * @param  Buf: Buffer of data to be received | ||||
|   * @param  Len: Number of data received (in bytes) | ||||
|   * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL | ||||
|   */ | ||||
| static int8_t CDC_TransmitCplt_FS(uint8_t *Buf, uint32_t *Len, uint8_t epnum) | ||||
| { | ||||
|   uint8_t result = USBD_OK; | ||||
|   /* USER CODE BEGIN 13 */ | ||||
|   UNUSED(Buf); | ||||
|   UNUSED(epnum); | ||||
|   _furi_hal_vcp_tx_complete(*Len); | ||||
|   /* USER CODE END 13 */ | ||||
|   return result; | ||||
| } | ||||
| 
 | ||||
| /* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */ | ||||
| 
 | ||||
| /* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
| @ -1,808 +0,0 @@ | ||||
| /* USER CODE BEGIN Header */ | ||||
| /**
 | ||||
|   ****************************************************************************** | ||||
|   * @file           : usbd_conf.c | ||||
|   * @version        : v3.0_Cube | ||||
|   * @brief          : This file implements the board support package for the USB device library | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2020 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
| /* USER CODE END Header */ | ||||
| 
 | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "stm32wbxx.h" | ||||
| #include "stm32wbxx_hal.h" | ||||
| #include "usbd_def.h" | ||||
| #include "usbd_core.h" | ||||
| 
 | ||||
| #include "usbd_cdc.h" | ||||
| 
 | ||||
| /* USER CODE BEGIN Includes */ | ||||
| 
 | ||||
| /* USER CODE END Includes */ | ||||
| 
 | ||||
| /* Private typedef -----------------------------------------------------------*/ | ||||
| /* Private define ------------------------------------------------------------*/ | ||||
| /* Private macro -------------------------------------------------------------*/ | ||||
| 
 | ||||
| /* Private variables ---------------------------------------------------------*/ | ||||
| /* USER CODE BEGIN PV */ | ||||
| 
 | ||||
| /* USER CODE END PV */ | ||||
| 
 | ||||
| PCD_HandleTypeDef hpcd_USB_FS; | ||||
| void Error_Handler(void); | ||||
| 
 | ||||
| /* USER CODE BEGIN 0 */ | ||||
| 
 | ||||
| /* USER CODE END 0 */ | ||||
| 
 | ||||
| /* Exported function prototypes ----------------------------------------------*/ | ||||
| 
 | ||||
| /* USER CODE BEGIN PFP */ | ||||
| /* Private function prototypes -----------------------------------------------*/ | ||||
| 
 | ||||
| /* USER CODE END PFP */ | ||||
| 
 | ||||
| /* Private functions ---------------------------------------------------------*/ | ||||
| static USBD_StatusTypeDef USBD_Get_USB_Status(HAL_StatusTypeDef hal_status); | ||||
| /* USER CODE BEGIN 1 */ | ||||
| static void SystemClockConfig_Resume(void); | ||||
| 
 | ||||
| /* USER CODE END 1 */ | ||||
| 
 | ||||
| /*******************************************************************************
 | ||||
|                        LL Driver Callbacks (PCD -> USB Device Library) | ||||
| *******************************************************************************/ | ||||
| /* MSP Init */ | ||||
| 
 | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACK == 1U) | ||||
| static void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) | ||||
| #else | ||||
| void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACK */ | ||||
| { | ||||
|   GPIO_InitTypeDef GPIO_InitStruct = {0}; | ||||
|   if(pcdHandle->Instance==USB) | ||||
|   { | ||||
|   /* USER CODE BEGIN USB_MspInit 0 */ | ||||
| 
 | ||||
|   /* USER CODE END USB_MspInit 0 */ | ||||
| 
 | ||||
|     __HAL_RCC_GPIOA_CLK_ENABLE(); | ||||
|     /**USB GPIO Configuration
 | ||||
|     PA11     ------> USB_DM | ||||
|     PA12     ------> USB_DP | ||||
|     */ | ||||
|     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_FREQ_VERY_HIGH; | ||||
|     GPIO_InitStruct.Alternate = GPIO_AF10_USB; | ||||
|     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | ||||
| 
 | ||||
|     /* Peripheral clock enable */ | ||||
|     __HAL_RCC_USB_CLK_ENABLE(); | ||||
| 
 | ||||
|     /* Peripheral interrupt init */ | ||||
|     HAL_NVIC_SetPriority(USB_LP_IRQn, 5, 0); | ||||
|     HAL_NVIC_EnableIRQ(USB_LP_IRQn); | ||||
|   /* USER CODE BEGIN USB_MspInit 1 */ | ||||
| 
 | ||||
|   /* USER CODE END USB_MspInit 1 */ | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACK == 1U) | ||||
| static void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) | ||||
| #else | ||||
| void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACK */ | ||||
| { | ||||
|   if(pcdHandle->Instance==USB) | ||||
|   { | ||||
|   /* USER CODE BEGIN USB_MspDeInit 0 */ | ||||
| 
 | ||||
|   /* USER CODE END USB_MspDeInit 0 */ | ||||
|     /* Peripheral clock disable */ | ||||
|     __HAL_RCC_USB_CLK_DISABLE(); | ||||
| 
 | ||||
|     /**USB GPIO Configuration
 | ||||
|     PA11     ------> USB_DM | ||||
|     PA12     ------> USB_DP | ||||
|     */ | ||||
|     HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12); | ||||
| 
 | ||||
|     /* Peripheral interrupt Deinit*/ | ||||
|     HAL_NVIC_DisableIRQ(USB_LP_IRQn); | ||||
| 
 | ||||
|   /* USER CODE BEGIN USB_MspDeInit 1 */ | ||||
| 
 | ||||
|   /* USER CODE END USB_MspDeInit 1 */ | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Setup stage callback | ||||
|   * @param  hpcd: PCD handle | ||||
|   * @retval None | ||||
|   */ | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
| static void PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) | ||||
| #else | ||||
| void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
| { | ||||
|   /* USER CODE BEGIN HAL_PCD_SetupStageCallback_PreTreatment */ | ||||
| 
 | ||||
|   /* USER CODE END  HAL_PCD_SetupStageCallback_PreTreatment */ | ||||
|   USBD_LL_SetupStage((USBD_HandleTypeDef*)hpcd->pData, (uint8_t *)hpcd->Setup); | ||||
|   /* USER CODE BEGIN HAL_PCD_SetupStageCallback_PostTreatment */ | ||||
| 
 | ||||
|   /* USER CODE END  HAL_PCD_SetupStageCallback_PostTreatment */ | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Data Out stage callback. | ||||
|   * @param  hpcd: PCD handle | ||||
|   * @param  epnum: Endpoint number | ||||
|   * @retval None | ||||
|   */ | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
| static void PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) | ||||
| #else | ||||
| void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
| { | ||||
|   /* USER CODE BEGIN HAL_PCD_DataOutStageCallback_PreTreatment */ | ||||
| 
 | ||||
|   /* USER CODE END HAL_PCD_DataOutStageCallback_PreTreatment */ | ||||
|   USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff); | ||||
|   /* USER CODE BEGIN HAL_PCD_DataOutStageCallback_PostTreatment */ | ||||
| 
 | ||||
|   /* USER CODE END HAL_PCD_DataOutStageCallback_PostTreatment */ | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Data In stage callback. | ||||
|   * @param  hpcd: PCD handle | ||||
|   * @param  epnum: Endpoint number | ||||
|   * @retval None | ||||
|   */ | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
| static void PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) | ||||
| #else | ||||
| void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
| { | ||||
|   /* USER CODE BEGIN HAL_PCD_DataInStageCallback_PreTreatment */ | ||||
| 
 | ||||
|   /* USER CODE END HAL_PCD_DataInStageCallback_PreTreatment */ | ||||
|   USBD_LL_DataInStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff); | ||||
|   /* USER CODE BEGIN HAL_PCD_DataInStageCallback_PostTreatment  */ | ||||
| 
 | ||||
|   /* USER CODE END HAL_PCD_DataInStageCallback_PostTreatment */ | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  SOF callback. | ||||
|   * @param  hpcd: PCD handle | ||||
|   * @retval None | ||||
|   */ | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
| static void PCD_SOFCallback(PCD_HandleTypeDef *hpcd) | ||||
| #else | ||||
| void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
| { | ||||
|   /* USER CODE BEGIN HAL_PCD_SOFCallback_PreTreatment */ | ||||
| 
 | ||||
|   /* USER CODE END HAL_PCD_SOFCallback_PreTreatment */ | ||||
|   USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData); | ||||
|   /* USER CODE BEGIN HAL_PCD_SOFCallback_PostTreatment */ | ||||
| 
 | ||||
|   /* USER CODE END HAL_PCD_SOFCallback_PostTreatment */ | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Reset callback. | ||||
|   * @param  hpcd: PCD handle | ||||
|   * @retval None | ||||
|   */ | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
| static void PCD_ResetCallback(PCD_HandleTypeDef *hpcd) | ||||
| #else | ||||
| void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
| { | ||||
|   /* USER CODE BEGIN HAL_PCD_ResetCallback_PreTreatment */ | ||||
| 
 | ||||
|   /* USER CODE END HAL_PCD_ResetCallback_PreTreatment */ | ||||
|   USBD_SpeedTypeDef speed = USBD_SPEED_FULL; | ||||
| 
 | ||||
|   if ( hpcd->Init.speed != PCD_SPEED_FULL) | ||||
|   { | ||||
|     Error_Handler(); | ||||
|   } | ||||
|     /* Set Speed. */ | ||||
|   USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, speed); | ||||
| 
 | ||||
|   /* Reset Device. */ | ||||
|   USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData); | ||||
|   /* USER CODE BEGIN HAL_PCD_ResetCallback_PostTreatment */ | ||||
| 
 | ||||
|   /* USER CODE END HAL_PCD_ResetCallback_PostTreatment */ | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Suspend callback. | ||||
|   * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) | ||||
|   * @param  hpcd: PCD handle | ||||
|   * @retval None | ||||
|   */ | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
| static void PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) | ||||
| #else | ||||
| void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
| { | ||||
|   /* USER CODE BEGIN HAL_PCD_SuspendCallback_PreTreatment */ | ||||
| 
 | ||||
|   /* USER CODE END HAL_PCD_SuspendCallback_PreTreatment */ | ||||
|   /* Inform USB library that core enters in suspend Mode. */ | ||||
|   USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData); | ||||
|   /* Enter in STOP mode. */ | ||||
|   /* USER CODE BEGIN 2 */ | ||||
|   if (hpcd->Init.low_power_enable) | ||||
|   { | ||||
|     /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */ | ||||
|     SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); | ||||
|   } | ||||
|   /* USER CODE END 2 */ | ||||
|   /* USER CODE BEGIN HAL_PCD_SuspendCallback_PostTreatment */ | ||||
| 
 | ||||
|   /* USER CODE END HAL_PCD_SuspendCallback_PostTreatment */ | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Resume callback. | ||||
|   * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) | ||||
|   * @param  hpcd: PCD handle | ||||
|   * @retval None | ||||
|   */ | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
| static void PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) | ||||
| #else | ||||
| void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
| { | ||||
|   /* USER CODE BEGIN HAL_PCD_ResumeCallback_PreTreatment */ | ||||
| 
 | ||||
|   /* USER CODE END HAL_PCD_ResumeCallback_PreTreatment */ | ||||
| 
 | ||||
|   /* USER CODE BEGIN 3 */ | ||||
|   if (hpcd->Init.low_power_enable) | ||||
|   { | ||||
|     /* Reset SLEEPDEEP bit of Cortex System Control Register. */ | ||||
|     SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); | ||||
|     SystemClockConfig_Resume(); | ||||
|   } | ||||
|   /* USER CODE END 3 */ | ||||
| 
 | ||||
|   USBD_LL_Resume((USBD_HandleTypeDef*)hpcd->pData); | ||||
|   /* USER CODE BEGIN HAL_PCD_ResumeCallback_PostTreatment */ | ||||
| 
 | ||||
|   /* USER CODE END HAL_PCD_ResumeCallback_PostTreatment */ | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  ISOOUTIncomplete callback. | ||||
|   * @param  hpcd: PCD handle | ||||
|   * @param  epnum: Endpoint number | ||||
|   * @retval None | ||||
|   */ | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
| static void PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) | ||||
| #else | ||||
| void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
| { | ||||
|   /* USER CODE BEGIN HAL_PCD_ISOOUTIncompleteCallback_PreTreatment */ | ||||
| 
 | ||||
|   /* USER CODE END HAL_PCD_ISOOUTIncompleteCallback_PreTreatment */ | ||||
|   USBD_LL_IsoOUTIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); | ||||
|   /* USER CODE BEGIN HAL_PCD_ISOOUTIncompleteCallback_PostTreatment */ | ||||
| 
 | ||||
|   /* USER CODE END HAL_PCD_ISOOUTIncompleteCallback_PostTreatment */ | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  ISOINIncomplete callback. | ||||
|   * @param  hpcd: PCD handle | ||||
|   * @param  epnum: Endpoint number | ||||
|   * @retval None | ||||
|   */ | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
| static void PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) | ||||
| #else | ||||
| void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
| { | ||||
|   /* USER CODE BEGIN HAL_PCD_ISOINIncompleteCallback_PreTreatment */ | ||||
| 
 | ||||
|   /* USER CODE END HAL_PCD_ISOINIncompleteCallback_PreTreatment */ | ||||
|   USBD_LL_IsoINIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); | ||||
|   /* USER CODE BEGIN HAL_PCD_ISOINIncompleteCallback_PostTreatment */ | ||||
| 
 | ||||
|   /* USER CODE END HAL_PCD_ISOINIncompleteCallback_PostTreatment */ | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Connect callback. | ||||
|   * @param  hpcd: PCD handle | ||||
|   * @retval None | ||||
|   */ | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
| static void PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) | ||||
| #else | ||||
| void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
| { | ||||
|   /* USER CODE BEGIN HAL_PCD_ConnectCallback_PreTreatment */ | ||||
| 
 | ||||
|   /* USER CODE END HAL_PCD_ConnectCallback_PreTreatment */ | ||||
|   USBD_LL_DevConnected((USBD_HandleTypeDef*)hpcd->pData); | ||||
|   /* USER CODE BEGIN HAL_PCD_ConnectCallback_PostTreatment */ | ||||
| 
 | ||||
|   /* USER CODE END HAL_PCD_ConnectCallback_PostTreatment */ | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Disconnect callback. | ||||
|   * @param  hpcd: PCD handle | ||||
|   * @retval None | ||||
|   */ | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
| static void PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) | ||||
| #else | ||||
| void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
| { | ||||
|   /* USER CODE BEGIN HAL_PCD_DisconnectCallback_PreTreatment */ | ||||
| 
 | ||||
|   /* USER CODE END HAL_PCD_DisconnectCallback_PreTreatment */ | ||||
|   USBD_LL_DevDisconnected((USBD_HandleTypeDef*)hpcd->pData); | ||||
|   /* USER CODE BEGIN HAL_PCD_DisconnectCallback_PostTreatment */ | ||||
| 
 | ||||
|   /* USER CODE END HAL_PCD_DisconnectCallback_PostTreatment */ | ||||
| } | ||||
| 
 | ||||
|   /* USER CODE BEGIN LowLevelInterface */ | ||||
| 
 | ||||
|   /* USER CODE END LowLevelInterface */ | ||||
| 
 | ||||
| /*******************************************************************************
 | ||||
|                        LL Driver Interface (USB Device Library --> PCD) | ||||
| *******************************************************************************/ | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Initializes the low level portion of the device driver. | ||||
|   * @param  pdev: Device handle | ||||
|   * @retval USBD status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev) | ||||
| { | ||||
|   /* Init USB Ip. */ | ||||
|   hpcd_USB_FS.pData = pdev; | ||||
|   /* Link the driver to the stack. */ | ||||
|   pdev->pData = &hpcd_USB_FS; | ||||
| /* Enable USB power on Pwrctrl CR2 register. */ | ||||
|   HAL_PWREx_EnableVddUSB(); | ||||
| 
 | ||||
|   hpcd_USB_FS.Instance = USB; | ||||
|   hpcd_USB_FS.Init.dev_endpoints = 8; | ||||
|   hpcd_USB_FS.Init.speed = PCD_SPEED_FULL; | ||||
|   hpcd_USB_FS.Init.phy_itface = PCD_PHY_EMBEDDED; | ||||
|   hpcd_USB_FS.Init.Sof_enable = DISABLE; | ||||
|   hpcd_USB_FS.Init.low_power_enable = DISABLE; | ||||
|   hpcd_USB_FS.Init.lpm_enable = DISABLE; | ||||
|   hpcd_USB_FS.Init.battery_charging_enable = DISABLE; | ||||
| 
 | ||||
|   #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
|   /* register Msp Callbacks (before the Init) */ | ||||
|   HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_MSPINIT_CB_ID, PCD_MspInit); | ||||
|   HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_MSPDEINIT_CB_ID, PCD_MspDeInit); | ||||
|   #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
| 
 | ||||
|   if (HAL_PCD_Init(&hpcd_USB_FS) != HAL_OK) | ||||
|   { | ||||
|     Error_Handler( ); | ||||
|   } | ||||
| 
 | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
|   /* Register USB PCD CallBacks */ | ||||
|   HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_SOF_CB_ID, PCD_SOFCallback); | ||||
|   HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_SETUPSTAGE_CB_ID, PCD_SetupStageCallback); | ||||
|   HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_RESET_CB_ID, PCD_ResetCallback); | ||||
|   HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_SUSPEND_CB_ID, PCD_SuspendCallback); | ||||
|   HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_RESUME_CB_ID, PCD_ResumeCallback); | ||||
|   HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_CONNECT_CB_ID, PCD_ConnectCallback); | ||||
|   HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_DISCONNECT_CB_ID, PCD_DisconnectCallback); | ||||
|   /* USER CODE BEGIN RegisterCallBackFirstPart */ | ||||
| 
 | ||||
|   /* USER CODE END RegisterCallBackFirstPart */ | ||||
|   HAL_PCD_RegisterLpmCallback(&hpcd_USB_FS, PCDEx_LPM_Callback); | ||||
|   HAL_PCD_RegisterDataOutStageCallback(&hpcd_USB_FS, PCD_DataOutStageCallback); | ||||
|   HAL_PCD_RegisterDataInStageCallback(&hpcd_USB_FS, PCD_DataInStageCallback); | ||||
|   HAL_PCD_RegisterIsoOutIncpltCallback(&hpcd_USB_FS, PCD_ISOOUTIncompleteCallback); | ||||
|   HAL_PCD_RegisterIsoInIncpltCallback(&hpcd_USB_FS, PCD_ISOINIncompleteCallback); | ||||
|   /* USER CODE BEGIN RegisterCallBackSecondPart */ | ||||
| 
 | ||||
|   /* USER CODE END RegisterCallBackSecondPart */ | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
|   /* USER CODE BEGIN EndPoint_Configuration */ | ||||
|   HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x00 , PCD_SNG_BUF, 0x18); | ||||
|   HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x80 , PCD_SNG_BUF, 0x58); | ||||
|   /* USER CODE END EndPoint_Configuration */ | ||||
|   /* USER CODE BEGIN EndPoint_Configuration_CDC */ | ||||
|   HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x81 , PCD_SNG_BUF, 0xC0); | ||||
|   HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x01 , PCD_SNG_BUF, 0x110); | ||||
|   HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x82 , PCD_SNG_BUF, 0x100); | ||||
|   /* USER CODE END EndPoint_Configuration_CDC */ | ||||
|   return USBD_OK; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  De-Initializes the low level portion of the device driver. | ||||
|   * @param  pdev: Device handle | ||||
|   * @retval USBD status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev) | ||||
| { | ||||
|   HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|   USBD_StatusTypeDef usb_status = USBD_OK; | ||||
| 
 | ||||
|   hal_status = HAL_PCD_DeInit(pdev->pData); | ||||
| 
 | ||||
|   usb_status =  USBD_Get_USB_Status(hal_status); | ||||
| 
 | ||||
|   return usb_status; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Starts the low level portion of the device driver. | ||||
|   * @param  pdev: Device handle | ||||
|   * @retval USBD status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev) | ||||
| { | ||||
|   HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|   USBD_StatusTypeDef usb_status = USBD_OK; | ||||
| 
 | ||||
|   hal_status = HAL_PCD_Start(pdev->pData); | ||||
| 
 | ||||
|   usb_status =  USBD_Get_USB_Status(hal_status); | ||||
| 
 | ||||
|   return usb_status; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Stops the low level portion of the device driver. | ||||
|   * @param  pdev: Device handle | ||||
|   * @retval USBD status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev) | ||||
| { | ||||
|   HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|   USBD_StatusTypeDef usb_status = USBD_OK; | ||||
| 
 | ||||
|   hal_status = HAL_PCD_Stop(pdev->pData); | ||||
| 
 | ||||
|   usb_status =  USBD_Get_USB_Status(hal_status); | ||||
| 
 | ||||
|   return usb_status; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Opens an endpoint of the low level driver. | ||||
|   * @param  pdev: Device handle | ||||
|   * @param  ep_addr: Endpoint number | ||||
|   * @param  ep_type: Endpoint type | ||||
|   * @param  ep_mps: Endpoint max packet size | ||||
|   * @retval USBD status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps) | ||||
| { | ||||
|   HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|   USBD_StatusTypeDef usb_status = USBD_OK; | ||||
| 
 | ||||
|   hal_status = HAL_PCD_EP_Open(pdev->pData, ep_addr, ep_mps, ep_type); | ||||
| 
 | ||||
|   usb_status =  USBD_Get_USB_Status(hal_status); | ||||
| 
 | ||||
|   return usb_status; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Closes an endpoint of the low level driver. | ||||
|   * @param  pdev: Device handle | ||||
|   * @param  ep_addr: Endpoint number | ||||
|   * @retval USBD status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) | ||||
| { | ||||
|   HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|   USBD_StatusTypeDef usb_status = USBD_OK; | ||||
| 
 | ||||
|   hal_status = HAL_PCD_EP_Close(pdev->pData, ep_addr); | ||||
| 
 | ||||
|   usb_status =  USBD_Get_USB_Status(hal_status); | ||||
| 
 | ||||
|   return usb_status; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Flushes an endpoint of the Low Level Driver. | ||||
|   * @param  pdev: Device handle | ||||
|   * @param  ep_addr: Endpoint number | ||||
|   * @retval USBD status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) | ||||
| { | ||||
|   HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|   USBD_StatusTypeDef usb_status = USBD_OK; | ||||
| 
 | ||||
|   hal_status = HAL_PCD_EP_Flush(pdev->pData, ep_addr); | ||||
| 
 | ||||
|   usb_status =  USBD_Get_USB_Status(hal_status); | ||||
| 
 | ||||
|   return usb_status; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Sets a Stall condition on an endpoint of the Low Level Driver. | ||||
|   * @param  pdev: Device handle | ||||
|   * @param  ep_addr: Endpoint number | ||||
|   * @retval USBD status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) | ||||
| { | ||||
|   HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|   USBD_StatusTypeDef usb_status = USBD_OK; | ||||
| 
 | ||||
|   hal_status = HAL_PCD_EP_SetStall(pdev->pData, ep_addr); | ||||
| 
 | ||||
|   usb_status =  USBD_Get_USB_Status(hal_status); | ||||
| 
 | ||||
|   return usb_status; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Clears a Stall condition on an endpoint of the Low Level Driver. | ||||
|   * @param  pdev: Device handle | ||||
|   * @param  ep_addr: Endpoint number | ||||
|   * @retval USBD status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) | ||||
| { | ||||
|   HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|   USBD_StatusTypeDef usb_status = USBD_OK; | ||||
| 
 | ||||
|   hal_status = HAL_PCD_EP_ClrStall(pdev->pData, ep_addr); | ||||
| 
 | ||||
|   usb_status =  USBD_Get_USB_Status(hal_status); | ||||
| 
 | ||||
|   return usb_status; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Returns Stall condition. | ||||
|   * @param  pdev: Device handle | ||||
|   * @param  ep_addr: Endpoint number | ||||
|   * @retval Stall (1: Yes, 0: No) | ||||
|   */ | ||||
| uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) | ||||
| { | ||||
|   PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData; | ||||
| 
 | ||||
|   if((ep_addr & 0x80) == 0x80) | ||||
|   { | ||||
|     return hpcd->IN_ep[ep_addr & 0x7F].is_stall; | ||||
|   } | ||||
|   else | ||||
|   { | ||||
|     return hpcd->OUT_ep[ep_addr & 0x7F].is_stall; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Assigns a USB address to the device. | ||||
|   * @param  pdev: Device handle | ||||
|   * @param  dev_addr: Device address | ||||
|   * @retval USBD status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr) | ||||
| { | ||||
|   HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|   USBD_StatusTypeDef usb_status = USBD_OK; | ||||
| 
 | ||||
|   hal_status = HAL_PCD_SetAddress(pdev->pData, dev_addr); | ||||
| 
 | ||||
|   usb_status =  USBD_Get_USB_Status(hal_status); | ||||
| 
 | ||||
|   return usb_status; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Transmits data over an endpoint. | ||||
|   * @param  pdev: Device handle | ||||
|   * @param  ep_addr: Endpoint number | ||||
|   * @param  pbuf: Pointer to data to be sent | ||||
|   * @param  size: Data size | ||||
|   * @retval USBD status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t size) | ||||
| { | ||||
|   HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|   USBD_StatusTypeDef usb_status = USBD_OK; | ||||
| 
 | ||||
|   hal_status = HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size); | ||||
| 
 | ||||
|   usb_status =  USBD_Get_USB_Status(hal_status); | ||||
| 
 | ||||
|   return usb_status; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Prepares an endpoint for reception. | ||||
|   * @param  pdev: Device handle | ||||
|   * @param  ep_addr: Endpoint number | ||||
|   * @param  pbuf: Pointer to data to be received | ||||
|   * @param  size: Data size | ||||
|   * @retval USBD status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t size) | ||||
| { | ||||
|   HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|   USBD_StatusTypeDef usb_status = USBD_OK; | ||||
| 
 | ||||
|   hal_status = HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size); | ||||
| 
 | ||||
|   usb_status =  USBD_Get_USB_Status(hal_status); | ||||
| 
 | ||||
|   return usb_status; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Returns the last transfered packet size. | ||||
|   * @param  pdev: Device handle | ||||
|   * @param  ep_addr: Endpoint number | ||||
|   * @retval Recived Data Size | ||||
|   */ | ||||
| uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr) | ||||
| { | ||||
|   return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*) pdev->pData, ep_addr); | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Send LPM message to user layer | ||||
|   * @param  hpcd: PCD handle | ||||
|   * @param  msg: LPM message | ||||
|   * @retval None | ||||
|   */ | ||||
| #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) | ||||
| static void PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg) | ||||
| #else | ||||
| void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg) | ||||
| #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ | ||||
| { | ||||
|   /* USER CODE BEGIN LPM_Callback */ | ||||
|   switch (msg) | ||||
|   { | ||||
|   case PCD_LPM_L0_ACTIVE: | ||||
|     if (hpcd->Init.low_power_enable) | ||||
|     { | ||||
|       SystemClockConfig_Resume(); | ||||
| 
 | ||||
|       /* Reset SLEEPDEEP bit of Cortex System Control Register. */ | ||||
|       SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); | ||||
|     } | ||||
|     USBD_LL_Resume(hpcd->pData); | ||||
|     break; | ||||
| 
 | ||||
|   case PCD_LPM_L1_ACTIVE: | ||||
|     USBD_LL_Suspend(hpcd->pData); | ||||
| 
 | ||||
|     /* Enter in STOP mode. */ | ||||
|     if (hpcd->Init.low_power_enable) | ||||
|     { | ||||
|       /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */ | ||||
|       SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); | ||||
|     } | ||||
|     break; | ||||
|   } | ||||
|   /* USER CODE END LPM_Callback */ | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Delays routine for the USB Device Library. | ||||
|   * @param  Delay: Delay in ms | ||||
|   * @retval None | ||||
|   */ | ||||
| void USBD_LL_Delay(uint32_t Delay) | ||||
| { | ||||
|   HAL_Delay(Delay); | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Static single allocation. | ||||
|   * @param  size: Size of allocated memory | ||||
|   * @retval None | ||||
|   */ | ||||
| void *USBD_static_malloc(uint32_t size) | ||||
| { | ||||
|   static uint32_t mem[(sizeof(USBD_CDC_HandleTypeDef)/4)+1];/* On 32-bit boundary */ | ||||
|   return mem; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Dummy memory free | ||||
|   * @param  p: Pointer to allocated  memory address | ||||
|   * @retval None | ||||
|   */ | ||||
| void USBD_static_free(void *p) | ||||
| { | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| /* USER CODE BEGIN 5 */ | ||||
| /**
 | ||||
|   * @brief  Configures system clock after wake-up from USB resume callBack: | ||||
|   *         enable HSI, PLL and select PLL as system clock source. | ||||
|   * @retval None | ||||
|   */ | ||||
| static void SystemClockConfig_Resume(void) | ||||
| { | ||||
| } | ||||
| /* USER CODE END 5 */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Retuns the USB status depending on the HAL status: | ||||
|   * @param  hal_status: HAL status | ||||
|   * @retval USB status | ||||
|   */ | ||||
| USBD_StatusTypeDef USBD_Get_USB_Status(HAL_StatusTypeDef hal_status) | ||||
| { | ||||
|   USBD_StatusTypeDef usb_status = USBD_OK; | ||||
| 
 | ||||
|   switch (hal_status) | ||||
|   { | ||||
|     case HAL_OK : | ||||
|       usb_status = USBD_OK; | ||||
|     break; | ||||
|     case HAL_ERROR : | ||||
|       usb_status = USBD_FAIL; | ||||
|     break; | ||||
|     case HAL_BUSY : | ||||
|       usb_status = USBD_BUSY; | ||||
|     break; | ||||
|     case HAL_TIMEOUT : | ||||
|       usb_status = USBD_FAIL; | ||||
|     break; | ||||
|     default : | ||||
|       usb_status = USBD_FAIL; | ||||
|     break; | ||||
|   } | ||||
|   return usb_status; | ||||
| } | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
| @ -1,391 +0,0 @@ | ||||
| /* USER CODE BEGIN Header */ | ||||
| /**
 | ||||
|   ****************************************************************************** | ||||
|   * @file           : usbd_desc.c | ||||
|   * @version        : v3.0_Cube | ||||
|   * @brief          : This file implements the USB device descriptors. | ||||
|   ****************************************************************************** | ||||
|   * @attention | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2020 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
| /* USER CODE END Header */ | ||||
| 
 | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "usbd_core.h" | ||||
| #include "usbd_desc.h" | ||||
| #include "usbd_conf.h" | ||||
| #include "furi-hal-version.h" | ||||
| /* USER CODE BEGIN INCLUDE */ | ||||
| 
 | ||||
| /* USER CODE END INCLUDE */ | ||||
| 
 | ||||
| /* Private typedef -----------------------------------------------------------*/ | ||||
| /* Private define ------------------------------------------------------------*/ | ||||
| /* Private macro -------------------------------------------------------------*/ | ||||
| 
 | ||||
| /* USER CODE BEGIN PV */ | ||||
| /* Private variables ---------------------------------------------------------*/ | ||||
| 
 | ||||
| /* USER CODE END PV */ | ||||
| 
 | ||||
| /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
 | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /** @addtogroup USBD_DESC
 | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_DESC_Private_TypesDefinitions USBD_DESC_Private_TypesDefinitions
 | ||||
|   * @brief Private types. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /* USER CODE BEGIN PRIVATE_TYPES */ | ||||
| 
 | ||||
| /* USER CODE END PRIVATE_TYPES */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_DESC_Private_Defines USBD_DESC_Private_Defines
 | ||||
|   * @brief Private defines. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| #define USBD_VID     1155 | ||||
| #define USBD_LANGID_STRING     1033 | ||||
| #define USBD_MANUFACTURER_STRING     "Flipper Devices Inc." | ||||
| #define USBD_PID     22336 | ||||
| #define USBD_CONFIGURATION_STRING     "CDC Config" | ||||
| #define USBD_INTERFACE_STRING     "CDC Interface" | ||||
| /* USER CODE BEGIN PRIVATE_DEFINES */ | ||||
| 
 | ||||
| /* USER CODE END PRIVATE_DEFINES */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /* USER CODE BEGIN 0 */ | ||||
| /* USER CODE END 0 */ | ||||
| 
 | ||||
| /** @defgroup USBD_DESC_Private_Macros USBD_DESC_Private_Macros
 | ||||
|   * @brief Private macros. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /* USER CODE BEGIN PRIVATE_MACRO */ | ||||
| 
 | ||||
| /* USER CODE END PRIVATE_MACRO */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes
 | ||||
|   * @brief Private functions declaration. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| static void Get_SerialNum(void); | ||||
| static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len); | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes
 | ||||
|   * @brief Private functions declaration. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| uint8_t * USBD_CDC_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | ||||
| uint8_t * USBD_CDC_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | ||||
| uint8_t * USBD_CDC_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | ||||
| uint8_t * USBD_CDC_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | ||||
| uint8_t * USBD_CDC_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | ||||
| uint8_t * USBD_CDC_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | ||||
| uint8_t * USBD_CDC_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables
 | ||||
|   * @brief Private variables. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| USBD_DescriptorsTypeDef CDC_Desc = | ||||
| { | ||||
|   USBD_CDC_DeviceDescriptor, | ||||
|   USBD_CDC_LangIDStrDescriptor, | ||||
|   USBD_CDC_ManufacturerStrDescriptor, | ||||
|   USBD_CDC_ProductStrDescriptor, | ||||
|   USBD_CDC_SerialStrDescriptor, | ||||
|   USBD_CDC_ConfigStrDescriptor, | ||||
|   USBD_CDC_InterfaceStrDescriptor | ||||
| }; | ||||
| 
 | ||||
| #if defined ( __ICCARM__ ) /* IAR Compiler */ | ||||
|   #pragma data_alignment=4 | ||||
| #endif /* defined ( __ICCARM__ ) */ | ||||
| /** USB standard device descriptor. */ | ||||
| __ALIGN_BEGIN uint8_t USBD_CDC_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = | ||||
| { | ||||
|   0x12,                       /*bLength */ | ||||
|   USB_DESC_TYPE_DEVICE,       /*bDescriptorType*/ | ||||
|   0x00,                       /*bcdUSB */ | ||||
|   0x02, | ||||
|   0x02,                       /*bDeviceClass*/ | ||||
|   0x02,                       /*bDeviceSubClass*/ | ||||
|   0x00,                       /*bDeviceProtocol*/ | ||||
|   USB_MAX_EP0_SIZE,           /*bMaxPacketSize*/ | ||||
|   LOBYTE(USBD_VID),           /*idVendor*/ | ||||
|   HIBYTE(USBD_VID),           /*idVendor*/ | ||||
|   LOBYTE(USBD_PID),           /*idProduct*/ | ||||
|   HIBYTE(USBD_PID),           /*idProduct*/ | ||||
|   0x00,                       /*bcdDevice rel. 2.00*/ | ||||
|   0x02, | ||||
|   USBD_IDX_MFC_STR,           /*Index of manufacturer  string*/ | ||||
|   USBD_IDX_PRODUCT_STR,       /*Index of product string*/ | ||||
|   USBD_IDX_SERIAL_STR,        /*Index of serial number string*/ | ||||
|   USBD_MAX_NUM_CONFIGURATION  /*bNumConfigurations*/ | ||||
| }; | ||||
| 
 | ||||
| /* USB_DeviceDescriptor */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables
 | ||||
|   * @brief Private variables. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| #if defined ( __ICCARM__ ) /* IAR Compiler */ | ||||
|   #pragma data_alignment=4 | ||||
| #endif /* defined ( __ICCARM__ ) */ | ||||
| 
 | ||||
| /** USB lang indentifier descriptor. */ | ||||
| __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = | ||||
| { | ||||
|      USB_LEN_LANGID_STR_DESC, | ||||
|      USB_DESC_TYPE_STRING, | ||||
|      LOBYTE(USBD_LANGID_STRING), | ||||
|      HIBYTE(USBD_LANGID_STRING) | ||||
| }; | ||||
| 
 | ||||
| #if defined ( __ICCARM__ ) /* IAR Compiler */ | ||||
|   #pragma data_alignment=4 | ||||
| #endif /* defined ( __ICCARM__ ) */ | ||||
| /* Internal string descriptor. */ | ||||
| __ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END; | ||||
| 
 | ||||
| #if defined ( __ICCARM__ ) /*!< IAR Compiler */ | ||||
|   #pragma data_alignment=4 | ||||
| #endif | ||||
| __ALIGN_BEGIN uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] __ALIGN_END = { | ||||
|   USB_SIZ_STRING_SERIAL, | ||||
|   USB_DESC_TYPE_STRING, | ||||
| }; | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /** @defgroup USBD_DESC_Private_Functions USBD_DESC_Private_Functions
 | ||||
|   * @brief Private functions. | ||||
|   * @{ | ||||
|   */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Return the device descriptor | ||||
|   * @param  speed : Current device speed | ||||
|   * @param  length : Pointer to data length variable | ||||
|   * @retval Pointer to descriptor buffer | ||||
|   */ | ||||
| uint8_t * USBD_CDC_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) | ||||
| { | ||||
|   UNUSED(speed); | ||||
|   *length = sizeof(USBD_CDC_DeviceDesc); | ||||
|   return USBD_CDC_DeviceDesc; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Return the LangID string descriptor | ||||
|   * @param  speed : Current device speed | ||||
|   * @param  length : Pointer to data length variable | ||||
|   * @retval Pointer to descriptor buffer | ||||
|   */ | ||||
| uint8_t * USBD_CDC_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) | ||||
| { | ||||
|   UNUSED(speed); | ||||
|   *length = sizeof(USBD_LangIDDesc); | ||||
|   return USBD_LangIDDesc; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Return the product string descriptor | ||||
|   * @param  speed : Current device speed | ||||
|   * @param  length : Pointer to data length variable | ||||
|   * @retval Pointer to descriptor buffer | ||||
|   */ | ||||
| uint8_t * USBD_CDC_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) | ||||
| { | ||||
|   USBD_GetString((uint8_t*)furi_hal_version_get_device_name_ptr(), USBD_StrDesc, length); | ||||
|   return USBD_StrDesc; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Return the manufacturer string descriptor | ||||
|   * @param  speed : Current device speed | ||||
|   * @param  length : Pointer to data length variable | ||||
|   * @retval Pointer to descriptor buffer | ||||
|   */ | ||||
| uint8_t * USBD_CDC_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) | ||||
| { | ||||
|   UNUSED(speed); | ||||
|   USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length); | ||||
|   return USBD_StrDesc; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Return the serial number string descriptor | ||||
|   * @param  speed : Current device speed | ||||
|   * @param  length : Pointer to data length variable | ||||
|   * @retval Pointer to descriptor buffer | ||||
|   */ | ||||
| uint8_t * USBD_CDC_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) | ||||
| { | ||||
|   UNUSED(speed); | ||||
|   *length = USB_SIZ_STRING_SERIAL; | ||||
| 
 | ||||
|   /* Update the serial number string descriptor with the data from the unique
 | ||||
|    * ID */ | ||||
|   if(furi_hal_version_get_name_ptr()){ | ||||
|     char buffer[14] = "flip_"; | ||||
|     strncat(buffer, furi_hal_version_get_name_ptr(), 8); | ||||
|     USBD_GetString((uint8_t*) buffer, USBD_StringSerial, length); | ||||
|   } else { | ||||
|     Get_SerialNum(); | ||||
|   } | ||||
|   /* USER CODE BEGIN USBD_CDC_SerialStrDescriptor */ | ||||
| 
 | ||||
|   /* USER CODE END USBD_CDC_SerialStrDescriptor */ | ||||
| 
 | ||||
|   return (uint8_t *) USBD_StringSerial; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Return the configuration string descriptor | ||||
|   * @param  speed : Current device speed | ||||
|   * @param  length : Pointer to data length variable | ||||
|   * @retval Pointer to descriptor buffer | ||||
|   */ | ||||
| uint8_t * USBD_CDC_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) | ||||
| { | ||||
|   if(speed == USBD_SPEED_HIGH) | ||||
|   { | ||||
|     USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING, USBD_StrDesc, length); | ||||
|   } | ||||
|   else | ||||
|   { | ||||
|     USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING, USBD_StrDesc, length); | ||||
|   } | ||||
|   return USBD_StrDesc; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Return the interface string descriptor | ||||
|   * @param  speed : Current device speed | ||||
|   * @param  length : Pointer to data length variable | ||||
|   * @retval Pointer to descriptor buffer | ||||
|   */ | ||||
| uint8_t * USBD_CDC_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) | ||||
| { | ||||
|   if(speed == 0) | ||||
|   { | ||||
|     USBD_GetString((uint8_t *)USBD_INTERFACE_STRING, USBD_StrDesc, length); | ||||
|   } | ||||
|   else | ||||
|   { | ||||
|     USBD_GetString((uint8_t *)USBD_INTERFACE_STRING, USBD_StrDesc, length); | ||||
|   } | ||||
|   return USBD_StrDesc; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Create the serial number string descriptor | ||||
|   * @param  None | ||||
|   * @retval None | ||||
|   */ | ||||
| static void Get_SerialNum(void) | ||||
| { | ||||
|   uint32_t deviceserial0, deviceserial1, deviceserial2; | ||||
| 
 | ||||
|   deviceserial0 = *(uint32_t *) DEVICE_ID1; | ||||
|   deviceserial1 = *(uint32_t *) DEVICE_ID2; | ||||
|   deviceserial2 = *(uint32_t *) DEVICE_ID3; | ||||
| 
 | ||||
|   deviceserial0 += deviceserial2; | ||||
| 
 | ||||
|   if (deviceserial0 != 0) | ||||
|   { | ||||
|     IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8); | ||||
|     IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|   * @brief  Convert Hex 32Bits value into char | ||||
|   * @param  value: value to convert | ||||
|   * @param  pbuf: pointer to the buffer | ||||
|   * @param  len: buffer length | ||||
|   * @retval None | ||||
|   */ | ||||
| static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len) | ||||
| { | ||||
|   uint8_t idx = 0; | ||||
| 
 | ||||
|   for (idx = 0; idx < len; idx++) | ||||
|   { | ||||
|     if (((value >> 28)) < 0xA) | ||||
|     { | ||||
|       pbuf[2 * idx] = (value >> 28) + '0'; | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|       pbuf[2 * idx] = (value >> 28) + 'A' - 10; | ||||
|     } | ||||
| 
 | ||||
|     value = value << 4; | ||||
| 
 | ||||
|     pbuf[2 * idx + 1] = 0; | ||||
|   } | ||||
| } | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /**
 | ||||
|   * @} | ||||
|   */ | ||||
| 
 | ||||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | ||||
| @ -9,7 +9,6 @@ | ||||
| 
 | ||||
| #include "cmsis_os.h" | ||||
| #include "shci.h" | ||||
| #include "stm32_lpm.h" | ||||
| #include "otp.h" | ||||
| #include "dis_app.h" | ||||
| #include "hrs_app.h" | ||||
|  | ||||
| @ -6,7 +6,6 @@ | ||||
| #include "tl.h" | ||||
| #include "cmsis_os.h" | ||||
| #include "shci_tl.h" | ||||
| #include "stm32_lpm.h" | ||||
| #include "app_debug.h" | ||||
| #include <furi-hal.h> | ||||
| 
 | ||||
|  | ||||
| @ -67,3 +67,7 @@ void furi_hal_console_printf(const char format[], ...) { | ||||
|     furi_hal_console_tx((const uint8_t*)string_get_cstr(string), string_size(string)); | ||||
|     string_clear(string); | ||||
| } | ||||
| 
 | ||||
| void furi_hal_console_puts(const char *data) { | ||||
|     furi_hal_console_tx((const uint8_t*)data, strlen(data)); | ||||
| } | ||||
| @ -11,8 +11,16 @@ void furi_hal_console_init(); | ||||
| 
 | ||||
| void furi_hal_console_tx(const uint8_t* buffer, size_t buffer_size); | ||||
| 
 | ||||
| /**
 | ||||
|  * Printf-like plain uart interface | ||||
|  * @warning Will not work in ISR context | ||||
|  * @param format  | ||||
|  * @param ...  | ||||
|  */ | ||||
| void furi_hal_console_printf(const char format[], ...); | ||||
| 
 | ||||
| void furi_hal_console_puts(const char* data); | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
|  | ||||
| @ -1,15 +1,20 @@ | ||||
| #include <furi-hal-vcp.h> | ||||
| #include <usbd_cdc_if.h> | ||||
| #include <furi-hal-vcp_i.h> | ||||
| 
 | ||||
| #include <furi.h> | ||||
| #include <usbd_cdc_if.h> | ||||
| #include <stream_buffer.h> | ||||
| 
 | ||||
| #define FURI_HAL_VCP_RX_BUFFER_SIZE 600 | ||||
| #define FURI_HAL_VCP_RX_BUFFER_SIZE (APP_RX_DATA_SIZE * 5) | ||||
| 
 | ||||
| extern USBD_HandleTypeDef hUsbDeviceFS; | ||||
| 
 | ||||
| typedef struct { | ||||
|     volatile bool connected; | ||||
| 
 | ||||
|     StreamBufferHandle_t rx_stream; | ||||
|     volatile bool rx_stream_full; | ||||
| 
 | ||||
|     osSemaphoreId_t tx_semaphore; | ||||
|     volatile bool alive; | ||||
|     volatile bool underrun; | ||||
| } FuriHalVcp; | ||||
| 
 | ||||
| static FuriHalVcp* furi_hal_vcp = NULL; | ||||
| @ -17,66 +22,31 @@ static FuriHalVcp* furi_hal_vcp = NULL; | ||||
| static const uint8_t ascii_soh = 0x01; | ||||
| static const uint8_t ascii_eot = 0x04; | ||||
| 
 | ||||
| void _furi_hal_vcp_init(); | ||||
| void _furi_hal_vcp_deinit(); | ||||
| void _furi_hal_vcp_control_line(uint8_t state); | ||||
| void _furi_hal_vcp_rx_callback(const uint8_t* buffer, size_t size); | ||||
| void _furi_hal_vcp_tx_complete(size_t size); | ||||
| 
 | ||||
| void furi_hal_vcp_init() { | ||||
|     furi_hal_vcp = furi_alloc(sizeof(FuriHalVcp)); | ||||
|     furi_hal_vcp->connected = false; | ||||
|      | ||||
|     furi_hal_vcp->rx_stream = xStreamBufferCreate(FURI_HAL_VCP_RX_BUFFER_SIZE, 1); | ||||
|     furi_hal_vcp->rx_stream_full = false; | ||||
| 
 | ||||
|     furi_hal_vcp->tx_semaphore = osSemaphoreNew(1, 1, NULL); | ||||
|     furi_hal_vcp->alive = false; | ||||
|     furi_hal_vcp->underrun = false; | ||||
| 
 | ||||
|     FURI_LOG_I("FuriHalVcp", "Init OK"); | ||||
| } | ||||
| 
 | ||||
| void _furi_hal_vcp_init() { | ||||
|     osSemaphoreRelease(furi_hal_vcp->tx_semaphore); | ||||
| } | ||||
| 
 | ||||
| void _furi_hal_vcp_deinit() { | ||||
|     furi_hal_vcp->alive = false; | ||||
|     osSemaphoreRelease(furi_hal_vcp->tx_semaphore); | ||||
| } | ||||
| 
 | ||||
| void _furi_hal_vcp_control_line(uint8_t state) { | ||||
|     // bit 0: DTR state, bit 1: RTS state
 | ||||
|     // bool dtr = state & 0b01;
 | ||||
|     bool dtr = state & 0b1; | ||||
| 
 | ||||
|     if (dtr) { | ||||
|         if (!furi_hal_vcp->alive) { | ||||
|             furi_hal_vcp->alive = true; | ||||
|             _furi_hal_vcp_rx_callback(&ascii_soh, 1); // SOH
 | ||||
|         } | ||||
|     } else { | ||||
|         if (furi_hal_vcp->alive) { | ||||
|             _furi_hal_vcp_rx_callback(&ascii_eot, 1); // EOT
 | ||||
|             furi_hal_vcp->alive = false; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     osSemaphoreRelease(furi_hal_vcp->tx_semaphore); | ||||
| } | ||||
| 
 | ||||
| void _furi_hal_vcp_rx_callback(const uint8_t* buffer, size_t size) { | ||||
|     BaseType_t xHigherPriorityTaskWoken = pdFALSE; | ||||
|     size_t ret = xStreamBufferSendFromISR(furi_hal_vcp->rx_stream, buffer, size, &xHigherPriorityTaskWoken); | ||||
|     if (ret != size) { | ||||
|         furi_hal_vcp->underrun = true; | ||||
|     } | ||||
|     portYIELD_FROM_ISR(xHigherPriorityTaskWoken); | ||||
| } | ||||
| 
 | ||||
| void _furi_hal_vcp_tx_complete(size_t size) { | ||||
|     osSemaphoreRelease(furi_hal_vcp->tx_semaphore); | ||||
| } | ||||
| 
 | ||||
| size_t furi_hal_vcp_rx(uint8_t* buffer, size_t size) { | ||||
|     furi_assert(furi_hal_vcp); | ||||
|     return xStreamBufferReceive(furi_hal_vcp->rx_stream, buffer, size, portMAX_DELAY); | ||||
| 
 | ||||
|     size_t received = xStreamBufferReceive(furi_hal_vcp->rx_stream, buffer, size, portMAX_DELAY); | ||||
| 
 | ||||
|     if(furi_hal_vcp->rx_stream_full | ||||
|         &&xStreamBufferSpacesAvailable(furi_hal_vcp->rx_stream) >= APP_RX_DATA_SIZE) { | ||||
|         furi_hal_vcp->rx_stream_full = false; | ||||
|         // data accepted, start waiting for next packet
 | ||||
|         USBD_CDC_ReceivePacket(&hUsbDeviceFS); | ||||
|     } | ||||
| 
 | ||||
|     return received; | ||||
| } | ||||
| 
 | ||||
| size_t furi_hal_vcp_rx_with_timeout(uint8_t* buffer, size_t size, uint32_t timeout) { | ||||
| @ -87,8 +57,10 @@ size_t furi_hal_vcp_rx_with_timeout(uint8_t* buffer, size_t size, uint32_t timeo | ||||
| void furi_hal_vcp_tx(const uint8_t* buffer, size_t size) { | ||||
|     furi_assert(furi_hal_vcp); | ||||
| 
 | ||||
|     while (size > 0 && furi_hal_vcp->alive) { | ||||
|     while (size > 0 && furi_hal_vcp->connected) { | ||||
|         furi_check(osSemaphoreAcquire(furi_hal_vcp->tx_semaphore, osWaitForever) == osOK); | ||||
|         if (!furi_hal_vcp->connected) | ||||
|             break; | ||||
| 
 | ||||
|         size_t batch_size = size; | ||||
|         if (batch_size > APP_TX_DATA_SIZE) { | ||||
| @ -99,8 +71,58 @@ void furi_hal_vcp_tx(const uint8_t* buffer, size_t size) { | ||||
|             size -= batch_size; | ||||
|             buffer += batch_size; | ||||
|         } else { | ||||
|             // Shouldn't be there 
 | ||||
|             osDelay(100); | ||||
|             FURI_LOG_E("FuriHalVcp", "CDC_Transmit_FS failed"); | ||||
|             osDelay(50); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void furi_hal_vcp_on_usb_resume() { | ||||
|     osSemaphoreRelease(furi_hal_vcp->tx_semaphore); | ||||
| } | ||||
| 
 | ||||
| void furi_hal_vcp_on_usb_suspend() { | ||||
|     if (furi_hal_vcp->connected) { | ||||
|         furi_hal_vcp->connected = false; | ||||
|         osSemaphoreRelease(furi_hal_vcp->tx_semaphore); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void furi_hal_vcp_on_cdc_control_line(uint8_t state) { | ||||
|     // bit 0: DTR state, bit 1: RTS state
 | ||||
|     // bool dtr = state & 0b01;
 | ||||
|     bool dtr = state & 0b1; | ||||
| 
 | ||||
|     if (dtr) { | ||||
|         if (!furi_hal_vcp->connected) { | ||||
|             furi_hal_vcp->connected = true; | ||||
|             furi_hal_vcp_on_cdc_rx(&ascii_soh, 1); // SOH
 | ||||
|         } | ||||
|     } else { | ||||
|         if (furi_hal_vcp->connected) { | ||||
|             furi_hal_vcp_on_cdc_rx(&ascii_eot, 1); // EOT
 | ||||
|             furi_hal_vcp->connected = false; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     osSemaphoreRelease(furi_hal_vcp->tx_semaphore); | ||||
| } | ||||
| 
 | ||||
| void furi_hal_vcp_on_cdc_rx(const uint8_t* buffer, size_t size) { | ||||
|     BaseType_t xHigherPriorityTaskWoken = pdFALSE; | ||||
|     size_t ret = xStreamBufferSendFromISR(furi_hal_vcp->rx_stream, buffer, size, &xHigherPriorityTaskWoken); | ||||
|     furi_check(ret == size); | ||||
|      | ||||
|     if (xStreamBufferSpacesAvailable(furi_hal_vcp->rx_stream) >= APP_RX_DATA_SIZE) { | ||||
|         USBD_CDC_ReceivePacket(&hUsbDeviceFS); | ||||
|     } else { | ||||
|         furi_hal_vcp->rx_stream_full = true; | ||||
|     } | ||||
| 
 | ||||
|     portYIELD_FROM_ISR(xHigherPriorityTaskWoken); | ||||
| } | ||||
| 
 | ||||
| void furi_hal_vcp_on_cdc_tx_complete(size_t size) { | ||||
|     osSemaphoreRelease(furi_hal_vcp->tx_semaphore); | ||||
| } | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										13
									
								
								firmware/targets/f6/furi-hal/furi-hal-vcp_i.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								firmware/targets/f6/furi-hal/furi-hal-vcp_i.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,13 @@ | ||||
| #pragma once | ||||
| 
 | ||||
| #include <furi-hal-vcp.h> | ||||
| 
 | ||||
| void furi_hal_vcp_on_usb_resume(); | ||||
| 
 | ||||
| void furi_hal_vcp_on_usb_suspend(); | ||||
| 
 | ||||
| void furi_hal_vcp_on_cdc_control_line(uint8_t state); | ||||
| 
 | ||||
| void furi_hal_vcp_on_cdc_rx(const uint8_t* buffer, size_t size); | ||||
| 
 | ||||
| void furi_hal_vcp_on_cdc_tx_complete(size_t size); | ||||
| @ -14,20 +14,6 @@ FLASH_ADDRESS	= 0x08000000 | ||||
| CFLAGS			+= -DNO_BOOTLOADER | ||||
| endif | ||||
| 
 | ||||
| FURI_HAL_OS_DEBUG ?= 0 | ||||
| ifeq ($(FURI_HAL_OS_DEBUG), 1) | ||||
| CFLAGS			+= -DFURI_HAL_OS_DEBUG | ||||
| endif | ||||
| 
 | ||||
| FURI_HAL_SUBGHZ_TX_GPIO ?= 0 | ||||
| ifneq ($(FURI_HAL_SUBGHZ_TX_GPIO), 0) | ||||
| CFLAGS			+= -DFURI_HAL_SUBGHZ_TX_GPIO=$(FURI_HAL_SUBGHZ_TX_GPIO) | ||||
| endif | ||||
| 
 | ||||
| ifeq ($(INVERT_RFID_IN), 1) | ||||
| CFLAGS += -DINVERT_RFID_IN | ||||
| endif | ||||
| 
 | ||||
| OPENOCD_OPTS	= -f interface/stlink.cfg -c "transport select hla_swd" -f ../debug/stm32wbx.cfg -c "stm32wbx.cpu configure -rtos auto" -c "init" | ||||
| BOOT_CFLAGS		= -DBOOT_ADDRESS=$(BOOT_ADDRESS) -DFW_ADDRESS=$(FW_ADDRESS) -DOS_OFFSET=$(OS_OFFSET) | ||||
| MCU_FLAGS		= -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard | ||||
| @ -39,9 +25,21 @@ CPPFLAGS		+= -fno-rtti -fno-use-cxa-atexit -fno-exceptions | ||||
| LDFLAGS			+= -Wl,--start-group -lstdc++ -lsupc++ -Wl,--end-group | ||||
| 
 | ||||
| MXPROJECT_DIR = $(TARGET_DIR) | ||||
| FURI_HAL_DIR = $(TARGET_DIR) | ||||
| 
 | ||||
| # Entry Point
 | ||||
| ASM_SOURCES += $(MXPROJECT_DIR)/startup_stm32wb55xx_cm4.s | ||||
| 
 | ||||
| # STM32WB HAL
 | ||||
| CUBE_DIR = ../lib/STM32CubeWB | ||||
| CFLAGS += \
 | ||||
| 	-DUSE_FULL_LL_DRIVER \
 | ||||
| 	-DUSE_HAL_DRIVER \
 | ||||
| 	-DHAVE_FREERTOS | ||||
| CFLAGS += \
 | ||||
| 	-I$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Inc \
 | ||||
| 	-I$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Inc/Legacy \
 | ||||
| 	-I$(CUBE_DIR)/Drivers/CMSIS/Device/ST/STM32WBxx/Include \
 | ||||
| 	-I$(CUBE_DIR)/Drivers/CMSIS/Include | ||||
| C_SOURCES += \
 | ||||
| 	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal.c \
 | ||||
| 	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_comp.c \
 | ||||
| @ -75,7 +73,14 @@ C_SOURCES		+= \ | ||||
| 	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_tim.c \
 | ||||
| 	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_usart.c \
 | ||||
| 	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_usb.c \
 | ||||
| 	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_utils.c \
 | ||||
| 	$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_utils.c | ||||
| 
 | ||||
| # FreeRTOS
 | ||||
| CFLAGS += \
 | ||||
| 	-I$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/include \
 | ||||
| 	-I$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 \
 | ||||
| 	-I$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F | ||||
| C_SOURCES += \
 | ||||
| 	$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/croutine.c \
 | ||||
| 	$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/event_groups.c \
 | ||||
| 	$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/list.c \
 | ||||
| @ -84,46 +89,11 @@ C_SOURCES		+= \ | ||||
| 	$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/tasks.c \
 | ||||
| 	$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/timers.c \
 | ||||
| 	$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c \
 | ||||
| 	$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c \
 | ||||
| 	$(CUBE_DIR)/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c \
 | ||||
| 	$(CUBE_DIR)/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c \
 | ||||
| 	$(CUBE_DIR)/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c \
 | ||||
| 	$(CUBE_DIR)/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c \
 | ||||
| 	$(wildcard $(MXPROJECT_DIR)/Src/*.c) \
 | ||||
| 	$(wildcard $(MXPROJECT_DIR)/Src/fatfs/*.c) \
 | ||||
| 	$(wildcard $(FURI_HAL_DIR)/furi-hal/*.c) | ||||
| 	$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c | ||||
| 
 | ||||
| ASM_SOURCES += $(MXPROJECT_DIR)/startup_stm32wb55xx_cm4.s | ||||
| 
 | ||||
| # Common
 | ||||
| # BLE glue 
 | ||||
| CFLAGS += \
 | ||||
| 	-DUSE_FULL_LL_DRIVER \
 | ||||
| 	-DUSE_HAL_DRIVER \
 | ||||
| 	-DHAVE_FREERTOS | ||||
| 
 | ||||
| ifeq ($(NO_BOOTLOADER), 1) | ||||
| LDFLAGS			+= -T$(MXPROJECT_DIR)/stm32wb55xx_flash_cm4_no_boot.ld | ||||
| else | ||||
| LDFLAGS			+= -T$(MXPROJECT_DIR)/stm32wb55xx_flash_cm4_boot.ld | ||||
| endif | ||||
| 
 | ||||
| CFLAGS += \
 | ||||
| 	-I$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Inc \
 | ||||
| 	-I$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Inc/Legacy \
 | ||||
| 	-I$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/include \
 | ||||
| 	-I$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 \
 | ||||
| 	-I$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F \
 | ||||
| 	-I$(CUBE_DIR)/Middlewares/ST/STM32_USB_Device_Library/Core/Inc \
 | ||||
| 	-I$(CUBE_DIR)/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc \
 | ||||
| 	-I$(CUBE_DIR)/Drivers/CMSIS/Device/ST/STM32WBxx/Include \
 | ||||
| 	-I$(CUBE_DIR)/Drivers/CMSIS/Include \
 | ||||
| 	-I$(MXPROJECT_DIR)/Inc \
 | ||||
| 	-I$(MXPROJECT_DIR)/Src/fatfs \
 | ||||
| 	-I$(FURI_HAL_DIR)/furi-hal \
 | ||||
| 
 | ||||
| # Ble glue 
 | ||||
| CFLAGS += -I$(TARGET_DIR)/ble-glue \
 | ||||
| 	-I$(CUBE_DIR)/Utilities/lpm/tiny_lpm \
 | ||||
| 	-I$(TARGET_DIR)/ble-glue \
 | ||||
| 	-I$(CUBE_DIR)/Middlewares/ST/STM32_WPAN \
 | ||||
| 	-I$(CUBE_DIR)/Middlewares/ST/STM32_WPAN/ble \
 | ||||
| 	-I$(CUBE_DIR)/Middlewares/ST/STM32_WPAN/ble/core \
 | ||||
| @ -132,7 +102,6 @@ CFLAGS += -I$(TARGET_DIR)/ble-glue \ | ||||
| 	-I$(CUBE_DIR)/Middlewares/ST/STM32_WPAN/interface/patterns/ble_thread \
 | ||||
| 	-I$(CUBE_DIR)/Middlewares/ST/STM32_WPAN/interface/patterns/ble_thread/tl \
 | ||||
| 	-I$(CUBE_DIR)/Middlewares/ST/STM32_WPAN/interface/patterns/ble_thread/shci | ||||
| 
 | ||||
| C_SOURCES += \
 | ||||
| 	$(wildcard $(TARGET_DIR)/ble-glue/*.c) \
 | ||||
| 	$(CUBE_DIR)/Middlewares/ST/STM32_WPAN/utilities/otp.c \
 | ||||
| @ -153,4 +122,50 @@ C_SOURCES		+= \ | ||||
| 	$(CUBE_DIR)/Middlewares/ST/STM32_WPAN/interface/patterns/ble_thread/tl/shci_tl_if.c \
 | ||||
| 	$(CUBE_DIR)/Middlewares/ST/STM32_WPAN/interface/patterns/ble_thread/shci/shci.c | ||||
| 
 | ||||
| # USB glue 
 | ||||
| CFLAGS += \
 | ||||
| 	-I$(TARGET_DIR)/usb-glue \
 | ||||
| 	-I$(CUBE_DIR)/Middlewares/ST/STM32_USB_Device_Library/Core/Inc \
 | ||||
| 	-I$(CUBE_DIR)/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc | ||||
| C_SOURCES += \
 | ||||
| 	$(wildcard $(TARGET_DIR)/usb-glue/*.c) \
 | ||||
| 	$(CUBE_DIR)/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c \
 | ||||
| 	$(CUBE_DIR)/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c \
 | ||||
| 	$(CUBE_DIR)/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c \
 | ||||
| 	$(CUBE_DIR)/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c | ||||
| 
 | ||||
| # Furi HAL
 | ||||
| FURI_HAL_OS_DEBUG ?= 0 | ||||
| ifeq ($(FURI_HAL_OS_DEBUG), 1) | ||||
| CFLAGS += -DFURI_HAL_OS_DEBUG | ||||
| endif | ||||
| 
 | ||||
| FURI_HAL_SUBGHZ_TX_GPIO ?= 0 | ||||
| ifneq ($(FURI_HAL_SUBGHZ_TX_GPIO), 0) | ||||
| CFLAGS += -DFURI_HAL_SUBGHZ_TX_GPIO=$(FURI_HAL_SUBGHZ_TX_GPIO) | ||||
| endif | ||||
| 
 | ||||
| ifeq ($(INVERT_RFID_IN), 1) | ||||
| CFLAGS += -DINVERT_RFID_IN | ||||
| endif | ||||
| 
 | ||||
| FURI_HAL_DIR = $(TARGET_DIR)/furi-hal | ||||
| CFLAGS += -I$(FURI_HAL_DIR) | ||||
| C_SOURCES += $(wildcard $(FURI_HAL_DIR)/*.c) | ||||
| 
 | ||||
| # Other
 | ||||
| CFLAGS += \
 | ||||
| 	-I$(MXPROJECT_DIR)/Inc \
 | ||||
| 	-I$(MXPROJECT_DIR)/Src/fatfs | ||||
| C_SOURCES += \
 | ||||
| 	$(wildcard $(MXPROJECT_DIR)/Src/*.c) \
 | ||||
| 	$(wildcard $(MXPROJECT_DIR)/Src/fatfs/*.c) | ||||
| 
 | ||||
| # Linker options
 | ||||
| ifeq ($(NO_BOOTLOADER), 1) | ||||
| LDFLAGS += -T$(MXPROJECT_DIR)/stm32wb55xx_flash_cm4_no_boot.ld | ||||
| else | ||||
| LDFLAGS += -T$(MXPROJECT_DIR)/stm32wb55xx_flash_cm4_boot.ld | ||||
| endif | ||||
| 
 | ||||
| SVD_FILE = ../debug/STM32WB55_CM4.svd | ||||
|  | ||||
							
								
								
									
										34
									
								
								firmware/targets/f6/usb-glue/usb_device.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								firmware/targets/f6/usb-glue/usb_device.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,34 @@ | ||||
| #include "usb_device.h" | ||||
| 
 | ||||
| #include "stm32wbxx.h" | ||||
| #include "stm32wbxx_hal.h" | ||||
| 
 | ||||
| #include "usbd_def.h" | ||||
| #include "usbd_core.h" | ||||
| #include "usbd_desc.h" | ||||
| #include "usbd_cdc.h" | ||||
| #include "usbd_cdc_if.h" | ||||
| 
 | ||||
| extern void Error_Handler(void); | ||||
| 
 | ||||
| /* USB Device Core handle declaration. */ | ||||
| USBD_HandleTypeDef hUsbDeviceFS; | ||||
| 
 | ||||
| extern USBD_DescriptorsTypeDef CDC_Desc; | ||||
| 
 | ||||
| /** Init USB device Library, add supported class and start the library */ | ||||
| void MX_USB_Device_Init(void) { | ||||
|     /* Init Device Library, add supported class and start the library. */ | ||||
|     if (USBD_Init(&hUsbDeviceFS, &CDC_Desc, DEVICE_FS) != USBD_OK) { | ||||
|         Error_Handler(); | ||||
|     } | ||||
|     if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK) { | ||||
|         Error_Handler(); | ||||
|     } | ||||
|     if (USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK) { | ||||
|         Error_Handler(); | ||||
|     } | ||||
|     if (USBD_Start(&hUsbDeviceFS) != USBD_OK) { | ||||
|         Error_Handler(); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								firmware/targets/f6/usb-glue/usb_device.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								firmware/targets/f6/usb-glue/usb_device.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,11 @@ | ||||
| #pragma once | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
|  extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| void MX_USB_Device_Init(); | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
							
								
								
									
										142
									
								
								firmware/targets/f6/usb-glue/usbd_cdc_if.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										142
									
								
								firmware/targets/f6/usb-glue/usbd_cdc_if.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,142 @@ | ||||
| #include "usbd_cdc_if.h" | ||||
| #include <furi-hal-vcp_i.h> | ||||
| 
 | ||||
| extern USBD_HandleTypeDef hUsbDeviceFS; | ||||
| 
 | ||||
| static int8_t CDC_Init_FS(void); | ||||
| static int8_t CDC_DeInit_FS(void); | ||||
| static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length); | ||||
| static int8_t CDC_Receive_FS(uint8_t* pbuf, uint32_t *Len); | ||||
| static int8_t CDC_TransmitCplt_FS(uint8_t *pbuf, uint32_t *Len, uint8_t epnum); | ||||
| 
 | ||||
| USBD_CDC_ItfTypeDef USBD_Interface_fops_FS = | ||||
| { | ||||
|     CDC_Init_FS, | ||||
|     CDC_DeInit_FS, | ||||
|     CDC_Control_FS, | ||||
|     CDC_Receive_FS, | ||||
|     CDC_TransmitCplt_FS | ||||
| }; | ||||
| 
 | ||||
| uint8_t UserRxBufferFS[APP_RX_DATA_SIZE]; | ||||
| uint8_t UserTxBufferFS[APP_TX_DATA_SIZE]; | ||||
| 
 | ||||
| /** Initializes the CDC media low layer over the FS USB IP
 | ||||
|  * @retval USBD_OK if all operations are OK else USBD_FAIL | ||||
|  */ | ||||
| static int8_t CDC_Init_FS(void) { | ||||
|     /* Set Application Buffers */ | ||||
|     USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0); | ||||
|     USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS); | ||||
|     return (USBD_OK); | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  DeInitializes the CDC media low layer | ||||
|  * @retval USBD_OK if all operations are OK else USBD_FAIL | ||||
|  */ | ||||
| static int8_t CDC_DeInit_FS(void) { | ||||
|     return (USBD_OK); | ||||
| } | ||||
| 
 | ||||
| /** Manage the CDC class requests
 | ||||
|  * @param  cmd: Command code | ||||
|  * @param  pbuf: Buffer containing command data (request parameters) | ||||
|  * @param  length: Number of data to be sent (in bytes) | ||||
|  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL | ||||
|  */ | ||||
| static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length) { | ||||
|     if (cmd == CDC_SEND_ENCAPSULATED_COMMAND) { | ||||
|     } else if (cmd == CDC_GET_ENCAPSULATED_RESPONSE) { | ||||
|     } else if (cmd == CDC_SET_COMM_FEATURE) { | ||||
|     } else if (cmd == CDC_GET_COMM_FEATURE) { | ||||
|     } else if (cmd == CDC_CLEAR_COMM_FEATURE) { | ||||
|     } else if (cmd == CDC_SET_LINE_CODING) { | ||||
|         /*******************************************************************************/ | ||||
|         /* Line Coding Structure                                                       */ | ||||
|         /*-----------------------------------------------------------------------------*/ | ||||
|         /* Offset | Field       | Size | Value  | Description                          */ | ||||
|         /* 0      | dwDTERate   |   4  | Number |Data terminal rate, in bits per second*/ | ||||
|         /* 4      | bCharFormat |   1  | Number | Stop bits                            */ | ||||
|         /*                                        0 - 1 Stop bit                       */ | ||||
|         /*                                        1 - 1.5 Stop bits                    */ | ||||
|         /*                                        2 - 2 Stop bits                      */ | ||||
|         /* 5      | bParityType |  1   | Number | Parity                               */ | ||||
|         /*                                        0 - None                             */ | ||||
|         /*                                        1 - Odd                              */ | ||||
|         /*                                        2 - Even                             */ | ||||
|         /*                                        3 - Mark                             */ | ||||
|         /*                                        4 - Space                            */ | ||||
|         /* 6      | bDataBits  |   1   | Number Data bits (5, 6, 7, 8 or 16).          */ | ||||
|         /*******************************************************************************/ | ||||
|     } else if (cmd == CDC_GET_LINE_CODING) { | ||||
|     } else if (cmd == CDC_SET_CONTROL_LINE_STATE) { | ||||
|         furi_hal_vcp_on_cdc_control_line(((USBD_SetupReqTypedef*)pbuf)->wValue); | ||||
|     } else if (cmd == CDC_SEND_BREAK) { | ||||
|     } else { | ||||
|     } | ||||
| 
 | ||||
|     return (USBD_OK); | ||||
| } | ||||
| 
 | ||||
| /** Data received over USB OUT endpoint are sent over CDC interface through this function.
 | ||||
|  * | ||||
|  * @note | ||||
|  * This function will issue a NAK packet on any OUT packet received on | ||||
|  * USB endpoint until exiting this function. If you exit this function | ||||
|  * before transfer is complete on CDC interface (ie. using DMA controller) | ||||
|  * it will result in receiving more data while previous ones are still | ||||
|  * not sent. | ||||
|  * | ||||
|  * @param  Buf: Buffer of data to be received | ||||
|  * @param  Len: Number of data received (in bytes) | ||||
|  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL | ||||
|  */ | ||||
| static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len) { | ||||
|     if (*Len) { | ||||
|         furi_hal_vcp_on_cdc_rx(Buf, *Len); | ||||
|     } else { | ||||
|         USBD_CDC_ReceivePacket(&hUsbDeviceFS); | ||||
|     } | ||||
|      | ||||
|     return (USBD_OK); | ||||
| } | ||||
| 
 | ||||
| /** CDC_Transmit_FS Data to send over USB IN endpoint are sent over CDC interface
 | ||||
|  * through this function. | ||||
|  * @param  Buf: Buffer of data to be sent | ||||
|  * @param  Len: Number of data to be sent (in bytes) | ||||
|  * @retval USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY | ||||
|  */ | ||||
| uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len) | ||||
| { | ||||
|     uint8_t result = USBD_OK; | ||||
| 
 | ||||
|     USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData; | ||||
|     if (hcdc->TxState != 0){ | ||||
|         return USBD_BUSY; | ||||
|     } | ||||
|     memcpy(UserTxBufferFS, Buf, Len); | ||||
|     USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, Len); | ||||
|     result = USBD_CDC_TransmitPacket(&hUsbDeviceFS); | ||||
| 
 | ||||
|     return result; | ||||
| } | ||||
| 
 | ||||
| /** CDC_TransmitCplt_FS Data transmited callback
 | ||||
|  * | ||||
|  * @note | ||||
|  * This function is IN transfer complete callback used to inform user that | ||||
|  * the submitted Data is successfully sent over USB. | ||||
|  * | ||||
|  * @param  Buf: Buffer of data to be received | ||||
|  * @param  Len: Number of data received (in bytes) | ||||
|  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL | ||||
|  */ | ||||
| static int8_t CDC_TransmitCplt_FS(uint8_t *Buf, uint32_t *Len, uint8_t epnum) { | ||||
|     uint8_t result = USBD_OK; | ||||
| 
 | ||||
|     furi_hal_vcp_on_cdc_tx_complete(*Len); | ||||
| 
 | ||||
|     return result; | ||||
| } | ||||
							
								
								
									
										22
									
								
								firmware/targets/f6/usb-glue/usbd_cdc_if.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								firmware/targets/f6/usb-glue/usbd_cdc_if.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,22 @@ | ||||
| #pragma once | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
|  extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| /* Includes ------------------------------------------------------------------*/ | ||||
| #include "usbd_cdc.h" | ||||
| 
 | ||||
| /* Define size for the receive and transmit buffer over CDC */ | ||||
| /* It's up to user to redefine and/or remove those define */ | ||||
| #define APP_RX_DATA_SIZE  CDC_DATA_FS_MAX_PACKET_SIZE | ||||
| #define APP_TX_DATA_SIZE  CDC_DATA_FS_MAX_PACKET_SIZE | ||||
| 
 | ||||
| /** CDC Interface callback. */ | ||||
| extern USBD_CDC_ItfTypeDef USBD_Interface_fops_FS; | ||||
| 
 | ||||
| uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len); | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
							
								
								
									
										506
									
								
								firmware/targets/f6/usb-glue/usbd_conf.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										506
									
								
								firmware/targets/f6/usb-glue/usbd_conf.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,506 @@ | ||||
| #include "stm32wbxx.h" | ||||
| #include "stm32wbxx_hal.h" | ||||
| 
 | ||||
| #include <furi-hal-vcp_i.h> | ||||
| 
 | ||||
| #include "usbd_def.h" | ||||
| #include "usbd_core.h" | ||||
| #include "usbd_cdc.h" | ||||
| 
 | ||||
| PCD_HandleTypeDef hpcd_USB_FS; | ||||
| void Error_Handler(void); | ||||
| 
 | ||||
| static USBD_StatusTypeDef USBD_Get_USB_Status(HAL_StatusTypeDef hal_status); | ||||
| 
 | ||||
| static void SystemClockConfig_Resume(void); | ||||
| 
 | ||||
| void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) { | ||||
|     GPIO_InitTypeDef GPIO_InitStruct = {0}; | ||||
|     if(pcdHandle->Instance==USB) { | ||||
|         __HAL_RCC_GPIOA_CLK_ENABLE(); | ||||
|         /**USB GPIO Configuration
 | ||||
|         PA11     ------> USB_DM | ||||
|         PA12     ------> USB_DP  | ||||
|         */ | ||||
|         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_FREQ_VERY_HIGH; | ||||
|         GPIO_InitStruct.Alternate = GPIO_AF10_USB; | ||||
|         HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | ||||
| 
 | ||||
|         /* Peripheral clock enable */ | ||||
|         __HAL_RCC_USB_CLK_ENABLE(); | ||||
| 
 | ||||
|         /* Peripheral interrupt init */ | ||||
|         HAL_NVIC_SetPriority(USB_LP_IRQn, 5, 0); | ||||
|         HAL_NVIC_EnableIRQ(USB_LP_IRQn); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) { | ||||
|     if(pcdHandle->Instance==USB) { | ||||
|         /* Peripheral clock disable */ | ||||
|         __HAL_RCC_USB_CLK_DISABLE(); | ||||
| 
 | ||||
|         /**USB GPIO Configuration
 | ||||
|         PA11     ------> USB_DM | ||||
|         PA12     ------> USB_DP | ||||
|         */ | ||||
|         HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12); | ||||
| 
 | ||||
|         /* Peripheral interrupt Deinit*/ | ||||
|         HAL_NVIC_DisableIRQ(USB_LP_IRQn); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /** Setup stage callback
 | ||||
|  * @param  hpcd: PCD handle | ||||
|  * @retval None | ||||
|  */ | ||||
| void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) { | ||||
|     USBD_LL_SetupStage((USBD_HandleTypeDef*)hpcd->pData, (uint8_t *)hpcd->Setup); | ||||
| } | ||||
| 
 | ||||
| /** Data Out stage callback.
 | ||||
|  * @param  hpcd: PCD handle | ||||
|  * @param  epnum: Endpoint number | ||||
|  * @retval None | ||||
|  */ | ||||
| void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) { | ||||
|     USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff); | ||||
| } | ||||
| 
 | ||||
| /** Data In stage callback.
 | ||||
|  * @param  hpcd: PCD handle | ||||
|  * @param  epnum: Endpoint number | ||||
|  * @retval None | ||||
|  */ | ||||
| void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) { | ||||
|     USBD_LL_DataInStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff); | ||||
| } | ||||
| 
 | ||||
| /** SOF callback.
 | ||||
|  * @param  hpcd: PCD handle | ||||
|  * @retval None | ||||
|  */ | ||||
| void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) { | ||||
|     USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData); | ||||
| } | ||||
| 
 | ||||
| /** Reset callback.
 | ||||
|  * @param  hpcd: PCD handle | ||||
|  * @retval None | ||||
|  */ | ||||
| void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) { | ||||
|     USBD_SpeedTypeDef speed = USBD_SPEED_FULL; | ||||
| 
 | ||||
|     if ( hpcd->Init.speed != PCD_SPEED_FULL) { | ||||
|         Error_Handler(); | ||||
|     } | ||||
| 
 | ||||
|     /* Set Speed. */ | ||||
|     USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, speed); | ||||
| 
 | ||||
|     /* Reset Device. */ | ||||
|     USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData); | ||||
| } | ||||
| 
 | ||||
| /** Suspend callback.
 | ||||
|  * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) | ||||
|  * @param  hpcd: PCD handle | ||||
|  * @retval None | ||||
|  */ | ||||
| void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) { | ||||
|     USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData); | ||||
| 
 | ||||
|     furi_hal_vcp_on_usb_suspend(); | ||||
|      | ||||
|     if (hpcd->Init.low_power_enable) { | ||||
|         /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */ | ||||
|         SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /** Resume callback.
 | ||||
|  * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) | ||||
|  * @param  hpcd: PCD handle | ||||
|  * @retval None | ||||
|  */ | ||||
| void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) { | ||||
|     if (hpcd->Init.low_power_enable) { | ||||
|         /* Reset SLEEPDEEP bit of Cortex System Control Register. */ | ||||
|         SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); | ||||
|         SystemClockConfig_Resume(); | ||||
|     } | ||||
| 
 | ||||
|     furi_hal_vcp_on_usb_resume(); | ||||
| 
 | ||||
|     USBD_LL_Resume((USBD_HandleTypeDef*)hpcd->pData); | ||||
| } | ||||
| 
 | ||||
| /** ISOOUTIncomplete callback.
 | ||||
|  * @param  hpcd: PCD handle | ||||
|  * @param  epnum: Endpoint number | ||||
|  * @retval None | ||||
|  */ | ||||
| void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) { | ||||
|     USBD_LL_IsoOUTIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); | ||||
| } | ||||
| 
 | ||||
| /** ISOINIncomplete callback.
 | ||||
|  * @param  hpcd: PCD handle | ||||
|  * @param  epnum: Endpoint number | ||||
|  * @retval None | ||||
|  */ | ||||
| void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) { | ||||
|     USBD_LL_IsoINIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); | ||||
| } | ||||
| 
 | ||||
| /** Connect callback.
 | ||||
|  * @param  hpcd: PCD handle | ||||
|  * @retval None | ||||
|  */ | ||||
| void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) { | ||||
|     USBD_LL_DevConnected((USBD_HandleTypeDef*)hpcd->pData); | ||||
| } | ||||
| 
 | ||||
| /** Disconnect callback.
 | ||||
|  * @param  hpcd: PCD handle | ||||
|  * @retval None | ||||
|  */ | ||||
| void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) { | ||||
|     USBD_LL_DevDisconnected((USBD_HandleTypeDef*)hpcd->pData); | ||||
| } | ||||
| 
 | ||||
| /** Initializes the low level portion of the device driver.
 | ||||
|  * @param  pdev: Device handle | ||||
|  * @retval USBD status | ||||
|  */ | ||||
| USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev) { | ||||
|     /* Init USB Ip. */ | ||||
|     hpcd_USB_FS.pData = pdev; | ||||
| 
 | ||||
|     /* Link the driver to the stack. */ | ||||
|     pdev->pData = &hpcd_USB_FS; | ||||
| 
 | ||||
|     /* Enable USB power on Pwrctrl CR2 register. */ | ||||
|     HAL_PWREx_EnableVddUSB(); | ||||
| 
 | ||||
|     hpcd_USB_FS.Instance = USB; | ||||
|     hpcd_USB_FS.Init.dev_endpoints = 8; | ||||
|     hpcd_USB_FS.Init.speed = PCD_SPEED_FULL; | ||||
|     hpcd_USB_FS.Init.phy_itface = PCD_PHY_EMBEDDED; | ||||
|     hpcd_USB_FS.Init.Sof_enable = DISABLE; | ||||
|     hpcd_USB_FS.Init.low_power_enable = DISABLE; | ||||
|     hpcd_USB_FS.Init.lpm_enable = DISABLE; | ||||
|     hpcd_USB_FS.Init.battery_charging_enable = DISABLE; | ||||
| 
 | ||||
|     if (HAL_PCD_Init(&hpcd_USB_FS) != HAL_OK) { | ||||
|         Error_Handler(); | ||||
|     } | ||||
| 
 | ||||
|     HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x00 , PCD_SNG_BUF, 0x18); | ||||
|     HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x80 , PCD_SNG_BUF, 0x58); | ||||
| 
 | ||||
|     HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x81 , PCD_SNG_BUF, 0xC0); | ||||
|     HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x01 , PCD_SNG_BUF, 0x110); | ||||
|     HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x82 , PCD_SNG_BUF, 0x100); | ||||
| 
 | ||||
|     return USBD_OK; | ||||
| } | ||||
| 
 | ||||
| /** De-Initializes the low level portion of the device driver.
 | ||||
|  * @param  pdev: Device handle | ||||
|  * @retval USBD status | ||||
|  */ | ||||
| USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev) | ||||
| { | ||||
|     HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|     USBD_StatusTypeDef usb_status = USBD_OK; | ||||
| 
 | ||||
|     hal_status = HAL_PCD_DeInit(pdev->pData); | ||||
| 
 | ||||
|     usb_status =  USBD_Get_USB_Status(hal_status); | ||||
| 
 | ||||
|     return usb_status; | ||||
| } | ||||
| 
 | ||||
| /** Starts the low level portion of the device driver.
 | ||||
|  * @param  pdev: Device handle | ||||
|  * @retval USBD status | ||||
|  */ | ||||
| USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev) { | ||||
|     HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|     USBD_StatusTypeDef usb_status = USBD_OK; | ||||
| 
 | ||||
|     hal_status = HAL_PCD_Start(pdev->pData); | ||||
| 
 | ||||
|     usb_status =  USBD_Get_USB_Status(hal_status); | ||||
| 
 | ||||
|     return usb_status; | ||||
| } | ||||
| 
 | ||||
| /** Stops the low level portion of the device driver.
 | ||||
|  * @param  pdev: Device handle | ||||
|  * @retval USBD status | ||||
|  */ | ||||
| USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev) { | ||||
|     HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|     USBD_StatusTypeDef usb_status = USBD_OK; | ||||
| 
 | ||||
|     hal_status = HAL_PCD_Stop(pdev->pData); | ||||
| 
 | ||||
|     usb_status =  USBD_Get_USB_Status(hal_status); | ||||
| 
 | ||||
|     return usb_status; | ||||
| } | ||||
| 
 | ||||
| /** Opens an endpoint of the low level driver.
 | ||||
|  * @param  pdev: Device handle | ||||
|  * @param  ep_addr: Endpoint number | ||||
|  * @param  ep_type: Endpoint type | ||||
|  * @param  ep_mps: Endpoint max packet size | ||||
|  * @retval USBD status | ||||
|  */ | ||||
| USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps) { | ||||
|     HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|     USBD_StatusTypeDef usb_status = USBD_OK; | ||||
| 
 | ||||
|     hal_status = HAL_PCD_EP_Open(pdev->pData, ep_addr, ep_mps, ep_type); | ||||
| 
 | ||||
|     usb_status =  USBD_Get_USB_Status(hal_status); | ||||
| 
 | ||||
|     return usb_status; | ||||
| } | ||||
| 
 | ||||
| /** Closes an endpoint of the low level driver.
 | ||||
|  * @param  pdev: Device handle | ||||
|  * @param  ep_addr: Endpoint number | ||||
|  * @retval USBD status | ||||
|  */ | ||||
| USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) { | ||||
|     HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|     USBD_StatusTypeDef usb_status = USBD_OK; | ||||
| 
 | ||||
|     hal_status = HAL_PCD_EP_Close(pdev->pData, ep_addr); | ||||
| 
 | ||||
|     usb_status =  USBD_Get_USB_Status(hal_status); | ||||
| 
 | ||||
|     return usb_status; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief  Flushes an endpoint of the Low Level Driver. | ||||
|  * @param  pdev: Device handle | ||||
|  * @param  ep_addr: Endpoint number | ||||
|  * @retval USBD status | ||||
|  */ | ||||
| USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) { | ||||
|     HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|     USBD_StatusTypeDef usb_status = USBD_OK; | ||||
| 
 | ||||
|     hal_status = HAL_PCD_EP_Flush(pdev->pData, ep_addr); | ||||
| 
 | ||||
|     usb_status =  USBD_Get_USB_Status(hal_status); | ||||
| 
 | ||||
|     return usb_status; | ||||
| } | ||||
| 
 | ||||
| /** Sets a Stall condition on an endpoint of the Low Level Driver.
 | ||||
|  * @param  pdev: Device handle | ||||
|  * @param  ep_addr: Endpoint number | ||||
|  * @retval USBD status | ||||
|  */ | ||||
| USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) { | ||||
|     HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|     USBD_StatusTypeDef usb_status = USBD_OK; | ||||
| 
 | ||||
|     hal_status = HAL_PCD_EP_SetStall(pdev->pData, ep_addr); | ||||
| 
 | ||||
|     usb_status =  USBD_Get_USB_Status(hal_status); | ||||
| 
 | ||||
|     return usb_status; | ||||
| } | ||||
| 
 | ||||
| /** Clears a Stall condition on an endpoint of the Low Level Driver.
 | ||||
|  * @param  pdev: Device handle | ||||
|  * @param  ep_addr: Endpoint number | ||||
|  * @retval USBD status | ||||
|  */ | ||||
| USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) { | ||||
|     HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|     USBD_StatusTypeDef usb_status = USBD_OK; | ||||
| 
 | ||||
|     hal_status = HAL_PCD_EP_ClrStall(pdev->pData, ep_addr); | ||||
| 
 | ||||
|     usb_status =  USBD_Get_USB_Status(hal_status); | ||||
| 
 | ||||
|     return usb_status; | ||||
| } | ||||
| 
 | ||||
| /** Returns Stall condition.
 | ||||
|  * @param  pdev: Device handle | ||||
|  * @param  ep_addr: Endpoint number | ||||
|  * @retval Stall (1: Yes, 0: No) | ||||
|  */ | ||||
| uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) { | ||||
|     PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData; | ||||
| 
 | ||||
|     if((ep_addr & 0x80) == 0x80) | ||||
|     { | ||||
|         return hpcd->IN_ep[ep_addr & 0x7F].is_stall; | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|         return hpcd->OUT_ep[ep_addr & 0x7F].is_stall; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /** Assigns a USB address to the device.
 | ||||
|  * @param  pdev: Device handle | ||||
|  * @param  dev_addr: Device address | ||||
|  * @retval USBD status | ||||
|  */ | ||||
| USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr) { | ||||
|     HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|     USBD_StatusTypeDef usb_status = USBD_OK; | ||||
| 
 | ||||
|     hal_status = HAL_PCD_SetAddress(pdev->pData, dev_addr); | ||||
| 
 | ||||
|     usb_status =  USBD_Get_USB_Status(hal_status); | ||||
| 
 | ||||
|     return usb_status; | ||||
| } | ||||
| 
 | ||||
| /** Transmits data over an endpoint.
 | ||||
|  * @param  pdev: Device handle | ||||
|  * @param  ep_addr: Endpoint number | ||||
|  * @param  pbuf: Pointer to data to be sent | ||||
|  * @param  size: Data size | ||||
|  * @retval USBD status | ||||
|  */ | ||||
| USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t size) { | ||||
|     HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|     USBD_StatusTypeDef usb_status = USBD_OK; | ||||
| 
 | ||||
|     hal_status = HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size); | ||||
| 
 | ||||
|     usb_status =  USBD_Get_USB_Status(hal_status); | ||||
| 
 | ||||
|     return usb_status; | ||||
| } | ||||
| 
 | ||||
| /** Prepares an endpoint for reception.
 | ||||
|  * @param  pdev: Device handle | ||||
|  * @param  ep_addr: Endpoint number | ||||
|  * @param  pbuf: Pointer to data to be received | ||||
|  * @param  size: Data size | ||||
|  * @retval USBD status | ||||
|  */ | ||||
| USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t size) { | ||||
|     HAL_StatusTypeDef hal_status = HAL_OK; | ||||
|     USBD_StatusTypeDef usb_status = USBD_OK; | ||||
| 
 | ||||
|     hal_status = HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size); | ||||
| 
 | ||||
|     usb_status =  USBD_Get_USB_Status(hal_status); | ||||
| 
 | ||||
|     return usb_status; | ||||
| } | ||||
| 
 | ||||
| /** Returns the last transfered packet size.
 | ||||
|  * @param  pdev: Device handle | ||||
|  * @param  ep_addr: Endpoint number | ||||
|  * @retval Recived Data Size | ||||
|  */ | ||||
| uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr) { | ||||
|     return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*) pdev->pData, ep_addr); | ||||
| } | ||||
| 
 | ||||
| /** Send LPM message to user layer
 | ||||
|  * @param  hpcd: PCD handle | ||||
|  * @param  msg: LPM message | ||||
|  * @retval None | ||||
|  */ | ||||
| void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg) { | ||||
|     switch (msg) { | ||||
|     case PCD_LPM_L0_ACTIVE: | ||||
|         if (hpcd->Init.low_power_enable) { | ||||
|             SystemClockConfig_Resume(); | ||||
|             /* Reset SLEEPDEEP bit of Cortex System Control Register. */ | ||||
|             SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); | ||||
|         } | ||||
|         USBD_LL_Resume(hpcd->pData); | ||||
|         break; | ||||
| 
 | ||||
|     case PCD_LPM_L1_ACTIVE: | ||||
|         USBD_LL_Suspend(hpcd->pData); | ||||
| 
 | ||||
|         /* Enter in STOP mode. */ | ||||
|         if (hpcd->Init.low_power_enable) { | ||||
|             /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */ | ||||
|             SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); | ||||
|         } | ||||
|         break; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /** Delays routine for the USB Device Library.
 | ||||
|  * @param  Delay: Delay in ms | ||||
|  * @retval None | ||||
|  */ | ||||
| void USBD_LL_Delay(uint32_t Delay) { | ||||
|     HAL_Delay(Delay); | ||||
| } | ||||
| 
 | ||||
| /** Static single allocation.
 | ||||
|  * @param  size: Size of allocated memory | ||||
|  * @retval None | ||||
|  */ | ||||
| void *USBD_static_malloc(uint32_t size) { | ||||
|     static uint32_t mem[(sizeof(USBD_CDC_HandleTypeDef)/4)+1];/* On 32-bit boundary */ | ||||
|     return mem; | ||||
| } | ||||
| 
 | ||||
| /** Dummy memory free
 | ||||
|  * @param  p: Pointer to allocated  memory address | ||||
|  * @retval None | ||||
|  */ | ||||
| void USBD_static_free(void *p) { | ||||
| } | ||||
| 
 | ||||
| /** Configures system clock after wake-up from USB resume callBack:
 | ||||
|  * enable HSI, PLL and select PLL as system clock source. | ||||
|  * @retval None | ||||
|  */ | ||||
| static void SystemClockConfig_Resume(void) { | ||||
| } | ||||
| 
 | ||||
| /** Retuns the USB status depending on the HAL status:
 | ||||
|  * @param  hal_status: HAL status | ||||
|  * @retval USB status | ||||
|  */ | ||||
| USBD_StatusTypeDef USBD_Get_USB_Status(HAL_StatusTypeDef hal_status) { | ||||
|     USBD_StatusTypeDef usb_status = USBD_OK; | ||||
| 
 | ||||
|     switch (hal_status) | ||||
|     { | ||||
|         case HAL_OK : | ||||
|             usb_status = USBD_OK; | ||||
|         break; | ||||
|         case HAL_ERROR : | ||||
|             usb_status = USBD_FAIL; | ||||
|         break; | ||||
|         case HAL_BUSY : | ||||
|             usb_status = USBD_BUSY; | ||||
|         break; | ||||
|         case HAL_TIMEOUT : | ||||
|             usb_status = USBD_FAIL; | ||||
|         break; | ||||
|         default : | ||||
|             usb_status = USBD_FAIL; | ||||
|         break; | ||||
|     } | ||||
|     return usb_status; | ||||
| } | ||||
							
								
								
									
										73
									
								
								firmware/targets/f6/usb-glue/usbd_conf.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								firmware/targets/f6/usb-glue/usbd_conf.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,73 @@ | ||||
| #pragma once | ||||
| 
 | ||||
| #include <stdio.h> | ||||
| #include <stdlib.h> | ||||
| #include <string.h> | ||||
| #include "stm32wbxx.h" | ||||
| #include "stm32wbxx_hal.h" | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
|  extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| #define USBD_MAX_NUM_INTERFACES     1U | ||||
| #define USBD_MAX_NUM_CONFIGURATION  1U | ||||
| #define USBD_MAX_STR_DESC_SIZ       512U | ||||
| #define USBD_DEBUG_LEVEL            0U | ||||
| #define USBD_LPM_ENABLED            0U | ||||
| #define USBD_SELF_POWERED           0U | ||||
| 
 | ||||
| /****************************************/ | ||||
| /* #define for FS and HS identification */ | ||||
| #define DEVICE_FS 0 | ||||
| 
 | ||||
| /* Memory management macros */ | ||||
| 
 | ||||
| /** Alias for memory allocation. */ | ||||
| #define USBD_malloc         (void *)USBD_static_malloc | ||||
| 
 | ||||
| /** Alias for memory release. */ | ||||
| #define USBD_free           USBD_static_free | ||||
| 
 | ||||
| /** Alias for memory set. */ | ||||
| #define USBD_memset         memset | ||||
| 
 | ||||
| /** Alias for memory copy. */ | ||||
| #define USBD_memcpy         memcpy | ||||
| 
 | ||||
| /** Alias for delay. */ | ||||
| #define USBD_Delay          HAL_Delay | ||||
| 
 | ||||
| /* DEBUG macros */ | ||||
| 
 | ||||
| #if (USBD_DEBUG_LEVEL > 0) | ||||
| #define USBD_UsrLog(...)    printf(__VA_ARGS__);\ | ||||
|                             printf("\n"); | ||||
| #else | ||||
| #define USBD_UsrLog(...) | ||||
| #endif | ||||
| 
 | ||||
| #if (USBD_DEBUG_LEVEL > 1) | ||||
| 
 | ||||
| #define USBD_ErrLog(...)    printf("ERROR: ") ;\ | ||||
|                             printf(__VA_ARGS__);\ | ||||
|                             printf("\n"); | ||||
| #else | ||||
| #define USBD_ErrLog(...) | ||||
| #endif | ||||
| 
 | ||||
| #if (USBD_DEBUG_LEVEL > 2) | ||||
| #define USBD_DbgLog(...)    printf("DEBUG : ") ;\ | ||||
|                             printf(__VA_ARGS__);\ | ||||
|                             printf("\n"); | ||||
| #else | ||||
| #define USBD_DbgLog(...) | ||||
| #endif | ||||
| 
 | ||||
| void *USBD_static_malloc(uint32_t size); | ||||
| void USBD_static_free(void *p); | ||||
| 
 | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
							
								
								
									
										206
									
								
								firmware/targets/f6/usb-glue/usbd_desc.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										206
									
								
								firmware/targets/f6/usb-glue/usbd_desc.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,206 @@ | ||||
| #include "usbd_core.h" | ||||
| #include "usbd_desc.h" | ||||
| #include "usbd_conf.h" | ||||
| #include "furi-hal-version.h" | ||||
| 
 | ||||
| #define USBD_VID                    1155 | ||||
| #define USBD_LANGID_STRING          1033 | ||||
| #define USBD_MANUFACTURER_STRING    "Flipper Devices Inc." | ||||
| #define USBD_PID                    22336 | ||||
| #define USBD_CONFIGURATION_STRING   "CDC Config" | ||||
| #define USBD_INTERFACE_STRING       "CDC Interface" | ||||
| 
 | ||||
| static void Get_SerialNum(void); | ||||
| static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len); | ||||
| 
 | ||||
| uint8_t* USBD_CDC_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | ||||
| uint8_t* USBD_CDC_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | ||||
| uint8_t* USBD_CDC_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | ||||
| uint8_t* USBD_CDC_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | ||||
| uint8_t* USBD_CDC_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | ||||
| uint8_t* USBD_CDC_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | ||||
| uint8_t* USBD_CDC_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); | ||||
| 
 | ||||
| USBD_DescriptorsTypeDef CDC_Desc = { | ||||
|     USBD_CDC_DeviceDescriptor, | ||||
|     USBD_CDC_LangIDStrDescriptor, | ||||
|     USBD_CDC_ManufacturerStrDescriptor, | ||||
|     USBD_CDC_ProductStrDescriptor, | ||||
|     USBD_CDC_SerialStrDescriptor, | ||||
|     USBD_CDC_ConfigStrDescriptor, | ||||
|     USBD_CDC_InterfaceStrDescriptor | ||||
| }; | ||||
| 
 | ||||
| /** USB standard device descriptor. */ | ||||
| __ALIGN_BEGIN uint8_t USBD_CDC_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = { | ||||
|     0x12,                       /*bLength */ | ||||
|     USB_DESC_TYPE_DEVICE,       /*bDescriptorType*/ | ||||
|     0x00,                       /*bcdUSB */ | ||||
|     0x02, | ||||
|     0x02,                       /*bDeviceClass*/ | ||||
|     0x02,                       /*bDeviceSubClass*/ | ||||
|     0x00,                       /*bDeviceProtocol*/ | ||||
|     USB_MAX_EP0_SIZE,           /*bMaxPacketSize*/ | ||||
|     LOBYTE(USBD_VID),           /*idVendor*/ | ||||
|     HIBYTE(USBD_VID),           /*idVendor*/ | ||||
|     LOBYTE(USBD_PID),           /*idProduct*/ | ||||
|     HIBYTE(USBD_PID),           /*idProduct*/ | ||||
|     0x00,                       /*bcdDevice rel. 2.00*/ | ||||
|     0x02, | ||||
|     USBD_IDX_MFC_STR,           /*Index of manufacturer  string*/ | ||||
|     USBD_IDX_PRODUCT_STR,       /*Index of product string*/ | ||||
|     USBD_IDX_SERIAL_STR,        /*Index of serial number string*/ | ||||
|     USBD_MAX_NUM_CONFIGURATION  /*bNumConfigurations*/ | ||||
| }; | ||||
| 
 | ||||
| /* USB_DeviceDescriptor */ | ||||
| 
 | ||||
| /** USB lang indentifier descriptor. */ | ||||
| __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = { | ||||
|     USB_LEN_LANGID_STR_DESC, | ||||
|     USB_DESC_TYPE_STRING, | ||||
|     LOBYTE(USBD_LANGID_STRING), | ||||
|     HIBYTE(USBD_LANGID_STRING) | ||||
| }; | ||||
| 
 | ||||
| /* Internal string descriptor. */ | ||||
| __ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END; | ||||
| 
 | ||||
| __ALIGN_BEGIN uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] __ALIGN_END = { | ||||
|     USB_SIZ_STRING_SERIAL, | ||||
|     USB_DESC_TYPE_STRING, | ||||
| }; | ||||
| 
 | ||||
| /** Return the device descriptor
 | ||||
|  * @param  speed : Current device speed | ||||
|  * @param  length : Pointer to data length variable | ||||
|  * @retval Pointer to descriptor buffer | ||||
|  */ | ||||
| uint8_t * USBD_CDC_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { | ||||
|     UNUSED(speed); | ||||
|     *length = sizeof(USBD_CDC_DeviceDesc); | ||||
|     return USBD_CDC_DeviceDesc; | ||||
| } | ||||
| 
 | ||||
| /** Return the LangID string descriptor
 | ||||
|  * @param  speed : Current device speed | ||||
|  * @param  length : Pointer to data length variable | ||||
|  * @retval Pointer to descriptor buffer | ||||
|  */ | ||||
| uint8_t * USBD_CDC_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { | ||||
|     UNUSED(speed); | ||||
|     *length = sizeof(USBD_LangIDDesc); | ||||
|     return USBD_LangIDDesc; | ||||
| } | ||||
| 
 | ||||
| /** Return the product string descriptor
 | ||||
|  * @param  speed : Current device speed | ||||
|  * @param  length : Pointer to data length variable | ||||
|  * @retval Pointer to descriptor buffer | ||||
|  */ | ||||
| uint8_t * USBD_CDC_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { | ||||
|     USBD_GetString((uint8_t*)furi_hal_version_get_device_name_ptr(), USBD_StrDesc, length); | ||||
|     return USBD_StrDesc; | ||||
| } | ||||
| 
 | ||||
| /** Return the manufacturer string descriptor
 | ||||
|  * @param  speed : Current device speed | ||||
|  * @param  length : Pointer to data length variable | ||||
|  * @retval Pointer to descriptor buffer | ||||
|  */ | ||||
| uint8_t * USBD_CDC_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { | ||||
|     UNUSED(speed); | ||||
|     USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length); | ||||
|     return USBD_StrDesc; | ||||
| } | ||||
| 
 | ||||
| /** Return the serial number string descriptor
 | ||||
|  * @param  speed : Current device speed | ||||
|  * @param  length : Pointer to data length variable | ||||
|  * @retval Pointer to descriptor buffer | ||||
|  */ | ||||
| uint8_t * USBD_CDC_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { | ||||
|     UNUSED(speed); | ||||
|     *length = USB_SIZ_STRING_SERIAL; | ||||
| 
 | ||||
|     /* Update the serial number string descriptor with the data from the unique
 | ||||
|      * ID */ | ||||
|     if(furi_hal_version_get_name_ptr()){ | ||||
|         char buffer[14] = "flip_"; | ||||
|         strncat(buffer, furi_hal_version_get_name_ptr(), 8); | ||||
|         USBD_GetString((uint8_t*) buffer, USBD_StringSerial, length); | ||||
|     } else { | ||||
|         Get_SerialNum(); | ||||
|     } | ||||
| 
 | ||||
|     return (uint8_t *) USBD_StringSerial; | ||||
| } | ||||
| 
 | ||||
| /** Return the configuration string descriptor
 | ||||
|  * @param  speed : Current device speed | ||||
|  * @param  length : Pointer to data length variable | ||||
|  * @retval Pointer to descriptor buffer | ||||
|  */ | ||||
| uint8_t * USBD_CDC_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { | ||||
|     if(speed == USBD_SPEED_HIGH) { | ||||
|         USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING, USBD_StrDesc, length); | ||||
|     } else { | ||||
|         USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING, USBD_StrDesc, length); | ||||
|     } | ||||
|     return USBD_StrDesc; | ||||
| } | ||||
| 
 | ||||
| /** Return the interface string descriptor
 | ||||
|  * @param  speed : Current device speed | ||||
|  * @param  length : Pointer to data length variable | ||||
|  * @retval Pointer to descriptor buffer | ||||
|  */ | ||||
| uint8_t * USBD_CDC_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { | ||||
|     if(speed == 0) { | ||||
|         USBD_GetString((uint8_t *)USBD_INTERFACE_STRING, USBD_StrDesc, length); | ||||
|     } else { | ||||
|         USBD_GetString((uint8_t *)USBD_INTERFACE_STRING, USBD_StrDesc, length); | ||||
|     } | ||||
|     return USBD_StrDesc; | ||||
| } | ||||
| 
 | ||||
| /** Create the serial number string descriptor
 | ||||
|  * @param  None | ||||
|  * @retval None | ||||
|  */ | ||||
| static void Get_SerialNum(void) { | ||||
|     uint32_t deviceserial0, deviceserial1, deviceserial2; | ||||
| 
 | ||||
|     deviceserial0 = *(uint32_t *) DEVICE_ID1; | ||||
|     deviceserial1 = *(uint32_t *) DEVICE_ID2; | ||||
|     deviceserial2 = *(uint32_t *) DEVICE_ID3; | ||||
| 
 | ||||
|     deviceserial0 += deviceserial2; | ||||
| 
 | ||||
|     if (deviceserial0 != 0) { | ||||
|         IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8); | ||||
|         IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /** Convert Hex 32Bits value into char
 | ||||
|  * @param  value: value to convert | ||||
|  * @param  pbuf: pointer to the buffer | ||||
|  * @param  len: buffer length | ||||
|  * @retval None | ||||
|  */ | ||||
| static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len) { | ||||
|     uint8_t idx = 0; | ||||
| 
 | ||||
|     for (idx = 0; idx < len; idx++) { | ||||
|         if (((value >> 28)) < 0xA) { | ||||
|             pbuf[2 * idx] = (value >> 28) + '0'; | ||||
|         } else { | ||||
|             pbuf[2 * idx] = (value >> 28) + 'A' - 10; | ||||
|         } | ||||
| 
 | ||||
|         value = value << 4; | ||||
| 
 | ||||
|         pbuf[2 * idx + 1] = 0; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										19
									
								
								firmware/targets/f6/usb-glue/usbd_desc.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								firmware/targets/f6/usb-glue/usbd_desc.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | ||||
| #pragma once | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| #include "usbd_def.h" | ||||
| 
 | ||||
| #define DEVICE_ID1 (UID_BASE) | ||||
| #define DEVICE_ID2 (UID_BASE + 0x4) | ||||
| #define DEVICE_ID3 (UID_BASE + 0x8) | ||||
| 
 | ||||
| #define USB_SIZ_STRING_SERIAL 0x1E | ||||
| 
 | ||||
| extern USBD_DescriptorsTypeDef CDC_Desc; | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| @ -19,7 +19,7 @@ $(shell test -d $(OBJ_DIR) || mkdir -p $(OBJ_DIR)) | ||||
| 
 | ||||
| BUILD_FLAGS_SHELL=\
 | ||||
| 	echo "$(CFLAGS)" > $(OBJ_DIR)/BUILD_FLAGS.tmp; \
 | ||||
| 	diff $(OBJ_DIR)/BUILD_FLAGS $(OBJ_DIR)/BUILD_FLAGS.tmp 2>/dev/null \
 | ||||
| 	diff -u $(OBJ_DIR)/BUILD_FLAGS $(OBJ_DIR)/BUILD_FLAGS.tmp 2>&1 > /dev/null \
 | ||||
| 		&& ( echo "CFLAGS ok"; rm $(OBJ_DIR)/BUILD_FLAGS.tmp) \
 | ||||
| 		|| ( echo "CFLAGS has been changed"; mv $(OBJ_DIR)/BUILD_FLAGS.tmp $(OBJ_DIR)/BUILD_FLAGS ) | ||||
| $(info $(shell $(BUILD_FLAGS_SHELL))) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 SG
						SG