refactor usb class structure
This commit is contained in:
@@ -284,7 +284,7 @@
|
||||
|
||||
<Group>
|
||||
<GroupName>Drivers/STM32F1xx_HAL_Driver</GroupName>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
@@ -539,8 +539,8 @@
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\..\..\core\usbd_core.c</PathWithFileName>
|
||||
<FilenameWithoutPath>usbd_core.c</FilenameWithoutPath>
|
||||
<PathWithFileName>..\..\..\..\class\msc\usbd_msc.c</PathWithFileName>
|
||||
<FilenameWithoutPath>usbd_msc.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
@@ -563,11 +563,35 @@
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\..\..\core\usbd_core.c</PathWithFileName>
|
||||
<FilenameWithoutPath>usbd_core.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>27</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\..\..\port\stm32\usb_dc_nohal.c</PathWithFileName>
|
||||
<FilenameWithoutPath>usb_dc_nohal.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>28</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\..\..\port\stm32\usb_dc_hal.c</PathWithFileName>
|
||||
<FilenameWithoutPath>usb_dc_hal.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
</Group>
|
||||
|
||||
<Group>
|
||||
@@ -578,7 +602,7 @@
|
||||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>27</FileNumber>
|
||||
<FileNumber>29</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -590,7 +614,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>28</FileNumber>
|
||||
<FileNumber>30</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -602,7 +626,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>29</FileNumber>
|
||||
<FileNumber>31</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -614,7 +638,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>30</FileNumber>
|
||||
<FileNumber>32</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -624,6 +648,18 @@
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>33</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\example\msc_ram\msc_ram_init.c</PathWithFileName>
|
||||
<FilenameWithoutPath>msc_ram_init.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
</Group>
|
||||
|
||||
<Group>
|
||||
|
||||
@@ -340,7 +340,7 @@
|
||||
<MiscControls></MiscControls>
|
||||
<Define>USE_HAL_DRIVER,STM32F103xB,STM32F1</Define>
|
||||
<Undefine></Undefine>
|
||||
<IncludePath>../Core/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy;../Drivers/CMSIS/Device/ST/STM32F1xx/Include;../Drivers/CMSIS/Include;..\..\..\..\common;..\..\..\..\core;..\..\..\..\class\cdc;..\..\..\..\class\winusb;..\example\hid_custom;..\example\cdc;..\example\hid_keyboard;..\example\hid_mouse;..\..\..\..\class\hid;..\example</IncludePath>
|
||||
<IncludePath>../Core/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc;../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy;../Drivers/CMSIS/Device/ST/STM32F1xx/Include;../Drivers/CMSIS/Include;..\..\..\..\common;..\..\..\..\core;..\..\..\..\class\cdc;..\..\..\..\class\msc;..\..\..\..\class\hid;..\example</IncludePath>
|
||||
</VariousControls>
|
||||
</Cads>
|
||||
<Aads>
|
||||
@@ -520,20 +520,81 @@
|
||||
<FilePath>..\..\..\..\class\cdc\usbd_cdc.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>usbd_core.c</FileName>
|
||||
<FileName>usbd_msc.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\..\..\core\usbd_core.c</FilePath>
|
||||
<FilePath>..\..\..\..\class\msc\usbd_msc.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>usbd_hid.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\..\..\class\hid\usbd_hid.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>usbd_core.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\..\..\core\usbd_core.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>usb_dc_nohal.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\..\..\port\stm32\usb_dc_nohal.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>usb_dc_hal.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\..\..\port\stm32\usb_dc_hal.c</FilePath>
|
||||
<FileOption>
|
||||
<CommonProperty>
|
||||
<UseCPPCompiler>2</UseCPPCompiler>
|
||||
<RVCTCodeConst>0</RVCTCodeConst>
|
||||
<RVCTZI>0</RVCTZI>
|
||||
<RVCTOtherData>0</RVCTOtherData>
|
||||
<ModuleSelection>0</ModuleSelection>
|
||||
<IncludeInBuild>0</IncludeInBuild>
|
||||
<AlwaysBuild>2</AlwaysBuild>
|
||||
<GenerateAssemblyFile>2</GenerateAssemblyFile>
|
||||
<AssembleAssemblyFile>2</AssembleAssemblyFile>
|
||||
<PublicsOnly>2</PublicsOnly>
|
||||
<StopOnExitCode>11</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>1</ComprImg>
|
||||
</CommonProperty>
|
||||
<FileArmAds>
|
||||
<Cads>
|
||||
<interw>2</interw>
|
||||
<Optim>0</Optim>
|
||||
<oTime>2</oTime>
|
||||
<SplitLS>2</SplitLS>
|
||||
<OneElfS>2</OneElfS>
|
||||
<Strict>2</Strict>
|
||||
<EnumInt>2</EnumInt>
|
||||
<PlainCh>2</PlainCh>
|
||||
<Ropi>2</Ropi>
|
||||
<Rwpi>2</Rwpi>
|
||||
<wLevel>0</wLevel>
|
||||
<uThumb>2</uThumb>
|
||||
<uSurpInc>2</uSurpInc>
|
||||
<uC99>2</uC99>
|
||||
<uGnu>2</uGnu>
|
||||
<useXO>2</useXO>
|
||||
<v6Lang>0</v6Lang>
|
||||
<v6LangP>0</v6LangP>
|
||||
<vShortEn>2</vShortEn>
|
||||
<vShortWch>2</vShortWch>
|
||||
<v6Lto>2</v6Lto>
|
||||
<v6WtE>2</v6WtE>
|
||||
<v6Rtti>2</v6Rtti>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
<Undefine></Undefine>
|
||||
<IncludePath></IncludePath>
|
||||
</VariousControls>
|
||||
</Cads>
|
||||
</FileArmAds>
|
||||
</FileOption>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
@@ -556,7 +617,7 @@
|
||||
<RVCTOtherData>0</RVCTOtherData>
|
||||
<ModuleSelection>0</ModuleSelection>
|
||||
<IncludeInBuild>0</IncludeInBuild>
|
||||
<AlwaysBuild>1</AlwaysBuild>
|
||||
<AlwaysBuild>2</AlwaysBuild>
|
||||
<GenerateAssemblyFile>2</GenerateAssemblyFile>
|
||||
<AssembleAssemblyFile>2</AssembleAssemblyFile>
|
||||
<PublicsOnly>2</PublicsOnly>
|
||||
@@ -617,7 +678,7 @@
|
||||
<RVCTOtherData>0</RVCTOtherData>
|
||||
<ModuleSelection>0</ModuleSelection>
|
||||
<IncludeInBuild>0</IncludeInBuild>
|
||||
<AlwaysBuild>1</AlwaysBuild>
|
||||
<AlwaysBuild>2</AlwaysBuild>
|
||||
<GenerateAssemblyFile>2</GenerateAssemblyFile>
|
||||
<AssembleAssemblyFile>2</AssembleAssemblyFile>
|
||||
<PublicsOnly>2</PublicsOnly>
|
||||
@@ -661,6 +722,11 @@
|
||||
</FileArmAds>
|
||||
</FileOption>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>msc_ram_init.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\example\msc_ram\msc_ram_init.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
|
||||
@@ -128,6 +128,7 @@ void usbd_cdc_acm_out(uint8_t ep)
|
||||
usbd_ep_read(ep, data, 64, &read_byte);
|
||||
printf("out\r\n");
|
||||
printf("read len:%d\r\n", read_byte);
|
||||
usbd_ep_read(ep, NULL, 0, NULL);
|
||||
}
|
||||
|
||||
void usbd_cdc_acm_in(uint8_t ep)
|
||||
@@ -163,4 +164,4 @@ void cdc_test(void)
|
||||
uint8_t data_buffer[10] = { 0x31, 0x32, 0x33, 0x34, 0x35, 0x31, 0x32, 0x33, 0x34, 0x35 };
|
||||
usbd_ep_write(CDC_IN_EP, data_buffer, 10, NULL);
|
||||
HAL_Delay(500);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/*!< Use macros to select the examples to test */
|
||||
|
||||
/*!< cdc */
|
||||
//#define USB_CDC
|
||||
#define USB_CDC
|
||||
|
||||
/*!< hid keyboard */
|
||||
//#define USB_HID_KEYBOARD
|
||||
@@ -14,4 +14,5 @@
|
||||
//#define USB_HID_CUSTOM
|
||||
|
||||
/*!< msc ram */
|
||||
#define USB_MSC_RAM
|
||||
//#define USB_MSC_RAM
|
||||
|
||||
|
||||
@@ -266,4 +266,4 @@ void hid_keyboard_test(void)
|
||||
uint8_t sendbuffer[8] = { 0x00, 0x00, HID_KEY_A, 0x00, 0x00, 0x00, 0x00, 0x00 }; //A
|
||||
hid_keyboard_send_report(HID_INT_EP, sendbuffer, HID_INT_EP_SIZE);
|
||||
HAL_Delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/** @mainpage msc_ram_demo_init
|
||||
* <table>
|
||||
* <tr><th>Project <td>msc_ram_demo
|
||||
* <tr><th>Author <td>LiGuo 1570139720@qq.com
|
||||
* <tr><th>Project <td>msc_ram_demo
|
||||
* <tr><th>Author <td>LiGuo 1570139720@qq.com
|
||||
* </table>
|
||||
* @section msc ram init demo
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @section 版本更新历史
|
||||
*
|
||||
*
|
||||
* 版本|作者|时间|描述
|
||||
* ----|----|----|----
|
||||
* 1.0|LiGuo|2021.11.19|creat project
|
||||
@@ -23,9 +23,8 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_msc.h"
|
||||
|
||||
|
||||
#define MSC_IN_EP 0x85
|
||||
#define MSC_OUT_EP 0x04
|
||||
#define MSC_IN_EP 0x81
|
||||
#define MSC_OUT_EP 0x01
|
||||
|
||||
#define USBD_VID 0xFFFF
|
||||
#define USBD_PID 0xFFFF
|
||||
@@ -111,31 +110,31 @@ const uint8_t msc_ram_descriptor[] = {
|
||||
};
|
||||
|
||||
#define BLOCK_SIZE 512
|
||||
#define BLOCK_COUNT 2
|
||||
#define BLOCK_COUNT 10
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t BlockSpace[BLOCK_SIZE];
|
||||
} BLOCK_TYPE;
|
||||
|
||||
// The CDC recv buffer size should equal to the out endpoint size
|
||||
// or we will need a timeout to flush the recv buffer
|
||||
BLOCK_TYPE mass_block[BLOCK_COUNT];
|
||||
|
||||
void usbd_msc_get_cap(uint8_t lun, uint32_t *block_num, uint16_t *block_size)
|
||||
{
|
||||
*block_num = BLOCK_COUNT;
|
||||
*block_num = 1000; //Pretend having so many buffer,not has actually.
|
||||
*block_size = BLOCK_SIZE;
|
||||
}
|
||||
int usbd_msc_sector_read(uint32_t sector, uint8_t *buffer, uint32_t length)
|
||||
{
|
||||
memcpy(buffer, mass_block[sector].BlockSpace, length);
|
||||
if (sector < 10)
|
||||
memcpy(buffer, mass_block[sector].BlockSpace, length);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_msc_sector_write(uint32_t sector, uint8_t *buffer, uint32_t length)
|
||||
{
|
||||
memcpy(mass_block[sector].BlockSpace, buffer, length);
|
||||
if (sector < 10)
|
||||
memcpy(mass_block[sector].BlockSpace, buffer, length);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -150,4 +149,4 @@ void msc_ram_init(void)
|
||||
{
|
||||
usbd_desc_register(msc_ram_descriptor);
|
||||
usbd_msc_class_init(MSC_OUT_EP, MSC_IN_EP);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user