#include "mx1_usb.h"
#include "mx1_uart.h"
#include <string.h>
//#define USB_DISK_START 0x08800000 // last 16M of SDRAM
//#define DISK_LAST_SECTOR 0x00006FFF // last sector of a 14M disk
static U32 USB_DISK_START;
static U32 DISK_LAST_SECTOR;
//extern void SerialOutputString(unsigned char *s);
//extern void printerror(int errnum, char *s);
//extern int strncmp(const char *s1, const char *s2, unsigned int maxlen);
#define printf( str ) MX1_UART_PutString( MX1_UART1, str, strlen(str) )
U8 bootSector[512] = {
0xEB,0x3C,0x90,0x4D,0x53,0x44,0x4F,0x53,0x35,0x2E,0x30,0x00,0x02,0x08,0x01,0x00,
0x02,0x00,0x02,0x00,0x70,0xF8,0x0B,0x00,0x3F,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x29,0x8F,0x08,0x77,0xFE,0x4E,0x4F,0x20,0x4E,0x41,
0x4D,0x45,0x20,0x20,0x20,0x20,0x46,0x41,0x54,0x31,0x32,0x20,0x20,0x20,0x33,0xC9,
0x8E,0xD1,0xBC,0xF0,0x7B,0x8E,0xD9,0xB8,0x00,0x20,0x8E,0xC0,0xFC,0xBD,0x00,0x7C,
0x38,0x4E,0x24,0x7D,0x24,0x8B,0xC1,0x99,0xE8,0x3C,0x01,0x72,0x1C,0x83,0xEB,0x3A,
0x66,0xA1,0x1C,0x7C,0x26,0x66,0x3B,0x07,0x26,0x8A,0x57,0xFC,0x75,0x06,0x80,0xCA,
0x02,0x88,0x56,0x02,0x80,0xC3,0x10,0x73,0xEB,0x33,0xC9,0x8A,0x46,0x10,0x98,0xF7,
0x66,0x16,0x03,0x46,0x1C,0x13,0x56,0x1E,0x03,0x46,0x0E,0x13,0xD1,0x8B,0x76,0x11,
0x60,0x89,0x46,0xFC,0x89,0x56,0xFE,0xB8,0x20,0x00,0xF7,0xE6,0x8B,0x5E,0x0B,0x03,
0xC3,0x48,0xF7,0xF3,0x01,0x46,0xFC,0x11,0x4E,0xFE,0x61,0xBF,0x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0x72,0x0B,0x40,0x75,0x01,0x42,0x03,
0x5E,0x0B,0x49,0x75,0x06,0xF8,0xC3,0x41,0xBB,0x00,0x00,0x60,0x66,0x6A,0x00,0xEB,
0xB0,0x4E,0x54,0x4C,0x44,0x52,0x20,0x20,0x20,0x20,0x20,0x20,0x0D,0x0A,0x4E,0x54,
0x4C,0x44,0x52,0x20,0x69,0x73,0x20,0x6D,0x69,0x73,0x73,0x69,0x6E,0x67,0xFF,0x0D,
0x0A,0x44,0x69,0x73,0x6B,0x20,0x65,0x72,0x72,0x6F,0x72,0xFF,0x0D,0x0A,0x50,0x72,
0x65,0x73,0x73,0x20,0x61,0x6E,0x79,0x20,0x6B,0x65,0x79,0x20,0x74,0x6F,0x20,0x72,
0x65,0x73,0x74,0x61,0x72,0x74,0x0D,0x0A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xAC,0xBF,0xCC,0x55,0xAA
};
U32 gEPconfigData[55] = {
// EP0
0x00000000,
0x00000000,
0x00000008,
0x00000000,
0x00000000,
// EP1
0x00000014, // EP#:1, CF#: 1, IF#:0
0x00000014, // BULK, IN
0x00000020, // MAX PS: 32
0x000000C0, // 0xC0, except for EP0
0x00000001, // FIFO#: 1
// EP2
0x00000024, // EP#:2, CF#: 1, IF#:0
0x00000010, // BULK, OUT
0x00000020, // MAX PS: 32
0x000000C0, // 0xC0, except for EP0
0x00000002, // FIFO#: 2
// EP3
0x00000034, // EP#:3, CF#: 1, IF#:0
0x0000001C, // INTR, IN
0x00000010, // MAX PS: 16
0x000000C0, // 0xC0, except for EP0
0x00000003, // FIFO#: 3
// EP4
0x00000044, // EP#:4, CF#: 1, IF#:0
0x00000018, // INTR, OIUT
0x00000010, // MAX PS: 16
0x000000C0, // 0xC0, except for EP0
0x00000004, // FIFO#: 4
// EP5
0x00000054, // EP#:5, CF#: 1, IF#:0
0x0000001C, // INTR, IN
0x00000010, // MAX PS: 16
0x000000C0, // 0xC0, except for EP0
0x00000005, // FIFO#: 5
// EP6
0x00000018, // EP#:1, CF#: 2, IF#:0
0x00000014, // BULK, IN
0x00000020, // MAX PS: 32
0x000000C0, // 0xC0, except for EP0
0x00000001, // FIFO#: 1
// EP7
0x00000028, // EP#:2, CF#: 2, IF#:0
0x00000010, // BULK, OUT
0x00000020, // MAX PS: 32
0x000000C0, // 0xC0, except for EP0
0x00000002, // FIFO#: 2
// EP8
0x00000038, // EP#:3, CF#: 2, IF#:0
0x0000001C, // INTR, IN
0x00000010, // MAX PS: 16
0x000000C0, // 0xC0, except for EP0
0x00000003, // FIFO#: 3
// EP9
0x00000048, // EP#:4, CF#: 2, IF#:0
0x00000018, // INTR, OIUT
0x00000010, // MAX PS: 16
0x000000C0, // 0xC0, except for EP0
0x00000004, // FIFO#: 4
// EP10
0x00000058, // EP#:5, CF#: 2, IF#:0
0x0000001C, // INTR, IN
0x00000010, // MAX PS: 16
0x000000C0, // 0xC0, except for EP0
0x00000005, // FIFO#: 5
};
U8 _gUsbDevReq[8]; /* device request from host */
const U32 _gUsbDevDscptr[5] = {
// 0x12011001, 0x00000008, 0xC40700A2, 0x00130000, 0x00000001 }; // assume big endian
0x12011001, 0x00000008, 0xC4070000, 0x00130000, 0x00000001 }; // assume big endian
const U32 _gUsbConfDscptr[8] = {
// 0x09022000, 0x01010080, 0xFA090400, 0x00020806,
0x09022000, 0x010100C0, 0x01090400, 0x00020806,
// 0x50000705, 0x81022000, 0x00070502, 0x02200000};
0x50040705, 0x81022000, 0x00070502, 0x02200000};
P_U8 _gpUsbBufPtr; // pointer to buffer data
U32 _gUsbNumSector; // number of sector to read/write
U32 _gUsbCurSector; // current sector being read/write
U32 _gUsbPacketCount; // USB packet count
U8 _gCBW[31]; // command block wrapper
U8 quit;
U32 gLastSector;
void formatDrive()
{
U32 i, j, k;
U8 *p;
p = (U8 *)USB_DISK_START;
// write boot sector
for (i=0; i<512; i++)
{
*(p++) = bootSector[i];
}
// write FAT (2 copies)
for (i=0; i<2; i++)
{
*(p++) = 0xF8;
*(p++) = 0xFF;
*(p++) = 0xFF;
for (j=3; j<512; j++)
*(p++) = 0;
for (j=1; j<11; j++)
for (k=0; k<512; k++)
*(p++) = 0;
}
// write directory entries
for (i=0; i<32; i++)
for (j=0; j<512; j++)
*(p++) = 0;
}
/*
void delay(U32 count)
{
U32 i;
i = 0;
while (i<count)
{
i++;
}
}
*/
void initUSB()
{
U8 i;
// SerialOutputString("Init USB module ...\n\r");
// set clock for 48 MHz USB clock
//_reg_CCM_CSCR = 0x47008403;
// PLAM
_reg_CCM_CSCR &= ~USB_DIV_MASK;
_reg_CCM_CSCR |= 0x04000000; // set USB DIV to divide-by-2
// _reg_CCM_CSCR=0x47008403;
// end PLAM
// config port for USBD
_reg_PTB_GIUS &= 0x000FFFFF; // set PB31-28 to UART2 and PB27-20 to USBD
_reg_PTB_GPR &= 0x000FFFFF; // select primary peripheral
// init USB module
// reset and enable USB device module
_reg_USBD_ENABLE &= ~0x40000000; /* disable module */
// delay(10);
i = 0;
while (i<10)
{
i++;
}
_reg_USBD_ENABLE &= ~0x00000001; /* select 32-bit mode FIFO */
_reg_USBD_ENABLE &= ~0x10000000; /* Set big endian */
_reg_USBD_ENABLE |= 0x40000000; /* remark: resetting the module will enable module automatically */
while (!(_reg_USBD_ENABLE & 0x40000000)); // wait until it is enabled
// SerialOutputString("USBD reset and enable okay.\n\r");
// fill endpoint configuration buffer
for (i=0; i<55; i++)
{
_reg_USBD_EPBUF = gEPconfigData[i];
while (_reg_USBD_CFGBSY & 0x40000000); // wait until busy bit is cleared
}
// SerialOutputString("USBD config okay.\n\r");
// mask interrupts
_reg_USBD_INTR_STAT = 0x800000FF; // clear general interrupts
_reg_USBD_INTR_MASK = 0x800000FF; // mask all general interrupts
_reg_USBD_EP0_INTR_STAT = 0x000001FF; // clear EP interrupts
_reg_USBD_EP0_INTR_MASK = 0x000001FF; // mask all EP interrupts
_reg_USBD_EP1_
usb.rar_USB驱动_ucos usb_usb ucos
版权申诉
125 浏览量
2022-09-22
16:59:42
上传
评论
收藏 7KB RAR 举报
刘良运
- 粉丝: 68
- 资源: 1万+
最新资源
- VIVADO中UART IP核使用
- 【深度学习实际案例解析】深度学习实际案例解析
- 封装swagger组件,提供全新UI以及无状态登录接口调用解决方案
- 小龙坎支局2024年4月渠道积分核对数据.xlam
- onlyoffice搭建及与alist使用的view.html
- Quadcopter-UAV-attitude-estimation-linux常用命令大全demo
- Quadcopter-UAV-attitude-estimation-based-on-数据库课程设计
- pbdlib-python-master.zip
- 43904245495352013_base.apk
- 基于springboot+vue + redis的工作流审批系统
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈