Tabs to whitespaces in USBH testhal
This commit is contained in:
parent
e2f7c9277c
commit
a6898a525f
|
@ -116,24 +116,24 @@
|
|||
#define HAL_USBHUVC_STATUS_PACKETS_COUNT 10
|
||||
|
||||
/* AOA */
|
||||
#define HAL_USBH_USE_AOA TRUE
|
||||
#define HAL_USBH_USE_AOA TRUE
|
||||
|
||||
#define HAL_USBHAOA_MAX_INSTANCES 1
|
||||
#define HAL_USBHAOA_MAX_INSTANCES 1
|
||||
/* Uncomment this if you need a filter for AOA devices:
|
||||
* #define HAL_USBHAOA_FILTER_CALLBACK _try_aoa
|
||||
* #define HAL_USBHAOA_FILTER_CALLBACK _try_aoa
|
||||
*/
|
||||
#define HAL_USBHAOA_DEFAULT_MANUFACTURER "Diego MFG & Co."
|
||||
#define HAL_USBHAOA_DEFAULT_MODEL "Diego's device"
|
||||
#define HAL_USBHAOA_DEFAULT_DESCRIPTION "Description of this device..."
|
||||
#define HAL_USBHAOA_DEFAULT_VERSION "1.0"
|
||||
#define HAL_USBHAOA_DEFAULT_URI NULL
|
||||
#define HAL_USBHAOA_DEFAULT_SERIAL NULL
|
||||
#define HAL_USBHAOA_DEFAULT_AUDIO_MODE USBHAOA_AUDIO_MODE_DISABLED
|
||||
#define HAL_USBHAOA_DEFAULT_MANUFACTURER "Diego MFG & Co."
|
||||
#define HAL_USBHAOA_DEFAULT_MODEL "Diego's device"
|
||||
#define HAL_USBHAOA_DEFAULT_DESCRIPTION "Description of this device..."
|
||||
#define HAL_USBHAOA_DEFAULT_VERSION "1.0"
|
||||
#define HAL_USBHAOA_DEFAULT_URI NULL
|
||||
#define HAL_USBHAOA_DEFAULT_SERIAL NULL
|
||||
#define HAL_USBHAOA_DEFAULT_AUDIO_MODE USBHAOA_AUDIO_MODE_DISABLED
|
||||
|
||||
/* HID */
|
||||
#define HAL_USBH_USE_HID TRUE
|
||||
#define HAL_USBHHID_MAX_INSTANCES 2
|
||||
#define HAL_USBHHID_USE_INTERRUPT_OUT FALSE
|
||||
#define HAL_USBH_USE_HID TRUE
|
||||
#define HAL_USBHHID_MAX_INSTANCES 2
|
||||
#define HAL_USBHHID_USE_INTERRUPT_OUT FALSE
|
||||
|
||||
|
||||
/* HUB */
|
||||
|
@ -179,15 +179,15 @@
|
|||
#define USBHFTDI_DEBUG_ENABLE_WARNINGS TRUE
|
||||
#define USBHFTDI_DEBUG_ENABLE_ERRORS TRUE
|
||||
|
||||
#define USBHAOA_DEBUG_ENABLE_TRACE FALSE
|
||||
#define USBHAOA_DEBUG_ENABLE_INFO TRUE
|
||||
#define USBHAOA_DEBUG_ENABLE_WARNINGS TRUE
|
||||
#define USBHAOA_DEBUG_ENABLE_ERRORS TRUE
|
||||
#define USBHAOA_DEBUG_ENABLE_TRACE FALSE
|
||||
#define USBHAOA_DEBUG_ENABLE_INFO TRUE
|
||||
#define USBHAOA_DEBUG_ENABLE_WARNINGS TRUE
|
||||
#define USBHAOA_DEBUG_ENABLE_ERRORS TRUE
|
||||
|
||||
#define USBHHID_DEBUG_ENABLE_TRACE TRUE
|
||||
#define USBHHID_DEBUG_ENABLE_INFO TRUE
|
||||
#define USBHHID_DEBUG_ENABLE_WARNINGS TRUE
|
||||
#define USBHHID_DEBUG_ENABLE_ERRORS TRUE
|
||||
#define USBHHID_DEBUG_ENABLE_TRACE TRUE
|
||||
#define USBHHID_DEBUG_ENABLE_INFO TRUE
|
||||
#define USBHHID_DEBUG_ENABLE_WARNINGS TRUE
|
||||
#define USBHHID_DEBUG_ENABLE_ERRORS TRUE
|
||||
|
||||
/*===========================================================================*/
|
||||
/* FSMCNAND driver related settings. */
|
||||
|
|
|
@ -58,7 +58,7 @@ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
while (chnGetTimeout((BaseChannel *)chp, TIME_IMMEDIATE) != Q_TIMEOUT) {
|
||||
//flush
|
||||
//flush
|
||||
}
|
||||
|
||||
while (chnGetTimeout((BaseChannel *)chp, TIME_IMMEDIATE) == Q_TIMEOUT) {
|
||||
|
@ -68,131 +68,131 @@ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
static const ShellCommand commands[] = {
|
||||
{"write", cmd_write},
|
||||
{NULL, NULL}
|
||||
{"write", cmd_write},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
static const ShellConfig shell_cfg1 = {
|
||||
(BaseSequentialStream *)&FTDIPD[0],
|
||||
commands
|
||||
(BaseSequentialStream *)&FTDIPD[0],
|
||||
commands
|
||||
};
|
||||
|
||||
static void ThreadTestFTDI(void *p) {
|
||||
(void)p;
|
||||
USBHFTDIPortDriver *const ftdipp = &FTDIPD[0];
|
||||
(void)p;
|
||||
USBHFTDIPortDriver *const ftdipp = &FTDIPD[0];
|
||||
|
||||
shellInit();
|
||||
shellInit();
|
||||
|
||||
start:
|
||||
while (usbhftdipGetState(ftdipp) != USBHFTDIP_STATE_ACTIVE) {
|
||||
chThdSleepMilliseconds(100);
|
||||
}
|
||||
while (usbhftdipGetState(ftdipp) != USBHFTDIP_STATE_ACTIVE) {
|
||||
chThdSleepMilliseconds(100);
|
||||
}
|
||||
|
||||
usbDbgPuts("FTDI: Connected");
|
||||
usbDbgPuts("FTDI: Connected");
|
||||
|
||||
USBHFTDIPortConfig config = {
|
||||
115200,
|
||||
USBHFTDI_FRAMING_DATABITS_8 | USBHFTDI_FRAMING_PARITY_NONE | USBHFTDI_FRAMING_STOP_BITS_1,
|
||||
USBHFTDI_HANDSHAKE_NONE,
|
||||
0,
|
||||
0
|
||||
};
|
||||
USBHFTDIPortConfig config = {
|
||||
115200,
|
||||
USBHFTDI_FRAMING_DATABITS_8 | USBHFTDI_FRAMING_PARITY_NONE | USBHFTDI_FRAMING_STOP_BITS_1,
|
||||
USBHFTDI_HANDSHAKE_NONE,
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
usbhftdipStart(ftdipp, &config);
|
||||
usbhftdipStart(ftdipp, &config);
|
||||
|
||||
//loopback
|
||||
if (0) {
|
||||
for(;;) {
|
||||
msg_t m = streamGet(ftdipp);
|
||||
if (m < MSG_OK) {
|
||||
usbDbgPuts("FTDI: Disconnected");
|
||||
goto start;
|
||||
}
|
||||
streamPut(ftdipp, (uint8_t)m);
|
||||
if (m == 'q')
|
||||
break;
|
||||
}
|
||||
}
|
||||
//loopback
|
||||
if (0) {
|
||||
for(;;) {
|
||||
msg_t m = streamGet(ftdipp);
|
||||
if (m < MSG_OK) {
|
||||
usbDbgPuts("FTDI: Disconnected");
|
||||
goto start;
|
||||
}
|
||||
streamPut(ftdipp, (uint8_t)m);
|
||||
if (m == 'q')
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//shell test
|
||||
if (1) {
|
||||
thread_t *shelltp = NULL;
|
||||
for(;;) {
|
||||
if (usbhftdipGetState(ftdipp) != USBHFTDIP_STATE_READY)
|
||||
goto start;
|
||||
if (!shelltp) {
|
||||
shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
|
||||
} else if (chThdTerminatedX(shelltp)) {
|
||||
chThdRelease(shelltp);
|
||||
if (usbhftdipGetState(ftdipp) != USBHFTDIP_STATE_READY)
|
||||
goto start;
|
||||
break;
|
||||
}
|
||||
chThdSleepMilliseconds(100);
|
||||
}
|
||||
}
|
||||
//shell test
|
||||
if (1) {
|
||||
thread_t *shelltp = NULL;
|
||||
for(;;) {
|
||||
if (usbhftdipGetState(ftdipp) != USBHFTDIP_STATE_READY)
|
||||
goto start;
|
||||
if (!shelltp) {
|
||||
shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
|
||||
} else if (chThdTerminatedX(shelltp)) {
|
||||
chThdRelease(shelltp);
|
||||
if (usbhftdipGetState(ftdipp) != USBHFTDIP_STATE_READY)
|
||||
goto start;
|
||||
break;
|
||||
}
|
||||
chThdSleepMilliseconds(100);
|
||||
}
|
||||
}
|
||||
|
||||
//FTDI uart RX to debug TX bridge
|
||||
if (0) {
|
||||
for(;;) {
|
||||
msg_t m = streamGet(ftdipp);
|
||||
if (m < MSG_OK) {
|
||||
usbDbgPuts("FTDI: Disconnected");
|
||||
goto start;
|
||||
}
|
||||
sdPut(&USBH_DEBUG_SD, (uint8_t)m);
|
||||
if (m == 'q')
|
||||
break;
|
||||
}
|
||||
}
|
||||
//FTDI uart RX to debug TX bridge
|
||||
if (0) {
|
||||
for(;;) {
|
||||
msg_t m = streamGet(ftdipp);
|
||||
if (m < MSG_OK) {
|
||||
usbDbgPuts("FTDI: Disconnected");
|
||||
goto start;
|
||||
}
|
||||
sdPut(&USBH_DEBUG_SD, (uint8_t)m);
|
||||
if (m == 'q')
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//write speed test
|
||||
if (1) {
|
||||
usbhftdipStop(ftdipp);
|
||||
config.speed = 3000000;
|
||||
usbhftdipStart(ftdipp, &config);
|
||||
//write speed test
|
||||
if (1) {
|
||||
usbhftdipStop(ftdipp);
|
||||
config.speed = 3000000;
|
||||
usbhftdipStart(ftdipp, &config);
|
||||
|
||||
systime_t st, et;
|
||||
int i;
|
||||
for (i = 0; i < 5; i++) {
|
||||
uint32_t bytes = config.speed / 10;
|
||||
uint32_t times = bytes / 1024;
|
||||
st = chVTGetSystemTimeX();
|
||||
while (times--) {
|
||||
if (streamWrite(ftdipp, buf, 1024) < 1024) {
|
||||
usbDbgPuts("FTDI: Disconnected");
|
||||
goto start;
|
||||
}
|
||||
bytes -= 1024;
|
||||
}
|
||||
if (bytes) {
|
||||
if (streamWrite(ftdipp, buf, bytes) < bytes) {
|
||||
usbDbgPuts("FTDI: Disconnected");
|
||||
goto start;
|
||||
}
|
||||
}
|
||||
et = chVTGetSystemTimeX();
|
||||
usbDbgPrintf("\tRate=%uB/s", (config.speed * 100) / (et - st));
|
||||
}
|
||||
}
|
||||
systime_t st, et;
|
||||
int i;
|
||||
for (i = 0; i < 5; i++) {
|
||||
uint32_t bytes = config.speed / 10;
|
||||
uint32_t times = bytes / 1024;
|
||||
st = chVTGetSystemTimeX();
|
||||
while (times--) {
|
||||
if (streamWrite(ftdipp, buf, 1024) < 1024) {
|
||||
usbDbgPuts("FTDI: Disconnected");
|
||||
goto start;
|
||||
}
|
||||
bytes -= 1024;
|
||||
}
|
||||
if (bytes) {
|
||||
if (streamWrite(ftdipp, buf, bytes) < bytes) {
|
||||
usbDbgPuts("FTDI: Disconnected");
|
||||
goto start;
|
||||
}
|
||||
}
|
||||
et = chVTGetSystemTimeX();
|
||||
usbDbgPrintf("\tRate=%uB/s", (config.speed * 100) / (et - st));
|
||||
}
|
||||
}
|
||||
|
||||
//single character write test (tests the timer)
|
||||
if (0) {
|
||||
for (;;) {
|
||||
if (streamPut(ftdipp, 'A') != MSG_OK) {
|
||||
usbDbgPuts("FTDI: Disconnected");
|
||||
goto start;
|
||||
}
|
||||
chThdSleepMilliseconds(100);
|
||||
}
|
||||
}
|
||||
//single character write test (tests the timer)
|
||||
if (0) {
|
||||
for (;;) {
|
||||
if (streamPut(ftdipp, 'A') != MSG_OK) {
|
||||
usbDbgPuts("FTDI: Disconnected");
|
||||
goto start;
|
||||
}
|
||||
chThdSleepMilliseconds(100);
|
||||
}
|
||||
}
|
||||
|
||||
usbhftdipStop(ftdipp);
|
||||
usbhftdipStop(ftdipp);
|
||||
|
||||
usbDbgPuts("FTDI: Tests done, restarting in 3s");
|
||||
chThdSleepMilliseconds(3000);
|
||||
usbDbgPuts("FTDI: Tests done, restarting in 3s");
|
||||
chThdSleepMilliseconds(3000);
|
||||
|
||||
goto start;
|
||||
goto start;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -206,80 +206,80 @@ static THD_WORKING_AREA(waTestAOA, 1024);
|
|||
#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256)
|
||||
|
||||
static void ThreadTestAOA(void *p) {
|
||||
(void)p;
|
||||
USBHAOADriver *const aoap = &USBHAOAD[0];
|
||||
USBHAOAChannel *const aoacp = &aoap->channel;
|
||||
(void)p;
|
||||
USBHAOADriver *const aoap = &USBHAOAD[0];
|
||||
USBHAOAChannel *const aoacp = &aoap->channel;
|
||||
|
||||
start:
|
||||
while (usbhaoaGetState(aoap) != USBHAOA_STATE_READY) {
|
||||
chThdSleepMilliseconds(100);
|
||||
}
|
||||
while (usbhaoaGetState(aoap) != USBHAOA_STATE_READY) {
|
||||
chThdSleepMilliseconds(100);
|
||||
}
|
||||
|
||||
usbDbgPuts("AOA: Connected");
|
||||
usbDbgPuts("AOA: Connected");
|
||||
|
||||
if (usbhaoaGetChannelState(aoap) != USBHAOA_CHANNEL_STATE_READY) {
|
||||
usbhaoaChannelStart(aoap);
|
||||
usbDbgPuts("AOA: Channel started");
|
||||
}
|
||||
if (usbhaoaGetChannelState(aoap) != USBHAOA_CHANNEL_STATE_READY) {
|
||||
usbhaoaChannelStart(aoap);
|
||||
usbDbgPuts("AOA: Channel started");
|
||||
}
|
||||
|
||||
//loopback
|
||||
if (1) {
|
||||
for(;;) {
|
||||
msg_t m = streamGet(aoacp);
|
||||
if (m < MSG_OK) {
|
||||
usbDbgPuts("AOA: Disconnected");
|
||||
goto start;
|
||||
}
|
||||
streamPut(aoacp, (uint8_t)m);
|
||||
if (m == 'q')
|
||||
break;
|
||||
}
|
||||
}
|
||||
//loopback
|
||||
if (1) {
|
||||
for(;;) {
|
||||
msg_t m = streamGet(aoacp);
|
||||
if (m < MSG_OK) {
|
||||
usbDbgPuts("AOA: Disconnected");
|
||||
goto start;
|
||||
}
|
||||
streamPut(aoacp, (uint8_t)m);
|
||||
if (m == 'q')
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#define AOA_WRITE_SPEED_TEST_BYTES 3000000UL
|
||||
//write speed test
|
||||
if (1) {
|
||||
systime_t st, et;
|
||||
int i;
|
||||
for (i = 0; i < 5; i++) {
|
||||
uint32_t bytes = AOA_WRITE_SPEED_TEST_BYTES;
|
||||
uint32_t times = bytes / 1024;
|
||||
st = chVTGetSystemTimeX();
|
||||
while (times--) {
|
||||
if (streamWrite(aoacp, buf, 1024) < 1024) {
|
||||
usbDbgPuts("AOA: Disconnected");
|
||||
goto start;
|
||||
}
|
||||
bytes -= 1024;
|
||||
}
|
||||
if (bytes) {
|
||||
if (streamWrite(aoacp, buf, bytes) < bytes) {
|
||||
usbDbgPuts("AOA: Disconnected");
|
||||
goto start;
|
||||
}
|
||||
}
|
||||
et = chVTGetSystemTimeX();
|
||||
usbDbgPrintf("\tRate=%uB/s", AOA_WRITE_SPEED_TEST_BYTES / (et - st) * 100);
|
||||
}
|
||||
}
|
||||
#define AOA_WRITE_SPEED_TEST_BYTES 3000000UL
|
||||
//write speed test
|
||||
if (1) {
|
||||
systime_t st, et;
|
||||
int i;
|
||||
for (i = 0; i < 5; i++) {
|
||||
uint32_t bytes = AOA_WRITE_SPEED_TEST_BYTES;
|
||||
uint32_t times = bytes / 1024;
|
||||
st = chVTGetSystemTimeX();
|
||||
while (times--) {
|
||||
if (streamWrite(aoacp, buf, 1024) < 1024) {
|
||||
usbDbgPuts("AOA: Disconnected");
|
||||
goto start;
|
||||
}
|
||||
bytes -= 1024;
|
||||
}
|
||||
if (bytes) {
|
||||
if (streamWrite(aoacp, buf, bytes) < bytes) {
|
||||
usbDbgPuts("AOA: Disconnected");
|
||||
goto start;
|
||||
}
|
||||
}
|
||||
et = chVTGetSystemTimeX();
|
||||
usbDbgPrintf("\tRate=%uB/s", AOA_WRITE_SPEED_TEST_BYTES / (et - st) * 100);
|
||||
}
|
||||
}
|
||||
|
||||
//single character write test (tests the timer)
|
||||
if (0) {
|
||||
for (;;) {
|
||||
if (streamPut(aoacp, 'A') != MSG_OK) {
|
||||
usbDbgPuts("AOA: Disconnected");
|
||||
goto start;
|
||||
}
|
||||
chThdSleepMilliseconds(100);
|
||||
}
|
||||
}
|
||||
//single character write test (tests the timer)
|
||||
if (0) {
|
||||
for (;;) {
|
||||
if (streamPut(aoacp, 'A') != MSG_OK) {
|
||||
usbDbgPuts("AOA: Disconnected");
|
||||
goto start;
|
||||
}
|
||||
chThdSleepMilliseconds(100);
|
||||
}
|
||||
}
|
||||
|
||||
usbhaoaChannelStop(aoap);
|
||||
usbhaoaChannelStop(aoap);
|
||||
|
||||
usbDbgPuts("AOA: Tests done, restarting in 3s");
|
||||
chThdSleepMilliseconds(3000);
|
||||
usbDbgPuts("AOA: Tests done, restarting in 3s");
|
||||
chThdSleepMilliseconds(3000);
|
||||
|
||||
goto start;
|
||||
goto start;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -320,7 +320,7 @@ static FRESULT scan_files(BaseSequentialStream *chp, char *path) {
|
|||
break;
|
||||
path[--i] = 0;
|
||||
} else {
|
||||
usbDbgPrintf("FS: %s/%s", path, fn);
|
||||
usbDbgPrintf("FS: %s/%s", path, fn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -328,131 +328,131 @@ static FRESULT scan_files(BaseSequentialStream *chp, char *path) {
|
|||
}
|
||||
static THD_WORKING_AREA(waTestMSD, 1024);
|
||||
static void ThreadTestMSD(void *p) {
|
||||
(void)p;
|
||||
(void)p;
|
||||
|
||||
FATFS *fsp;
|
||||
DWORD clusters;
|
||||
FRESULT res;
|
||||
BaseSequentialStream * const chp = (BaseSequentialStream *)&USBH_DEBUG_SD;
|
||||
blkstate_t state;
|
||||
systime_t st, et;
|
||||
uint32_t j;
|
||||
FATFS *fsp;
|
||||
DWORD clusters;
|
||||
FRESULT res;
|
||||
BaseSequentialStream * const chp = (BaseSequentialStream *)&USBH_DEBUG_SD;
|
||||
blkstate_t state;
|
||||
systime_t st, et;
|
||||
uint32_t j;
|
||||
|
||||
start:
|
||||
for(;;) {
|
||||
chThdSleepMilliseconds(100);
|
||||
for(;;) {
|
||||
chThdSleepMilliseconds(100);
|
||||
|
||||
chSysLock();
|
||||
state = blkGetDriverState(&MSBLKD[0]);
|
||||
chSysUnlock();
|
||||
if (state != BLK_READY)
|
||||
continue;
|
||||
chSysLock();
|
||||
state = blkGetDriverState(&MSBLKD[0]);
|
||||
chSysUnlock();
|
||||
if (state != BLK_READY)
|
||||
continue;
|
||||
|
||||
//raw read test
|
||||
if (1) {
|
||||
#define RAW_READ_SZ_MB 1
|
||||
#define NBLOCKS (sizeof(fbuff) / 512)
|
||||
#define NITERATIONS ((RAW_READ_SZ_MB * 1024UL * 1024UL) / sizeof(fbuff))
|
||||
uint32_t start = 0;
|
||||
chThdSetPriority(HIGHPRIO);
|
||||
usbDbgPrintf("BLK: Raw read test (%dMB, %dB blocks)", RAW_READ_SZ_MB, sizeof(fbuff));
|
||||
st = chVTGetSystemTime();
|
||||
for (j = 0; j < NITERATIONS; j++) {
|
||||
blkRead(&MSBLKD[0], start, fbuff, NBLOCKS);
|
||||
start += NBLOCKS;
|
||||
}
|
||||
et = chVTGetSystemTime();
|
||||
usbDbgPrintf("BLK: Raw read in %d ms, %dkB/s",
|
||||
et - st,
|
||||
(RAW_READ_SZ_MB * 1024UL * 1000) / (et - st));
|
||||
chThdSetPriority(NORMALPRIO);
|
||||
}
|
||||
//raw read test
|
||||
if (1) {
|
||||
#define RAW_READ_SZ_MB 1
|
||||
#define NBLOCKS (sizeof(fbuff) / 512)
|
||||
#define NITERATIONS ((RAW_READ_SZ_MB * 1024UL * 1024UL) / sizeof(fbuff))
|
||||
uint32_t start = 0;
|
||||
chThdSetPriority(HIGHPRIO);
|
||||
usbDbgPrintf("BLK: Raw read test (%dMB, %dB blocks)", RAW_READ_SZ_MB, sizeof(fbuff));
|
||||
st = chVTGetSystemTime();
|
||||
for (j = 0; j < NITERATIONS; j++) {
|
||||
blkRead(&MSBLKD[0], start, fbuff, NBLOCKS);
|
||||
start += NBLOCKS;
|
||||
}
|
||||
et = chVTGetSystemTime();
|
||||
usbDbgPrintf("BLK: Raw read in %d ms, %dkB/s",
|
||||
et - st,
|
||||
(RAW_READ_SZ_MB * 1024UL * 1000) / (et - st));
|
||||
chThdSetPriority(NORMALPRIO);
|
||||
}
|
||||
|
||||
usbDbgPuts("FS: Block driver ready, try mount...");
|
||||
usbDbgPuts("FS: Block driver ready, try mount...");
|
||||
|
||||
res = f_mount(&MSDLUN0FS, "0:", 1);
|
||||
if (res != FR_OK) {
|
||||
usbDbgPuts("FS: Can't mount. Check file system.");
|
||||
continue;
|
||||
}
|
||||
usbDbgPuts("FS: Mounted.");
|
||||
res = f_mount(&MSDLUN0FS, "0:", 1);
|
||||
if (res != FR_OK) {
|
||||
usbDbgPuts("FS: Can't mount. Check file system.");
|
||||
continue;
|
||||
}
|
||||
usbDbgPuts("FS: Mounted.");
|
||||
|
||||
res = f_getfree("0:", &clusters, &fsp);
|
||||
if (res != FR_OK) {
|
||||
usbDbgPuts("FS: f_getfree() failed");
|
||||
continue;
|
||||
}
|
||||
res = f_getfree("0:", &clusters, &fsp);
|
||||
if (res != FR_OK) {
|
||||
usbDbgPuts("FS: f_getfree() failed");
|
||||
continue;
|
||||
}
|
||||
|
||||
usbDbgPrintf("FS: %lu free clusters, %lu sectors per cluster, %lu bytes free",
|
||||
clusters, (uint32_t)MSDLUN0FS.csize,
|
||||
clusters * (uint32_t)MSDLUN0FS.csize * MSBLKD[0].info.blk_size);
|
||||
usbDbgPrintf("FS: %lu free clusters, %lu sectors per cluster, %lu bytes free",
|
||||
clusters, (uint32_t)MSDLUN0FS.csize,
|
||||
clusters * (uint32_t)MSDLUN0FS.csize * MSBLKD[0].info.blk_size);
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//FATFS test
|
||||
if (1) {
|
||||
UINT bw;
|
||||
const uint8_t *src;
|
||||
const uint8_t *const start = (uint8_t *)0x08000000;
|
||||
const uint8_t *const top = (uint8_t *)0x08020000;
|
||||
//FATFS test
|
||||
if (1) {
|
||||
UINT bw;
|
||||
const uint8_t *src;
|
||||
const uint8_t *const start = (uint8_t *)0x08000000;
|
||||
const uint8_t *const top = (uint8_t *)0x08020000;
|
||||
|
||||
//write test
|
||||
if (1) {
|
||||
usbDbgPuts("FS: Write test (create file /test.dat, 1MB)");
|
||||
f_open(&file, "/test.dat", FA_CREATE_ALWAYS | FA_WRITE);
|
||||
src = start;
|
||||
st = chVTGetSystemTime();
|
||||
for (j = 0; j < 2048; j++) {
|
||||
if (f_write(&file, src, 512, &bw) != FR_OK)
|
||||
goto start;
|
||||
src += bw;
|
||||
if (src >= top)
|
||||
src = start;
|
||||
}
|
||||
et = chVTGetSystemTime();
|
||||
usbDbgPrintf("FS: Written 1MB in %d ms, %dkB/s",
|
||||
et - st,
|
||||
(1024UL*1000) / (et - st));
|
||||
f_close(&file);
|
||||
}
|
||||
//write test
|
||||
if (1) {
|
||||
usbDbgPuts("FS: Write test (create file /test.dat, 1MB)");
|
||||
f_open(&file, "/test.dat", FA_CREATE_ALWAYS | FA_WRITE);
|
||||
src = start;
|
||||
st = chVTGetSystemTime();
|
||||
for (j = 0; j < 2048; j++) {
|
||||
if (f_write(&file, src, 512, &bw) != FR_OK)
|
||||
goto start;
|
||||
src += bw;
|
||||
if (src >= top)
|
||||
src = start;
|
||||
}
|
||||
et = chVTGetSystemTime();
|
||||
usbDbgPrintf("FS: Written 1MB in %d ms, %dkB/s",
|
||||
et - st,
|
||||
(1024UL*1000) / (et - st));
|
||||
f_close(&file);
|
||||
}
|
||||
|
||||
//read test
|
||||
if (1) {
|
||||
usbDbgPuts("FS: Read test (read file /test.dat, 1MB, compare)");
|
||||
f_open(&file, "/test.dat", FA_READ);
|
||||
src = start;
|
||||
st = chVTGetSystemTime();
|
||||
for (j = 0; j < 2048; j++) {
|
||||
if (f_read(&file, fbuff, 512, &bw) != FR_OK)
|
||||
goto start;
|
||||
if (memcmp(src, fbuff, bw)) {
|
||||
usbDbgPrintf("Compare error @%08x", (uint32_t)src);
|
||||
goto start;
|
||||
}
|
||||
src += bw;
|
||||
if (src >= top)
|
||||
src = start;
|
||||
}
|
||||
et = chVTGetSystemTime();
|
||||
usbDbgPrintf("FS: Read 1MB in %d ms, %dkB/s",
|
||||
et - st,
|
||||
(1024UL*1000) / (et - st));
|
||||
f_close(&file);
|
||||
}
|
||||
//read test
|
||||
if (1) {
|
||||
usbDbgPuts("FS: Read test (read file /test.dat, 1MB, compare)");
|
||||
f_open(&file, "/test.dat", FA_READ);
|
||||
src = start;
|
||||
st = chVTGetSystemTime();
|
||||
for (j = 0; j < 2048; j++) {
|
||||
if (f_read(&file, fbuff, 512, &bw) != FR_OK)
|
||||
goto start;
|
||||
if (memcmp(src, fbuff, bw)) {
|
||||
usbDbgPrintf("Compare error @%08x", (uint32_t)src);
|
||||
goto start;
|
||||
}
|
||||
src += bw;
|
||||
if (src >= top)
|
||||
src = start;
|
||||
}
|
||||
et = chVTGetSystemTime();
|
||||
usbDbgPrintf("FS: Read 1MB in %d ms, %dkB/s",
|
||||
et - st,
|
||||
(1024UL*1000) / (et - st));
|
||||
f_close(&file);
|
||||
}
|
||||
|
||||
//scan files test
|
||||
if (1) {
|
||||
usbDbgPuts("FS: Scan files test");
|
||||
fbuff[0] = 0;
|
||||
scan_files(chp, (char *)fbuff);
|
||||
}
|
||||
}
|
||||
//scan files test
|
||||
if (1) {
|
||||
usbDbgPuts("FS: Scan files test");
|
||||
fbuff[0] = 0;
|
||||
scan_files(chp, (char *)fbuff);
|
||||
}
|
||||
}
|
||||
|
||||
usbDbgPuts("FS: Tests done, restarting in 3s");
|
||||
chThdSleepMilliseconds(3000);
|
||||
usbDbgPuts("FS: Tests done, restarting in 3s");
|
||||
chThdSleepMilliseconds(3000);
|
||||
|
||||
goto start;
|
||||
goto start;
|
||||
|
||||
}
|
||||
#endif
|
||||
|
@ -464,65 +464,65 @@ start:
|
|||
static THD_WORKING_AREA(waTestHID, 1024);
|
||||
|
||||
static void _hid_report_callback(USBHHIDDriver *hidp, uint16_t len) {
|
||||
uint8_t *report = (uint8_t *)hidp->config->report_buffer;
|
||||
uint8_t *report = (uint8_t *)hidp->config->report_buffer;
|
||||
|
||||
if (hidp->type == USBHHID_DEVTYPE_BOOT_MOUSE) {
|
||||
usbDbgPrintf("Mouse report: buttons=%02x, Dx=%d, Dy=%d",
|
||||
report[0],
|
||||
(int8_t)report[1],
|
||||
(int8_t)report[2]);
|
||||
} else if (hidp->type == USBHHID_DEVTYPE_BOOT_KEYBOARD) {
|
||||
usbDbgPrintf("Keyboard report: modifier=%02x, keys=%02x %02x %02x %02x %02x %02x",
|
||||
report[0],
|
||||
report[2],
|
||||
report[3],
|
||||
report[4],
|
||||
report[5],
|
||||
report[6],
|
||||
report[7]);
|
||||
} else {
|
||||
usbDbgPrintf("Generic report, %d bytes", len);
|
||||
}
|
||||
if (hidp->type == USBHHID_DEVTYPE_BOOT_MOUSE) {
|
||||
usbDbgPrintf("Mouse report: buttons=%02x, Dx=%d, Dy=%d",
|
||||
report[0],
|
||||
(int8_t)report[1],
|
||||
(int8_t)report[2]);
|
||||
} else if (hidp->type == USBHHID_DEVTYPE_BOOT_KEYBOARD) {
|
||||
usbDbgPrintf("Keyboard report: modifier=%02x, keys=%02x %02x %02x %02x %02x %02x",
|
||||
report[0],
|
||||
report[2],
|
||||
report[3],
|
||||
report[4],
|
||||
report[5],
|
||||
report[6],
|
||||
report[7]);
|
||||
} else {
|
||||
usbDbgPrintf("Generic report, %d bytes", len);
|
||||
}
|
||||
}
|
||||
|
||||
static USBH_DEFINE_BUFFER(uint8_t report[HAL_USBHHID_MAX_INSTANCES][8]);
|
||||
static USBHHIDConfig hidcfg[HAL_USBHHID_MAX_INSTANCES];
|
||||
|
||||
static void ThreadTestHID(void *p) {
|
||||
(void)p;
|
||||
uint8_t i;
|
||||
static uint8_t kbd_led_states[HAL_USBHHID_MAX_INSTANCES];
|
||||
(void)p;
|
||||
uint8_t i;
|
||||
static uint8_t kbd_led_states[HAL_USBHHID_MAX_INSTANCES];
|
||||
|
||||
for (i = 0; i < HAL_USBHHID_MAX_INSTANCES; i++) {
|
||||
hidcfg[i].cb_report = _hid_report_callback;
|
||||
hidcfg[i].protocol = USBHHID_PROTOCOL_BOOT;
|
||||
hidcfg[i].report_buffer = report[i];
|
||||
hidcfg[i].report_len = 8;
|
||||
}
|
||||
for (i = 0; i < HAL_USBHHID_MAX_INSTANCES; i++) {
|
||||
hidcfg[i].cb_report = _hid_report_callback;
|
||||
hidcfg[i].protocol = USBHHID_PROTOCOL_BOOT;
|
||||
hidcfg[i].report_buffer = report[i];
|
||||
hidcfg[i].report_len = 8;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
for (i = 0; i < HAL_USBHHID_MAX_INSTANCES; i++) {
|
||||
if (usbhhidGetState(&USBHHIDD[i]) == USBHHID_STATE_ACTIVE) {
|
||||
usbDbgPrintf("HID: Connected, HID%d", i);
|
||||
usbhhidStart(&USBHHIDD[i], &hidcfg[i]);
|
||||
if (usbhhidGetType(&USBHHIDD[i]) != USBHHID_DEVTYPE_GENERIC) {
|
||||
usbhhidSetIdle(&USBHHIDD[i], 0, 0);
|
||||
}
|
||||
kbd_led_states[i] = 1;
|
||||
} else if (usbhhidGetState(&USBHHIDD[i]) == USBHHID_STATE_READY) {
|
||||
if (usbhhidGetType(&USBHHIDD[i]) == USBHHID_DEVTYPE_BOOT_KEYBOARD) {
|
||||
USBH_DEFINE_BUFFER(uint8_t val);
|
||||
val = kbd_led_states[i] << 1;
|
||||
if (val == 0x08) {
|
||||
val = 1;
|
||||
}
|
||||
usbhhidSetReport(&USBHHIDD[i], 0, USBHHID_REPORTTYPE_OUTPUT, &val, 1);
|
||||
kbd_led_states[i] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
chThdSleepMilliseconds(200);
|
||||
}
|
||||
for (;;) {
|
||||
for (i = 0; i < HAL_USBHHID_MAX_INSTANCES; i++) {
|
||||
if (usbhhidGetState(&USBHHIDD[i]) == USBHHID_STATE_ACTIVE) {
|
||||
usbDbgPrintf("HID: Connected, HID%d", i);
|
||||
usbhhidStart(&USBHHIDD[i], &hidcfg[i]);
|
||||
if (usbhhidGetType(&USBHHIDD[i]) != USBHHID_DEVTYPE_GENERIC) {
|
||||
usbhhidSetIdle(&USBHHIDD[i], 0, 0);
|
||||
}
|
||||
kbd_led_states[i] = 1;
|
||||
} else if (usbhhidGetState(&USBHHIDD[i]) == USBHHID_STATE_READY) {
|
||||
if (usbhhidGetType(&USBHHIDD[i]) == USBHHID_DEVTYPE_BOOT_KEYBOARD) {
|
||||
USBH_DEFINE_BUFFER(uint8_t val);
|
||||
val = kbd_led_states[i] << 1;
|
||||
if (val == 0x08) {
|
||||
val = 1;
|
||||
}
|
||||
usbhhidSetReport(&USBHHIDD[i], 0, USBHHID_REPORTTYPE_OUTPUT, &val, 1);
|
||||
kbd_led_states[i] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
chThdSleepMilliseconds(200);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
@ -530,20 +530,20 @@ static void ThreadTestHID(void *p) {
|
|||
|
||||
int main(void) {
|
||||
|
||||
IWDG->KR = 0x5555;
|
||||
IWDG->PR = 7;
|
||||
IWDG->KR = 0x5555;
|
||||
IWDG->PR = 7;
|
||||
|
||||
halInit();
|
||||
chSysInit();
|
||||
halInit();
|
||||
chSysInit();
|
||||
|
||||
//PA2(TX) and PA3(RX) are routed to USART2
|
||||
sdStart(&SD2, NULL);
|
||||
palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7));
|
||||
palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));
|
||||
//PA2(TX) and PA3(RX) are routed to USART2
|
||||
sdStart(&SD2, NULL);
|
||||
palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7));
|
||||
palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));
|
||||
|
||||
#if STM32_USBH_USE_OTG1
|
||||
//VBUS - configured in board.h
|
||||
//USB_FS - configured in board.h
|
||||
//VBUS - configured in board.h
|
||||
//USB_FS - configured in board.h
|
||||
#endif
|
||||
|
||||
#if STM32_USBH_USE_OTG2
|
||||
|
@ -551,41 +551,41 @@ int main(void) {
|
|||
#endif
|
||||
|
||||
#if HAL_USBH_USE_MSD
|
||||
chThdCreateStatic(waTestMSD, sizeof(waTestMSD), NORMALPRIO, ThreadTestMSD, 0);
|
||||
chThdCreateStatic(waTestMSD, sizeof(waTestMSD), NORMALPRIO, ThreadTestMSD, 0);
|
||||
#endif
|
||||
|
||||
#if HAL_USBH_USE_FTDI
|
||||
chThdCreateStatic(waTestFTDI, sizeof(waTestFTDI), NORMALPRIO, ThreadTestFTDI, 0);
|
||||
chThdCreateStatic(waTestFTDI, sizeof(waTestFTDI), NORMALPRIO, ThreadTestFTDI, 0);
|
||||
#endif
|
||||
|
||||
#if HAL_USBH_USE_AOA
|
||||
chThdCreateStatic(waTestAOA, sizeof(waTestAOA), NORMALPRIO, ThreadTestAOA, 0);
|
||||
chThdCreateStatic(waTestAOA, sizeof(waTestAOA), NORMALPRIO, ThreadTestAOA, 0);
|
||||
#endif
|
||||
|
||||
#if HAL_USBH_USE_HID
|
||||
chThdCreateStatic(waTestHID, sizeof(waTestHID), NORMALPRIO, ThreadTestHID, 0);
|
||||
chThdCreateStatic(waTestHID, sizeof(waTestHID), NORMALPRIO, ThreadTestHID, 0);
|
||||
#endif
|
||||
|
||||
//turn on USB power
|
||||
palClearPad(GPIOC, GPIOC_OTG_FS_POWER_ON);
|
||||
//turn on USB power
|
||||
palClearPad(GPIOC, GPIOC_OTG_FS_POWER_ON);
|
||||
|
||||
//start
|
||||
//start
|
||||
#if STM32_USBH_USE_OTG1
|
||||
usbhStart(&USBHD1);
|
||||
usbhStart(&USBHD1);
|
||||
#endif
|
||||
#if STM32_USBH_USE_OTG2
|
||||
usbhStart(&USBHD2);
|
||||
usbhStart(&USBHD2);
|
||||
#endif
|
||||
|
||||
for(;;) {
|
||||
for(;;) {
|
||||
#if STM32_USBH_USE_OTG1
|
||||
usbhMainLoop(&USBHD1);
|
||||
usbhMainLoop(&USBHD1);
|
||||
#endif
|
||||
#if STM32_USBH_USE_OTG2
|
||||
usbhMainLoop(&USBHD2);
|
||||
usbhMainLoop(&USBHD2);
|
||||
#endif
|
||||
chThdSleepMilliseconds(100);
|
||||
chThdSleepMilliseconds(100);
|
||||
|
||||
IWDG->KR = 0xAAAA;
|
||||
}
|
||||
IWDG->KR = 0xAAAA;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue