USB Host fixes
- Cleaned up alignment macros for GCC & IAR - Corrected EP halt and Clear halt behaviours - Initialization of class drivers by USB Host main driver - Minor cosmetic fixes - Updated USB_HOST testhal app
This commit is contained in:
parent
eec17ec12e
commit
5ecaf7722b
|
@ -20,6 +20,9 @@
|
|||
|
||||
#include "hal.h"
|
||||
|
||||
#ifndef HAL_USE_USBH
|
||||
#define HAL_USE_USBH FALSE
|
||||
#endif
|
||||
|
||||
#ifndef HAL_USBH_USE_FTDI
|
||||
#define HAL_USBH_USE_FTDI FALSE
|
||||
|
@ -37,6 +40,8 @@
|
|||
#define HAL_USBH_USE_UVC FALSE
|
||||
#endif
|
||||
|
||||
#define HAL_USBH_USE_IAD HAL_USBH_USE_UVC
|
||||
|
||||
#if (HAL_USE_USBH == TRUE) || defined(__DOXYGEN__)
|
||||
|
||||
#include "osal.h"
|
||||
|
@ -104,13 +109,11 @@ enum usbh_urbstatus {
|
|||
USBH_URBSTATUS_UNINITIALIZED = 0,
|
||||
USBH_URBSTATUS_INITIALIZED,
|
||||
USBH_URBSTATUS_PENDING,
|
||||
// USBH_URBSTATUS_QUEUED,
|
||||
USBH_URBSTATUS_ERROR,
|
||||
USBH_URBSTATUS_TIMEOUT,
|
||||
USBH_URBSTATUS_CANCELLED,
|
||||
USBH_URBSTATUS_STALL,
|
||||
USBH_URBSTATUS_DISCONNECTED,
|
||||
// USBH_URBSTATUS_EPCLOSED,
|
||||
USBH_URBSTATUS_OK,
|
||||
};
|
||||
|
||||
|
@ -145,7 +148,8 @@ typedef void (*usbh_completion_cb)(usbh_urb_t *);
|
|||
/* include the low level driver; the required definitions are above */
|
||||
#include "hal_usbh_lld.h"
|
||||
|
||||
#define USBH_DEFINE_BUFFER(type, name) USBH_LLD_DEFINE_BUFFER(type, name)
|
||||
#define USBH_DEFINE_BUFFER(var) USBH_LLD_DEFINE_BUFFER(var)
|
||||
#define USBH_DECLARE_STRUCT_MEMBER(member) USBH_LLD_DECLARE_STRUCT_MEMBER(member)
|
||||
|
||||
struct usbh_urb {
|
||||
usbh_ep_t *ep;
|
||||
|
@ -198,9 +202,8 @@ struct usbh_device {
|
|||
usbh_devstatus_t status;
|
||||
usbh_devspeed_t speed;
|
||||
|
||||
USBH_DEFINE_BUFFER(usbh_device_descriptor_t, devDesc);
|
||||
unsigned char align_bytes[2];
|
||||
USBH_DEFINE_BUFFER(usbh_config_descriptor_t, basicConfigDesc);
|
||||
USBH_DECLARE_STRUCT_MEMBER(usbh_device_descriptor_t devDesc);
|
||||
USBH_DECLARE_STRUCT_MEMBER(usbh_config_descriptor_t basicConfigDesc);
|
||||
|
||||
uint8_t *fullConfigurationDescriptor;
|
||||
uint8_t keepFullCfgDesc;
|
||||
|
@ -362,10 +365,13 @@ extern "C" {
|
|||
usbhEPCloseS(ep);
|
||||
osalSysUnlock();
|
||||
}
|
||||
static inline void usbhEPResetI(usbh_ep_t *ep) {
|
||||
osalDbgCheckClassI();
|
||||
osalDbgCheck(ep != NULL);
|
||||
usbh_lld_epreset(ep);
|
||||
bool usbhEPResetS(usbh_ep_t *ep);
|
||||
static inline bool usbhEPReset(usbh_ep_t *ep) {
|
||||
bool ret;
|
||||
osalSysLock();
|
||||
ret = usbhEPResetS(ep);
|
||||
osalSysUnlock();
|
||||
return ret;
|
||||
}
|
||||
static inline bool usbhEPIsPeriodic(usbh_ep_t *ep) {
|
||||
osalDbgCheck(ep != NULL);
|
||||
|
|
|
@ -23,8 +23,6 @@
|
|||
|
||||
#if HAL_USE_USBH
|
||||
|
||||
//TODO: Debug is only for USBHD1, make it generic.
|
||||
|
||||
#if USBH_DEBUG_ENABLE
|
||||
void usbDbgPrintf(const char *fmt, ...);
|
||||
void usbDbgPuts(const char *s);
|
||||
|
|
|
@ -25,12 +25,12 @@
|
|||
#include "osal.h"
|
||||
|
||||
#ifdef __IAR_SYSTEMS_ICC__
|
||||
#define PACKED_STRUCT typedef PACKED_VAR struct
|
||||
#define PACKED_STRUCT PACKED_VAR struct
|
||||
#else
|
||||
#define PACKED_STRUCT typedef struct PACKED_VAR
|
||||
#define PACKED_STRUCT struct PACKED_VAR
|
||||
#endif
|
||||
|
||||
PACKED_STRUCT {
|
||||
typedef PACKED_STRUCT {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint16_t bcdUSB;
|
||||
|
@ -49,7 +49,7 @@ PACKED_STRUCT {
|
|||
#define USBH_DT_DEVICE 0x01
|
||||
#define USBH_DT_DEVICE_SIZE 18
|
||||
|
||||
PACKED_STRUCT {
|
||||
typedef PACKED_STRUCT {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint16_t wTotalLength;
|
||||
|
@ -62,7 +62,7 @@ PACKED_STRUCT {
|
|||
#define USBH_DT_CONFIG 0x02
|
||||
#define USBH_DT_CONFIG_SIZE 9
|
||||
|
||||
PACKED_STRUCT {
|
||||
typedef PACKED_STRUCT {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint16_t wData[1];
|
||||
|
@ -70,7 +70,7 @@ PACKED_STRUCT {
|
|||
#define USBH_DT_STRING 0x03
|
||||
#define USBH_DT_STRING_SIZE 2
|
||||
|
||||
PACKED_STRUCT {
|
||||
typedef PACKED_STRUCT {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bInterfaceNumber;
|
||||
|
@ -84,7 +84,7 @@ PACKED_STRUCT {
|
|||
#define USBH_DT_INTERFACE 0x04
|
||||
#define USBH_DT_INTERFACE_SIZE 9
|
||||
|
||||
PACKED_STRUCT {
|
||||
typedef PACKED_STRUCT {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bEndpointAddress;
|
||||
|
@ -95,7 +95,7 @@ PACKED_STRUCT {
|
|||
#define USBH_DT_ENDPOINT 0x05
|
||||
#define USBH_DT_ENDPOINT_SIZE 7
|
||||
|
||||
PACKED_STRUCT {
|
||||
typedef PACKED_STRUCT {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bFirstInterface;
|
||||
|
@ -108,7 +108,7 @@ PACKED_STRUCT {
|
|||
#define USBH_DT_INTERFACE_ASSOCIATION 0x0b
|
||||
#define USBH_DT_INTERFACE_ASSOCIATION_SIZE 8
|
||||
|
||||
PACKED_STRUCT {
|
||||
typedef PACKED_STRUCT {
|
||||
uint8_t bDescLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bNbrPorts;
|
||||
|
@ -120,7 +120,7 @@ PACKED_STRUCT {
|
|||
#define USBH_DT_HUB 0x29
|
||||
#define USBH_DT_HUB_SIZE (7 + 4)
|
||||
|
||||
PACKED_STRUCT {
|
||||
typedef PACKED_STRUCT {
|
||||
uint8_t bmRequestType;
|
||||
uint8_t bRequest;
|
||||
uint16_t wValue;
|
||||
|
|
|
@ -96,7 +96,7 @@ struct USBHFTDIPortDriver {
|
|||
usbh_urb_t iq_urb;
|
||||
threads_queue_t iq_waiting;
|
||||
uint32_t iq_counter;
|
||||
USBH_DEFINE_BUFFER(uint8_t, iq_buff[64]);
|
||||
USBH_DECLARE_STRUCT_MEMBER(uint8_t iq_buff[64]);
|
||||
uint8_t *iq_ptr;
|
||||
|
||||
|
||||
|
@ -104,7 +104,7 @@ struct USBHFTDIPortDriver {
|
|||
usbh_urb_t oq_urb;
|
||||
threads_queue_t oq_waiting;
|
||||
uint32_t oq_counter;
|
||||
USBH_DEFINE_BUFFER(uint8_t, oq_buff[64]);
|
||||
USBH_DECLARE_STRUCT_MEMBER(uint8_t oq_buff[64]);
|
||||
uint8_t *oq_ptr;
|
||||
|
||||
virtual_timer_t vt;
|
||||
|
@ -113,7 +113,7 @@ struct USBHFTDIPortDriver {
|
|||
USBHFTDIPortDriver *next;
|
||||
};
|
||||
|
||||
typedef struct USBHFTDIDriver {
|
||||
struct USBHFTDIDriver {
|
||||
/* inherited from abstract class driver */
|
||||
_usbh_base_classdriver_data
|
||||
|
||||
|
@ -121,11 +121,12 @@ typedef struct USBHFTDIDriver {
|
|||
USBHFTDIPortDriver *ports;
|
||||
|
||||
mutex_t mtx;
|
||||
} USBHFTDIDriver;
|
||||
};
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver macros. */
|
||||
/*===========================================================================*/
|
||||
#define usbhftdipGetState(ftdipp) ((ftdipp)->state)
|
||||
|
||||
|
||||
/*===========================================================================*/
|
||||
|
@ -144,6 +145,9 @@ extern "C" {
|
|||
void usbhftdipObjectInit(USBHFTDIPortDriver *ftdipp);
|
||||
void usbhftdipStart(USBHFTDIPortDriver *ftdipp, const USBHFTDIPortConfig *config);
|
||||
void usbhftdipStop(USBHFTDIPortDriver *ftdipp);
|
||||
|
||||
/* global initializer */
|
||||
void usbhftdiInit(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#if HAL_USE_USBH
|
||||
#if HAL_USBH_USE_HUB
|
||||
|
||||
typedef struct USBHHubDriver {
|
||||
struct USBHHubDriver {
|
||||
/* inherited from abstract class driver */
|
||||
_usbh_base_classdriver_data
|
||||
|
||||
|
@ -32,19 +32,19 @@ typedef struct USBHHubDriver {
|
|||
usbh_ep_t epint;
|
||||
usbh_urb_t urb;
|
||||
|
||||
USBH_DEFINE_BUFFER(uint8_t, scbuff[4]);
|
||||
USBH_DECLARE_STRUCT_MEMBER(uint8_t scbuff[4]);
|
||||
volatile uint32_t statuschange;
|
||||
uint16_t status;
|
||||
uint16_t c_status;
|
||||
|
||||
usbh_port_t *ports;
|
||||
|
||||
USBH_DEFINE_BUFFER(usbh_hub_descriptor_t, hubDesc);
|
||||
USBH_DECLARE_STRUCT_MEMBER(usbh_hub_descriptor_t hubDesc);
|
||||
|
||||
/* Low level part */
|
||||
_usbh_hub_ll_data
|
||||
|
||||
} USBHHubDriver;
|
||||
};
|
||||
|
||||
extern USBHHubDriver USBHHUBD[HAL_USBHHUB_MAX_INSTANCES];
|
||||
|
||||
|
@ -89,6 +89,9 @@ static inline usbh_urbstatus_t usbhhubSetFeaturePort(usbh_port_t *port, uint8_t
|
|||
}
|
||||
|
||||
void usbhhubObjectInit(USBHHubDriver *hubdp);
|
||||
|
||||
void usbhhubInit(void);
|
||||
|
||||
#else
|
||||
|
||||
static inline usbh_urbstatus_t usbhhubControlRequest(USBHDriver *host,
|
||||
|
|
|
@ -65,7 +65,7 @@ struct USBHMassStorageLUNDriver {
|
|||
USBHMassStorageLUNDriver *next;
|
||||
};
|
||||
|
||||
typedef struct USBHMassStorageDriver {
|
||||
struct USBHMassStorageDriver {
|
||||
/* inherited from abstract class driver */
|
||||
_usbh_base_classdriver_data
|
||||
|
||||
|
@ -81,7 +81,7 @@ typedef struct USBHMassStorageDriver {
|
|||
uint32_t tag;
|
||||
|
||||
USBHMassStorageLUNDriver *luns;
|
||||
} USBHMassStorageDriver;
|
||||
};
|
||||
|
||||
|
||||
/*===========================================================================*/
|
||||
|
@ -116,6 +116,9 @@ extern "C" {
|
|||
bool usbhmsdLUNGetInfo(USBHMassStorageLUNDriver *lunp, BlockDeviceInfo *bdip);
|
||||
bool usbhmsdLUNIsInserted(USBHMassStorageLUNDriver *lunp);
|
||||
bool usbhmsdLUNIsProtected(USBHMassStorageLUNDriver *lunp);
|
||||
|
||||
/* global initializer */
|
||||
void usbhmsdInit(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -7,11 +7,8 @@
|
|||
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
|
||||
#endif
|
||||
|
||||
#define container_of(ptr, type, member) ((type *)(void *)((char *)(ptr) - offsetof(type, member)))
|
||||
#ifndef container_of
|
||||
#define container_of(ptr, type, member) ({ \
|
||||
const typeof(((type *)0)->member) * __mptr = (ptr); \
|
||||
(type *)((char *)__mptr - offsetof(type, member)); })
|
||||
#define container_of(ptr, type, member) ((type *)(void *)((char *)(ptr) - offsetof(type, member)))
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
|
|
@ -21,6 +21,53 @@
|
|||
#include "usbh/internal.h"
|
||||
#include <string.h>
|
||||
|
||||
#if STM32_USBH_USE_OTG1
|
||||
#if !defined(STM32_OTG1_CHANNELS_NUMBER)
|
||||
#error "STM32_OTG1_CHANNELS_NUMBER must be defined"
|
||||
#endif
|
||||
#if !defined(STM32_OTG1_RXFIFO_SIZE)
|
||||
#define STM32_OTG1_RXFIFO_SIZE 1024
|
||||
#endif
|
||||
#if !defined(STM32_OTG1_PTXFIFO_SIZE)
|
||||
#define STM32_OTG1_PTXFIFO_SIZE 128
|
||||
#endif
|
||||
#if !defined(STM32_OTG1_NPTXFIFO_SIZE)
|
||||
#define STM32_OTG1_NPTXFIFO_SIZE 128
|
||||
#endif
|
||||
#if (STM32_OTG1_RXFIFO_SIZE + STM32_OTG1_PTXFIFO_SIZE + STM32_OTG1_NPTXFIFO_SIZE) > (STM32_OTG1_FIFO_MEM_SIZE * 4)
|
||||
#error "Not enough memory in OTG1 implementation"
|
||||
#elif (STM32_OTG1_RXFIFO_SIZE + STM32_OTG1_PTXFIFO_SIZE + STM32_OTG1_NPTXFIFO_SIZE) < (STM32_OTG1_FIFO_MEM_SIZE * 4)
|
||||
#warning "Spare memory in OTG1; could enlarge RX, PTX or NPTX FIFO sizes"
|
||||
#endif
|
||||
#if (STM32_OTG1_RXFIFO_SIZE % 4) || (STM32_OTG1_PTXFIFO_SIZE % 4) || (STM32_OTG1_NPTXFIFO_SIZE % 4)
|
||||
#error "FIFO sizes must be a multiple of 32-bit words"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if STM32_USBH_USE_OTG2
|
||||
#if !defined(STM32_OTG2_CHANNELS_NUMBER)
|
||||
#error "STM32_OTG2_CHANNELS_NUMBER must be defined"
|
||||
#endif
|
||||
#if !defined(STM32_OTG2_RXFIFO_SIZE)
|
||||
#define STM32_OTG2_RXFIFO_SIZE 2048
|
||||
#endif
|
||||
#if !defined(STM32_OTG2_PTXFIFO_SIZE)
|
||||
#define STM32_OTG2_PTXFIFO_SIZE 1024
|
||||
#endif
|
||||
#if !defined(STM32_OTG2_NPTXFIFO_SIZE)
|
||||
#define STM32_OTG2_NPTXFIFO_SIZE 1024
|
||||
#endif
|
||||
#if (STM32_OTG2_RXFIFO_SIZE + STM32_OTG2_PTXFIFO_SIZE + STM32_OTG2_NPTXFIFO_SIZE) > (STM32_OTG2_FIFO_MEM_SIZE * 4)
|
||||
#error "Not enough memory in OTG2 implementation"
|
||||
#elif (STM32_OTG2_RXFIFO_SIZE + STM32_OTG2_PTXFIFO_SIZE + STM32_OTG2_NPTXFIFO_SIZE) < (STM32_OTG2_FIFO_MEM_SIZE * 4)
|
||||
#warning "Spare memory in OTG2; could enlarge RX, PTX or NPTX FIFO sizes"
|
||||
#endif
|
||||
#if (STM32_OTG2_RXFIFO_SIZE % 4) || (STM32_OTG2_PTXFIFO_SIZE % 4) || (STM32_OTG2_NPTXFIFO_SIZE % 4)
|
||||
#error "FIFO sizes must be a multiple of 32-bit words"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if USBH_LLD_DEBUG_ENABLE_TRACE
|
||||
#define udbgf(f, ...) usbDbgPrintf(f, ##__VA_ARGS__)
|
||||
#define udbg(f, ...) usbDbgPuts(f, ##__VA_ARGS__)
|
||||
|
@ -492,7 +539,7 @@ static uint32_t _write_packet(struct list_head *list, uint32_t space_available)
|
|||
|
||||
void usbh_lld_ep_object_init(usbh_ep_t *ep) {
|
||||
/* CTRL(IN) CTRL(OUT) INT(IN) INT(OUT) BULK(IN) BULK(OUT) ISO(IN) ISO(OUT)
|
||||
* STALL si sólo DAT/STAT si si si si no no ep->type != ISO && (ep->type != CTRL || ctrlphase != SETUP)
|
||||
* STALL si solo DAT/STAT si si si si no no ep->type != ISO && (ep->type != CTRL || ctrlphase != SETUP)
|
||||
* ACK si si si si si si no no ep->type != ISO
|
||||
* NAK si si si si si si no no ep->type != ISO
|
||||
* BBERR si no si no si no si no ep->in
|
||||
|
@ -563,6 +610,11 @@ void usbh_lld_ep_close(usbh_ep_t *ep) {
|
|||
osalOsRescheduleS();
|
||||
}
|
||||
|
||||
bool usbh_lld_ep_reset(usbh_ep_t *ep) {
|
||||
ep->dt_mask = HCTSIZ_DPID_DATA0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void usbh_lld_urb_submit(usbh_urb_t *urb) {
|
||||
usbh_ep_t *const ep = urb->ep;
|
||||
|
||||
|
@ -596,17 +648,20 @@ bool usbh_lld_urb_abort(usbh_urb_t *urb, usbh_urbstatus_t status) {
|
|||
|
||||
if (hcm->halt_reason == USBH_LLD_HALTREASON_NONE) {
|
||||
/* The channel is not being halted */
|
||||
uinfof("\t%s: usbh_lld_urb_abort: channel is not being halted", hcm->ep->name);
|
||||
urb->status = status;
|
||||
_halt_channel(ep->device->host, hcm, USBH_LLD_HALTREASON_ABORT);
|
||||
} else {
|
||||
/* The channel is being halted, so we can't re-halt it. The CHH interrupt will
|
||||
* be in charge of completing the transfer, but the URB will not have the specified status.
|
||||
*/
|
||||
uinfof("\t%s: usbh_lld_urb_abort: channel is being halted", hcm->ep->name);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* This URB is active, we can cancel it now */
|
||||
uinfof("\t%s: usbh_lld_urb_abort: URB is not active", hcm->ep->name);
|
||||
_transfer_completedI(ep, urb, status);
|
||||
|
||||
return TRUE;
|
||||
|
@ -855,8 +910,12 @@ static inline void _chh_int(USBHDriver *host, stm32_hc_management_t *hcm, stm32_
|
|||
break;
|
||||
|
||||
case USBH_LLD_HALTREASON_STALL:
|
||||
if ((ep->type == USBH_EPTYPE_CTRL) && (ep->xfer.u.ctrl_phase == USBH_LLD_CTRLPHASE_SETUP)) {
|
||||
uerrf("\t%s: Faulty device: STALLed SETUP phase", ep->name);
|
||||
if (ep->type == USBH_EPTYPE_CTRL) {
|
||||
if (ep->xfer.u.ctrl_phase == USBH_LLD_CTRLPHASE_SETUP) {
|
||||
uerrf("\t%s: Faulty device: STALLed SETUP phase", ep->name);
|
||||
}
|
||||
} else {
|
||||
ep->status = USBH_EPSTATUS_HALTED;
|
||||
}
|
||||
_transfer_completed(ep, urb, USBH_URBSTATUS_STALL);
|
||||
break;
|
||||
|
@ -926,10 +985,15 @@ static inline void _hcint_int(USBHDriver *host) {
|
|||
haint = host->otg->HAINT;
|
||||
haint &= host->otg->HAINTMSK;
|
||||
|
||||
#if USBH_LLD_DEBUG_ENABLE_ERRORS
|
||||
if (!haint) {
|
||||
uerrf("HAINT=%08x, HAINTMSK=%08x", host->otg->HAINT, host->otg->HAINTMSK);
|
||||
uint32_t a, b;
|
||||
a = host->otg->HAINT;
|
||||
b = host->otg->HAINTMSK;
|
||||
uerrf("HAINT=%08x, HAINTMSK=%08x", a, b);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 1 //channel lookup loop
|
||||
uint8_t i;
|
||||
|
@ -1186,11 +1250,17 @@ static void usb_lld_serve_interrupt(USBHDriver *host) {
|
|||
}
|
||||
|
||||
gintsts &= otg->GINTMSK;
|
||||
#if USBH_DEBUG_ENABLE_WARNINGS
|
||||
if (!gintsts) {
|
||||
uwarnf("GINTSTS=%08x, GINTMSK=%08x", otg->GINTSTS, otg->GINTMSK);
|
||||
uint32_t a, b;
|
||||
a = otg->GINTSTS;
|
||||
b = otg->GINTMSK;
|
||||
uwarnf("GINTSTS=%08x, GINTMSK=%08x", a, b);
|
||||
return;
|
||||
}
|
||||
// otg->GINTMSK &= ~(GINTMSK_NPTXFEM | GINTMSK_PTXFEM);
|
||||
#endif
|
||||
|
||||
// otg->GINTMSK &= ~(GINTMSK_NPTXFEM | GINTMSK_PTXFEM);
|
||||
otg->GINTSTS = gintsts;
|
||||
|
||||
if (gintsts & GINTSTS_SOF)
|
||||
|
@ -1437,6 +1507,7 @@ static void _usbh_start(USBHDriver *usbh) {
|
|||
}
|
||||
#endif
|
||||
#endif
|
||||
#undef HNPTXFSIZ
|
||||
|
||||
otg_txfifo_flush(usbh, 0x10);
|
||||
otg_rxfifo_flush(usbh);
|
||||
|
@ -1478,18 +1549,18 @@ usbh_urbstatus_t usbh_lld_root_hub_request(USBHDriver *usbh, uint8_t bmRequestTy
|
|||
break;
|
||||
|
||||
case ClearPortFeature:
|
||||
chDbgAssert(windex == 1, "invalid windex");
|
||||
osalDbgAssert(windex == 1, "invalid windex");
|
||||
|
||||
osalSysLock();
|
||||
switch (wvalue) {
|
||||
case USBH_PORT_FEAT_ENABLE:
|
||||
case USBH_PORT_FEAT_SUSPEND:
|
||||
case USBH_PORT_FEAT_POWER:
|
||||
chDbgAssert(0, "unimplemented"); /* TODO */
|
||||
osalDbgAssert(0, "unimplemented"); /* TODO */
|
||||
break;
|
||||
|
||||
case USBH_PORT_FEAT_INDICATOR:
|
||||
chDbgAssert(0, "unsupported");
|
||||
osalDbgAssert(0, "unsupported");
|
||||
break;
|
||||
|
||||
case USBH_PORT_FEAT_C_CONNECTION:
|
||||
|
@ -1541,7 +1612,7 @@ usbh_urbstatus_t usbh_lld_root_hub_request(USBHDriver *usbh, uint8_t bmRequestTy
|
|||
break;
|
||||
|
||||
case GetPortStatus:
|
||||
chDbgAssert(windex == 1, "invalid windex");
|
||||
osalDbgAssert(windex == 1, "invalid windex");
|
||||
osalDbgCheck(wlength >= 4);
|
||||
osalSysLock();
|
||||
*(uint32_t *)buf = usbh->rootport.lld_status | (usbh->rootport.lld_c_status << 16);
|
||||
|
@ -1550,17 +1621,17 @@ usbh_urbstatus_t usbh_lld_root_hub_request(USBHDriver *usbh, uint8_t bmRequestTy
|
|||
break;
|
||||
|
||||
case SetHubFeature:
|
||||
chDbgAssert(0, "unsupported");
|
||||
osalDbgAssert(0, "unsupported");
|
||||
break;
|
||||
|
||||
case SetPortFeature:
|
||||
chDbgAssert(windex == 1, "invalid windex");
|
||||
osalDbgAssert(windex == 1, "invalid windex");
|
||||
|
||||
switch (wvalue) {
|
||||
case USBH_PORT_FEAT_TEST:
|
||||
case USBH_PORT_FEAT_SUSPEND:
|
||||
case USBH_PORT_FEAT_POWER:
|
||||
chDbgAssert(0, "unimplemented"); /* TODO */
|
||||
osalDbgAssert(0, "unimplemented"); /* TODO */
|
||||
break;
|
||||
|
||||
case USBH_PORT_FEAT_RESET: {
|
||||
|
@ -1580,7 +1651,7 @@ usbh_urbstatus_t usbh_lld_root_hub_request(USBHDriver *usbh, uint8_t bmRequestTy
|
|||
} break;
|
||||
|
||||
case USBH_PORT_FEAT_INDICATOR:
|
||||
chDbgAssert(0, "unsupported");
|
||||
osalDbgAssert(0, "unsupported");
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -127,25 +127,26 @@ typedef struct stm32_hc_management {
|
|||
"use USBH_DEFINE_BUFFER() to declare the IO buffers"); \
|
||||
} while (0)
|
||||
|
||||
|
||||
|
||||
void usbh_lld_init(void);
|
||||
void usbh_lld_start(USBHDriver *usbh);
|
||||
void usbh_lld_ep_object_init(usbh_ep_t *ep);
|
||||
void usbh_lld_ep_open(usbh_ep_t *ep);
|
||||
void usbh_lld_ep_close(usbh_ep_t *ep);
|
||||
bool usbh_lld_ep_reset(usbh_ep_t *ep);
|
||||
void usbh_lld_urb_submit(usbh_urb_t *urb);
|
||||
bool usbh_lld_urb_abort(usbh_urb_t *urb, usbh_urbstatus_t status);
|
||||
usbh_urbstatus_t usbh_lld_root_hub_request(USBHDriver *usbh, uint8_t bmRequestType, uint8_t bRequest,
|
||||
uint16_t wvalue, uint16_t windex, uint16_t wlength, uint8_t *buf);
|
||||
uint8_t usbh_lld_roothub_get_statuschange_bitmap(USBHDriver *usbh);
|
||||
|
||||
#define usbh_lld_epreset(ep) do {(ep)->dt_mask = HCTSIZ_DPID_DATA0;} while (0);
|
||||
|
||||
#ifdef __IAR_SYSTEMS_ICC__
|
||||
#define USBH_LLD_DEFINE_BUFFER(type, name) type name
|
||||
#define USBH_LLD_DEFINE_BUFFER(var) _Pragma("data_alignment=4") var
|
||||
#define USBH_LLD_DECLARE_STRUCT_MEMBER_H1(x, y) x ## y
|
||||
#define USBH_LLD_DECLARE_STRUCT_MEMBER_H2(x, y) USBH_LLD_DECLARE_STRUCT_MEMBER_H1(x, y)
|
||||
#define USBH_LLD_DECLARE_STRUCT_MEMBER(member) unsigned int USBH_LLD_DECLARE_STRUCT_MEMBER_H2(dummy_align_, __COUNTER__); member
|
||||
#else
|
||||
#define USBH_LLD_DEFINE_BUFFER(type, name) type name __attribute__((aligned(4)))
|
||||
#define USBH_LLD_DEFINE_BUFFER(var) var __attribute__((aligned(4)))
|
||||
#define USBH_LLD_DECLARE_STRUCT_MEMBER(member) member __attribute__((aligned(4)))
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -19,10 +19,14 @@
|
|||
|
||||
#if HAL_USE_USBH
|
||||
|
||||
#include "usbh/dev/hub.h"
|
||||
#include "usbh/internal.h"
|
||||
#include <string.h>
|
||||
|
||||
//devices
|
||||
#include "usbh/dev/hub.h"
|
||||
#include "usbh/dev/ftdi.h"
|
||||
#include "usbh/dev/msd.h"
|
||||
|
||||
#if USBH_DEBUG_ENABLE_TRACE
|
||||
#define udbgf(f, ...) usbDbgPrintf(f, ##__VA_ARGS__)
|
||||
#define udbg(f, ...) usbDbgPuts(f, ##__VA_ARGS__)
|
||||
|
@ -107,11 +111,14 @@ void usbhObjectInit(USBHDriver *usbh) {
|
|||
}
|
||||
|
||||
void usbhInit(void) {
|
||||
#if HAL_USBH_USE_FTDI
|
||||
usbhftdiInit();
|
||||
#endif
|
||||
#if HAL_USBH_USE_MSD
|
||||
usbhmsdInit();
|
||||
#endif
|
||||
#if HAL_USBH_USE_HUB
|
||||
uint8_t i;
|
||||
for (i = 0; i < HAL_USBHHUB_MAX_INSTANCES; i++) {
|
||||
usbhhubObjectInit(&USBHHUBD[i]);
|
||||
}
|
||||
usbhhubInit();
|
||||
#endif
|
||||
usbh_lld_init();
|
||||
}
|
||||
|
@ -128,7 +135,6 @@ void usbhStart(USBHDriver *usbh) {
|
|||
osalSysUnlock();
|
||||
}
|
||||
|
||||
|
||||
void usbhStop(USBHDriver *usbh) {
|
||||
//TODO: implement
|
||||
(void)usbh;
|
||||
|
@ -181,6 +187,22 @@ static void _ep0_object_init(usbh_device_t *dev, uint16_t wMaxPacketSize) {
|
|||
usbhEPSetName(&dev->ctrl, "DEV[CTRL]");
|
||||
}
|
||||
|
||||
bool usbhEPResetS(usbh_ep_t *ep) {
|
||||
osalDbgCheckClassS();
|
||||
osalDbgCheck(ep != NULL);
|
||||
osalDbgAssert((ep->status == USBH_EPSTATUS_OPEN) || (ep->status == USBH_EPSTATUS_HALTED), "invalid state");
|
||||
osalDbgAssert(ep->type != USBH_EPTYPE_CTRL, "don't need to reset control endpoint");
|
||||
|
||||
usbh_urbstatus_t ret = usbhControlRequest(ep->device,
|
||||
USBH_STANDARDOUT(USBH_REQTYPE_ENDPOINT, USBH_REQ_CLEAR_FEATURE, 0, ep->address | (ep->in ? 0x80 : 0x00)),
|
||||
0, 0);
|
||||
|
||||
/* TODO: GET_STATUS to see if endpoint is still halted */
|
||||
if ((ret == USBH_URBSTATUS_OK) && usbh_lld_ep_reset(ep)) {
|
||||
return HAL_SUCCESS;
|
||||
}
|
||||
return HAL_FAILED;
|
||||
}
|
||||
|
||||
/*===========================================================================*/
|
||||
/* URB API. */
|
||||
|
@ -258,7 +280,6 @@ bool _usbh_urb_abortI(usbh_urb_t *urb, usbh_urbstatus_t status) {
|
|||
_usbh_urb_completeI(urb, status);
|
||||
return TRUE;
|
||||
|
||||
// case USBH_URBSTATUS_QUEUED:
|
||||
case USBH_URBSTATUS_PENDING:
|
||||
return usbh_lld_urb_abort(urb, status);
|
||||
}
|
||||
|
@ -271,11 +292,18 @@ void _usbh_urb_abort_and_waitS(usbh_urb_t *urb, usbh_urbstatus_t status) {
|
|||
if (_usbh_urb_abortI(urb, status) == FALSE) {
|
||||
uwarn("URB wasn't aborted immediately, suspend");
|
||||
osalThreadSuspendS(&urb->abortingThread);
|
||||
urb->abortingThread = 0;
|
||||
} else {
|
||||
osalDbgAssert(urb->abortingThread == 0, "maybe we should uncomment the line below");
|
||||
//urb->abortingThread = 0;
|
||||
}
|
||||
#if !(USBH_DEBUG_ENABLE && USBH_DEBUG_ENABLE_WARNINGS)
|
||||
else {
|
||||
osalOsRescheduleS();
|
||||
}
|
||||
#else
|
||||
uwarn("URB aborted");
|
||||
osalOsRescheduleS(); /* debug printing functions call I-class functions inside
|
||||
which may cause a priority violation without this call */
|
||||
#endif
|
||||
}
|
||||
|
||||
bool usbhURBCancelI(usbh_urb_t *urb) {
|
||||
|
@ -295,9 +323,9 @@ msg_t usbhURBWaitTimeoutS(usbh_urb_t *urb, systime_t timeout) {
|
|||
switch (urb->status) {
|
||||
case USBH_URBSTATUS_INITIALIZED:
|
||||
case USBH_URBSTATUS_PENDING:
|
||||
// case USBH_URBSTATUS_QUEUED:
|
||||
ret = osalThreadSuspendTimeoutS(&urb->waitingThread, timeout);
|
||||
urb->waitingThread = 0;
|
||||
osalDbgAssert(urb->waitingThread == 0, "maybe we should uncomment the line below");
|
||||
//urb->waitingThread = 0;
|
||||
break;
|
||||
|
||||
case USBH_URBSTATUS_OK:
|
||||
|
@ -408,7 +436,7 @@ usbh_urbstatus_t usbhControlRequest(usbh_device_t *dev,
|
|||
uint16_t wLength,
|
||||
uint8_t *buff) {
|
||||
|
||||
const USBH_DEFINE_BUFFER(usbh_control_request_t, req) = {
|
||||
USBH_DEFINE_BUFFER(const usbh_control_request_t req) = {
|
||||
bmRequestType,
|
||||
bRequest,
|
||||
wValue,
|
||||
|
@ -511,7 +539,7 @@ bool usbhStdReqGetInterface(usbh_device_t *dev,
|
|||
uint8_t bInterfaceNumber,
|
||||
uint8_t *bAlternateSetting) {
|
||||
|
||||
USBH_DEFINE_BUFFER(uint8_t, alt);
|
||||
USBH_DEFINE_BUFFER(uint8_t alt);
|
||||
|
||||
usbh_urbstatus_t ret = usbhControlRequest(dev, USBH_GET_INTERFACE(bInterfaceNumber), 1, &alt);
|
||||
if (ret != USBH_URBSTATUS_OK)
|
||||
|
@ -720,7 +748,7 @@ static bool _device_enumerate(usbh_device_t *dev) {
|
|||
|
||||
#if USBH_DEBUG_ENABLE && USBH_DEBUG_ENABLE_INFO
|
||||
void usbhDevicePrintInfo(usbh_device_t *dev) {
|
||||
USBH_DEFINE_BUFFER(char, str[64]);
|
||||
USBH_DEFINE_BUFFER(char str[64]);
|
||||
usbh_device_descriptor_t *const desc = &dev->devDesc;
|
||||
|
||||
uinfo("----- Device info -----");
|
||||
|
@ -934,7 +962,7 @@ static void _port_connected(usbh_port_t *port) {
|
|||
uint8_t i;
|
||||
uint8_t retries;
|
||||
usbh_devspeed_t speed;
|
||||
USBH_DEFINE_BUFFER(usbh_string_descriptor_t, strdesc);
|
||||
USBH_DEFINE_BUFFER(usbh_string_descriptor_t strdesc);
|
||||
|
||||
uinfof("Port %d connected, wait debounce...", port->number);
|
||||
|
||||
|
@ -1313,9 +1341,11 @@ static bool _classdriver_load(usbh_device_t *dev, uint8_t class,
|
|||
|
||||
success:
|
||||
/* Link this driver to the device */
|
||||
drv->next = dev->drivers;
|
||||
dev->drivers = drv;
|
||||
drv->dev = dev;
|
||||
if (!drv->dev) {
|
||||
drv->next = dev->drivers;
|
||||
dev->drivers = drv;
|
||||
drv->dev = dev;
|
||||
}
|
||||
return HAL_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,15 +17,13 @@
|
|||
|
||||
#include "hal.h"
|
||||
|
||||
#if HAL_USE_USBH
|
||||
#if HAL_USE_USBH && USBH_DEBUG_ENABLE
|
||||
|
||||
#include "ch.h"
|
||||
#include "usbh/debug.h"
|
||||
#include <stdarg.h>
|
||||
#include "chprintf.h"
|
||||
|
||||
#if USBH_DEBUG_ENABLE
|
||||
|
||||
#define MAX_FILLER 11
|
||||
#define FLOAT_PRECISION 9
|
||||
#define MPRINTF_USE_FLOAT 0
|
||||
|
@ -472,8 +470,8 @@ void usbDbgSystemHalted(void) {
|
|||
}
|
||||
}
|
||||
|
||||
static void usb_debug_thread(void *p) {
|
||||
USBHDriver *host = (USBHDriver *)p;
|
||||
static void usb_debug_thread(void *arg) {
|
||||
USBHDriver *host = (USBHDriver *)arg;
|
||||
uint8_t state = 0;
|
||||
|
||||
chRegSetThreadName("USBH_DBG");
|
||||
|
@ -531,6 +529,5 @@ void usbDbgInit(USBHDriver *host) {
|
|||
iqObjectInit(&USBH_DEBUG_USBHD.iq, USBH_DEBUG_USBHD.dbg_buff, sizeof(USBH_DEBUG_USBHD.dbg_buff), 0, 0);
|
||||
chThdCreateStatic(USBH_DEBUG_USBHD.waDebug, sizeof(USBH_DEBUG_USBHD.waDebug), NORMALPRIO, usb_debug_thread, &USBH_DEBUG_USBHD);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -134,22 +134,18 @@ void cs_iter_next(generic_iterator_t *ics) {
|
|||
if ((curr[0] < 2) || (rem < 2) || (rem < curr[0]))
|
||||
return;
|
||||
|
||||
//for (;;) {
|
||||
rem -= curr[0];
|
||||
curr += curr[0];
|
||||
rem -= curr[0];
|
||||
curr += curr[0];
|
||||
|
||||
if ((curr[0] < 2) || (rem < 2) || (rem < curr[0]))
|
||||
return;
|
||||
if ((curr[0] < 2) || (rem < 2) || (rem < curr[0]))
|
||||
return;
|
||||
|
||||
if ((curr[1] == USBH_DT_INTERFACE_ASSOCIATION)
|
||||
|| (curr[1] == USBH_DT_INTERFACE)
|
||||
|| (curr[1] == USBH_DT_CONFIG)
|
||||
|| (curr[1] == USBH_DT_ENDPOINT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// break;
|
||||
//}
|
||||
if ((curr[1] == USBH_DT_INTERFACE_ASSOCIATION)
|
||||
|| (curr[1] == USBH_DT_INTERFACE)
|
||||
|| (curr[1] == USBH_DT_CONFIG)
|
||||
|| (curr[1] == USBH_DT_ENDPOINT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ics->valid = 1;
|
||||
ics->rem = rem;
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
|
||||
#include "hal.h"
|
||||
#include "hal_usbh.h"
|
||||
|
||||
#if HAL_USBH_USE_FTDI
|
||||
|
||||
|
@ -114,8 +113,7 @@ static usbh_baseclassdriver_t *_ftdi_load(usbh_device_t *dev, const uint8_t *des
|
|||
if ((rem < descriptor[0]) || (descriptor[1] != USBH_DT_INTERFACE))
|
||||
return NULL;
|
||||
|
||||
const usbh_interface_descriptor_t * const ifdesc = (const usbh_interface_descriptor_t * const)descriptor;
|
||||
if (ifdesc->bInterfaceNumber != 0) {
|
||||
if (((const usbh_interface_descriptor_t *)descriptor)->bInterfaceNumber != 0) {
|
||||
uwarn("FTDI: Will allocate driver along with IF #0");
|
||||
}
|
||||
|
||||
|
@ -324,7 +322,7 @@ static usbh_urbstatus_t _ftdi_port_control(USBHFTDIPortDriver *ftdipp,
|
|||
osalDbgCheck(bRequest < sizeof_array(bmRequestType));
|
||||
osalDbgCheck(bRequest != 1);
|
||||
|
||||
const USBH_DEFINE_BUFFER(usbh_control_request_t, req) = {
|
||||
USBH_DEFINE_BUFFER(const usbh_control_request_t req) = {
|
||||
bmRequestType[bRequest],
|
||||
bRequest,
|
||||
wValue,
|
||||
|
@ -387,7 +385,7 @@ static usbh_urbstatus_t _set_baudrate(USBHFTDIPortDriver *ftdipp, uint32_t baudr
|
|||
if (ftdipp->ftdip->dev->basicConfigDesc.bNumInterfaces > 1)
|
||||
wIndex = (wIndex << 8) | (ftdipp->ifnum + 1);
|
||||
|
||||
const USBH_DEFINE_BUFFER(usbh_control_request_t, req) = {
|
||||
USBH_DEFINE_BUFFER(const usbh_control_request_t req) = {
|
||||
USBH_REQTYPE_VENDOR | USBH_REQTYPE_OUT | USBH_REQTYPE_DEVICE,
|
||||
FTDI_COMMAND_SETBAUD,
|
||||
wValue,
|
||||
|
@ -714,4 +712,14 @@ void usbhftdipObjectInit(USBHFTDIPortDriver *ftdipp) {
|
|||
ftdipp->state = USBHFTDIP_STATE_STOP;
|
||||
}
|
||||
|
||||
void usbhftdiInit(void) {
|
||||
uint8_t i;
|
||||
for (i = 0; i < HAL_USBHFTDI_MAX_INSTANCES; i++) {
|
||||
usbhftdiObjectInit(&USBHFTDID[i]);
|
||||
}
|
||||
for (i = 0; i < HAL_USBHFTDI_MAX_PORTS; i++) {
|
||||
usbhftdipObjectInit(&FTDIPD[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -15,10 +15,7 @@
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "hal.h"
|
||||
#include "hal_usbh.h"
|
||||
#include "usbh/internal.h"
|
||||
|
||||
#if HAL_USBH_USE_HUB
|
||||
|
||||
|
@ -28,6 +25,7 @@
|
|||
|
||||
#include <string.h>
|
||||
#include "usbh/dev/hub.h"
|
||||
#include "usbh/internal.h"
|
||||
|
||||
#if USBHHUB_DEBUG_ENABLE_TRACE
|
||||
#define udbgf(f, ...) usbDbgPrintf(f, ##__VA_ARGS__)
|
||||
|
@ -63,7 +61,7 @@
|
|||
|
||||
|
||||
USBHHubDriver USBHHUBD[HAL_USBHHUB_MAX_INSTANCES];
|
||||
usbh_port_t USBHPorts[HAL_USBHHUB_MAX_PORTS];
|
||||
static usbh_port_t USBHPorts[HAL_USBHHUB_MAX_PORTS];
|
||||
|
||||
static usbh_baseclassdriver_t *hub_load(usbh_device_t *dev, const uint8_t *descriptor, uint16_t rem);
|
||||
static void hub_unload(usbh_baseclassdriver_t *drv);
|
||||
|
@ -290,9 +288,18 @@ void usbhhubObjectInit(USBHHubDriver *hubdp) {
|
|||
memset(hubdp, 0, sizeof(*hubdp));
|
||||
hubdp->info = &usbhhubClassDriverInfo;
|
||||
}
|
||||
|
||||
void usbhhubInit(void) {
|
||||
uint8_t i;
|
||||
for (i = 0; i < HAL_USBHHUB_MAX_INSTANCES; i++) {
|
||||
usbhhubObjectInit(&USBHHUBD[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#if HAL_USE_USBH
|
||||
#include <string.h>
|
||||
void _usbhub_port_object_init(usbh_port_t *port, USBHDriver *usbh, uint8_t number) {
|
||||
memset(port, 0, sizeof(*port));
|
||||
port->number = number;
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
|
||||
#include "hal.h"
|
||||
#include "hal_usbh.h"
|
||||
|
||||
#if HAL_USBH_USE_MSD
|
||||
|
||||
|
@ -91,8 +90,8 @@ const usbh_classdriverinfo_t usbhmsdClassDriverInfo = {
|
|||
static usbh_baseclassdriver_t *_msd_load(usbh_device_t *dev, const uint8_t *descriptor, uint16_t rem) {
|
||||
int i;
|
||||
USBHMassStorageDriver *msdp;
|
||||
uint8_t luns; // should declare it here to eliminate 'control bypass initialization' warning
|
||||
usbh_urbstatus_t stat; // should declare it here to eliminate 'control bypass initialization' warning
|
||||
uint8_t luns;
|
||||
usbh_urbstatus_t stat;
|
||||
|
||||
if ((rem < descriptor[0]) || (descriptor[1] != USBH_DT_INTERFACE))
|
||||
return NULL;
|
||||
|
@ -157,7 +156,7 @@ alloc_ok:
|
|||
|
||||
/* read the number of LUNs */
|
||||
uinfo("Reading Max LUN:");
|
||||
USBH_DEFINE_BUFFER(uint8_t, buff[4]);
|
||||
USBH_DEFINE_BUFFER(uint8_t buff[4]);
|
||||
stat = usbhControlRequest(dev,
|
||||
USBH_CLASSIN(USBH_REQTYPE_INTERFACE, MSD_GET_MAX_LUN, 0, msdp->ifnum),
|
||||
1, buff);
|
||||
|
@ -240,7 +239,7 @@ static void _msd_unload(usbh_baseclassdriver_t *drv) {
|
|||
|
||||
|
||||
/* USB Bulk Only Transport SCSI Command block wrapper */
|
||||
PACKED_STRUCT {
|
||||
typedef PACKED_STRUCT {
|
||||
uint32_t dCBWSignature;
|
||||
uint32_t dCBWTag;
|
||||
uint32_t dCBWDataTransferLength;
|
||||
|
@ -253,9 +252,8 @@ PACKED_STRUCT {
|
|||
#define MSD_CBWFLAGS_D2H 0x80
|
||||
#define MSD_CBWFLAGS_H2D 0x00
|
||||
|
||||
|
||||
/* USB Bulk Only Transport SCSI Command status wrapper */
|
||||
PACKED_STRUCT {
|
||||
typedef PACKED_STRUCT {
|
||||
uint32_t dCSWSignature;
|
||||
uint32_t dCSWTag;
|
||||
uint32_t dCSWDataResidue;
|
||||
|
@ -299,7 +297,7 @@ typedef struct {
|
|||
|
||||
/* Request sense */
|
||||
#define SCSI_CMD_REQUEST_SENSE 0x03
|
||||
PACKED_STRUCT {
|
||||
typedef PACKED_STRUCT {
|
||||
uint8_t byte[18];
|
||||
} scsi_sense_response_t;
|
||||
|
||||
|
@ -333,7 +331,7 @@ PACKED_STRUCT {
|
|||
|
||||
/* Inquiry */
|
||||
#define SCSI_CMD_INQUIRY 0x12
|
||||
PACKED_STRUCT {
|
||||
typedef PACKED_STRUCT {
|
||||
uint8_t peripheral;
|
||||
uint8_t removable;
|
||||
uint8_t version;
|
||||
|
@ -349,14 +347,14 @@ PACKED_STRUCT {
|
|||
|
||||
/* Read Capacity 10 */
|
||||
#define SCSI_CMD_READ_CAPACITY_10 0x25
|
||||
PACKED_STRUCT {
|
||||
typedef PACKED_STRUCT {
|
||||
uint32_t last_block_addr;
|
||||
uint32_t block_size;
|
||||
} scsi_readcapacity10_response_t;
|
||||
|
||||
/* Start/Stop Unit */
|
||||
#define SCSI_CMD_START_STOP_UNIT 0x1B
|
||||
PACKED_STRUCT {
|
||||
typedef PACKED_STRUCT {
|
||||
uint8_t op_code;
|
||||
uint8_t lun_immed;
|
||||
uint8_t res1;
|
||||
|
@ -682,7 +680,7 @@ bool usbhmsdLUNConnect(USBHMassStorageLUNDriver *lunp) {
|
|||
|
||||
USBH_DEFINE_BUFFER(union {
|
||||
scsi_inquiry_response_t inq;
|
||||
scsi_readcapacity10_response_t cap; }, u);
|
||||
scsi_readcapacity10_response_t cap; } u);
|
||||
|
||||
uinfo("INQUIRY...");
|
||||
res = scsi_inquiry(lunp, &u.inq);
|
||||
|
@ -936,4 +934,13 @@ void usbhmsdObjectInit(USBHMassStorageDriver *msdp) {
|
|||
osalMutexObjectInit(&msdp->mtx);
|
||||
}
|
||||
|
||||
void usbhmsdInit(void) {
|
||||
uint8_t i;
|
||||
for (i = 0; i < HAL_USBHMSD_MAX_INSTANCES; i++) {
|
||||
usbhmsdObjectInit(&USBHMSD[i]);
|
||||
}
|
||||
for (i = 0; i < HAL_USBHMSD_MAX_LUNS; i++) {
|
||||
usbhmsdLUNObjectInit(&MSBLKD[i]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
# FATFS files.
|
||||
FATFSSRC = ${CHIBIOS_CONTRIB}/os/various/fatfs_bindings/fatfs_diskio.c \
|
||||
${CHIBIOS}/os/various/fatfs_bindings/fatfs_syscall.c \
|
||||
${CHIBIOS}/ext/fatfs/src/ff.c \
|
||||
${CHIBIOS}/ext/fatfs/src/option/unicode.c
|
||||
|
||||
FATFSINC = ${CHIBIOS}/ext/fatfs/src
|
|
@ -0,0 +1,320 @@
|
|||
/*-----------------------------------------------------------------------*/
|
||||
/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2007 */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* This is a stub disk I/O module that acts as front end of the existing */
|
||||
/* disk I/O modules and attach it to FatFs module with common interface. */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
#include "hal.h"
|
||||
#include "ffconf.h"
|
||||
#include "diskio.h"
|
||||
#include "usbh/dev/msd.h"
|
||||
|
||||
#if HAL_USE_MMC_SPI && HAL_USE_SDC
|
||||
#error "cannot specify both MMC_SPI and SDC drivers"
|
||||
#endif
|
||||
|
||||
#if HAL_USE_MMC_SPI
|
||||
extern MMCDriver MMCD1;
|
||||
#elif HAL_USE_SDC
|
||||
extern SDCDriver SDCD1;
|
||||
#elif HAL_USBH_USE_MSD
|
||||
|
||||
#else
|
||||
#error "MMC_SPI, SDC or USBH_MSD driver must be specified"
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Correspondence between physical drive number and physical drive. */
|
||||
#if HAL_USE_MMC_SPI
|
||||
#define MMC 0
|
||||
#endif
|
||||
|
||||
#if HAL_USE_SDC
|
||||
#define SDC 0
|
||||
#endif
|
||||
|
||||
#if HAL_USBH_USE_MSD
|
||||
#if defined(MMC) || defined(SDC)
|
||||
#define MSDLUN0 1
|
||||
#else
|
||||
#define MSDLUN0 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Inidialize a Drive */
|
||||
|
||||
DSTATUS disk_initialize (
|
||||
BYTE pdrv /* Physical drive nmuber (0..) */
|
||||
)
|
||||
{
|
||||
DSTATUS stat;
|
||||
|
||||
switch (pdrv) {
|
||||
#if HAL_USE_MMC_SPI
|
||||
case MMC:
|
||||
stat = 0;
|
||||
/* It is initialized externally, just reads the status.*/
|
||||
if (blkGetDriverState(&MMCD1) != BLK_READY)
|
||||
stat |= STA_NOINIT;
|
||||
if (mmcIsWriteProtected(&MMCD1))
|
||||
stat |= STA_PROTECT;
|
||||
return stat;
|
||||
#elif HAL_USE_SDC
|
||||
case SDC:
|
||||
stat = 0;
|
||||
/* It is initialized externally, just reads the status.*/
|
||||
if (blkGetDriverState(&SDCD1) != BLK_READY)
|
||||
stat |= STA_NOINIT;
|
||||
if (sdcIsWriteProtected(&SDCD1))
|
||||
stat |= STA_PROTECT;
|
||||
return stat;
|
||||
#endif
|
||||
#if HAL_USBH_USE_MSD
|
||||
case MSDLUN0:
|
||||
stat = 0;
|
||||
/* It is initialized externally, just reads the status.*/
|
||||
if (blkGetDriverState(&MSBLKD[0]) != BLK_READY)
|
||||
stat |= STA_NOINIT;
|
||||
return stat;
|
||||
#endif
|
||||
}
|
||||
return STA_NOINIT;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Return Disk Status */
|
||||
|
||||
DSTATUS disk_status (
|
||||
BYTE pdrv /* Physical drive nmuber (0..) */
|
||||
)
|
||||
{
|
||||
DSTATUS stat;
|
||||
|
||||
switch (pdrv) {
|
||||
#if HAL_USE_MMC_SPI
|
||||
case MMC:
|
||||
stat = 0;
|
||||
/* It is initialized externally, just reads the status.*/
|
||||
if (blkGetDriverState(&MMCD1) != BLK_READY)
|
||||
stat |= STA_NOINIT;
|
||||
if (mmcIsWriteProtected(&MMCD1))
|
||||
stat |= STA_PROTECT;
|
||||
return stat;
|
||||
#elif HAL_USE_SDC
|
||||
case SDC:
|
||||
stat = 0;
|
||||
/* It is initialized externally, just reads the status.*/
|
||||
if (blkGetDriverState(&SDCD1) != BLK_READY)
|
||||
stat |= STA_NOINIT;
|
||||
if (sdcIsWriteProtected(&SDCD1))
|
||||
stat |= STA_PROTECT;
|
||||
return stat;
|
||||
#endif
|
||||
#if HAL_USBH_USE_MSD
|
||||
case MSDLUN0:
|
||||
stat = 0;
|
||||
/* It is initialized externally, just reads the status.*/
|
||||
if (blkGetDriverState(&MSBLKD[0]) != BLK_READY)
|
||||
stat |= STA_NOINIT;
|
||||
return stat;
|
||||
#endif
|
||||
}
|
||||
return STA_NOINIT;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Read Sector(s) */
|
||||
|
||||
DRESULT disk_read (
|
||||
BYTE pdrv, /* Physical drive nmuber (0..) */
|
||||
BYTE *buff, /* Data buffer to store read data */
|
||||
DWORD sector, /* Sector address (LBA) */
|
||||
UINT count /* Number of sectors to read (1..255) */
|
||||
)
|
||||
{
|
||||
switch (pdrv) {
|
||||
#if HAL_USE_MMC_SPI
|
||||
case MMC:
|
||||
if (blkGetDriverState(&MMCD1) != BLK_READY)
|
||||
return RES_NOTRDY;
|
||||
if (mmcStartSequentialRead(&MMCD1, sector))
|
||||
return RES_ERROR;
|
||||
while (count > 0) {
|
||||
if (mmcSequentialRead(&MMCD1, buff))
|
||||
return RES_ERROR;
|
||||
buff += MMCSD_BLOCK_SIZE;
|
||||
count--;
|
||||
}
|
||||
if (mmcStopSequentialRead(&MMCD1))
|
||||
return RES_ERROR;
|
||||
return RES_OK;
|
||||
#elif HAL_USE_SDC
|
||||
case SDC:
|
||||
if (blkGetDriverState(&SDCD1) != BLK_READY)
|
||||
return RES_NOTRDY;
|
||||
if (sdcRead(&SDCD1, sector, buff, count))
|
||||
return RES_ERROR;
|
||||
return RES_OK;
|
||||
#endif
|
||||
#if HAL_USBH_USE_MSD
|
||||
case MSDLUN0:
|
||||
/* It is initialized externally, just reads the status.*/
|
||||
if (blkGetDriverState(&MSBLKD[0]) != BLK_READY)
|
||||
return RES_NOTRDY;
|
||||
if (usbhmsdLUNRead(&MSBLKD[0], sector, buff, count))
|
||||
return RES_ERROR;
|
||||
return RES_OK;
|
||||
#endif
|
||||
}
|
||||
return RES_PARERR;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Write Sector(s) */
|
||||
|
||||
#if _USE_WRITE
|
||||
DRESULT disk_write (
|
||||
BYTE pdrv, /* Physical drive nmuber (0..) */
|
||||
const BYTE *buff, /* Data to be written */
|
||||
DWORD sector, /* Sector address (LBA) */
|
||||
UINT count /* Number of sectors to write (1..255) */
|
||||
)
|
||||
{
|
||||
switch (pdrv) {
|
||||
#if HAL_USE_MMC_SPI
|
||||
case MMC:
|
||||
if (blkGetDriverState(&MMCD1) != BLK_READY)
|
||||
return RES_NOTRDY;
|
||||
if (mmcIsWriteProtected(&MMCD1))
|
||||
return RES_WRPRT;
|
||||
if (mmcStartSequentialWrite(&MMCD1, sector))
|
||||
return RES_ERROR;
|
||||
while (count > 0) {
|
||||
if (mmcSequentialWrite(&MMCD1, buff))
|
||||
return RES_ERROR;
|
||||
buff += MMCSD_BLOCK_SIZE;
|
||||
count--;
|
||||
}
|
||||
if (mmcStopSequentialWrite(&MMCD1))
|
||||
return RES_ERROR;
|
||||
return RES_OK;
|
||||
#elif HAL_USE_SDC
|
||||
case SDC:
|
||||
if (blkGetDriverState(&SDCD1) != BLK_READY)
|
||||
return RES_NOTRDY;
|
||||
if (sdcWrite(&SDCD1, sector, buff, count))
|
||||
return RES_ERROR;
|
||||
return RES_OK;
|
||||
#endif
|
||||
#if HAL_USBH_USE_MSD
|
||||
case MSDLUN0:
|
||||
/* It is initialized externally, just reads the status.*/
|
||||
if (blkGetDriverState(&MSBLKD[0]) != BLK_READY)
|
||||
return RES_NOTRDY;
|
||||
if (usbhmsdLUNWrite(&MSBLKD[0], sector, buff, count))
|
||||
return RES_ERROR;
|
||||
return RES_OK;
|
||||
#endif
|
||||
}
|
||||
return RES_PARERR;
|
||||
}
|
||||
#endif /* _USE_WRITE */
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Miscellaneous Functions */
|
||||
|
||||
#if _USE_IOCTL
|
||||
DRESULT disk_ioctl (
|
||||
BYTE pdrv, /* Physical drive nmuber (0..) */
|
||||
BYTE cmd, /* Control code */
|
||||
void *buff /* Buffer to send/receive control data */
|
||||
)
|
||||
{
|
||||
switch (pdrv) {
|
||||
#if HAL_USE_MMC_SPI
|
||||
case MMC:
|
||||
switch (cmd) {
|
||||
case CTRL_SYNC:
|
||||
return RES_OK;
|
||||
case GET_SECTOR_SIZE:
|
||||
*((WORD *)buff) = MMCSD_BLOCK_SIZE;
|
||||
return RES_OK;
|
||||
#if _USE_ERASE
|
||||
case CTRL_ERASE_SECTOR:
|
||||
mmcErase(&MMCD1, *((DWORD *)buff), *((DWORD *)buff + 1));
|
||||
return RES_OK;
|
||||
#endif
|
||||
default:
|
||||
return RES_PARERR;
|
||||
}
|
||||
#elif HAL_USE_SDC
|
||||
case SDC:
|
||||
switch (cmd) {
|
||||
case CTRL_SYNC:
|
||||
return RES_OK;
|
||||
case GET_SECTOR_COUNT:
|
||||
*((DWORD *)buff) = mmcsdGetCardCapacity(&SDCD1);
|
||||
return RES_OK;
|
||||
case GET_SECTOR_SIZE:
|
||||
*((WORD *)buff) = MMCSD_BLOCK_SIZE;
|
||||
return RES_OK;
|
||||
case GET_BLOCK_SIZE:
|
||||
*((DWORD *)buff) = 256; /* 512b blocks in one erase block */
|
||||
return RES_OK;
|
||||
#if _USE_ERASE
|
||||
case CTRL_ERASE_SECTOR:
|
||||
sdcErase(&SDCD1, *((DWORD *)buff), *((DWORD *)buff + 1));
|
||||
return RES_OK;
|
||||
#endif
|
||||
default:
|
||||
return RES_PARERR;
|
||||
}
|
||||
#endif
|
||||
#if HAL_USBH_USE_MSD
|
||||
case MSDLUN0:
|
||||
switch (cmd) {
|
||||
case CTRL_SYNC:
|
||||
return RES_OK;
|
||||
case GET_SECTOR_COUNT:
|
||||
*((DWORD *)buff) = MSBLKD[0].info.blk_num;
|
||||
return RES_OK;
|
||||
case GET_SECTOR_SIZE:
|
||||
*((WORD *)buff) = MSBLKD[0].info.blk_size;
|
||||
return RES_OK;
|
||||
#if _USE_ERASE
|
||||
#error "unimplemented yet!"
|
||||
// case CTRL_ERASE_SECTOR:
|
||||
// ....
|
||||
// return RES_OK;
|
||||
#endif
|
||||
default:
|
||||
return RES_PARERR;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return RES_PARERR;
|
||||
}
|
||||
#endif /* _USE_IOCTL */
|
||||
|
||||
DWORD get_fattime(void) {
|
||||
#if HAL_USE_RTC
|
||||
RTCDateTime timespec;
|
||||
|
||||
rtcGetTime(&RTCD1, ×pec);
|
||||
return rtcConvertDateTimeToFAT(×pec);
|
||||
#else
|
||||
return ((uint32_t)0 | (1 << 16)) | (1 << 21); /* wrong but valid time */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
<folderInfo id="0.1003150841." name="/" resourcePath="">
|
||||
<toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.748316353" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
|
||||
<targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.748316353.81353447" name=""/>
|
||||
<builder id="org.eclipse.cdt.build.core.settings.default.builder.1044649944" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
|
||||
<builder arguments="-j8" command="make" id="org.eclipse.cdt.build.core.settings.default.builder.1044649944" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
|
||||
<tool id="org.eclipse.cdt.build.core.settings.holder.libs.883535580" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
|
||||
<tool id="org.eclipse.cdt.build.core.settings.holder.97391908" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
|
||||
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.133315636" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
|
||||
|
@ -39,11 +39,26 @@
|
|||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<project id="STM32F4xx-USB_HOST.null.1232072164" name="STM32F4xx-USB_HOST"/>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||
<storageModule moduleId="refreshScope" versionNumber="2">
|
||||
<configuration configurationName="Default">
|
||||
<resource resourceType="PROJECT" workspacePath="/STM32F4xx-USB_HOST"/>
|
||||
</configuration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="scannerConfiguration">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
<scannerConfigBuildInfo instanceId="0.1003150841">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile"/>
|
||||
<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile">
|
||||
<buildOutputProvider>
|
||||
<openAction enabled="true" filePath="D:/proyectos/ChibiOS-contrib-devel/ChibiOS-Contrib/testhal/STM32/STM32F4xx/USB_HOST/build/ch.elf"/>
|
||||
<parser enabled="true"/>
|
||||
</buildOutputProvider>
|
||||
<scannerInfoProvider id="specsFile">
|
||||
<runAction arguments="-E -P -v -dD "${plugin_state_location}/${specs_file}"" command="arm-none-eabi-gcc" useDefault="true"/>
|
||||
<parser enabled="true"/>
|
||||
</scannerInfoProvider>
|
||||
</profile>
|
||||
</scannerConfigBuildInfo>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||
</cproject>
|
||||
|
|
|
@ -24,4 +24,16 @@
|
|||
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
|
||||
</natures>
|
||||
<linkedResources>
|
||||
<link>
|
||||
<name>ChibiOS-Contrib-os</name>
|
||||
<type>2</type>
|
||||
<locationURI>$%7BPARENT-5-PROJECT_LOC%7D/ChibiOS-contrib/os</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>ChibiOS-RT-os</name>
|
||||
<type>2</type>
|
||||
<locationURI>$%7BPARENT-5-PROJECT_LOC%7D/ChibiOS-RT/os</locationURI>
|
||||
</link>
|
||||
</linkedResources>
|
||||
</projectDescription>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
# Compiler options here.
|
||||
ifeq ($(USE_OPT),)
|
||||
USE_OPT = -Os -ggdb -fomit-frame-pointer -falign-functions=16
|
||||
USE_OPT = -Og -ggdb3 -fomit-frame-pointer -falign-functions=16
|
||||
endif
|
||||
|
||||
# C specific options here (added to USE_OPT).
|
||||
|
@ -30,7 +30,7 @@ endif
|
|||
|
||||
# Enable this if you want link time optimizations (LTO)
|
||||
ifeq ($(USE_LTO),)
|
||||
USE_LTO = yes
|
||||
USE_LTO = no
|
||||
endif
|
||||
|
||||
# If enabled, this option allows to compile the application in THUMB mode.
|
||||
|
@ -89,7 +89,7 @@ PROJECT = ch
|
|||
CHIBIOS = ../../../../../ChibiOS-RT
|
||||
CHIBIOS_CONTRIB = $(CHIBIOS)/../ChibiOS-Contrib
|
||||
# Startup files.
|
||||
include $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f4xx.mk
|
||||
include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/startup_stm32f4xx.mk
|
||||
# HAL-OSAL files (optional).
|
||||
include $(CHIBIOS_CONTRIB)/os/hal/hal.mk
|
||||
include $(CHIBIOS_CONTRIB)/os/hal/ports/STM32/STM32F4xx/platform.mk
|
||||
|
@ -97,12 +97,15 @@ include $(CHIBIOS)/os/hal/boards/ST_STM32F4_DISCOVERY/board.mk
|
|||
include $(CHIBIOS)/os/hal/osal/rt/osal.mk
|
||||
# RTOS files (optional).
|
||||
include $(CHIBIOS)/os/rt/rt.mk
|
||||
include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
|
||||
include $(CHIBIOS)/os/rt/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
|
||||
# Other files (optional).
|
||||
include $(CHIBIOS)/test/rt/test.mk
|
||||
include $(CHIBIOS)/os/hal/lib/streams/streams.mk
|
||||
include $(CHIBIOS)/os/various/shell/shell.mk
|
||||
include $(CHIBIOS)/os/various/fatfs_bindings/fatfs.mk
|
||||
include $(CHIBIOS_CONTRIB)/os/various/fatfs_bindings/fatfs.mk
|
||||
|
||||
STREAMSSRC = $(CHIBIOS)/os/hal/lib/streams/chprintf.c
|
||||
STREAMSINC = $(CHIBIOS)/os/hal/lib/streams/
|
||||
SHELLSRC = $(CHIBIOS)/os/various/shell.c
|
||||
SHELLINC = $(CHIBIOS)/os/various/
|
||||
|
||||
# Define linker script file here
|
||||
LDSCRIPT= $(STARTUPLD)/STM32F407xG.ld
|
||||
|
@ -147,8 +150,7 @@ TCSRC =
|
|||
TCPPSRC =
|
||||
|
||||
# List ASM source files here
|
||||
ASMSRC =
|
||||
ASMXSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
|
||||
ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
|
||||
|
||||
INCDIR = $(CHIBIOS)/os/license \
|
||||
$(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
|
||||
|
@ -222,5 +224,5 @@ ULIBS =
|
|||
# End of user defines
|
||||
##############################################################################
|
||||
|
||||
RULESPATH = $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC
|
||||
RULESPATH = $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC
|
||||
include $(RULESPATH)/rules.mk
|
||||
|
|
|
@ -1,80 +0,0 @@
|
|||
/*-----------------------------------------------------------------------/
|
||||
/ Low level disk interface modlue include file (C)ChaN, 2014 /
|
||||
/-----------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _DISKIO_DEFINED
|
||||
#define _DISKIO_DEFINED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define _USE_WRITE 1 /* 1: Enable disk_write function */
|
||||
#define _USE_IOCTL 1 /* 1: Enable disk_ioctl fucntion */
|
||||
|
||||
#include "integer.h"
|
||||
|
||||
|
||||
/* Status of Disk Functions */
|
||||
typedef BYTE DSTATUS;
|
||||
|
||||
/* Results of Disk Functions */
|
||||
typedef enum {
|
||||
RES_OK = 0, /* 0: Successful */
|
||||
RES_ERROR, /* 1: R/W Error */
|
||||
RES_WRPRT, /* 2: Write Protected */
|
||||
RES_NOTRDY, /* 3: Not Ready */
|
||||
RES_PARERR /* 4: Invalid Parameter */
|
||||
} DRESULT;
|
||||
|
||||
|
||||
/*---------------------------------------*/
|
||||
/* Prototypes for disk control functions */
|
||||
|
||||
|
||||
DSTATUS disk_initialize (BYTE pdrv);
|
||||
DSTATUS disk_status (BYTE pdrv);
|
||||
DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count);
|
||||
DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count);
|
||||
DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
|
||||
|
||||
|
||||
/* Disk Status Bits (DSTATUS) */
|
||||
|
||||
#define STA_NOINIT 0x01 /* Drive not initialized */
|
||||
#define STA_NODISK 0x02 /* No medium in the drive */
|
||||
#define STA_PROTECT 0x04 /* Write protected */
|
||||
|
||||
|
||||
/* Command code for disk_ioctrl fucntion */
|
||||
|
||||
/* Generic command (Used by FatFs) */
|
||||
#define CTRL_SYNC 0 /* Complete pending write process (needed at _FS_READONLY == 0) */
|
||||
#define GET_SECTOR_COUNT 1 /* Get media size (needed at _USE_MKFS == 1) */
|
||||
#define GET_SECTOR_SIZE 2 /* Get sector size (needed at _MAX_SS != _MIN_SS) */
|
||||
#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at _USE_MKFS == 1) */
|
||||
#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */
|
||||
|
||||
/* Generic command (Not used by FatFs) */
|
||||
#define CTRL_POWER 5 /* Get/Set power status */
|
||||
#define CTRL_LOCK 6 /* Lock/Unlock media removal */
|
||||
#define CTRL_EJECT 7 /* Eject media */
|
||||
#define CTRL_FORMAT 8 /* Create physical format on the media */
|
||||
|
||||
/* MMC/SDC specific ioctl command */
|
||||
#define MMC_GET_TYPE 10 /* Get card type */
|
||||
#define MMC_GET_CSD 11 /* Get CSD */
|
||||
#define MMC_GET_CID 12 /* Get CID */
|
||||
#define MMC_GET_OCR 13 /* Get OCR */
|
||||
#define MMC_GET_SDSTAT 14 /* Get SD status */
|
||||
|
||||
/* ATA/CF specific ioctl command */
|
||||
#define ATA_GET_REV 20 /* Get F/W revision */
|
||||
#define ATA_GET_MODEL 21 /* Get model name */
|
||||
#define ATA_GET_SN 22 /* Get serial number */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,143 +0,0 @@
|
|||
/*-----------------------------------------------------------------------*/
|
||||
/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2007 */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* This is a stub disk I/O module that acts as front end of the existing */
|
||||
/* disk I/O modules and attach it to FatFs module with common interface. */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
#include "hal.h"
|
||||
#include "ffconf.h"
|
||||
#include "diskio.h"
|
||||
|
||||
#include "usbh/dev/msd.h"
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Correspondence between physical drive number and physical drive. */
|
||||
#define MSDLUN0 0
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Inidialize a Drive */
|
||||
|
||||
DSTATUS disk_initialize (
|
||||
BYTE pdrv /* Physical drive nmuber (0..) */
|
||||
)
|
||||
{
|
||||
DSTATUS stat;
|
||||
|
||||
switch (pdrv) {
|
||||
case MSDLUN0:
|
||||
stat = 0;
|
||||
/* It is initialized externally, just reads the status.*/
|
||||
if (blkGetDriverState(&MSBLKD[0]) != BLK_READY)
|
||||
stat |= STA_NOINIT;
|
||||
return stat;
|
||||
}
|
||||
return STA_NOINIT;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Return Disk Status */
|
||||
|
||||
DSTATUS disk_status (
|
||||
BYTE pdrv /* Physical drive nmuber (0..) */
|
||||
)
|
||||
{
|
||||
DSTATUS stat;
|
||||
|
||||
switch (pdrv) {
|
||||
case MSDLUN0:
|
||||
stat = 0;
|
||||
/* It is initialized externally, just reads the status.*/
|
||||
if (blkGetDriverState(&MSBLKD[0]) != BLK_READY)
|
||||
stat |= STA_NOINIT;
|
||||
return stat;
|
||||
}
|
||||
return STA_NOINIT;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Read Sector(s) */
|
||||
|
||||
DRESULT disk_read (
|
||||
BYTE pdrv, /* Physical drive nmuber (0..) */
|
||||
BYTE *buff, /* Data buffer to store read data */
|
||||
DWORD sector, /* Sector address (LBA) */
|
||||
UINT count /* Number of sectors to read (1..255) */
|
||||
)
|
||||
{
|
||||
switch (pdrv) {
|
||||
case MSDLUN0:
|
||||
/* It is initialized externally, just reads the status.*/
|
||||
if (blkGetDriverState(&MSBLKD[0]) != BLK_READY)
|
||||
return RES_NOTRDY;
|
||||
if (usbhmsdLUNRead(&MSBLKD[0], sector, buff, count))
|
||||
return RES_ERROR;
|
||||
return RES_OK;
|
||||
}
|
||||
return RES_PARERR;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Write Sector(s) */
|
||||
|
||||
#if _USE_WRITE
|
||||
DRESULT disk_write (
|
||||
BYTE pdrv, /* Physical drive nmuber (0..) */
|
||||
const BYTE *buff, /* Data to be written */
|
||||
DWORD sector, /* Sector address (LBA) */
|
||||
UINT count /* Number of sectors to write (1..255) */
|
||||
)
|
||||
{
|
||||
switch (pdrv) {
|
||||
case MSDLUN0:
|
||||
/* It is initialized externally, just reads the status.*/
|
||||
if (blkGetDriverState(&MSBLKD[0]) != BLK_READY)
|
||||
return RES_NOTRDY;
|
||||
if (usbhmsdLUNWrite(&MSBLKD[0], sector, buff, count))
|
||||
return RES_ERROR;
|
||||
return RES_OK;
|
||||
}
|
||||
return RES_PARERR;
|
||||
}
|
||||
#endif /* _USE_WRITE */
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Miscellaneous Functions */
|
||||
|
||||
#if _USE_IOCTL
|
||||
DRESULT disk_ioctl (
|
||||
BYTE pdrv, /* Physical drive nmuber (0..) */
|
||||
BYTE cmd, /* Control code */
|
||||
void *buff /* Buffer to send/receive control data */
|
||||
)
|
||||
{
|
||||
switch (pdrv) {
|
||||
case MSDLUN0:
|
||||
switch (cmd) {
|
||||
case CTRL_SYNC:
|
||||
return RES_OK;
|
||||
case GET_SECTOR_COUNT:
|
||||
*((DWORD *)buff) = MSBLKD[0].info.blk_num;
|
||||
return RES_OK;
|
||||
case GET_SECTOR_SIZE:
|
||||
*((WORD *)buff) = MSBLKD[0].info.blk_size;
|
||||
return RES_OK;
|
||||
default:
|
||||
return RES_PARERR;
|
||||
}
|
||||
}
|
||||
return RES_PARERR;
|
||||
}
|
||||
#endif /* _USE_IOCTL */
|
||||
|
||||
DWORD get_fattime(void) {
|
||||
return ((uint32_t)0 | (1 << 16)) | (1 << 21); /* wrong but valid time */
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,342 +0,0 @@
|
|||
/*---------------------------------------------------------------------------/
|
||||
/ FatFs - FAT file system module include file R0.10b (C)ChaN, 2014
|
||||
/----------------------------------------------------------------------------/
|
||||
/ FatFs module is a generic FAT file system module for small embedded systems.
|
||||
/ This is a free software that opened for education, research and commercial
|
||||
/ developments under license policy of following terms.
|
||||
/
|
||||
/ Copyright (C) 2014, ChaN, all right reserved.
|
||||
/
|
||||
/ * The FatFs module is a free software and there is NO WARRANTY.
|
||||
/ * No restriction on use. You can use, modify and redistribute it for
|
||||
/ personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY.
|
||||
/ * Redistributions of source code must retain the above copyright notice.
|
||||
/
|
||||
/----------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _FATFS
|
||||
#define _FATFS 8051 /* Revision ID */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "integer.h" /* Basic integer types */
|
||||
#include "ffconf.h" /* FatFs configuration options */
|
||||
|
||||
#if _FATFS != _FFCONF
|
||||
#error Wrong configuration file (ffconf.h).
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Definitions of volume management */
|
||||
|
||||
#if _MULTI_PARTITION /* Multiple partition configuration */
|
||||
typedef struct {
|
||||
BYTE pd; /* Physical drive number */
|
||||
BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
|
||||
} PARTITION;
|
||||
extern PARTITION VolToPart[]; /* Volume - Partition resolution table */
|
||||
#define LD2PD(vol) (VolToPart[vol].pd) /* Get physical drive number */
|
||||
#define LD2PT(vol) (VolToPart[vol].pt) /* Get partition index */
|
||||
|
||||
#else /* Single partition configuration */
|
||||
#define LD2PD(vol) (BYTE)(vol) /* Each logical drive is bound to the same physical drive number */
|
||||
#define LD2PT(vol) 0 /* Find first valid partition or in SFD */
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Type of path name strings on FatFs API */
|
||||
|
||||
#if _LFN_UNICODE /* Unicode string */
|
||||
#if !_USE_LFN
|
||||
#error _LFN_UNICODE must be 0 at non-LFN cfg.
|
||||
#endif
|
||||
#ifndef _INC_TCHAR
|
||||
typedef WCHAR TCHAR;
|
||||
#define _T(x) L ## x
|
||||
#define _TEXT(x) L ## x
|
||||
#endif
|
||||
|
||||
#else /* ANSI/OEM string */
|
||||
#ifndef _INC_TCHAR
|
||||
typedef char TCHAR;
|
||||
#define _T(x) x
|
||||
#define _TEXT(x) x
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* File system object structure (FATFS) */
|
||||
|
||||
typedef struct {
|
||||
BYTE fs_type; /* FAT sub-type (0:Not mounted) */
|
||||
BYTE drv; /* Physical drive number */
|
||||
BYTE csize; /* Sectors per cluster (1,2,4...128) */
|
||||
BYTE n_fats; /* Number of FAT copies (1 or 2) */
|
||||
BYTE wflag; /* win[] flag (b0:dirty) */
|
||||
BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */
|
||||
WORD id; /* File system mount ID */
|
||||
WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
|
||||
#if _MAX_SS != _MIN_SS
|
||||
WORD ssize; /* Bytes per sector (512, 1024, 2048 or 4096) */
|
||||
#endif
|
||||
#if _FS_REENTRANT
|
||||
_SYNC_t sobj; /* Identifier of sync object */
|
||||
#endif
|
||||
#if !_FS_READONLY
|
||||
DWORD last_clust; /* Last allocated cluster */
|
||||
DWORD free_clust; /* Number of free clusters */
|
||||
#endif
|
||||
#if _FS_RPATH
|
||||
DWORD cdir; /* Current directory start cluster (0:root) */
|
||||
#endif
|
||||
DWORD n_fatent; /* Number of FAT entries, = number of clusters + 2 */
|
||||
DWORD fsize; /* Sectors per FAT */
|
||||
DWORD volbase; /* Volume start sector */
|
||||
DWORD fatbase; /* FAT start sector */
|
||||
DWORD dirbase; /* Root directory start sector (FAT32:Cluster#) */
|
||||
DWORD database; /* Data start sector */
|
||||
DWORD winsect; /* Current sector appearing in the win[] */
|
||||
BYTE win[_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */
|
||||
} FATFS;
|
||||
|
||||
|
||||
|
||||
/* File object structure (FIL) */
|
||||
|
||||
typedef struct {
|
||||
FATFS* fs; /* Pointer to the related file system object (**do not change order**) */
|
||||
WORD id; /* Owner file system mount ID (**do not change order**) */
|
||||
BYTE flag; /* Status flags */
|
||||
BYTE err; /* Abort flag (error code) */
|
||||
DWORD fptr; /* File read/write pointer (Zeroed on file open) */
|
||||
DWORD fsize; /* File size */
|
||||
DWORD sclust; /* File start cluster (0:no cluster chain, always 0 when fsize is 0) */
|
||||
DWORD clust; /* Current cluster of fpter (not valid when fprt is 0) */
|
||||
DWORD dsect; /* Sector number appearing in buf[] (0:invalid) */
|
||||
#if !_FS_READONLY
|
||||
DWORD dir_sect; /* Sector number containing the directory entry */
|
||||
BYTE* dir_ptr; /* Pointer to the directory entry in the win[] */
|
||||
#endif
|
||||
#if _USE_FASTSEEK
|
||||
DWORD* cltbl; /* Pointer to the cluster link map table (Nulled on file open) */
|
||||
#endif
|
||||
#if _FS_LOCK
|
||||
UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */
|
||||
#endif
|
||||
#if !_FS_TINY
|
||||
BYTE buf[_MAX_SS]; /* File private data read/write window */
|
||||
#endif
|
||||
} FIL;
|
||||
|
||||
|
||||
|
||||
/* Directory object structure (DIR) */
|
||||
|
||||
typedef struct {
|
||||
FATFS* fs; /* Pointer to the owner file system object (**do not change order**) */
|
||||
WORD id; /* Owner file system mount ID (**do not change order**) */
|
||||
WORD index; /* Current read/write index number */
|
||||
DWORD sclust; /* Table start cluster (0:Root dir) */
|
||||
DWORD clust; /* Current cluster */
|
||||
DWORD sect; /* Current sector */
|
||||
BYTE* dir; /* Pointer to the current SFN entry in the win[] */
|
||||
BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
|
||||
#if _FS_LOCK
|
||||
UINT lockid; /* File lock ID (index of file semaphore table Files[]) */
|
||||
#endif
|
||||
#if _USE_LFN
|
||||
WCHAR* lfn; /* Pointer to the LFN working buffer */
|
||||
WORD lfn_idx; /* Last matched LFN index number (0xFFFF:No LFN) */
|
||||
#endif
|
||||
} DIR;
|
||||
|
||||
|
||||
|
||||
/* File status structure (FILINFO) */
|
||||
|
||||
typedef struct {
|
||||
DWORD fsize; /* File size */
|
||||
WORD fdate; /* Last modified date */
|
||||
WORD ftime; /* Last modified time */
|
||||
BYTE fattrib; /* Attribute */
|
||||
TCHAR fname[13]; /* Short file name (8.3 format) */
|
||||
#if _USE_LFN
|
||||
TCHAR* lfname; /* Pointer to the LFN buffer */
|
||||
UINT lfsize; /* Size of LFN buffer in TCHAR */
|
||||
#endif
|
||||
} FILINFO;
|
||||
|
||||
|
||||
|
||||
/* File function return code (FRESULT) */
|
||||
|
||||
typedef enum {
|
||||
FR_OK = 0, /* (0) Succeeded */
|
||||
FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */
|
||||
FR_INT_ERR, /* (2) Assertion failed */
|
||||
FR_NOT_READY, /* (3) The physical drive cannot work */
|
||||
FR_NO_FILE, /* (4) Could not find the file */
|
||||
FR_NO_PATH, /* (5) Could not find the path */
|
||||
FR_INVALID_NAME, /* (6) The path name format is invalid */
|
||||
FR_DENIED, /* (7) Access denied due to prohibited access or directory full */
|
||||
FR_EXIST, /* (8) Access denied due to prohibited access */
|
||||
FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */
|
||||
FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */
|
||||
FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */
|
||||
FR_NOT_ENABLED, /* (12) The volume has no work area */
|
||||
FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
|
||||
FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any parameter error */
|
||||
FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */
|
||||
FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */
|
||||
FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
|
||||
FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_SHARE */
|
||||
FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
|
||||
} FRESULT;
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
/* FatFs module application interface */
|
||||
|
||||
FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */
|
||||
FRESULT f_close (FIL* fp); /* Close an open file object */
|
||||
FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from a file */
|
||||
FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to a file */
|
||||
FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */
|
||||
FRESULT f_lseek (FIL* fp, DWORD ofs); /* Move file pointer of a file object */
|
||||
FRESULT f_truncate (FIL* fp); /* Truncate file */
|
||||
FRESULT f_sync (FIL* fp); /* Flush cached data of a writing file */
|
||||
FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */
|
||||
FRESULT f_closedir (DIR* dp); /* Close an open directory */
|
||||
FRESULT f_readdir (DIR* dp, FILINFO* fno); /* Read a directory item */
|
||||
FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */
|
||||
FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */
|
||||
FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */
|
||||
FRESULT f_stat (const TCHAR* path, FILINFO* fno); /* Get file status */
|
||||
FRESULT f_chmod (const TCHAR* path, BYTE value, BYTE mask); /* Change attribute of the file/dir */
|
||||
FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change times-tamp of the file/dir */
|
||||
FRESULT f_chdir (const TCHAR* path); /* Change current directory */
|
||||
FRESULT f_chdrive (const TCHAR* path); /* Change current drive */
|
||||
FRESULT f_getcwd (TCHAR* buff, UINT len); /* Get current directory */
|
||||
FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get number of free clusters on the drive */
|
||||
FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */
|
||||
FRESULT f_setlabel (const TCHAR* label); /* Set volume label */
|
||||
FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */
|
||||
FRESULT f_mkfs (const TCHAR* path, BYTE sfd, UINT au); /* Create a file system on the volume */
|
||||
FRESULT f_fdisk (BYTE pdrv, const DWORD szt[], void* work); /* Divide a physical drive into some partitions */
|
||||
int f_putc (TCHAR c, FIL* fp); /* Put a character to the file */
|
||||
int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
|
||||
int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */
|
||||
TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
|
||||
|
||||
#define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0)
|
||||
#define f_error(fp) ((fp)->err)
|
||||
#define f_tell(fp) ((fp)->fptr)
|
||||
#define f_size(fp) ((fp)->fsize)
|
||||
|
||||
#ifndef EOF
|
||||
#define EOF (-1)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
/* Additional user defined functions */
|
||||
|
||||
/* RTC function */
|
||||
#if !_FS_READONLY
|
||||
DWORD get_fattime (void);
|
||||
#endif
|
||||
|
||||
/* Unicode support functions */
|
||||
#if _USE_LFN /* Unicode - OEM code conversion */
|
||||
WCHAR ff_convert (WCHAR chr, UINT dir); /* OEM-Unicode bidirectional conversion */
|
||||
WCHAR ff_wtoupper (WCHAR chr); /* Unicode upper-case conversion */
|
||||
#if _USE_LFN == 3 /* Memory functions */
|
||||
void* ff_memalloc (UINT msize); /* Allocate memory block */
|
||||
void ff_memfree (void* mblock); /* Free memory block */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Sync functions */
|
||||
#if _FS_REENTRANT
|
||||
int ff_cre_syncobj (BYTE vol, _SYNC_t* sobj); /* Create a sync object */
|
||||
int ff_req_grant (_SYNC_t sobj); /* Lock sync object */
|
||||
void ff_rel_grant (_SYNC_t sobj); /* Unlock sync object */
|
||||
int ff_del_syncobj (_SYNC_t sobj); /* Delete a sync object */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
/* Flags and offset address */
|
||||
|
||||
|
||||
/* File access control and file status flags (FIL.flag) */
|
||||
|
||||
#define FA_READ 0x01
|
||||
#define FA_OPEN_EXISTING 0x00
|
||||
|
||||
#if !_FS_READONLY
|
||||
#define FA_WRITE 0x02
|
||||
#define FA_CREATE_NEW 0x04
|
||||
#define FA_CREATE_ALWAYS 0x08
|
||||
#define FA_OPEN_ALWAYS 0x10
|
||||
#define FA__WRITTEN 0x20
|
||||
#define FA__DIRTY 0x40
|
||||
#endif
|
||||
|
||||
|
||||
/* FAT sub type (FATFS.fs_type) */
|
||||
|
||||
#define FS_FAT12 1
|
||||
#define FS_FAT16 2
|
||||
#define FS_FAT32 3
|
||||
|
||||
|
||||
/* File attribute bits for directory entry */
|
||||
|
||||
#define AM_RDO 0x01 /* Read only */
|
||||
#define AM_HID 0x02 /* Hidden */
|
||||
#define AM_SYS 0x04 /* System */
|
||||
#define AM_VOL 0x08 /* Volume label */
|
||||
#define AM_LFN 0x0F /* LFN entry */
|
||||
#define AM_DIR 0x10 /* Directory */
|
||||
#define AM_ARC 0x20 /* Archive */
|
||||
#define AM_MASK 0x3F /* Mask of defined bits */
|
||||
|
||||
|
||||
/* Fast seek feature */
|
||||
#define CREATE_LINKMAP 0xFFFFFFFF
|
||||
|
||||
|
||||
|
||||
/*--------------------------------*/
|
||||
/* Multi-byte word access macros */
|
||||
|
||||
#if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */
|
||||
#define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
|
||||
#define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
|
||||
#define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
|
||||
#define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
|
||||
#else /* Use byte-by-byte access to the FAT structure */
|
||||
#define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
|
||||
#define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr))
|
||||
#define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8)
|
||||
#define ST_DWORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8); *((BYTE*)(ptr)+2)=(BYTE)((DWORD)(val)>>16); *((BYTE*)(ptr)+3)=(BYTE)((DWORD)(val)>>24)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _FATFS */
|
|
@ -8,7 +8,6 @@
|
|||
#ifndef _FFCONF
|
||||
#define _FFCONF 8051 /* Revision ID */
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ Functions and Buffer Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
@ -92,7 +91,7 @@
|
|||
/ 1 - ASCII (Valid for only non-LFN configuration) */
|
||||
|
||||
|
||||
#define _USE_LFN 3 /* 0 to 3 */
|
||||
#define _USE_LFN 0 /* 0 to 3 */
|
||||
#define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */
|
||||
/* The _USE_LFN option switches the LFN feature.
|
||||
/
|
||||
|
|
|
@ -91,13 +91,13 @@
|
|||
#define HAL_USBH_DEVICE_ADDRESS_STABILIZATION 20
|
||||
|
||||
/* MSD */
|
||||
#define HAL_USBH_USE_MSD 1
|
||||
#define HAL_USBH_USE_MSD TRUE
|
||||
|
||||
#define HAL_USBHMSD_MAX_LUNS 1
|
||||
#define HAL_USBHMSD_MAX_INSTANCES 1
|
||||
|
||||
/* IAD */
|
||||
#define HAL_USBH_USE_FTDI 1
|
||||
/* FTDI */
|
||||
#define HAL_USBH_USE_FTDI TRUE
|
||||
|
||||
#define HAL_USBHFTDI_MAX_PORTS 1
|
||||
#define HAL_USBHFTDI_MAX_INSTANCES 1
|
||||
|
@ -107,12 +107,8 @@
|
|||
#define HAL_USBHFTDI_DEFAULT_XON 0x11
|
||||
#define HAL_USBHFTDI_DEFAULT_XOFF 0x13
|
||||
|
||||
|
||||
/* IAD */
|
||||
#define HAL_USBH_USE_IAD 0
|
||||
|
||||
/* UVC */
|
||||
#define HAL_USBH_USE_UVC 0
|
||||
#define HAL_USBH_USE_UVC FALSE
|
||||
|
||||
#define HAL_USBHUVC_MAX_INSTANCES 1
|
||||
#define HAL_USBHUVC_MAX_MAILBOX_SZ 70
|
||||
|
@ -121,47 +117,47 @@
|
|||
|
||||
|
||||
/* HUB */
|
||||
#define HAL_USBH_USE_HUB 1
|
||||
#define HAL_USBH_USE_HUB TRUE
|
||||
|
||||
#define HAL_USBHHUB_MAX_INSTANCES 1
|
||||
#define HAL_USBHHUB_MAX_PORTS 6
|
||||
|
||||
|
||||
/* debug */
|
||||
#define USBH_DEBUG_ENABLE 1
|
||||
#define USBH_DEBUG_ENABLE TRUE
|
||||
#define USBH_DEBUG_USBHD USBHD1
|
||||
#define USBH_DEBUG_SD SD2
|
||||
#define USBH_DEBUG_BUFFER 25000
|
||||
|
||||
#define USBH_DEBUG_ENABLE_TRACE 0
|
||||
#define USBH_DEBUG_ENABLE_INFO 1
|
||||
#define USBH_DEBUG_ENABLE_WARNINGS 1
|
||||
#define USBH_DEBUG_ENABLE_ERRORS 1
|
||||
#define USBH_DEBUG_ENABLE_TRACE FALSE
|
||||
#define USBH_DEBUG_ENABLE_INFO TRUE
|
||||
#define USBH_DEBUG_ENABLE_WARNINGS TRUE
|
||||
#define USBH_DEBUG_ENABLE_ERRORS TRUE
|
||||
|
||||
#define USBH_LLD_DEBUG_ENABLE_TRACE 0
|
||||
#define USBH_LLD_DEBUG_ENABLE_INFO 1
|
||||
#define USBH_LLD_DEBUG_ENABLE_WARNINGS 1
|
||||
#define USBH_LLD_DEBUG_ENABLE_ERRORS 1
|
||||
#define USBH_LLD_DEBUG_ENABLE_TRACE FALSE
|
||||
#define USBH_LLD_DEBUG_ENABLE_INFO TRUE
|
||||
#define USBH_LLD_DEBUG_ENABLE_WARNINGS TRUE
|
||||
#define USBH_LLD_DEBUG_ENABLE_ERRORS TRUE
|
||||
|
||||
#define USBHHUB_DEBUG_ENABLE_TRACE 0
|
||||
#define USBHHUB_DEBUG_ENABLE_INFO 1
|
||||
#define USBHHUB_DEBUG_ENABLE_WARNINGS 1
|
||||
#define USBHHUB_DEBUG_ENABLE_ERRORS 1
|
||||
#define USBHHUB_DEBUG_ENABLE_TRACE FALSE
|
||||
#define USBHHUB_DEBUG_ENABLE_INFO TRUE
|
||||
#define USBHHUB_DEBUG_ENABLE_WARNINGS TRUE
|
||||
#define USBHHUB_DEBUG_ENABLE_ERRORS TRUE
|
||||
|
||||
#define USBHMSD_DEBUG_ENABLE_TRACE 0
|
||||
#define USBHMSD_DEBUG_ENABLE_INFO 1
|
||||
#define USBHMSD_DEBUG_ENABLE_WARNINGS 1
|
||||
#define USBHMSD_DEBUG_ENABLE_ERRORS 1
|
||||
#define USBHMSD_DEBUG_ENABLE_TRACE FALSE
|
||||
#define USBHMSD_DEBUG_ENABLE_INFO TRUE
|
||||
#define USBHMSD_DEBUG_ENABLE_WARNINGS TRUE
|
||||
#define USBHMSD_DEBUG_ENABLE_ERRORS TRUE
|
||||
|
||||
#define USBHUVC_DEBUG_ENABLE_TRACE 0
|
||||
#define USBHUVC_DEBUG_ENABLE_INFO 1
|
||||
#define USBHUVC_DEBUG_ENABLE_WARNINGS 1
|
||||
#define USBHUVC_DEBUG_ENABLE_ERRORS 1
|
||||
#define USBHUVC_DEBUG_ENABLE_TRACE FALSE
|
||||
#define USBHUVC_DEBUG_ENABLE_INFO TRUE
|
||||
#define USBHUVC_DEBUG_ENABLE_WARNINGS TRUE
|
||||
#define USBHUVC_DEBUG_ENABLE_ERRORS TRUE
|
||||
|
||||
#define USBHFTDI_DEBUG_ENABLE_TRACE 0
|
||||
#define USBHFTDI_DEBUG_ENABLE_INFO 1
|
||||
#define USBHFTDI_DEBUG_ENABLE_WARNINGS 1
|
||||
#define USBHFTDI_DEBUG_ENABLE_ERRORS 1
|
||||
#define USBHFTDI_DEBUG_ENABLE_TRACE FALSE
|
||||
#define USBHFTDI_DEBUG_ENABLE_INFO TRUE
|
||||
#define USBHFTDI_DEBUG_ENABLE_WARNINGS TRUE
|
||||
#define USBHFTDI_DEBUG_ENABLE_ERRORS TRUE
|
||||
|
||||
/*===========================================================================*/
|
||||
/* FSMCNAND driver related settings. */
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
/*-------------------------------------------*/
|
||||
/* Integer type definitions for FatFs module */
|
||||
/*-------------------------------------------*/
|
||||
|
||||
#ifndef _FF_INTEGER
|
||||
#define _FF_INTEGER
|
||||
|
||||
#ifdef _WIN32 /* FatFs development platform */
|
||||
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
|
||||
#else /* Embedded platform */
|
||||
|
||||
/* This type MUST be 8 bit */
|
||||
typedef unsigned char BYTE;
|
||||
|
||||
/* These types MUST be 16 bit */
|
||||
typedef short SHORT;
|
||||
typedef unsigned short WORD;
|
||||
typedef unsigned short WCHAR;
|
||||
|
||||
/* These types MUST be 16 bit or 32 bit */
|
||||
typedef int INT;
|
||||
typedef unsigned int UINT;
|
||||
|
||||
/* These types MUST be 32 bit */
|
||||
typedef long LONG;
|
||||
typedef unsigned long DWORD;
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -85,7 +85,7 @@ static void ThreadTestFTDI(void *p) {
|
|||
shellInit();
|
||||
|
||||
start:
|
||||
while (ftdipp->state != USBHFTDIP_STATE_ACTIVE) {
|
||||
while (usbhftdipGetState(ftdipp) != USBHFTDIP_STATE_ACTIVE) {
|
||||
chThdSleepMilliseconds(100);
|
||||
}
|
||||
|
||||
|
@ -119,13 +119,13 @@ start:
|
|||
if (1) {
|
||||
thread_t *shelltp = NULL;
|
||||
for(;;) {
|
||||
if (ftdipp->state != USBHFTDIP_STATE_READY)
|
||||
if (usbhftdipGetState(ftdipp) != USBHFTDIP_STATE_READY)
|
||||
goto start;
|
||||
if (!shelltp) {
|
||||
shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, "shell", NORMALPRIO, shellThread, (void *) &shell_cfg1);
|
||||
shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
|
||||
} else if (chThdTerminatedX(shelltp)) {
|
||||
chThdRelease(shelltp);
|
||||
if (ftdipp->state != USBHFTDIP_STATE_READY)
|
||||
if (usbhftdipGetState(ftdipp) != USBHFTDIP_STATE_READY)
|
||||
goto start;
|
||||
break;
|
||||
}
|
||||
|
@ -247,7 +247,7 @@ static void ThreadTestMSD(void *p) {
|
|||
(void)p;
|
||||
|
||||
FATFS *fsp;
|
||||
uint32_t clusters;
|
||||
DWORD clusters;
|
||||
FRESULT res;
|
||||
BaseSequentialStream * const chp = (BaseSequentialStream *)&USBH_DEBUG_SD;
|
||||
blkstate_t state;
|
||||
|
@ -373,15 +373,9 @@ start:
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main(void) {
|
||||
|
||||
halInit();
|
||||
usbhInit();
|
||||
chSysInit();
|
||||
|
||||
//PA2(TX) and PA3(RX) are routed to USART2
|
||||
|
@ -395,18 +389,14 @@ int main(void) {
|
|||
#endif
|
||||
|
||||
#if STM32_USBH_USE_OTG2
|
||||
//USB_HS
|
||||
//TODO: Initialize Pads
|
||||
#error "TODO: Initialize USB_HS pads"
|
||||
#endif
|
||||
|
||||
#if HAL_USBH_USE_MSD
|
||||
usbhmsdObjectInit(&USBHMSD[0]);
|
||||
usbhmsdLUNObjectInit(&MSBLKD[0]);
|
||||
chThdCreateStatic(waTestMSD, sizeof(waTestMSD), NORMALPRIO, ThreadTestMSD, 0);
|
||||
#endif
|
||||
|
||||
#if HAL_USBH_USE_FTDI
|
||||
usbhftdiObjectInit(&USBHFTDID[0]);
|
||||
usbhftdipObjectInit(&FTDIPD[0]);
|
||||
chThdCreateStatic(waTestFTDI, sizeof(waTestFTDI), NORMALPRIO, ThreadTestFTDI, 0);
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue