USB MSC: add example code for testing in documentation

This commit is contained in:
Daniel Fekete 2017-05-12 05:59:45 +02:00
parent 330013e1ee
commit 745c653a7f
23 changed files with 604 additions and 69 deletions

View File

@ -66,7 +66,7 @@ MapleMini_F103CB.menu.upload_method.BMPMethod.upload.tool=bmp_upload
MapleMini_F103CB.menu.usb.SerialUSB=Serial [Virtual COM port, 24(PA11)/23(PA12) pins]
MapleMini_F103CB.menu.usb.SerialUSB.build.extra_flags_usb=-DMENU_USB_SERIAL
MapleMini_F103CB.menu.usb.SerialMSC=Mass storage
MapleMini_F103CB.menu.usb.SerialMSC=Mass storage [testing, see documentation]
MapleMini_F103CB.menu.usb.SerialMSC.build.extra_flags_usb=-DMENU_USB_MASS_STORAGE
MapleMini_F103CB.menu.usb.Disabled=Disabled, no USB
@ -125,7 +125,7 @@ BluePill.menu.upload_method.BMPMethod.upload.tool=bmp_upload
BluePill.menu.usb.SerialUSB=Serial [Virtual COM port, PA11/PA12 pins]
BluePill.menu.usb.SerialUSB.build.extra_flags_usb=-DMENU_USB_SERIAL
BluePill.menu.usb.SerialMSC=Mass storage
BluePill.menu.usb.SerialMSC=Mass storage [testing, see documentation]
BluePill.menu.usb.SerialMSC.build.extra_flags_usb=-DMENU_USB_MASS_STORAGE
BluePill.menu.usb.Disabled=Disabled, no USB
@ -164,7 +164,7 @@ BLACK_F407XX.menu.upload_method.serialMethod.build.extra_flags_serial_auto=-DMEN
BLACK_F407XX.menu.usb.SerialUSB=Serial [Virtual COM port, PA11/PA12 pins]
BLACK_F407XX.menu.usb.SerialUSB.build.extra_flags_usb=-DMENU_USB_SERIAL
BLACK_F407XX.menu.usb.SerialMSC=Mass storage
BLACK_F407XX.menu.usb.SerialMSC=Mass storage [testing, see documentation]
BLACK_F407XX.menu.usb.SerialMSC.build.extra_flags_usb=-DMENU_USB_MASS_STORAGE
BLACK_F407XX.menu.usb.Disabled=Disabled, no USB
@ -323,7 +323,7 @@ DISCOVERY_L053C8.menu.upload_method.STLinkMethod.upload.tool=stlink_upload
DISCOVERY_L053C8.menu.usb.SerialUSB=Serial [Virtual COM port, PA11/PA12 pins]
DISCOVERY_L053C8.menu.usb.SerialUSB.build.extra_flags_usb=-DMENU_USB_SERIAL
DISCOVERY_L053C8.menu.usb.SerialMSC=Mass storage
DISCOVERY_L053C8.menu.usb.SerialMSC=Mass storage [testing, see documentation]
DISCOVERY_L053C8.menu.usb.SerialMSC.build.extra_flags_usb=-DMENU_USB_MASS_STORAGE
DISCOVERY_L053C8.menu.usb.Disabled=Disabled, no USB
@ -355,7 +355,7 @@ DISCOVERY_F407VG.upload.tool=stlink_upload
DISCOVERY_F407VG.menu.usb.SerialUSB=Serial [Virtual COM port]
DISCOVERY_F407VG.menu.usb.SerialUSB.build.extra_flags_usb=-DMENU_USB_SERIAL
DISCOVERY_F407VG.menu.usb.SerialMSC=Mass storage
DISCOVERY_F407VG.menu.usb.SerialMSC=Mass storage [testing, see documentation]
DISCOVERY_F407VG.menu.usb.SerialMSC.build.extra_flags_usb=-DMENU_USB_MASS_STORAGE
DISCOVERY_F407VG.menu.usb.Disabled=Disabled, no USB
@ -389,7 +389,7 @@ DISCOVERY_F429ZI.upload.tool=stlink_upload
DISCOVERY_F429ZI.menu.usb.SerialUSB=Serial [Virtual COM port]
DISCOVERY_F429ZI.menu.usb.SerialUSB.build.extra_flags_usb=-DMENU_USB_SERIAL
DISCOVERY_F429ZI.menu.usb.SerialMSC=Mass storage
DISCOVERY_F429ZI.menu.usb.SerialMSC=Mass storage [testing, see documentation]
DISCOVERY_F429ZI.menu.usb.SerialMSC.build.extra_flags_usb=-DMENU_USB_MASS_STORAGE
DISCOVERY_F429ZI.menu.usb.Disabled=Disabled, no USB
@ -429,7 +429,7 @@ DISCOVERY_F746NG.menu.upload_method.STLinkMethod.upload.tool=stlink_upload
DISCOVERY_F746NG.menu.usb.SerialUSB=Serial [Virtual COM port, PA11/PA12 pins]
DISCOVERY_F746NG.menu.usb.SerialUSB.build.extra_flags_usb=-DMENU_USB_SERIAL
DISCOVERY_F746NG.menu.usb.SerialMSC=Mass storage
DISCOVERY_F746NG.menu.usb.SerialMSC=Mass storage [testing, see documentation]
DISCOVERY_F746NG.menu.usb.SerialMSC.build.extra_flags_usb=-DMENU_USB_MASS_STORAGE
DISCOVERY_F746NG.menu.usb.Disabled=Disabled, no USB

View File

@ -102,13 +102,19 @@
<li >
<a href="../uart/">Serial UART</a>
<a href="../uart/">UART Serial</a>
</li>
<li >
<a href="../usb_cdc/">Serial USB</a>
<a href="../usb_cdc/">USB Serial</a>
</li>
<li >
<a href="../usb_msc/">USB Mass Storage</a>
</li>

View File

@ -102,13 +102,19 @@
<li >
<a href="../uart/">Serial UART</a>
<a href="../uart/">UART Serial</a>
</li>
<li >
<a href="../usb_cdc/">Serial USB</a>
<a href="../usb_cdc/">USB Serial</a>
</li>
<li >
<a href="../usb_msc/">USB Mass Storage</a>
</li>

View File

@ -102,13 +102,19 @@
<li >
<a href="../uart/">Serial UART</a>
<a href="../uart/">UART Serial</a>
</li>
<li >
<a href="../usb_cdc/">Serial USB</a>
<a href="../usb_cdc/">USB Serial</a>
</li>
<li >
<a href="../usb_msc/">USB Mass Storage</a>
</li>

View File

@ -102,13 +102,19 @@
<li >
<a href="../uart/">Serial UART</a>
<a href="../uart/">UART Serial</a>
</li>
<li >
<a href="../usb_cdc/">Serial USB</a>
<a href="../usb_cdc/">USB Serial</a>
</li>
<li >
<a href="../usb_msc/">USB Mass Storage</a>
</li>

View File

@ -102,13 +102,19 @@
<li >
<a href="../uart/">Serial UART</a>
<a href="../uart/">UART Serial</a>
</li>
<li >
<a href="../usb_cdc/">Serial USB</a>
<a href="../usb_cdc/">USB Serial</a>
</li>
<li >
<a href="../usb_msc/">USB Mass Storage</a>
</li>

View File

@ -102,13 +102,19 @@
<li >
<a href="../uart/">Serial UART</a>
<a href="../uart/">UART Serial</a>
</li>
<li >
<a href="../usb_cdc/">Serial USB</a>
<a href="../usb_cdc/">USB Serial</a>
</li>
<li >
<a href="../usb_msc/">USB Mass Storage</a>
</li>

View File

@ -102,13 +102,19 @@
<li >
<a href="uart/">Serial UART</a>
<a href="uart/">UART Serial</a>
</li>
<li >
<a href="usb_cdc/">Serial USB</a>
<a href="usb_cdc/">USB Serial</a>
</li>
<li >
<a href="usb_msc/">USB Mass Storage</a>
</li>

View File

@ -102,13 +102,19 @@
<li >
<a href="../uart/">Serial UART</a>
<a href="../uart/">UART Serial</a>
</li>
<li >
<a href="../usb_cdc/">Serial USB</a>
<a href="../usb_cdc/">USB Serial</a>
</li>
<li >
<a href="../usb_msc/">USB Mass Storage</a>
</li>

View File

@ -102,13 +102,19 @@
<li >
<a href="../uart/">Serial UART</a>
<a href="../uart/">UART Serial</a>
</li>
<li >
<a href="../usb_cdc/">Serial USB</a>
<a href="../usb_cdc/">USB Serial</a>
</li>
<li >
<a href="../usb_msc/">USB Mass Storage</a>
</li>

View File

@ -463,7 +463,7 @@
{
"location": "/uart/",
"text": "Serial UART\n\n\nThere are two implementations of Serial communication: UART and USB. \n\n\nThis page describes the UART based.\n\n\nPlease check the \nMenu option\n to see which one is selected.\n\n\nSerialUART1\nis bound to UART1, \nSerialUART2\n to UART2 etc...\n\n\nPlease refer to the \nofficial documentation\n for\nthe description of Serial functions.\n\n\nSerialUARTx.stm32SetRX(uint8_t pin)\n\n\nSet the RX signal to the specified pin. Please check the chip documentation for which pin can be used for RX.\nThis must be called before begin()!\n\n\nSerialUARTx.stm32SetTx(uint8_t pin)\n\n\nSet the TX signal to the specified pin. Please check the chip documentation for which pin can be used for TX.\nThis must be called before begin()!\n\n\n\n\nExample: The following code will echo the received bytes on UART2\n\n\n\n\nvoid setup() {\n SerialUART2.stm32SetRX(Pcd);\n SerialUART2.stm32SetTX(Pab);\n SerualUART2.begin(115200);\n}\nvoid loop() {\n int data = SerialUART2.read();\n if (data != -1) {\n SerialUART2.write(data);\n }\n}",
"title": "Serial UART"
"title": "UART Serial"
},
{
"location": "/uart/#serial-uart",
@ -482,13 +482,28 @@
},
{
"location": "/usb_cdc/",
"text": "Serial UART\n\n\nThere are two implementations of Serial communication: UART and USB. \n\n\nThis page describes the USB based.\n\n\nPlease check the \nMenu option\n to see which one is selected as \nSerial\n.\n\n\nIf the \nUSB menu\n is set to include Serial, SerialUSB is set as a virtual COM port, and can be used just like a regular UART based.\n\n\nTODO explain windows 7 driver\n\n\nPlease refer to the \nofficial documentation\n for\nthe description of Serial functions.",
"title": "Serial USB"
"text": "USB: Serial\n\n\nThere are two implementations of Serial communication: UART and USB. \n\n\nThis page describes the USB based.\n\n\nPlease check the \nMenu option\n to see which one is selected as \nSerial\n.\n\n\nIf the \nUSB menu\n is set to include Serial, SerialUSB is set as a virtual COM port, and can be used just like a regular UART based.\n\n\nTODO explain windows 7 driver\n\n\nPlease refer to the \nofficial documentation\n for\nthe description of Serial functions.",
"title": "USB Serial"
},
{
"location": "/usb_cdc/#serial-uart",
"location": "/usb_cdc/#usb-serial",
"text": "There are two implementations of Serial communication: UART and USB. This page describes the USB based. Please check the Menu option to see which one is selected as Serial . If the USB menu is set to include Serial, SerialUSB is set as a virtual COM port, and can be used just like a regular UART based. TODO explain windows 7 driver Please refer to the official documentation for\nthe description of Serial functions.",
"title": "Serial UART"
"title": "USB: Serial"
},
{
"location": "/usb_msc/",
"text": "USB: Mass Storage\n\n\nThis library is in beta, and the API / implementation is for testing only!\n\n\nUntil there is an official API, you can test mass storage with the following code:\n\n\n#include \nmsc/usbd_msc.h\n\n\nconst uint8_t MSC_Inquirydata[] = {\n /* LUN 0 */\n 0x00,\n 0x80,\n 0x02,\n 0x02,\n (STANDARD_INQUIRY_DATA_LEN - 5),\n 0x00,\n 0x00,\n 0x00,\n 'S', 'T', 'M', ' ', ' ', ' ', ' ', ' ', /* Manufacturer : 8 bytes */\n 'P', 'r', 'o', 'd', 'u', 'c', 't', ' ', /* Product : 16 Bytes */\n ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',\n '0', '.', '0' ,'1', /* Version : 4 Bytes */\n};\n\nconst uint16_t blockSize = 512;\nconst uint32_t blockCount = 100;\n\nuint8_t ramdisk[blockSize * blockCount] = {0};\n\nnamespace Testing {\n\n// See UM1734, 6.2.4\n// See usbd_msc.h\nUSBD_StorageTypeDef USBD_DISK_fops = {\n //Init\n [](uint8_t lun) -\n int8_t {\n return USBD_OK;\n },\n\n //GetCapacity\n [](uint8_t lun, uint32_t *block_num, uint16_t *block_size) -\n int8_t {\n *block_num = blockCount;\n *block_size = blockSize;\n return USBD_OK;\n },\n\n //IsReady\n [](uint8_t lun) -\n int8_t {\n return USBD_OK;\n },\n\n //IsWriteProtected\n [](uint8_t lun) -\n int8_t {\n return USBD_OK;\n },\n\n //Read\n [](uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) -\n int8_t {\n memcpy(buf, ramdisk + blk_addr * blockSize, blk_len * blockSize);\n return USBD_OK;\n },\n\n //Write\n [](uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) -\n int8_t {\n digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));\n memcpy(ramdisk + blk_addr * blockSize, buf, blk_len * blockSize);\n return USBD_OK;\n },\n\n //GetMaxLun\n []() -\n int8_t {return 0;},\n\n (int8_t *)MSC_Inquirydata\n\n};\n\n}\n\nvoid setup() {\n pinMode(LED_BUILTIN, OUTPUT);\n}\n\nvoid loop() {\n\n}",
"title": "USB Mass Storage"
},
{
"location": "/usb_msc/#usb-mass-storage",
"text": "",
"title": "USB: Mass Storage"
},
{
"location": "/usb_msc/#this-library-is-in-beta-and-the-api-implementation-is-for-testing-only",
"text": "Until there is an official API, you can test mass storage with the following code: #include msc/usbd_msc.h \n\nconst uint8_t MSC_Inquirydata[] = {\n /* LUN 0 */\n 0x00,\n 0x80,\n 0x02,\n 0x02,\n (STANDARD_INQUIRY_DATA_LEN - 5),\n 0x00,\n 0x00,\n 0x00,\n 'S', 'T', 'M', ' ', ' ', ' ', ' ', ' ', /* Manufacturer : 8 bytes */\n 'P', 'r', 'o', 'd', 'u', 'c', 't', ' ', /* Product : 16 Bytes */\n ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',\n '0', '.', '0' ,'1', /* Version : 4 Bytes */\n};\n\nconst uint16_t blockSize = 512;\nconst uint32_t blockCount = 100;\n\nuint8_t ramdisk[blockSize * blockCount] = {0};\n\nnamespace Testing {\n\n// See UM1734, 6.2.4\n// See usbd_msc.h\nUSBD_StorageTypeDef USBD_DISK_fops = {\n //Init\n [](uint8_t lun) - int8_t {\n return USBD_OK;\n },\n\n //GetCapacity\n [](uint8_t lun, uint32_t *block_num, uint16_t *block_size) - int8_t {\n *block_num = blockCount;\n *block_size = blockSize;\n return USBD_OK;\n },\n\n //IsReady\n [](uint8_t lun) - int8_t {\n return USBD_OK;\n },\n\n //IsWriteProtected\n [](uint8_t lun) - int8_t {\n return USBD_OK;\n },\n\n //Read\n [](uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) - int8_t {\n memcpy(buf, ramdisk + blk_addr * blockSize, blk_len * blockSize);\n return USBD_OK;\n },\n\n //Write\n [](uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) - int8_t {\n digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));\n memcpy(ramdisk + blk_addr * blockSize, buf, blk_len * blockSize);\n return USBD_OK;\n },\n\n //GetMaxLun\n []() - int8_t {return 0;},\n\n (int8_t *)MSC_Inquirydata\n\n};\n\n}\n\nvoid setup() {\n pinMode(LED_BUILTIN, OUTPUT);\n}\n\nvoid loop() {\n\n}",
"title": "This library is in beta, and the API / implementation is for testing only!"
},
{
"location": "/stm32_hal/",

View File

@ -102,13 +102,19 @@
<li >
<a href="../uart/">Serial UART</a>
<a href="../uart/">UART Serial</a>
</li>
<li >
<a href="../usb_cdc/">Serial USB</a>
<a href="../usb_cdc/">USB Serial</a>
</li>
<li >
<a href="../usb_msc/">USB Mass Storage</a>
</li>

View File

@ -4,7 +4,7 @@
<url>
<loc>/</loc>
<lastmod>2017-05-06</lastmod>
<lastmod>2017-05-12</lastmod>
<changefreq>daily</changefreq>
</url>
@ -12,7 +12,7 @@
<url>
<loc>/upload/</loc>
<lastmod>2017-05-06</lastmod>
<lastmod>2017-05-12</lastmod>
<changefreq>daily</changefreq>
</url>
@ -21,55 +21,61 @@
<url>
<loc>/menu_options/</loc>
<lastmod>2017-05-06</lastmod>
<lastmod>2017-05-12</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>/arduino_api/</loc>
<lastmod>2017-05-06</lastmod>
<lastmod>2017-05-12</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>/spi/</loc>
<lastmod>2017-05-06</lastmod>
<lastmod>2017-05-12</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>/i2c/</loc>
<lastmod>2017-05-06</lastmod>
<lastmod>2017-05-12</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>/i2s/</loc>
<lastmod>2017-05-06</lastmod>
<lastmod>2017-05-12</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>/sdio/</loc>
<lastmod>2017-05-06</lastmod>
<lastmod>2017-05-12</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>/uart/</loc>
<lastmod>2017-05-06</lastmod>
<lastmod>2017-05-12</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>/usb_cdc/</loc>
<lastmod>2017-05-06</lastmod>
<lastmod>2017-05-12</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>/usb_msc/</loc>
<lastmod>2017-05-12</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>/stm32_hal/</loc>
<lastmod>2017-05-06</lastmod>
<lastmod>2017-05-12</lastmod>
<changefreq>daily</changefreq>
</url>
@ -78,7 +84,7 @@
<url>
<loc>/libraries/</loc>
<lastmod>2017-05-06</lastmod>
<lastmod>2017-05-12</lastmod>
<changefreq>daily</changefreq>
</url>
@ -87,19 +93,19 @@
<url>
<loc>/boards/</loc>
<lastmod>2017-05-06</lastmod>
<lastmod>2017-05-12</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>/add_board/</loc>
<lastmod>2017-05-06</lastmod>
<lastmod>2017-05-12</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>/test/</loc>
<lastmod>2017-05-06</lastmod>
<lastmod>2017-05-12</lastmod>
<changefreq>daily</changefreq>
</url>
@ -108,7 +114,7 @@
<url>
<loc>/about/</loc>
<lastmod>2017-05-06</lastmod>
<lastmod>2017-05-12</lastmod>
<changefreq>daily</changefreq>
</url>

View File

@ -102,13 +102,19 @@
<li >
<a href="../uart/">Serial UART</a>
<a href="../uart/">UART Serial</a>
</li>
<li >
<a href="../usb_cdc/">Serial USB</a>
<a href="../usb_cdc/">USB Serial</a>
</li>
<li >
<a href="../usb_msc/">USB Mass Storage</a>
</li>

View File

@ -102,13 +102,19 @@
<li >
<a href="../uart/">Serial UART</a>
<a href="../uart/">UART Serial</a>
</li>
<li >
<a href="../usb_cdc/">Serial USB</a>
<a href="../usb_cdc/">USB Serial</a>
</li>
<li >
<a href="../usb_msc/">USB Mass Storage</a>
</li>
@ -171,7 +177,7 @@
</a>
</li>
<li >
<a rel="next" href="../usb_cdc/">
<a rel="next" href="../usb_msc/">
<i class="fa fa-arrow-left"></i> Previous
</a>
</li>

View File

@ -102,13 +102,19 @@
<li >
<a href="../uart/">Serial UART</a>
<a href="../uart/">UART Serial</a>
</li>
<li >
<a href="../usb_cdc/">Serial USB</a>
<a href="../usb_cdc/">USB Serial</a>
</li>
<li >
<a href="../usb_msc/">USB Mass Storage</a>
</li>

View File

@ -8,7 +8,7 @@
<link rel="shortcut icon" href="../img/favicon.ico">
<title>Serial UART - STM32GENERIC</title>
<title>UART Serial - STM32GENERIC</title>
<link href="../css/bootstrap-custom.min.css" rel="stylesheet">
<link href="../css/font-awesome-4.0.3.css" rel="stylesheet">
<link rel="stylesheet" href="../css/highlight.css">
@ -102,13 +102,19 @@
<li class="active">
<a href="./">Serial UART</a>
<a href="./">UART Serial</a>
</li>
<li >
<a href="../usb_cdc/">Serial USB</a>
<a href="../usb_cdc/">USB Serial</a>
</li>
<li >
<a href="../usb_msc/">USB Mass Storage</a>
</li>

View File

@ -102,13 +102,19 @@
<li >
<a href="../uart/">Serial UART</a>
<a href="../uart/">UART Serial</a>
</li>
<li >
<a href="../usb_cdc/">Serial USB</a>
<a href="../usb_cdc/">USB Serial</a>
</li>
<li >
<a href="../usb_msc/">USB Mass Storage</a>
</li>

View File

@ -8,7 +8,7 @@
<link rel="shortcut icon" href="../img/favicon.ico">
<title>Serial USB - STM32GENERIC</title>
<title>USB Serial - STM32GENERIC</title>
<link href="../css/bootstrap-custom.min.css" rel="stylesheet">
<link href="../css/font-awesome-4.0.3.css" rel="stylesheet">
<link rel="stylesheet" href="../css/highlight.css">
@ -102,13 +102,19 @@
<li >
<a href="../uart/">Serial UART</a>
<a href="../uart/">UART Serial</a>
</li>
<li class="active">
<a href="./">Serial USB</a>
<a href="./">USB Serial</a>
</li>
<li >
<a href="../usb_msc/">USB Mass Storage</a>
</li>
@ -176,7 +182,7 @@
</a>
</li>
<li >
<a rel="prev" href="../stm32_hal/">
<a rel="prev" href="../usb_msc/">
Next <i class="fa fa-arrow-right"></i>
</a>
</li>
@ -191,7 +197,7 @@
<ul class="nav bs-sidenav">
<li class="main active"><a href="#serial-uart">Serial UART</a></li>
<li class="main active"><a href="#usb-serial">USB: Serial</a></li>
@ -199,7 +205,7 @@
</div></div>
<div class="col-md-9" role="main">
<h2 id="serial-uart">Serial UART</h2>
<h2 id="usb-serial">USB: Serial</h2>
<p>There are two implementations of Serial communication: UART and USB. </p>
<p>This page describes the USB based.</p>
<p>Please check the <a href="../menu_options#automatic-serial">Menu option</a> to see which one is selected as <code>Serial</code>.</p>

330
docs/usb_msc/index.html Normal file
View File

@ -0,0 +1,330 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="../img/favicon.ico">
<title>USB Mass Storage - STM32GENERIC</title>
<link href="../css/bootstrap-custom.min.css" rel="stylesheet">
<link href="../css/font-awesome-4.0.3.css" rel="stylesheet">
<link rel="stylesheet" href="../css/highlight.css">
<link href="../css/base.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
<script src="../js/jquery-1.10.2.min.js"></script>
<script src="../js/bootstrap-3.0.3.min.js"></script>
<script src="../js/highlight.pack.js"></script>
</head>
<body>
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<!-- Collapsed navigation -->
<div class="navbar-header">
<!-- Expander button -->
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="..">STM32GENERIC</a>
</div>
<!-- Expanded navigation -->
<div class="navbar-collapse collapse">
<!-- Main navigation -->
<ul class="nav navbar-nav">
<li >
<a href="..">Installation</a>
</li>
<li >
<a href="../upload/">Uploading</a>
</li>
<li class="dropdown active">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Documentation <b class="caret"></b></a>
<ul class="dropdown-menu">
<li >
<a href="../menu_options/">Menu options</a>
</li>
<li >
<a href="../arduino_api/">Arduino API</a>
</li>
<li >
<a href="../spi/">SPI</a>
</li>
<li >
<a href="../i2c/">I2C</a>
</li>
<li >
<a href="../i2s/">I2S</a>
</li>
<li >
<a href="../sdio/">SDIO</a>
</li>
<li >
<a href="../uart/">UART Serial</a>
</li>
<li >
<a href="../usb_cdc/">USB Serial</a>
</li>
<li class="active">
<a href="./">USB Mass Storage</a>
</li>
<li >
<a href="../stm32_hal/">STM32 HAL</a>
</li>
</ul>
</li>
<li >
<a href="../libraries/">Libraries</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">STM32 Boards <b class="caret"></b></a>
<ul class="dropdown-menu">
<li >
<a href="../boards/">Boards list</a>
</li>
<li >
<a href="../add_board/">Adding a board</a>
</li>
<li >
<a href="../test/">Testing a board</a>
</li>
</ul>
</li>
<li >
<a href="../about/">About</a>
</li>
</ul>
<!-- Search, Navigation and Repo links -->
<ul class="nav navbar-nav navbar-right">
<li>
<a href="#" data-toggle="modal" data-target="#mkdocs_search_modal">
<i class="fa fa-search"></i> Search
</a>
</li>
<li >
<a rel="next" href="../usb_cdc/">
<i class="fa fa-arrow-left"></i> Previous
</a>
</li>
<li >
<a rel="prev" href="../stm32_hal/">
Next <i class="fa fa-arrow-right"></i>
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="container">
<div class="col-md-3"><div class="bs-sidebar hidden-print affix well" role="complementary">
<ul class="nav bs-sidenav">
<li class="main active"><a href="#usb-mass-storage">USB: Mass Storage</a></li>
<li class="main "><a href="#this-library-is-in-beta-and-the-api-implementation-is-for-testing-only">This library is in beta, and the API / implementation is for testing only!</a></li>
</ul>
</div></div>
<div class="col-md-9" role="main">
<h2 id="usb-mass-storage">USB: Mass Storage</h2>
<h2 id="this-library-is-in-beta-and-the-api-implementation-is-for-testing-only"><strong>This library is in beta, and the API / implementation is for testing only!</strong></h2>
<p>Until there is an official API, you can test mass storage with the following code:</p>
<pre><code class="c++">#include &quot;msc/usbd_msc.h&quot;
const uint8_t MSC_Inquirydata[] = {
/* LUN 0 */
0x00,
0x80,
0x02,
0x02,
(STANDARD_INQUIRY_DATA_LEN - 5),
0x00,
0x00,
0x00,
'S', 'T', 'M', ' ', ' ', ' ', ' ', ' ', /* Manufacturer : 8 bytes */
'P', 'r', 'o', 'd', 'u', 'c', 't', ' ', /* Product : 16 Bytes */
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
'0', '.', '0' ,'1', /* Version : 4 Bytes */
};
const uint16_t blockSize = 512;
const uint32_t blockCount = 100;
uint8_t ramdisk[blockSize * blockCount] = {0};
namespace Testing {
// See UM1734, 6.2.4
// See usbd_msc.h
USBD_StorageTypeDef USBD_DISK_fops = {
//Init
[](uint8_t lun) -&gt; int8_t {
return USBD_OK;
},
//GetCapacity
[](uint8_t lun, uint32_t *block_num, uint16_t *block_size) -&gt; int8_t {
*block_num = blockCount;
*block_size = blockSize;
return USBD_OK;
},
//IsReady
[](uint8_t lun) -&gt; int8_t {
return USBD_OK;
},
//IsWriteProtected
[](uint8_t lun) -&gt; int8_t {
return USBD_OK;
},
//Read
[](uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) -&gt; int8_t {
memcpy(buf, ramdisk + blk_addr * blockSize, blk_len * blockSize);
return USBD_OK;
},
//Write
[](uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) -&gt; int8_t {
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
memcpy(ramdisk + blk_addr * blockSize, buf, blk_len * blockSize);
return USBD_OK;
},
//GetMaxLun
[]() -&gt; int8_t {return 0;},
(int8_t *)MSC_Inquirydata
};
}
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
}
</code></pre></div>
</div>
<footer class="col-md-12">
<hr>
<center>Documentation built with <a href="http://www.mkdocs.org/">MkDocs</a>.</center>
</footer>
<script>var base_url = '..';</script>
<script data-main="../mkdocs/js/search.js" src="../mkdocs/js/require.js"></script>
<script src="../js/base.js"></script>
<div class="modal" id="mkdocs_search_modal" tabindex="-1" role="dialog" aria-labelledby="Search Modal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="exampleModalLabel">Search</h4>
</div>
<div class="modal-body">
<p>
From here you can search these documents. Enter
your search terms below.
</p>
<form role="form">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search..." id="mkdocs-search-query">
</div>
</form>
<div id="mkdocs-search-results"></div>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
</body>
</html>

View File

@ -10,8 +10,9 @@ pages:
- I2C: i2c.md
- I2S: i2s.md
- SDIO: sdio.md
- Serial UART: uart.md
- Serial USB: usb_cdc.md
- UART Serial: uart.md
- USB Serial: usb_cdc.md
- USB Mass Storage: usb_msc.md
- STM32 HAL: stm32_hal.md
- Libraries: libraries.md
- STM32 Boards:

View File

@ -1,4 +1,4 @@
## Serial UART
## USB: Serial
There are two implementations of Serial communication: UART and USB.

View File

@ -0,0 +1,87 @@
## USB: Mass Storage
## **This library is in beta, and the API / implementation is for testing only!**
Until there is an official API, you can test mass storage with the following code:
```c++
#include "msc/usbd_msc.h"
const uint8_t MSC_Inquirydata[] = {
/* LUN 0 */
0x00,
0x80,
0x02,
0x02,
(STANDARD_INQUIRY_DATA_LEN - 5),
0x00,
0x00,
0x00,
'S', 'T', 'M', ' ', ' ', ' ', ' ', ' ', /* Manufacturer : 8 bytes */
'P', 'r', 'o', 'd', 'u', 'c', 't', ' ', /* Product : 16 Bytes */
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
'0', '.', '0' ,'1', /* Version : 4 Bytes */
};
const uint16_t blockSize = 512;
const uint32_t blockCount = 100;
uint8_t ramdisk[blockSize * blockCount] = {0};
namespace Testing {
// See UM1734, 6.2.4
// See usbd_msc.h
USBD_StorageTypeDef USBD_DISK_fops = {
//Init
[](uint8_t lun) -> int8_t {
return USBD_OK;
},
//GetCapacity
[](uint8_t lun, uint32_t *block_num, uint16_t *block_size) -> int8_t {
*block_num = blockCount;
*block_size = blockSize;
return USBD_OK;
},
//IsReady
[](uint8_t lun) -> int8_t {
return USBD_OK;
},
//IsWriteProtected
[](uint8_t lun) -> int8_t {
return USBD_OK;
},
//Read
[](uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) -> int8_t {
memcpy(buf, ramdisk + blk_addr * blockSize, blk_len * blockSize);
return USBD_OK;
},
//Write
[](uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) -> int8_t {
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
memcpy(ramdisk + blk_addr * blockSize, buf, blk_len * blockSize);
return USBD_OK;
},
//GetMaxLun
[]() -> int8_t {return 0;},
(int8_t *)MSC_Inquirydata
};
}
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
}
```