aboutsummaryrefslogtreecommitdiffstats
path: root/testhal
diff options
context:
space:
mode:
authorFabien Poussin <fabien.poussin@gmail.com>2017-08-07 16:34:34 +0200
committerGitHub <noreply@github.com>2017-08-07 16:34:34 +0200
commitfa733674e6c0a0ac773121779882f16fe7e00bc1 (patch)
tree2bcd088deb6ab67b3b27c6ab54143ff8ce1dcff5 /testhal
parent4092650b1bc013a21c0eaf27f62c84dbf2aece42 (diff)
parent02585210d1f33b3d5dd52267faa15576d5f7f8b2 (diff)
downloadChibiOS-Contrib-fa733674e6c0a0ac773121779882f16fe7e00bc1.tar.gz
ChibiOS-Contrib-fa733674e6c0a0ac773121779882f16fe7e00bc1.tar.bz2
ChibiOS-Contrib-fa733674e6c0a0ac773121779882f16fe7e00bc1.zip
Merge pull request #122 from dismirlian/usbh_devel
USBH: Various improvo
Diffstat (limited to 'testhal')
-rw-r--r--testhal/STM32/STM32F4xx/USB_HOST/Makefile2
-rw-r--r--testhal/STM32/STM32F4xx/USB_HOST/halconf_community.h3
-rw-r--r--testhal/STM32/STM32F4xx/USB_HOST/main.c22
-rw-r--r--testhal/STM32/STM32F4xx/USB_HOST/usbh_additional_class_drivers.h38
-rw-r--r--testhal/STM32/STM32F4xx/USB_HOST/usbh_custom_class_example.c144
-rw-r--r--testhal/STM32/STM32F4xx/USB_HOST/usbh_custom_class_example.h80
6 files changed, 281 insertions, 8 deletions
diff --git a/testhal/STM32/STM32F4xx/USB_HOST/Makefile b/testhal/STM32/STM32F4xx/USB_HOST/Makefile
index 0174baf..33d032a 100644
--- a/testhal/STM32/STM32F4xx/USB_HOST/Makefile
+++ b/testhal/STM32/STM32F4xx/USB_HOST/Makefile
@@ -120,7 +120,7 @@ CSRC = $(STARTUPSRC) \
$(FATFSSRC) \
$(STREAMSSRC) \
$(SHELLSRC) \
- main.c
+ main.c usbh_custom_class_example.c
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
diff --git a/testhal/STM32/STM32F4xx/USB_HOST/halconf_community.h b/testhal/STM32/STM32F4xx/USB_HOST/halconf_community.h
index 51e9a8d..9b22a79 100644
--- a/testhal/STM32/STM32F4xx/USB_HOST/halconf_community.h
+++ b/testhal/STM32/STM32F4xx/USB_HOST/halconf_community.h
@@ -89,6 +89,7 @@
#define HAL_USBH_PORT_DEBOUNCE_TIME 200
#define HAL_USBH_PORT_RESET_TIMEOUT 500
#define HAL_USBH_DEVICE_ADDRESS_STABILIZATION 20
+#define HAL_USBH_CONTROL_REQUEST_DEFAULT_TIMEOUT MS2ST(1000)
/* MSD */
#define HAL_USBH_USE_MSD TRUE
@@ -141,6 +142,8 @@
#define HAL_USBHHUB_MAX_INSTANCES 1
#define HAL_USBHHUB_MAX_PORTS 6
+#define HAL_USBH_USE_ADDITIONAL_CLASS_DRIVERS TRUE
+
/* debug */
#define USBH_DEBUG_ENABLE TRUE
#define USBH_DEBUG_USBHD USBHD1
diff --git a/testhal/STM32/STM32F4xx/USB_HOST/main.c b/testhal/STM32/STM32F4xx/USB_HOST/main.c
index 9652da3..595e454 100644
--- a/testhal/STM32/STM32F4xx/USB_HOST/main.c
+++ b/testhal/STM32/STM32F4xx/USB_HOST/main.c
@@ -18,8 +18,10 @@
#include "hal.h"
#include "ff.h"
#include <string.h>
+#include "usbh/debug.h" /* for usbDbgPuts/usbDbgPrintf */
-#define UVC_TO_MSD_PHOTOS_CAPTURE TRUE
+
+#define UVC_TO_MSD_PHOTOS_CAPTURE FALSE
#if HAL_USBH_USE_FTDI || HAL_USBH_USE_AOA
@@ -343,7 +345,7 @@ static void ThreadTestMSD(void *p) {
FATFS *fsp;
DWORD clusters;
FRESULT res;
- blkstate_t state;
+
#if !UVC_TO_MSD_PHOTOS_CAPTURE
BaseSequentialStream * const chp = (BaseSequentialStream *)&USBH_DEBUG_SD;
systime_t st, et;
@@ -354,11 +356,15 @@ start:
for(;;) {
chThdSleepMilliseconds(100);
- chSysLock();
- state = blkGetDriverState(&MSBLKD[0]);
- chSysUnlock();
- if (state != BLK_READY)
+ if (blkGetDriverState(&MSBLKD[0]) == BLK_ACTIVE) {
+ usbDbgPuts("BLK: Active, connect....");
+ usbhmsdLUNConnect(&MSBLKD[0]);
+ }
+ if (blkGetDriverState(&MSBLKD[0]) != BLK_READY) {
continue;
+ }
+
+ usbDbgPuts("BLK: Ready.");
#if !UVC_TO_MSD_PHOTOS_CAPTURE
//raw read test
@@ -371,7 +377,8 @@ start:
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);
+ if (blkRead(&MSBLKD[0], start, fbuff, NBLOCKS) != HAL_SUCCESS)
+ goto start;
start += NBLOCKS;
}
et = chVTGetSystemTime();
@@ -914,6 +921,7 @@ int main(void) {
//turn on USB power
palClearPad(GPIOC, GPIOC_OTG_FS_POWER_ON);
+ chThdSleepMilliseconds(100);
//start
#if STM32_USBH_USE_OTG1
diff --git a/testhal/STM32/STM32F4xx/USB_HOST/usbh_additional_class_drivers.h b/testhal/STM32/STM32F4xx/USB_HOST/usbh_additional_class_drivers.h
new file mode 100644
index 0000000..ac9fc18
--- /dev/null
+++ b/testhal/STM32/STM32F4xx/USB_HOST/usbh_additional_class_drivers.h
@@ -0,0 +1,38 @@
+/*
+ ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio
+ Copyright (C) 2015..2017 Diego Ismirlian, (dismirlian (at) google's mail)
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#ifndef USBH_ADDITIONAL_H_
+#define USBH_ADDITIONAL_H_
+
+#include "hal_usbh.h"
+
+#if HAL_USE_USBH && HAL_USBH_USE_ADDITIONAL_CLASS_DRIVERS
+
+/* Declarations */
+extern const usbh_classdriverinfo_t usbhCustomClassDriverInfo;
+
+
+
+/* Comma separated list of additional class drivers */
+#define HAL_USBH_ADDITIONAL_CLASS_DRIVERS \
+ &usbhCustomClassDriverInfo,
+
+
+
+#endif
+
+#endif /* USBH_ADDITIONAL_H_ */
diff --git a/testhal/STM32/STM32F4xx/USB_HOST/usbh_custom_class_example.c b/testhal/STM32/STM32F4xx/USB_HOST/usbh_custom_class_example.c
new file mode 100644
index 0000000..4585a5c
--- /dev/null
+++ b/testhal/STM32/STM32F4xx/USB_HOST/usbh_custom_class_example.c
@@ -0,0 +1,144 @@
+/*
+ ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio
+ Copyright (C) 2015..2017 Diego Ismirlian, (dismirlian (at) google's mail)
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#include "hal.h"
+
+#if HAL_USBH_USE_ADDITIONAL_CLASS_DRIVERS
+
+#include <string.h>
+#include "usbh_custom_class_example.h"
+#include "usbh/internal.h"
+
+#if USBH_DEBUG_ENABLE_TRACE
+#define udbgf(f, ...) usbDbgPrintf(f, ##__VA_ARGS__)
+#define udbg(f, ...) usbDbgPuts(f, ##__VA_ARGS__)
+#else
+#define udbgf(f, ...) do {} while(0)
+#define udbg(f, ...) do {} while(0)
+#endif
+
+#if USBH_DEBUG_ENABLE_INFO
+#define uinfof(f, ...) usbDbgPrintf(f, ##__VA_ARGS__)
+#define uinfo(f, ...) usbDbgPuts(f, ##__VA_ARGS__)
+#else
+#define uinfof(f, ...) do {} while(0)
+#define uinfo(f, ...) do {} while(0)
+#endif
+
+#if USBH_DEBUG_ENABLE_WARNINGS
+#define uwarnf(f, ...) usbDbgPrintf(f, ##__VA_ARGS__)
+#define uwarn(f, ...) usbDbgPuts(f, ##__VA_ARGS__)
+#else
+#define uwarnf(f, ...) do {} while(0)
+#define uwarn(f, ...) do {} while(0)
+#endif
+
+#if USBH_DEBUG_ENABLE_ERRORS
+#define uerrf(f, ...) usbDbgPrintf(f, ##__VA_ARGS__)
+#define uerr(f, ...) usbDbgPuts(f, ##__VA_ARGS__)
+#else
+#define uerrf(f, ...) do {} while(0)
+#define uerr(f, ...) do {} while(0)
+#endif
+
+/*===========================================================================*/
+/* USB Class driver loader for Custom Class Example */
+/*===========================================================================*/
+
+USBHCustomDriver USBHCUSTOMD[USBH_CUSTOM_CLASS_MAX_INSTANCES];
+
+static void _init(void);
+static usbh_baseclassdriver_t *_load(usbh_device_t *dev, const uint8_t *descriptor, uint16_t rem);
+static void _unload(usbh_baseclassdriver_t *drv);
+
+static const usbh_classdriver_vmt_t class_driver_vmt = {
+ _init,
+ _load,
+ _unload
+};
+
+const usbh_classdriverinfo_t usbhCustomClassDriverInfo = {
+ "CUSTOM", &class_driver_vmt
+};
+
+static usbh_baseclassdriver_t *_load(usbh_device_t *dev, const uint8_t *descriptor, uint16_t rem) {
+ int i;
+ USBHCustomDriver *custp;
+ (void)dev;
+
+ if (_usbh_match_vid_pid(dev, 0xABCD, 0x0123) != HAL_SUCCESS)
+ return NULL;
+
+ const usbh_interface_descriptor_t * const ifdesc = (const usbh_interface_descriptor_t *)descriptor;
+
+ /* alloc driver */
+ for (i = 0; i < USBH_CUSTOM_CLASS_MAX_INSTANCES; i++) {
+ if (USBHCUSTOMD[i].dev == NULL) {
+ custp = &USBHCUSTOMD[i];
+ goto alloc_ok;
+ }
+ }
+
+ uwarn("Can't alloc CUSTOM driver");
+
+ /* can't alloc */
+ return NULL;
+
+alloc_ok:
+ /* initialize the driver's variables */
+ custp->ifnum = ifdesc->bInterfaceNumber;
+
+ /* parse the configuration descriptor */
+ if_iterator_t iif;
+ generic_iterator_t iep;
+ iif.iad = 0;
+ iif.curr = descriptor;
+ iif.rem = rem;
+ for (ep_iter_init(&iep, &iif); iep.valid; ep_iter_next(&iep)) {
+ const usbh_endpoint_descriptor_t *const epdesc = ep_get(&iep);
+ if ((epdesc->bEndpointAddress & 0x80) && (epdesc->bmAttributes == USBH_EPTYPE_INT)) {
+ /* ... */
+ } else {
+ uinfof("unsupported endpoint found: bEndpointAddress=%02x, bmAttributes=%02x",
+ epdesc->bEndpointAddress, epdesc->bmAttributes);
+ }
+ }
+
+ custp->state = USBHCUSTOM_STATE_ACTIVE;
+
+ return (usbh_baseclassdriver_t *)custp;
+
+}
+
+static void _unload(usbh_baseclassdriver_t *drv) {
+ (void)drv;
+}
+
+static void _object_init(USBHCustomDriver *custp) {
+ osalDbgCheck(custp != NULL);
+ memset(custp, 0, sizeof(*custp));
+ custp->state = USBHCUSTOM_STATE_STOP;
+}
+
+static void _init(void) {
+ uint8_t i;
+ for (i = 0; i < USBH_CUSTOM_CLASS_MAX_INSTANCES; i++) {
+ _object_init(&USBHCUSTOMD[i]);
+ }
+}
+
+#endif
diff --git a/testhal/STM32/STM32F4xx/USB_HOST/usbh_custom_class_example.h b/testhal/STM32/STM32F4xx/USB_HOST/usbh_custom_class_example.h
new file mode 100644
index 0000000..3f00fe7
--- /dev/null
+++ b/testhal/STM32/STM32F4xx/USB_HOST/usbh_custom_class_example.h
@@ -0,0 +1,80 @@
+/*
+ ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio
+ Copyright (C) 2015..2017 Diego Ismirlian, (dismirlian (at) google's mail)
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#ifndef USBH_CUSTOM_H_
+#define USBH_CUSTOM_H_
+
+#include "hal_usbh.h"
+
+#if HAL_USE_USBH && HAL_USBH_USE_ADDITIONAL_CLASS_DRIVERS
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+#define USBH_CUSTOM_CLASS_MAX_INSTANCES 1
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+typedef enum {
+ USBHCUSTOM_STATE_UNINIT = 0,
+ USBHCUSTOM_STATE_STOP = 1,
+ USBHCUSTOM_STATE_ACTIVE = 2,
+ USBHCUSTOM_STATE_READY = 3
+} usbhcustom_state_t;
+
+typedef struct USBHCustomDriver USBHCustomDriver;
+
+struct USBHCustomDriver {
+ /* inherited from abstract class driver */
+ _usbh_base_classdriver_data
+
+ uint8_t ifnum;
+
+ usbhcustom_state_t state;
+};
+
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+extern USBHCustomDriver USBHCUSTOMD[USBH_CUSTOM_CLASS_MAX_INSTANCES];
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ /* API goes here */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+#endif /* USBH_CUSTOM_H_ */