25 changed files with 1924 additions and 96 deletions
-
36.cproject
-
81.mxproject
-
4.settings/language.settings.xml
-
3.vscode/c_cpp_properties.json
-
6.vscode/settings.json
-
2Core
-
2Drivers
-
54FATFS/App/fatfs.c
-
47FATFS/App/fatfs.h
-
273FATFS/Target/ffconf.h
-
267FATFS/Target/usbh_diskio.c
-
40FATFS/Target/usbh_diskio.h
-
2Middlewares
-
5README.md
-
128USB_HOST/App/usb_host.c
-
90USB_HOST/App/usb_host.h
-
539USB_HOST/Target/usbh_conf.c
-
194USB_HOST/Target/usbh_conf.h
-
52USB_HOST/Target/usbh_platform.c
-
42USB_HOST/Target/usbh_platform.h
-
99hand_acid_mainboard.ioc
-
2stm32halport
-
45uappbase/apphal/apphal.cpp
-
1uappbase/apphal/apphal.hpp
-
6usrc/service/app_core.cpp
81
.mxproject
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -1 +1 @@ |
|||
Subproject commit fe78220f807588b84f1a45712eacb4a5fded971e |
|||
Subproject commit fd9810003dcdd1c419fea3444dad1528b881822a |
@ -1 +1 @@ |
|||
Subproject commit ec0007fadbdd5a34d2dd0f1fc86811675458f19f |
|||
Subproject commit c3dadcb8c6850dff86543647e73fb80b2b236dfa |
@ -0,0 +1,54 @@ |
|||
/* USER CODE BEGIN Header */ |
|||
/** |
|||
****************************************************************************** |
|||
* @file fatfs.c |
|||
* @brief Code for fatfs applications |
|||
****************************************************************************** |
|||
* @attention |
|||
* |
|||
* Copyright (c) 2024 STMicroelectronics. |
|||
* All rights reserved. |
|||
* |
|||
* This software is licensed under terms that can be found in the LICENSE file |
|||
* in the root directory of this software component. |
|||
* If no LICENSE file comes with this software, it is provided AS-IS. |
|||
* |
|||
****************************************************************************** |
|||
*/ |
|||
/* USER CODE END Header */ |
|||
#include "fatfs.h" |
|||
|
|||
uint8_t retUSBH; /* Return value for USBH */ |
|||
char USBHPath[4]; /* USBH logical drive path */ |
|||
FATFS USBHFatFS; /* File system object for USBH logical drive */ |
|||
FIL USBHFile; /* File object for USBH */ |
|||
|
|||
/* USER CODE BEGIN Variables */ |
|||
|
|||
/* USER CODE END Variables */ |
|||
|
|||
void MX_FATFS_Init(void) |
|||
{ |
|||
/*## FatFS: Link the USBH driver ###########################*/ |
|||
retUSBH = FATFS_LinkDriver(&USBH_Driver, USBHPath); |
|||
|
|||
/* USER CODE BEGIN Init */ |
|||
/* additional user code for init */ |
|||
/* USER CODE END Init */ |
|||
} |
|||
|
|||
/** |
|||
* @brief Gets Time from RTC |
|||
* @param None |
|||
* @retval Time in DWORD |
|||
*/ |
|||
DWORD get_fattime(void) |
|||
{ |
|||
/* USER CODE BEGIN get_fattime */ |
|||
return 0; |
|||
/* USER CODE END get_fattime */ |
|||
} |
|||
|
|||
/* USER CODE BEGIN Application */ |
|||
|
|||
/* USER CODE END Application */ |
@ -0,0 +1,47 @@ |
|||
/* USER CODE BEGIN Header */ |
|||
/** |
|||
****************************************************************************** |
|||
* @file fatfs.h |
|||
* @brief Header for fatfs applications |
|||
****************************************************************************** |
|||
* @attention |
|||
* |
|||
* Copyright (c) 2024 STMicroelectronics. |
|||
* All rights reserved. |
|||
* |
|||
* This software is licensed under terms that can be found in the LICENSE file |
|||
* in the root directory of this software component. |
|||
* If no LICENSE file comes with this software, it is provided AS-IS. |
|||
* |
|||
****************************************************************************** |
|||
*/ |
|||
/* USER CODE END Header */ |
|||
/* Define to prevent recursive inclusion -------------------------------------*/ |
|||
#ifndef __fatfs_H |
|||
#define __fatfs_H |
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
|
|||
#include "ff.h" |
|||
#include "ff_gen_drv.h" |
|||
#include "usbh_diskio.h" /* defines USBH_Driver as external */ |
|||
|
|||
/* USER CODE BEGIN Includes */ |
|||
|
|||
/* USER CODE END Includes */ |
|||
|
|||
extern uint8_t retUSBH; /* Return value for USBH */ |
|||
extern char USBHPath[4]; /* USBH logical drive path */ |
|||
extern FATFS USBHFatFS; /* File system object for USBH logical drive */ |
|||
extern FIL USBHFile; /* File object for USBH */ |
|||
|
|||
void MX_FATFS_Init(void); |
|||
|
|||
/* USER CODE BEGIN Prototypes */ |
|||
|
|||
/* USER CODE END Prototypes */ |
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
|||
#endif /*__fatfs_H */ |
@ -0,0 +1,273 @@ |
|||
/* USER CODE BEGIN Header */ |
|||
/** |
|||
****************************************************************************** |
|||
* FatFs - Generic FAT file system module R0.12c (C)ChaN, 2017 |
|||
****************************************************************************** |
|||
* @attention |
|||
* |
|||
* Copyright (c) 2024 STMicroelectronics. |
|||
* All rights reserved. |
|||
* |
|||
* This software is licensed under terms that can be found in the LICENSE file |
|||
* in the root directory of this software component. |
|||
* If no LICENSE file comes with this software, it is provided AS-IS. |
|||
* |
|||
****************************************************************************** |
|||
*/ |
|||
/* USER CODE END Header */ |
|||
|
|||
#ifndef _FFCONF |
|||
#define _FFCONF 68300 /* Revision ID */ |
|||
|
|||
/*-----------------------------------------------------------------------------/ |
|||
/ Additional user header to be used |
|||
/-----------------------------------------------------------------------------*/ |
|||
#include "main.h" |
|||
#include "stm32f4xx_hal.h" |
|||
#include "usbh_core.h" |
|||
#include "usbh_msc.h" |
|||
#include "cmsis_os.h" /* _FS_REENTRANT set to 1 and CMSIS API chosen */ |
|||
/* Handle for USB Host */ |
|||
#define hUSB_Host hUsbHostFS |
|||
|
|||
/*-----------------------------------------------------------------------------/ |
|||
/ Function Configurations |
|||
/-----------------------------------------------------------------------------*/ |
|||
|
|||
#define _FS_READONLY 0 /* 0:Read/Write or 1:Read only */ |
|||
/* This option switches read-only configuration. (0:Read/Write or 1:Read-only) |
|||
/ Read-only configuration removes writing API functions, f_write(), f_sync(), |
|||
/ f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree() |
|||
/ and optional writing functions as well. */ |
|||
|
|||
#define _FS_MINIMIZE 0 /* 0 to 3 */ |
|||
/* This option defines minimization level to remove some basic API functions. |
|||
/ |
|||
/ 0: All basic functions are enabled. |
|||
/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename() |
|||
/ are removed. |
|||
/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1. |
|||
/ 3: f_lseek() function is removed in addition to 2. */ |
|||
|
|||
#define _USE_STRFUNC 2 /* 0:Disable or 1-2:Enable */ |
|||
/* This option switches string functions, f_gets(), f_putc(), f_puts() and |
|||
/ f_printf(). |
|||
/ |
|||
/ 0: Disable string functions. |
|||
/ 1: Enable without LF-CRLF conversion. |
|||
/ 2: Enable with LF-CRLF conversion. */ |
|||
|
|||
#define _USE_FIND 0 |
|||
/* This option switches filtered directory read functions, f_findfirst() and |
|||
/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */ |
|||
|
|||
#define _USE_MKFS 1 |
|||
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */ |
|||
|
|||
#define _USE_FASTSEEK 1 |
|||
/* This option switches fast seek feature. (0:Disable or 1:Enable) */ |
|||
|
|||
#define _USE_EXPAND 0 |
|||
/* This option switches f_expand function. (0:Disable or 1:Enable) */ |
|||
|
|||
#define _USE_CHMOD 0 |
|||
/* This option switches attribute manipulation functions, f_chmod() and f_utime(). |
|||
/ (0:Disable or 1:Enable) Also _FS_READONLY needs to be 0 to enable this option. */ |
|||
|
|||
#define _USE_LABEL 0 |
|||
/* This option switches volume label functions, f_getlabel() and f_setlabel(). |
|||
/ (0:Disable or 1:Enable) */ |
|||
|
|||
#define _USE_FORWARD 0 |
|||
/* This option switches f_forward() function. (0:Disable or 1:Enable) */ |
|||
|
|||
/*-----------------------------------------------------------------------------/ |
|||
/ Locale and Namespace Configurations |
|||
/-----------------------------------------------------------------------------*/ |
|||
|
|||
#define _CODE_PAGE 936 |
|||
/* This option specifies the OEM code page to be used on the target system. |
|||
/ Incorrect setting of the code page can cause a file open failure. |
|||
/ |
|||
/ 1 - ASCII (No extended character. Non-LFN cfg. only) |
|||
/ 437 - U.S. |
|||
/ 720 - Arabic |
|||
/ 737 - Greek |
|||
/ 771 - KBL |
|||
/ 775 - Baltic |
|||
/ 850 - Latin 1 |
|||
/ 852 - Latin 2 |
|||
/ 855 - Cyrillic |
|||
/ 857 - Turkish |
|||
/ 860 - Portuguese |
|||
/ 861 - Icelandic |
|||
/ 862 - Hebrew |
|||
/ 863 - Canadian French |
|||
/ 864 - Arabic |
|||
/ 865 - Nordic |
|||
/ 866 - Russian |
|||
/ 869 - Greek 2 |
|||
/ 932 - Japanese (DBCS) |
|||
/ 936 - Simplified Chinese (DBCS) |
|||
/ 949 - Korean (DBCS) |
|||
/ 950 - Traditional Chinese (DBCS) |
|||
*/ |
|||
|
|||
#define _USE_LFN 0 /* 0 to 3 */ |
|||
#define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */ |
|||
/* The _USE_LFN switches the support of long file name (LFN). |
|||
/ |
|||
/ 0: Disable support of LFN. _MAX_LFN has no effect. |
|||
/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe. |
|||
/ 2: Enable LFN with dynamic working buffer on the STACK. |
|||
/ 3: Enable LFN with dynamic working buffer on the HEAP. |
|||
/ |
|||
/ To enable the LFN, Unicode handling functions (option/unicode.c) must be added |
|||
/ to the project. The working buffer occupies (_MAX_LFN + 1) * 2 bytes and |
|||
/ additional 608 bytes at exFAT enabled. _MAX_LFN can be in range from 12 to 255. |
|||
/ It should be set 255 to support full featured LFN operations. |
|||
/ When use stack for the working buffer, take care on stack overflow. When use heap |
|||
/ memory for the working buffer, memory management functions, ff_memalloc() and |
|||
/ ff_memfree(), must be added to the project. */ |
|||
|
|||
#define _LFN_UNICODE 0 /* 0:ANSI/OEM or 1:Unicode */ |
|||
/* This option switches character encoding on the API. (0:ANSI/OEM or 1:UTF-16) |
|||
/ To use Unicode string for the path name, enable LFN and set _LFN_UNICODE = 1. |
|||
/ This option also affects behavior of string I/O functions. */ |
|||
|
|||
#define _STRF_ENCODE 3 |
|||
/* When _LFN_UNICODE == 1, this option selects the character encoding ON THE FILE to |
|||
/ be read/written via string I/O functions, f_gets(), f_putc(), f_puts and f_printf(). |
|||
/ |
|||
/ 0: ANSI/OEM |
|||
/ 1: UTF-16LE |
|||
/ 2: UTF-16BE |
|||
/ 3: UTF-8 |
|||
/ |
|||
/ This option has no effect when _LFN_UNICODE == 0. */ |
|||
|
|||
#define _FS_RPATH 0 /* 0 to 2 */ |
|||
/* This option configures support of relative path. |
|||
/ |
|||
/ 0: Disable relative path and remove related functions. |
|||
/ 1: Enable relative path. f_chdir() and f_chdrive() are available. |
|||
/ 2: f_getcwd() function is available in addition to 1. |
|||
*/ |
|||
|
|||
/*---------------------------------------------------------------------------/ |
|||
/ Drive/Volume Configurations |
|||
/----------------------------------------------------------------------------*/ |
|||
|
|||
#define _VOLUMES 1 |
|||
/* Number of volumes (logical drives) to be used. */ |
|||
|
|||
/* USER CODE BEGIN Volumes */ |
|||
#define _STR_VOLUME_ID 0 /* 0:Use only 0-9 for drive ID, 1:Use strings for drive ID */ |
|||
#define _VOLUME_STRS "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3" |
|||
/* _STR_VOLUME_ID switches string support of volume ID. |
|||
/ When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive |
|||
/ number in the path name. _VOLUME_STRS defines the drive ID strings for each |
|||
/ logical drives. Number of items must be equal to _VOLUMES. Valid characters for |
|||
/ the drive ID strings are: A-Z and 0-9. */ |
|||
/* USER CODE END Volumes */ |
|||
|
|||
#define _MULTI_PARTITION 0 /* 0:Single partition, 1:Multiple partition */ |
|||
/* This option switches support of multi-partition on a physical drive. |
|||
/ By default (0), each logical drive number is bound to the same physical drive |
|||
/ number and only an FAT volume found on the physical drive will be mounted. |
|||
/ When multi-partition is enabled (1), each logical drive number can be bound to |
|||
/ arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk() |
|||
/ function will be available. */ |
|||
#define _MIN_SS 512 /* 512, 1024, 2048 or 4096 */ |
|||
#define _MAX_SS 512 /* 512, 1024, 2048 or 4096 */ |
|||
/* These options configure the range of sector size to be supported. (512, 1024, |
|||
/ 2048 or 4096) Always set both 512 for most systems, all type of memory cards and |
|||
/ harddisk. But a larger value may be required for on-board flash memory and some |
|||
/ type of optical media. When _MAX_SS is larger than _MIN_SS, FatFs is configured |
|||
/ to variable sector size and GET_SECTOR_SIZE command must be implemented to the |
|||
/ disk_ioctl() function. */ |
|||
|
|||
#define _USE_TRIM 0 |
|||
/* This option switches support of ATA-TRIM. (0:Disable or 1:Enable) |
|||
/ To enable Trim function, also CTRL_TRIM command should be implemented to the |
|||
/ disk_ioctl() function. */ |
|||
|
|||
#define _FS_NOFSINFO 0 /* 0,1,2 or 3 */ |
|||
/* If you need to know correct free space on the FAT32 volume, set bit 0 of this |
|||
/ option, and f_getfree() function at first time after volume mount will force |
|||
/ a full FAT scan. Bit 1 controls the use of last allocated cluster number. |
|||
/ |
|||
/ bit0=0: Use free cluster count in the FSINFO if available. |
|||
/ bit0=1: Do not trust free cluster count in the FSINFO. |
|||
/ bit1=0: Use last allocated cluster number in the FSINFO if available. |
|||
/ bit1=1: Do not trust last allocated cluster number in the FSINFO. |
|||
*/ |
|||
|
|||
/*---------------------------------------------------------------------------/ |
|||
/ System Configurations |
|||
/----------------------------------------------------------------------------*/ |
|||
|
|||
#define _FS_TINY 0 /* 0:Normal or 1:Tiny */ |
|||
/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny) |
|||
/ At the tiny configuration, size of file object (FIL) is reduced _MAX_SS bytes. |
|||
/ Instead of private sector buffer eliminated from the file object, common sector |
|||
/ buffer in the file system object (FATFS) is used for the file data transfer. */ |
|||
|
|||
#define _FS_EXFAT 0 |
|||
/* This option switches support of exFAT file system. (0:Disable or 1:Enable) |
|||
/ When enable exFAT, also LFN needs to be enabled. (_USE_LFN >= 1) |
|||
/ Note that enabling exFAT discards C89 compatibility. */ |
|||
|
|||
#define _FS_NORTC 0 |
|||
#define _NORTC_MON 6 |
|||
#define _NORTC_MDAY 4 |
|||
#define _NORTC_YEAR 2015 |
|||
/* The option _FS_NORTC switches timestamp function. If the system does not have |
|||
/ any RTC function or valid timestamp is not needed, set _FS_NORTC = 1 to disable |
|||
/ the timestamp function. All objects modified by FatFs will have a fixed timestamp |
|||
/ defined by _NORTC_MON, _NORTC_MDAY and _NORTC_YEAR in local time. |
|||
/ To enable timestamp function (_FS_NORTC = 0), get_fattime() function need to be |
|||
/ added to the project to get current time form real-time clock. _NORTC_MON, |
|||
/ _NORTC_MDAY and _NORTC_YEAR have no effect. |
|||
/ These options have no effect at read-only configuration (_FS_READONLY = 1). */ |
|||
|
|||
#define _FS_LOCK 2 /* 0:Disable or >=1:Enable */ |
|||
/* The option _FS_LOCK switches file lock function to control duplicated file open |
|||
/ and illegal operation to open objects. This option must be 0 when _FS_READONLY |
|||
/ is 1. |
|||
/ |
|||
/ 0: Disable file lock function. To avoid volume corruption, application program |
|||
/ should avoid illegal open, remove and rename to the open objects. |
|||
/ >0: Enable file lock function. The value defines how many files/sub-directories |
|||
/ can be opened simultaneously under file lock control. Note that the file |
|||
/ lock control is independent of re-entrancy. */ |
|||
|
|||
#define _FS_REENTRANT 1 /* 0:Disable or 1:Enable */ |
|||
|
|||
#define _USE_MUTEX 0 /* 0:Disable or 1:Enable */ |
|||
#define _FS_TIMEOUT 1000 /* Timeout period in unit of time ticks */ |
|||
#define _SYNC_t osSemaphoreId |
|||
/* The option _FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs |
|||
/ module itself. Note that regardless of this option, file access to different |
|||
/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs() |
|||
/ and f_fdisk() function, are always not re-entrant. Only file/directory access |
|||
/ to the same volume is under control of this function. |
|||
/ |
|||
/ 0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect. |
|||
/ 1: Enable re-entrancy. Also user provided synchronization handlers, |
|||
/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj() |
|||
/ function, must be added to the project. Samples are available in |
|||
/ option/syscall.c. |
|||
/ |
|||
/ The _FS_TIMEOUT defines timeout period in unit of time tick. |
|||
/ The _SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*, |
|||
/ SemaphoreHandle_t and etc.. A header file for O/S definitions needs to be |
|||
/ included somewhere in the scope of ff.h. */ |
|||
|
|||
/* define the ff_malloc ff_free macros as FreeRTOS pvPortMalloc and vPortFree macros */ |
|||
#if !defined(ff_malloc) && !defined(ff_free) |
|||
#define ff_malloc pvPortMalloc |
|||
#define ff_free vPortFree |
|||
#endif |
|||
|
|||
#endif /* _FFCONF */ |
@ -0,0 +1,267 @@ |
|||
/* USER CODE BEGIN Header */ |
|||
/** |
|||
****************************************************************************** |
|||
* @file usbh_diskio.c (based on usbh_diskio_template.c v2.0.2) |
|||
* @brief USB Host Disk I/O driver |
|||
****************************************************************************** |
|||
* @attention |
|||
* |
|||
* Copyright (c) 2024 STMicroelectronics. |
|||
* All rights reserved. |
|||
* |
|||
* This software is licensed under terms that can be found in the LICENSE file |
|||
* in the root directory of this software component. |
|||
* If no LICENSE file comes with this software, it is provided AS-IS. |
|||
* |
|||
****************************************************************************** |
|||
*/ |
|||
/* USER CODE END Header */ |
|||
/* USER CODE BEGIN firstSection */ |
|||
/* can be used to modify / undefine following code or add new definitions */ |
|||
/* USER CODE END firstSection */ |
|||
|
|||
/* Includes ------------------------------------------------------------------*/ |
|||
#include "ff_gen_drv.h" |
|||
#include "usbh_diskio.h" |
|||
|
|||
/* Private typedef -----------------------------------------------------------*/ |
|||
/* Private define ------------------------------------------------------------*/ |
|||
|
|||
#define USB_DEFAULT_BLOCK_SIZE 512 |
|||
|
|||
/* Private variables ---------------------------------------------------------*/ |
|||
extern USBH_HandleTypeDef hUSB_Host; |
|||
|
|||
/* Private function prototypes -----------------------------------------------*/ |
|||
DSTATUS USBH_initialize (BYTE); |
|||
DSTATUS USBH_status (BYTE); |
|||
DRESULT USBH_read (BYTE, BYTE*, DWORD, UINT); |
|||
|
|||
#if _USE_WRITE == 1 |
|||
DRESULT USBH_write (BYTE, const BYTE*, DWORD, UINT); |
|||
#endif /* _USE_WRITE == 1 */ |
|||
|
|||
#if _USE_IOCTL == 1 |
|||
DRESULT USBH_ioctl (BYTE, BYTE, void*); |
|||
#endif /* _USE_IOCTL == 1 */ |
|||
|
|||
const Diskio_drvTypeDef USBH_Driver = |
|||
{ |
|||
USBH_initialize, |
|||
USBH_status, |
|||
USBH_read, |
|||
#if _USE_WRITE == 1 |
|||
USBH_write, |
|||
#endif /* _USE_WRITE == 1 */ |
|||
#if _USE_IOCTL == 1 |
|||
USBH_ioctl, |
|||
#endif /* _USE_IOCTL == 1 */ |
|||
}; |
|||
|
|||
/* USER CODE BEGIN beforeFunctionSection */ |
|||
/* can be used to modify / undefine following code or add new code */ |
|||
/* USER CODE END beforeFunctionSection */ |
|||
|
|||
/* Private functions ---------------------------------------------------------*/ |
|||
|
|||
/** |
|||
* @brief Initializes a Drive |
|||
* @param lun : lun id |
|||
* @retval DSTATUS: Operation status |
|||
*/ |
|||
DSTATUS USBH_initialize(BYTE lun) |
|||
{ |
|||
/* CAUTION : USB Host library has to be initialized in the application */ |
|||
|
|||
return RES_OK; |
|||
} |
|||
|
|||
/** |
|||
* @brief Gets Disk Status |
|||
* @param lun : lun id |
|||
* @retval DSTATUS: Operation status |
|||
*/ |
|||
DSTATUS USBH_status(BYTE lun) |
|||
{ |
|||
DRESULT res = RES_ERROR; |
|||
|
|||
if(USBH_MSC_UnitIsReady(&hUSB_Host, lun)) |
|||
{ |
|||
res = RES_OK; |
|||
} |
|||
else |
|||
{ |
|||
res = RES_ERROR; |
|||
} |
|||
|
|||
return res; |
|||
} |
|||
|
|||
/* USER CODE BEGIN beforeReadSection */ |
|||
/* can be used to modify previous code / undefine following code / add new code */ |
|||
/* USER CODE END beforeReadSection */ |
|||
|
|||
/** |
|||
* @brief Reads Sector(s) |
|||
* @param lun : lun id |
|||
* @param *buff: Data buffer to store read data |
|||
* @param sector: Sector address (LBA) |
|||
* @param count: Number of sectors to read (1..128) |
|||
* @retval DRESULT: Operation result |
|||
*/ |
|||
DRESULT USBH_read(BYTE lun, BYTE *buff, DWORD sector, UINT count) |
|||
{ |
|||
DRESULT res = RES_ERROR; |
|||
MSC_LUNTypeDef info; |
|||
|
|||
if(USBH_MSC_Read(&hUSB_Host, lun, sector, buff, count) == USBH_OK) |
|||
{ |
|||
res = RES_OK; |
|||
} |
|||
else |
|||
{ |
|||
USBH_MSC_GetLUNInfo(&hUSB_Host, lun, &info); |
|||
|
|||
switch (info.sense.asc) |
|||
{ |
|||
case SCSI_ASC_LOGICAL_UNIT_NOT_READY: |
|||
case SCSI_ASC_MEDIUM_NOT_PRESENT: |
|||
case SCSI_ASC_NOT_READY_TO_READY_CHANGE: |
|||
USBH_ErrLog ("USB Disk is not ready!"); |
|||
res = RES_NOTRDY; |
|||
break; |
|||
|
|||
default: |
|||
res = RES_ERROR; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
return res; |
|||
} |
|||
|
|||
/* USER CODE BEGIN beforeWriteSection */ |
|||
/* can be used to modify previous code / undefine following code / add new code */ |
|||
/* USER CODE END beforeWriteSection */ |
|||
|
|||
/** |
|||
* @brief Writes Sector(s) |
|||
* @param lun : lun id |
|||
* @param *buff: Data to be written |
|||
* @param sector: Sector address (LBA) |
|||
* @param count: Number of sectors to write (1..128) |
|||
* @retval DRESULT: Operation result |
|||
*/ |
|||
#if _USE_WRITE == 1 |
|||
DRESULT USBH_write(BYTE lun, const BYTE *buff, DWORD sector, UINT count) |
|||
{ |
|||
DRESULT res = RES_ERROR; |
|||
MSC_LUNTypeDef info; |
|||
|
|||
if(USBH_MSC_Write(&hUSB_Host, lun, sector, (BYTE *)buff, count) == USBH_OK) |
|||
{ |
|||
res = RES_OK; |
|||
} |
|||
else |
|||
{ |
|||
USBH_MSC_GetLUNInfo(&hUSB_Host, lun, &info); |
|||
|
|||
switch (info.sense.asc) |
|||
{ |
|||
case SCSI_ASC_WRITE_PROTECTED: |
|||
USBH_ErrLog("USB Disk is Write protected!"); |
|||
res = RES_WRPRT; |
|||
break; |
|||
|
|||
case SCSI_ASC_LOGICAL_UNIT_NOT_READY: |
|||
case SCSI_ASC_MEDIUM_NOT_PRESENT: |
|||
case SCSI_ASC_NOT_READY_TO_READY_CHANGE: |
|||
USBH_ErrLog("USB Disk is not ready!"); |
|||
res = RES_NOTRDY; |
|||
break; |
|||
|
|||
default: |
|||
res = RES_ERROR; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
return res; |
|||
} |
|||
#endif /* _USE_WRITE == 1 */ |
|||
|
|||
/* USER CODE BEGIN beforeIoctlSection */ |
|||
/* can be used to modify previous code / undefine following code / add new code */ |
|||
/* USER CODE END beforeIoctlSection */ |
|||
|
|||
/** |
|||
* @brief I/O control operation |
|||
* @param lun : lun id |
|||
* @param cmd: Control code |
|||
* @param *buff: Buffer to send/receive control data |
|||
* @retval DRESULT: Operation result |
|||
*/ |
|||
#if _USE_IOCTL == 1 |
|||
DRESULT USBH_ioctl(BYTE lun, BYTE cmd, void *buff) |
|||
{ |
|||
DRESULT res = RES_ERROR; |
|||
MSC_LUNTypeDef info; |
|||
|
|||
switch (cmd) |
|||
{ |
|||
/* Make sure that no pending write process */ |
|||
case CTRL_SYNC: |
|||
res = RES_OK; |
|||
break; |
|||
|
|||
/* Get number of sectors on the disk (DWORD) */ |
|||
case GET_SECTOR_COUNT : |
|||
if(USBH_MSC_GetLUNInfo(&hUSB_Host, lun, &info) == USBH_OK) |
|||
{ |
|||
*(DWORD*)buff = info.capacity.block_nbr; |
|||
res = RES_OK; |
|||
} |
|||
else |
|||
{ |
|||
res = RES_ERROR; |
|||
} |
|||
break; |
|||
|
|||
/* Get R/W sector size (WORD) */ |
|||
case GET_SECTOR_SIZE : |
|||
if(USBH_MSC_GetLUNInfo(&hUSB_Host, lun, &info) == USBH_OK) |
|||
{ |
|||
*(DWORD*)buff = info.capacity.block_size; |
|||
res = RES_OK; |
|||
} |
|||
else |
|||
{ |
|||
res = RES_ERROR; |
|||
} |
|||
break; |
|||
|
|||
/* Get erase block size in unit of sector (DWORD) */ |
|||
case GET_BLOCK_SIZE : |
|||
|
|||
if(USBH_MSC_GetLUNInfo(&hUSB_Host, lun, &info) == USBH_OK) |
|||
{ |
|||
*(DWORD*)buff = info.capacity.block_size / USB_DEFAULT_BLOCK_SIZE; |
|||
res = RES_OK; |
|||
} |
|||
else |
|||
{ |
|||
res = RES_ERROR; |
|||
} |
|||
break; |
|||
|
|||
default: |
|||
res = RES_PARERR; |
|||
} |
|||
|
|||
return res; |
|||
} |
|||
#endif /* _USE_IOCTL == 1 */ |
|||
|
|||
/* USER CODE BEGIN lastSection */ |
|||
/* can be used to modify / undefine previous code or add new code */ |
|||
/* USER CODE END lastSection */ |
@ -0,0 +1,40 @@ |
|||
/* USER CODE BEGIN Header */ |
|||
/** |
|||
****************************************************************************** |
|||
* @file usbh_diskio.h (based on usbh_diskio_template.h v2.0.2) |
|||
* @brief Header for usbh_diskio.c module |
|||
****************************************************************************** |
|||
* @attention |
|||
* |
|||
* Copyright (c) 2024 STMicroelectronics. |
|||
* All rights reserved. |
|||
* |
|||
* This software is licensed under terms that can be found in the LICENSE file |
|||
* in the root directory of this software component. |
|||
* If no LICENSE file comes with this software, it is provided AS-IS. |
|||
* |
|||
****************************************************************************** |
|||
*/ |
|||
/* USER CODE END Header */ |
|||
/* Define to prevent recursive inclusion -------------------------------------*/ |
|||
#ifndef __USBH_DISKIO_H |
|||
#define __USBH_DISKIO_H |
|||
|
|||
/* USER CODE BEGIN firstSection */ |
|||
/* can be used to modify / undefine following code or add new definitions */ |
|||
/* USER CODE END firstSection */ |
|||
|
|||
/* Includes ------------------------------------------------------------------*/ |
|||
#include "usbh_core.h" |
|||
#include "usbh_msc.h" |
|||
/* Exported types ------------------------------------------------------------*/ |
|||
/* Exported constants --------------------------------------------------------*/ |
|||
/* Exported functions ------------------------------------------------------- */ |
|||
extern const Diskio_drvTypeDef USBH_Driver; |
|||
|
|||
/* USER CODE BEGIN lastSection */ |
|||
/* can be used to modify / undefine previous code or add new definitions */ |
|||
/* USER CODE END lastSection */ |
|||
|
|||
#endif /* __USBH_DISKIO_H */ |
|||
|
@ -1 +1 @@ |
|||
Subproject commit 5047b0506d61e226ae953e58e47293d466a509be |
|||
Subproject commit 0aa6384240f5489d7c81d21823fbd8018294b07b |
@ -0,0 +1,128 @@ |
|||
/* USER CODE BEGIN Header */ |
|||
/** |
|||
****************************************************************************** |
|||
* @file : usb_host.c |
|||
* @version : v1.0_Cube |
|||
* @brief : This file implements the USB Host |
|||
****************************************************************************** |
|||
* @attention |
|||
* |
|||
* Copyright (c) 2024 STMicroelectronics. |
|||
* All rights reserved. |
|||
* |
|||
* This software is licensed under terms that can be found in the LICENSE file |
|||
* in the root directory of this software component. |
|||
* If no LICENSE file comes with this software, it is provided AS-IS. |
|||
* |
|||
****************************************************************************** |
|||
*/ |
|||
/* USER CODE END Header */ |
|||
|
|||
/* Includes ------------------------------------------------------------------*/ |
|||
|
|||
#include "usb_host.h" |
|||
#include "usbh_core.h" |
|||
#include "usbh_msc.h" |
|||
|
|||
/* USER CODE BEGIN Includes */ |
|||
|
|||
/* USER CODE END Includes */ |
|||
|
|||
/* USER CODE BEGIN PV */ |
|||
/* Private variables ---------------------------------------------------------*/ |
|||
|
|||
/* USER CODE END PV */ |
|||
|
|||
/* USER CODE BEGIN PFP */ |
|||
/* Private function prototypes -----------------------------------------------*/ |
|||
|
|||
/* USER CODE END PFP */ |
|||
|
|||
/* USB Host core handle declaration */ |
|||
USBH_HandleTypeDef hUsbHostFS; |
|||
ApplicationTypeDef Appli_state = APPLICATION_IDLE; |
|||
|
|||
/* |
|||
* -- Insert your variables declaration here -- |
|||
*/ |
|||
/* USER CODE BEGIN 0 */ |
|||
|
|||
/* USER CODE END 0 */ |
|||
|
|||
/* |
|||
* user callback declaration |
|||
*/ |
|||
static void USBH_UserProcess(USBH_HandleTypeDef *phost, uint8_t id); |
|||
|
|||
/* |
|||
* -- Insert your external function declaration here -- |
|||
*/ |
|||
/* USER CODE BEGIN 1 */ |
|||
|
|||
/* USER CODE END 1 */ |
|||
|
|||
/** |
|||
* Init USB host library, add supported class and start the library |
|||
* @retval None |
|||
*/ |
|||
void MX_USB_HOST_Init(void) |
|||
{ |
|||
/* USER CODE BEGIN USB_HOST_Init_PreTreatment */ |
|||
|
|||
/* USER CODE END USB_HOST_Init_PreTreatment */ |
|||
|
|||
/* Init host Library, add supported class and start the library. */ |
|||
if (USBH_Init(&hUsbHostFS, USBH_UserProcess, HOST_FS) != USBH_OK) |
|||
{ |
|||
Error_Handler(); |
|||
} |
|||
if (USBH_RegisterClass(&hUsbHostFS, USBH_MSC_CLASS) != USBH_OK) |
|||
{ |
|||
Error_Handler(); |
|||
} |
|||
if (USBH_Start(&hUsbHostFS) != USBH_OK) |
|||
{ |
|||
Error_Handler(); |
|||
} |
|||
/* USER CODE BEGIN USB_HOST_Init_PostTreatment */ |
|||
|
|||
/* USER CODE END USB_HOST_Init_PostTreatment */ |
|||
} |
|||
|
|||
/* |
|||
* user callback definition |
|||
*/ |
|||
static void USBH_UserProcess (USBH_HandleTypeDef *phost, uint8_t id) |
|||
{ |
|||
/* USER CODE BEGIN CALL_BACK_1 */ |
|||
switch(id) |
|||
{ |
|||
case HOST_USER_SELECT_CONFIGURATION: |
|||
break; |
|||
|
|||
case HOST_USER_DISCONNECTION: |
|||
Appli_state = APPLICATION_DISCONNECT; |
|||
break; |
|||
|
|||
case HOST_USER_CLASS_ACTIVE: |
|||
Appli_state = APPLICATION_READY; |
|||
break; |
|||
|
|||
case HOST_USER_CONNECTION: |
|||
Appli_state = APPLICATION_START; |
|||
break; |
|||
|
|||
default: |
|||
break; |
|||
} |
|||
/* USER CODE END CALL_BACK_1 */ |
|||
} |
|||
|
|||
/** |
|||
* @} |
|||
*/ |
|||
|
|||
/** |
|||
* @} |
|||
*/ |
|||
|
@ -0,0 +1,90 @@ |
|||
/* USER CODE BEGIN Header */ |
|||
/** |
|||
****************************************************************************** |
|||
* @file : usb_host.h |
|||
* @version : v1.0_Cube |
|||
* @brief : Header for usb_host.c file. |
|||
****************************************************************************** |
|||
* @attention |
|||
* |
|||
* Copyright (c) 2024 STMicroelectronics. |
|||
* All rights reserved. |
|||
* |
|||
* This software is licensed under terms that can be found in the LICENSE file |
|||
* in the root directory of this software component. |
|||
* If no LICENSE file comes with this software, it is provided AS-IS. |
|||
* |
|||
****************************************************************************** |
|||
*/ |
|||
/* USER CODE END Header */ |
|||
|
|||
/* Define to prevent recursive inclusion -------------------------------------*/ |
|||
#ifndef __USB_HOST__H__ |
|||
#define __USB_HOST__H__ |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
|
|||
/* Includes ------------------------------------------------------------------*/ |
|||
#include "stm32f4xx.h" |
|||
#include "stm32f4xx_hal.h" |
|||
|
|||
/* USER CODE BEGIN INCLUDE */ |
|||
|
|||
/* USER CODE END INCLUDE */ |
|||
|
|||
/** @addtogroup USBH_OTG_DRIVER |
|||
* @{ |
|||
*/ |
|||
|
|||
/** @defgroup USBH_HOST USBH_HOST |
|||
* @brief Host file for Usb otg low level driver. |
|||
* @{ |
|||
*/ |
|||
|
|||
/** @defgroup USBH_HOST_Exported_Variables USBH_HOST_Exported_Variables |
|||
* @brief Public variables. |
|||
* @{ |
|||
*/ |
|||
|
|||
/** |
|||
* @} |
|||
*/ |
|||
|
|||
/** Status of the application. */ |
|||
typedef enum { |
|||
APPLICATION_IDLE = 0, |
|||
APPLICATION_START, |
|||
APPLICATION_READY, |
|||
APPLICATION_DISCONNECT |
|||
}ApplicationTypeDef; |
|||
|
|||
/** @defgroup USBH_HOST_Exported_FunctionsPrototype USBH_HOST_Exported_FunctionsPrototype |
|||
* @brief Declaration of public functions for Usb host. |
|||
* @{ |
|||
*/ |
|||
|
|||
/* Exported functions -------------------------------------------------------*/ |
|||
|
|||
/** @brief USB Host initialization function. */ |
|||
void MX_USB_HOST_Init(void); |
|||
|
|||
/** |
|||
* @} |
|||
*/ |
|||
|
|||
/** |
|||
* @} |
|||
*/ |
|||
|
|||
/** |
|||
* @} |
|||
*/ |
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
|||
|
|||
#endif /* __USB_HOST__H__ */ |
|||
|
@ -0,0 +1,539 @@ |
|||
/* USER CODE BEGIN Header */ |
|||
/** |
|||
****************************************************************************** |
|||
* @file : Target/usbh_conf.c |
|||
* @version : v1.0_Cube |
|||
* @brief : This file implements the board support package for the USB host library |
|||
****************************************************************************** |
|||
* @attention |
|||
* |
|||
* Copyright (c) 2024 STMicroelectronics. |
|||
* All rights reserved. |
|||
* |
|||
* This software is licensed under terms that can be found in the LICENSE file |
|||
* in the root directory of this software component. |
|||
* If no LICENSE file comes with this software, it is provided AS-IS. |
|||
* |
|||
****************************************************************************** |
|||
*/ |
|||
/* USER CODE END Header */ |
|||
|
|||
/* Includes ------------------------------------------------------------------*/ |
|||
#include "usbh_core.h" |
|||
#include "usbh_platform.h" |
|||
|
|||
/* USER CODE BEGIN Includes */ |
|||
|
|||
/* USER CODE END Includes */ |
|||
|
|||
/* Private typedef -----------------------------------------------------------*/ |
|||
/* Private define ------------------------------------------------------------*/ |
|||
/* Private macro -------------------------------------------------------------*/ |
|||
|
|||
/* USER CODE BEGIN PV */ |
|||
/* Private variables ---------------------------------------------------------*/ |
|||
|
|||
/* USER CODE END PV */ |
|||
|
|||
extern HCD_HandleTypeDef hhcd_USB_OTG_FS; |
|||
void Error_Handler(void); |
|||
|
|||
/* USER CODE BEGIN 0 */ |
|||
|
|||
/* USER CODE END 0 */ |
|||
|
|||
/* USER CODE BEGIN PFP */ |
|||
/* Private function prototypes -----------------------------------------------*/ |
|||
USBH_StatusTypeDef USBH_Get_USB_Status(HAL_StatusTypeDef hal_status); |
|||
|
|||
/* USER CODE END PFP */ |
|||
|
|||
/* Private functions ---------------------------------------------------------*/ |
|||
|
|||
/* USER CODE BEGIN 1 */ |
|||
|
|||
/* USER CODE END 1 */ |
|||
|
|||
/******************************************************************************* |
|||
LL Driver Callbacks (HCD -> USB Host Library) |
|||
*******************************************************************************/ |
|||
/* MSP Init */ |
|||
|
|||
void HAL_HCD_MspInit(HCD_HandleTypeDef* hcdHandle) |
|||
{ |
|||
GPIO_InitTypeDef GPIO_InitStruct = {0}; |
|||
if(hcdHandle->Instance==USB_OTG_FS) |
|||
{ |
|||
/* USER CODE BEGIN USB_OTG_FS_MspInit 0 */ |
|||
|
|||
/* USER CODE END USB_OTG_FS_MspInit 0 */ |
|||
|
|||
__HAL_RCC_GPIOA_CLK_ENABLE(); |
|||
/**USB_OTG_FS GPIO Configuration |
|||
PA11 ------> USB_OTG_FS_DM |
|||
PA12 ------> USB_OTG_FS_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_OTG_FS; |
|||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|||
|
|||
/* Peripheral clock enable */ |
|||
__HAL_RCC_USB_OTG_FS_CLK_ENABLE(); |
|||
|
|||
/* Peripheral interrupt init */ |
|||
HAL_NVIC_SetPriority(OTG_FS_IRQn, 5, 0); |
|||
HAL_NVIC_EnableIRQ(OTG_FS_IRQn); |
|||
/* USER CODE BEGIN USB_OTG_FS_MspInit 1 */ |
|||
|
|||
/* USER CODE END USB_OTG_FS_MspInit 1 */ |
|||
} |
|||
} |
|||
|
|||
void HAL_HCD_MspDeInit(HCD_HandleTypeDef* hcdHandle) |
|||
{ |
|||
if(hcdHandle->Instance==USB_OTG_FS) |
|||
{ |
|||
/* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */ |
|||
|
|||
/* USER CODE END USB_OTG_FS_MspDeInit 0 */ |
|||
/* Peripheral clock disable */ |
|||
__HAL_RCC_USB_OTG_FS_CLK_DISABLE(); |
|||
|
|||
/**USB_OTG_FS GPIO Configuration |
|||
PA11 ------> USB_OTG_FS_DM |
|||
PA12 ------> USB_OTG_FS_DP |
|||
*/ |
|||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12); |
|||
|
|||
/* Peripheral interrupt Deinit*/ |
|||
HAL_NVIC_DisableIRQ(OTG_FS_IRQn); |
|||
|
|||
/* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */ |
|||
|
|||
/* USER CODE END USB_OTG_FS_MspDeInit 1 */ |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @brief SOF callback. |
|||
* @param hhcd: HCD handle |
|||
* @retval None |
|||
*/ |
|||
void HAL_HCD_SOF_Callback(HCD_HandleTypeDef *hhcd) |
|||
{ |
|||
USBH_LL_IncTimer(hhcd->pData); |
|||
} |
|||
|
|||
/** |
|||
* @brief SOF callback. |
|||
* @param hhcd: HCD handle |
|||
* @retval None |
|||
*/ |
|||
void HAL_HCD_Connect_Callback(HCD_HandleTypeDef *hhcd) |
|||
{ |
|||
USBH_LL_Connect(hhcd->pData); |
|||
} |
|||
|
|||
/** |
|||
* @brief SOF callback. |
|||
* @param hhcd: HCD handle |
|||
* @retval None |
|||
*/ |
|||
void HAL_HCD_Disconnect_Callback(HCD_HandleTypeDef *hhcd) |
|||
{ |
|||
USBH_LL_Disconnect(hhcd->pData); |
|||
} |
|||
|
|||
/** |
|||
* @brief Notify URB state change callback. |
|||
* @param hhcd: HCD handle |
|||
* @param chnum: channel number |
|||
* @param urb_state: state |
|||
* @retval None |
|||
*/ |
|||
void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum, HCD_URBStateTypeDef urb_state) |
|||
{ |
|||
/* To be used with OS to sync URB state with the global state machine */ |
|||
#if (USBH_USE_OS == 1) |
|||
USBH_LL_NotifyURBChange(hhcd->pData); |
|||
#endif |
|||
} |
|||
/** |
|||
* @brief Port Port Enabled callback. |
|||
* @param hhcd: HCD handle |
|||
* @retval None |
|||
*/ |
|||
void HAL_HCD_PortEnabled_Callback(HCD_HandleTypeDef *hhcd) |
|||
{ |
|||
USBH_LL_PortEnabled(hhcd->pData); |
|||
} |
|||
|
|||
/** |
|||
* @brief Port Port Disabled callback. |
|||
* @param hhcd: HCD handle |
|||
* @retval None |
|||
*/ |
|||
void HAL_HCD_PortDisabled_Callback(HCD_HandleTypeDef *hhcd) |
|||
{ |
|||
USBH_LL_PortDisabled(hhcd->pData); |
|||
} |
|||
|
|||
/******************************************************************************* |
|||
LL Driver Interface (USB Host Library --> HCD) |
|||
*******************************************************************************/ |
|||
|
|||
/** |
|||
* @brief Initialize the low level portion of the host driver. |
|||
* @param phost: Host handle |
|||
* @retval USBH status |
|||
*/ |
|||
USBH_StatusTypeDef USBH_LL_Init(USBH_HandleTypeDef *phost) |
|||
{ |
|||
/* Init USB_IP */ |
|||
if (phost->id == HOST_FS) { |
|||
/* Link the driver to the stack. */ |
|||
hhcd_USB_OTG_FS.pData = phost; |
|||
phost->pData = &hhcd_USB_OTG_FS; |
|||
|
|||
hhcd_USB_OTG_FS.Instance = USB_OTG_FS; |
|||
hhcd_USB_OTG_FS.Init.Host_channels = 8; |
|||
hhcd_USB_OTG_FS.Init.speed = HCD_SPEED_FULL; |
|||
hhcd_USB_OTG_FS.Init.dma_enable = DISABLE; |
|||
hhcd_USB_OTG_FS.Init.phy_itface = HCD_PHY_EMBEDDED; |
|||
hhcd_USB_OTG_FS.Init.Sof_enable = DISABLE; |
|||
if (HAL_HCD_Init(&hhcd_USB_OTG_FS) != HAL_OK) |
|||
{ |
|||
Error_Handler( ); |
|||
} |
|||
|
|||
USBH_LL_SetTimer(phost, HAL_HCD_GetCurrentFrame(&hhcd_USB_OTG_FS)); |
|||
} |
|||
return USBH_OK; |
|||
} |
|||
|
|||
/** |
|||
* @brief De-Initialize the low level portion of the host driver. |
|||
* @param phost: Host handle |
|||
* @retval USBH status |
|||
*/ |
|||
USBH_StatusTypeDef USBH_LL_DeInit(USBH_HandleTypeDef *phost) |
|||
{ |
|||
HAL_StatusTypeDef hal_status = HAL_OK; |
|||
USBH_StatusTypeDef usb_status = USBH_OK; |
|||
|
|||
hal_status = HAL_HCD_DeInit(phost->pData); |
|||
|
|||
usb_status = USBH_Get_USB_Status(hal_status); |
|||
|
|||
return usb_status; |
|||
} |
|||
|
|||
/** |
|||
* @brief Start the low level portion of the host driver. |
|||
* @param phost: Host handle |
|||
* @retval USBH status |
|||
*/ |
|||
USBH_StatusTypeDef USBH_LL_Start(USBH_HandleTypeDef *phost) |
|||
{ |
|||
HAL_StatusTypeDef hal_status = HAL_OK; |
|||
USBH_StatusTypeDef usb_status = USBH_OK; |
|||
|
|||
hal_status = HAL_HCD_Start(phost->pData); |
|||
|
|||
usb_status = USBH_Get_USB_Status(hal_status); |
|||
|
|||
return usb_status; |
|||
} |
|||
|
|||
/** |
|||
* @brief Stop the low level portion of the host driver. |
|||
* @param phost: Host handle |
|||
* @retval USBH status |
|||
*/ |
|||
USBH_StatusTypeDef USBH_LL_Stop(USBH_HandleTypeDef *phost) |
|||
{ |
|||
HAL_StatusTypeDef hal_status = HAL_OK; |
|||
USBH_StatusTypeDef usb_status = USBH_OK; |
|||
|
|||
hal_status = HAL_HCD_Stop(phost->pData); |
|||
|
|||
usb_status = USBH_Get_USB_Status(hal_status); |
|||
|
|||
return usb_status; |
|||
} |
|||
|
|||
/** |
|||
* @brief Return the USB host speed from the low level driver. |
|||
* @param phost: Host handle |
|||
* @retval USBH speeds |
|||
*/ |
|||
USBH_SpeedTypeDef USBH_LL_GetSpeed(USBH_HandleTypeDef *phost) |
|||
{ |
|||
USBH_SpeedTypeDef speed = USBH_SPEED_FULL; |
|||
|
|||
switch (HAL_HCD_GetCurrentSpeed(phost->pData)) |
|||
{ |
|||
case 0 : |
|||
speed = USBH_SPEED_HIGH; |
|||
break; |
|||
|
|||
case 1 : |
|||
speed = USBH_SPEED_FULL; |
|||
break; |
|||
|
|||
case 2 : |
|||
speed = USBH_SPEED_LOW; |
|||
break; |
|||
|
|||
default: |
|||
speed = USBH_SPEED_FULL; |
|||
break; |
|||
} |
|||
return speed; |
|||
} |
|||
|
|||
/** |
|||
* @brief Reset the Host port of the low level driver. |
|||
* @param phost: Host handle |
|||
* @retval USBH status |
|||
*/ |
|||
USBH_StatusTypeDef USBH_LL_ResetPort(USBH_HandleTypeDef *phost) |
|||
{ |
|||
HAL_StatusTypeDef hal_status = HAL_OK; |
|||
USBH_StatusTypeDef usb_status = USBH_OK; |
|||
|
|||
hal_status = HAL_HCD_ResetPort(phost->pData); |
|||
|
|||
usb_status = USBH_Get_USB_Status(hal_status); |
|||
|
|||
return usb_status; |
|||
} |
|||
|
|||
/** |
|||
* @brief Return the last transferred packet size. |
|||
* @param phost: Host handle |
|||
* @param pipe: Pipe index |
|||
* @retval Packet size |
|||
*/ |
|||
uint32_t USBH_LL_GetLastXferSize(USBH_HandleTypeDef *phost, uint8_t pipe) |
|||
{ |
|||
return HAL_HCD_HC_GetXferCount(phost->pData, pipe); |
|||
} |
|||
|
|||
/** |
|||
* @brief Open a pipe of the low level driver. |
|||
* @param phost: Host handle |
|||
* @param pipe_num: Pipe index |
|||
* @param epnum: Endpoint number |
|||
* @param dev_address: Device USB address |
|||
* @param speed: Device Speed |
|||
* @param ep_type: Endpoint type |
|||
* @param mps: Endpoint max packet size |
|||
* @retval USBH status |
|||
*/ |
|||
USBH_StatusTypeDef USBH_LL_OpenPipe(USBH_HandleTypeDef *phost, uint8_t pipe_num, uint8_t epnum, |
|||
uint8_t dev_address, uint8_t speed, uint8_t ep_type, uint16_t mps) |
|||
{ |
|||
HAL_StatusTypeDef hal_status = HAL_OK; |
|||
USBH_StatusTypeDef usb_status = USBH_OK; |
|||
|
|||
hal_status = HAL_HCD_HC_Init(phost->pData, pipe_num, epnum, |
|||
dev_address, speed, ep_type, mps); |
|||
|
|||
usb_status = USBH_Get_USB_Status(hal_status); |
|||
|
|||
return usb_status; |
|||
} |
|||
|
|||
/** |
|||
* @brief Close a pipe of the low level driver. |
|||
* @param phost: Host handle |
|||
* @param pipe: Pipe index |
|||
* @retval USBH status |
|||
*/ |
|||
USBH_StatusTypeDef USBH_LL_ClosePipe(USBH_HandleTypeDef *phost, uint8_t pipe) |
|||
{ |
|||
HAL_StatusTypeDef hal_status = HAL_OK; |
|||
USBH_StatusTypeDef usb_status = USBH_OK; |
|||
|
|||
hal_status = HAL_HCD_HC_Halt(phost->pData, pipe); |
|||
|
|||
usb_status = USBH_Get_USB_Status(hal_status); |
|||
|
|||
return usb_status; |
|||
} |
|||
|
|||
/** |
|||
* @brief Submit a new URB to the low level driver. |
|||
* @param phost: Host handle |
|||
* @param pipe: Pipe index |
|||
* This parameter can be a value from 1 to 15 |
|||
* @param direction : Channel number |
|||
* This parameter can be one of the these values: |
|||
* 0 : Output |
|||
* 1 : Input |
|||
* @param ep_type : Endpoint Type |
|||
* This parameter can be one of the these values: |
|||
* @arg EP_TYPE_CTRL: Control type |
|||
* @arg EP_TYPE_ISOC: Isochrounous type |
|||
* @arg EP_TYPE_BULK: Bulk type |
|||
* @arg EP_TYPE_INTR: Interrupt type |
|||
* @param token : Endpoint Type |
|||
* This parameter can be one of the these values: |
|||
* @arg 0: PID_SETUP |
|||
* @arg 1: PID_DATA |
|||
* @param pbuff : pointer to URB data |
|||
* @param length : Length of URB data |
|||
* @param do_ping : activate do ping protocol (for high speed only) |
|||
* This parameter can be one of the these values: |
|||
* 0 : do ping inactive |
|||
* 1 : do ping active |
|||
* @retval Status |
|||
*/ |
|||
USBH_StatusTypeDef USBH_LL_SubmitURB(USBH_HandleTypeDef *phost, uint8_t pipe, uint8_t direction, |
|||
uint8_t ep_type, uint8_t token, uint8_t *pbuff, uint16_t length, |
|||
uint8_t do_ping) |
|||
{ |
|||
HAL_StatusTypeDef hal_status = HAL_OK; |
|||
USBH_StatusTypeDef usb_status = USBH_OK; |
|||
|
|||
hal_status = HAL_HCD_HC_SubmitRequest(phost->pData, pipe, direction , |
|||
ep_type, token, pbuff, length, |
|||
do_ping); |
|||
usb_status = USBH_Get_USB_Status(hal_status); |
|||
|
|||
return usb_status; |
|||
} |
|||
|
|||
/** |
|||
* @brief Get a URB state from the low level driver. |
|||
* @param phost: Host handle |
|||
* @param pipe: Pipe index |
|||
* This parameter can be a value from 1 to 15 |
|||
* @retval URB state |
|||
* This parameter can be one of the these values: |
|||
* @arg URB_IDLE |
|||
* @arg URB_DONE |
|||
* @arg URB_NOTREADY |
|||
* @arg URB_NYET |
|||
* @arg URB_ERROR |
|||
* @arg URB_STALL |
|||
*/ |
|||
USBH_URBStateTypeDef USBH_LL_GetURBState(USBH_HandleTypeDef *phost, uint8_t pipe) |
|||
{ |
|||
return (USBH_URBStateTypeDef)HAL_HCD_HC_GetURBState (phost->pData, pipe); |
|||
} |
|||
|
|||
/** |
|||
* @brief Drive VBUS. |
|||
* @param phost: Host handle |
|||
* @param state : VBUS state |
|||
* This parameter can be one of the these values: |
|||
* 0 : VBUS Inactive |
|||
* 1 : VBUS Active |
|||
* @retval Status |
|||
*/ |
|||
USBH_StatusTypeDef USBH_LL_DriverVBUS(USBH_HandleTypeDef *phost, uint8_t state) |
|||
{ |
|||
if (phost->id == HOST_FS) { |
|||
MX_DriverVbusFS(state); |
|||
} |
|||
|
|||
/* USER CODE BEGIN 0 */ |
|||
|
|||
/* USER CODE END 0*/ |
|||
|
|||
HAL_Delay(200); |
|||
return USBH_OK; |
|||
} |
|||
|
|||
/** |
|||
* @brief Set toggle for a pipe. |
|||
* @param phost: Host handle |
|||
* @param pipe: Pipe index |
|||
* @param toggle: toggle (0/1) |
|||
* @retval Status |
|||
*/ |
|||
USBH_StatusTypeDef USBH_LL_SetToggle(USBH_HandleTypeDef *phost, uint8_t pipe, uint8_t toggle) |
|||
{ |
|||
HCD_HandleTypeDef *pHandle; |
|||
pHandle = phost->pData; |
|||
|
|||
if(pHandle->hc[pipe].ep_is_in) |
|||
{ |
|||
pHandle->hc[pipe].toggle_in = toggle; |
|||
} |
|||
else |
|||
{ |
|||
pHandle->hc[pipe].toggle_out = toggle; |
|||
} |
|||
|
|||
return USBH_OK; |
|||
} |
|||
|
|||
/** |
|||
* @brief Return the current toggle of a pipe. |
|||
* @param phost: Host handle |
|||
* @param pipe: Pipe index |
|||
* @retval toggle (0/1) |
|||
*/ |
|||
uint8_t USBH_LL_GetToggle(USBH_HandleTypeDef *phost, uint8_t pipe) |
|||
{ |
|||
uint8_t toggle = 0; |
|||
HCD_HandleTypeDef *pHandle; |
|||
pHandle = phost->pData; |
|||
|
|||
if(pHandle->hc[pipe].ep_is_in) |
|||
{ |
|||
toggle = pHandle->hc[pipe].toggle_in; |
|||
} |
|||
else |
|||
{ |
|||
toggle = pHandle->hc[pipe].toggle_out; |
|||
} |
|||
return toggle; |
|||
} |
|||
|
|||
/** |
|||
* @brief Delay routine for the USB Host Library |
|||
* @param Delay: Delay in ms |
|||
* @retval None |
|||
*/ |
|||
void USBH_Delay(uint32_t Delay) |
|||
{ |
|||
HAL_Delay(Delay); |
|||
} |
|||
|
|||
/** |
|||
* @brief Returns the USB status depending on the HAL status: |
|||
* @param hal_status: HAL status |
|||
* @retval USB status |
|||
*/ |
|||
USBH_StatusTypeDef USBH_Get_USB_Status(HAL_StatusTypeDef hal_status) |
|||
{ |
|||
USBH_StatusTypeDef usb_status = USBH_OK; |
|||
|
|||
switch (hal_status) |
|||
{ |
|||
case HAL_OK : |
|||
usb_status = USBH_OK; |
|||
break; |
|||
case HAL_ERROR : |
|||
usb_status = USBH_FAIL; |
|||
break; |
|||
case HAL_BUSY : |
|||
usb_status = USBH_BUSY; |
|||
break; |
|||
case HAL_TIMEOUT : |
|||
usb_status = USBH_FAIL; |
|||
break; |
|||
default : |
|||
usb_status = USBH_FAIL; |
|||
break; |
|||
} |
|||
return usb_status; |
|||
} |
|||
|
@ -0,0 +1,194 @@ |
|||
/* USER CODE BEGIN Header */ |
|||
/** |
|||
****************************************************************************** |
|||
* @file : Target/usbh_conf.h |
|||
* @version : v1.0_Cube |
|||
* @brief : Header for usbh_conf.c file. |
|||
****************************************************************************** |
|||
* @attention |
|||
* |
|||
* Copyright (c) 2024 STMicroelectronics. |
|||
* All rights reserved. |
|||
* |
|||
* This software is licensed under terms that can be found in the LICENSE file |
|||
* in the root directory of this software component. |
|||
* If no LICENSE file comes with this software, it is provided AS-IS. |
|||
* |
|||
****************************************************************************** |
|||
*/ |
|||
/* USER CODE END Header */ |
|||
|
|||
/* Define to prevent recursive inclusion -------------------------------------*/ |
|||
#ifndef __USBH_CONF__H__ |
|||
#define __USBH_CONF__H__ |
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
/* Includes ------------------------------------------------------------------*/ |
|||
|
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
#include <string.h> |
|||
#include "main.h" |
|||
|
|||
#include "stm32f4xx.h" |
|||
#include "stm32f4xx_hal.h" |
|||
|
|||
/* USER CODE BEGIN INCLUDE */ |
|||
|
|||
/* USER CODE END INCLUDE */ |
|||
|
|||
/** @addtogroup STM32_USB_HOST_LIBRARY |
|||
* @{ |
|||
*/ |
|||
|
|||
/** @defgroup USBH_CONF |
|||
* @brief usb host low level driver configuration file |
|||
* @{ |
|||
*/ |
|||
|
|||
/** @defgroup USBH_CONF_Exported_Variables USBH_CONF_Exported_Variables |
|||
* @brief Public variables. |
|||
* @{ |
|||
*/ |
|||
|
|||
/** |
|||
* @} |
|||
*/ |
|||
|
|||
/** @defgroup USBH_CONF_Exported_Defines USBH_CONF_Exported_Defines |
|||
* @brief Defines for configuration of the Usb host. |
|||
* @{ |
|||
*/ |
|||
|
|||
/*---------- -----------*/ |
|||
#define USBH_MAX_NUM_ENDPOINTS 2U |
|||
|
|||
/*---------- -----------*/ |
|||
#define USBH_MAX_NUM_INTERFACES 2U |
|||
|
|||
/*---------- -----------*/ |
|||
#define USBH_MAX_NUM_CONFIGURATION 1U |
|||
|
|||
/*---------- -----------*/ |
|||
#define USBH_KEEP_CFG_DESCRIPTOR 1U |
|||
|
|||
/*---------- -----------*/ |
|||
#define USBH_MAX_NUM_SUPPORTED_CLASS 1U |
|||
|
|||
/*---------- -----------*/ |
|||
#define USBH_MAX_SIZE_CONFIGURATION 256U |
|||
|
|||
/*---------- -----------*/ |
|||
#define USBH_MAX_DATA_BUFFER 512U |
|||
|
|||
/*---------- -----------*/ |
|||
#define USBH_DEBUG_LEVEL 0U |
|||
|
|||
/*---------- -----------*/ |
|||
#define USBH_USE_OS 1U |
|||
|
|||
/****************************************/ |
|||
/* #define for FS and HS identification */ |
|||
#define HOST_HS 0 |
|||
#define HOST_FS 1 |
|||
|
|||
#if (USBH_USE_OS == 1) |
|||
#include "cmsis_os.h" |
|||
#define USBH_PROCESS_PRIO osPriorityNormal |
|||
#define USBH_PROCESS_STACK_SIZE ((uint16_t)512) |
|||
#endif /* (USBH_USE_OS == 1) */ |
|||
|
|||
/** |
|||
* @} |
|||
*/ |
|||
|
|||
/** @defgroup USBH_CONF_Exported_Macros USBH_CONF_Exported_Macros |
|||
* @brief Aliases. |
|||
* @{ |
|||
*/ |
|||
|
|||
/* Memory management macros */ |
|||
|
|||
/** Alias for memory allocation. */ |
|||
#define USBH_malloc malloc |
|||
|
|||
/** Alias for memory release. */ |
|||
#define USBH_free free |
|||
|
|||
/** Alias for memory set. */ |
|||
#define USBH_memset memset |
|||
|
|||
/** Alias for memory copy. */ |
|||
#define USBH_memcpy memcpy |
|||
|
|||
/* DEBUG macros */ |
|||
|
|||
#if (USBH_DEBUG_LEVEL > 0U) |
|||
#define USBH_UsrLog(...) do { \ |
|||
printf(__VA_ARGS__); \ |
|||
printf("\n"); \ |
|||
} while (0) |
|||
#else |
|||
#define USBH_UsrLog(...) do {} while (0) |
|||
#endif |
|||
|
|||
#if (USBH_DEBUG_LEVEL > 1U) |
|||
|
|||
#define USBH_ErrLog(...) do { \ |
|||
printf("ERROR: "); \ |
|||
printf(__VA_ARGS__); \ |
|||
printf("\n"); \ |
|||
} while (0) |
|||
#else |
|||
#define USBH_ErrLog(...) do {} while (0) |
|||
#endif |
|||
|
|||
#if (USBH_DEBUG_LEVEL > 2U) |
|||
#define USBH_DbgLog(...) do { \ |
|||
printf("DEBUG : "); \ |
|||
printf(__VA_ARGS__); \ |
|||
printf("\n"); \ |
|||
} while (0) |
|||
#else |
|||
#define USBH_DbgLog(...) do {} while (0) |
|||
#endif |
|||
|
|||
/** |
|||
* @} |
|||
*/ |
|||
|
|||
/** @defgroup USBH_CONF_Exported_Types USBH_CONF_Exported_Types |
|||
* @brief Types. |
|||
* @{ |
|||
*/ |
|||
|
|||
/** |
|||
* @} |
|||
*/ |
|||
|
|||
/** @defgroup USBH_CONF_Exported_FunctionsPrototype USBH_CONF_Exported_FunctionsPrototype |
|||
* @brief Declaration of public functions for Usb host. |
|||
* @{ |
|||
*/ |
|||
|
|||
/* Exported functions -------------------------------------------------------*/ |
|||
|
|||
/** |
|||
* @} |
|||
*/ |
|||
|
|||
/** |
|||
* @} |
|||
*/ |
|||
|
|||
/** |
|||
* @} |
|||
*/ |
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
|||
|
|||
#endif /* __USBH_CONF__H__ */ |
|||
|
@ -0,0 +1,52 @@ |
|||
/* USER CODE BEGIN Header */ |
|||
/** |
|||
****************************************************************************** |
|||
* @file : usbh_platform.c |
|||
|
|||
* @brief : This file implements the USB platform |
|||
****************************************************************************** |
|||
* @attention |
|||
* |
|||
* Copyright (c) 2024 STMicroelectronics. |
|||
* All rights reserved. |
|||
* |
|||
* This software is licensed under terms that can be found in the LICENSE file |
|||
* in the root directory of this software component. |
|||
* If no LICENSE file comes with this software, it is provided AS-IS. |
|||
* |
|||
****************************************************************************** |
|||
*/ |
|||
/* USER CODE END Header */ |
|||
|
|||
/* Includes ------------------------------------------------------------------*/ |
|||
#include "usbh_platform.h" |
|||
|
|||
/* USER CODE BEGIN INCLUDE */ |
|||
|
|||
/* USER CODE END INCLUDE */ |
|||
|
|||
/** |
|||
* @brief Drive VBUS. |
|||
* @param state : VBUS state |
|||
* This parameter can be one of the these values: |
|||
* - 1 : VBUS Active |
|||
* - 0 : VBUS Inactive |
|||
*/ |
|||
void MX_DriverVbusFS(uint8_t state) |
|||
{ |
|||
uint8_t data = state; |
|||
/* USER CODE BEGIN PREPARE_GPIO_DATA_VBUS_FS */ |
|||
if(state == 0) |
|||
{ |
|||
/* Drive high Charge pump */ |
|||
data = GPIO_PIN_RESET; |
|||
} |
|||
else |
|||
{ |
|||
/* Drive low Charge pump */ |
|||
data = GPIO_PIN_SET; |
|||
} |
|||
/* USER CODE END PREPARE_GPIO_DATA_VBUS_FS */ |
|||
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_15,(GPIO_PinState)data); |
|||
} |
|||
|
@ -0,0 +1,42 @@ |
|||
/* USER CODE BEGIN Header */ |
|||
/** |
|||
****************************************************************************** |
|||
* @file : usbh_platform.h |
|||
* @brief : Header for usbh_platform.c file. |
|||
****************************************************************************** |
|||
* @attention |
|||
* |
|||
* Copyright (c) 2024 STMicroelectronics. |
|||
* All rights reserved. |
|||
* |
|||
* This software is licensed under terms that can be found in the LICENSE file |
|||
* in the root directory of this software component. |
|||
* If no LICENSE file comes with this software, it is provided AS-IS. |
|||
* |
|||
****************************************************************************** |
|||
*/ |
|||
/* USER CODE END Header */ |
|||
|
|||
/* Define to prevent recursive inclusion -------------------------------------*/ |
|||
#ifndef __USBH_PLATFORM_H__ |
|||
#define __USBH_PLATFORM_H__ |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
|
|||
/* Includes ------------------------------------------------------------------*/ |
|||
#include "usb_host.h" |
|||
|
|||
/* USER CODE BEGIN INCLUDE */ |
|||
|
|||
/* USER CODE END INCLUDE */ |
|||
|
|||
void MX_DriverVbusFS(uint8_t state); |
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
|||
|
|||
#endif /* __USBH_PLATFORM_H__ */ |
|||
|
@ -1 +1 @@ |
|||
Subproject commit 5fe45de21864dd3b53b0a8683f0067fa429d15a0 |
|||
Subproject commit e0cd077ca7616f1ec6c299b13925c98d772cc970 |
Write
Preview
Loading…
Cancel
Save
Reference in new issue