forked from xuos/xiuos
feat add third_party_driver/usb for hc32f4a0 board, support Mount file-system
This commit is contained in:
parent
696c9f6fe0
commit
452699ac02
|
@ -71,21 +71,35 @@ void SystemClockConfig(void)
|
|||
(void)CLK_XtalInit(&stcXtalInit);
|
||||
|
||||
(void)CLK_PLLStructInit(&stcPLLHInit);
|
||||
/* VCO = (8/1)*100 = 800MHz*/
|
||||
|
||||
stcPLLHInit.u8PLLState = CLK_PLL_ON;
|
||||
stcPLLHInit.PLLCFGR = 0UL;
|
||||
stcPLLHInit.PLLCFGR_f.PLLM = 1UL - 1UL;
|
||||
|
||||
#ifdef BSP_USING_USB
|
||||
/* VCO = (8/1)*120 = 960MHz*/
|
||||
stcPLLHInit.PLLCFGR_f.PLLN = 120UL - 1UL;
|
||||
#else
|
||||
/* VCO = (8/1)*100 = 800MHz*/
|
||||
stcPLLHInit.PLLCFGR_f.PLLN = 100UL - 1UL;
|
||||
#endif
|
||||
stcPLLHInit.PLLCFGR_f.PLLP = 4UL - 1UL;
|
||||
stcPLLHInit.PLLCFGR_f.PLLQ = 4UL - 1UL;
|
||||
stcPLLHInit.PLLCFGR_f.PLLR = 4UL - 1UL;
|
||||
stcPLLHInit.PLLCFGR_f.PLLSRC = CLK_PLL_SRC_XTAL;
|
||||
(void)CLK_PLLInit(&stcPLLHInit);
|
||||
|
||||
#ifdef BSP_USING_USB
|
||||
/* Highspeed SRAM set to 0 Read/Write wait cycle */
|
||||
SRAM_SetWaitCycle(SRAM_SRAMH, SRAM_WAIT_CYCLE0, SRAM_WAIT_CYCLE0);
|
||||
/* SRAM1_2_3_4_backup set to 1 Read/Write wait cycle */
|
||||
SRAM_SetWaitCycle((SRAM_SRAM123 | SRAM_SRAM4 | SRAM_SRAMB), SRAM_WAIT_CYCLE1, SRAM_WAIT_CYCLE1);
|
||||
#else
|
||||
/* Highspeed SRAM set to 1 Read/Write wait cycle */
|
||||
SRAM_SetWaitCycle(SRAM_SRAMH, SRAM_WAIT_CYCLE1, SRAM_WAIT_CYCLE1);
|
||||
/* SRAM1_2_3_4_backup set to 2 Read/Write wait cycle */
|
||||
SRAM_SetWaitCycle((SRAM_SRAM123 | SRAM_SRAM4 | SRAM_SRAMB), SRAM_WAIT_CYCLE2, SRAM_WAIT_CYCLE2);
|
||||
#endif
|
||||
/* 0-wait @ 40MHz */
|
||||
EFM_SetWaitCycle(EFM_WAIT_CYCLE5);
|
||||
/* 4 cycles for 200 ~ 250MHz */
|
||||
|
|
|
@ -12,13 +12,13 @@ if BSP_USING_SDIO
|
|||
default "sdio_dev"
|
||||
|
||||
config MOUNT_SDCARD_FS
|
||||
bool "mount sd card file system"
|
||||
bool "mount sd card file system : if y then not support usb-mount-fs"
|
||||
default y
|
||||
select MOUNT_SDCARD
|
||||
|
||||
if MOUNT_SDCARD_FS
|
||||
config MOUNT_SDCARD_FS_TYPE
|
||||
int "choose file system type : FATFS(0) LWEXT4(3)"
|
||||
int "choose file system type : FATFS(0)"
|
||||
default 0
|
||||
endif
|
||||
endif
|
||||
|
|
|
@ -11,5 +11,15 @@ config BSP_USING_HC32_USBH
|
|||
config USB_DEVICE_NAME
|
||||
string "usb bus device name"
|
||||
default "usb_dev"
|
||||
config MOUNT_USB_FS
|
||||
bool "mount usb file system : if y then not support sdcard-mount-fs"
|
||||
default y
|
||||
select MOUNT_USB
|
||||
|
||||
if MOUNT_USB_FS
|
||||
config MOUNT_USB_FS_TYPE
|
||||
int "choose file system type : FATFS(0)"
|
||||
default 0
|
||||
endif
|
||||
endif
|
||||
|
||||
|
|
|
@ -35,6 +35,8 @@ Modification:
|
|||
usb_core_instance usb_app_instance;
|
||||
USBH_HOST usb_app_host;
|
||||
|
||||
static void UsbHostTask(void *parameter);
|
||||
|
||||
#if defined(FS_VFS)
|
||||
void UsbMountFileSystem()
|
||||
{
|
||||
|
@ -48,6 +50,23 @@ void UsbUnmountFileSystem()
|
|||
{
|
||||
UnmountFileSystem(UDISK_MOUNTPOINT);
|
||||
}
|
||||
|
||||
#ifdef MOUNT_USB
|
||||
int MountUsb(void)
|
||||
{
|
||||
int32 usb_host_task = 0;
|
||||
usb_host_task = KTaskCreate("usbh", UsbHostTask, NONE,
|
||||
USB_HOST_STACK_SIZE, 8);
|
||||
if(usb_host_task < 0) {
|
||||
KPrintf("usb_host_task create failed ...%s %d.\n", __FUNCTION__, __LINE__);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
StartupKTask(usb_host_task);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static uint32 UsbHostOpen(void *dev)
|
||||
|
@ -127,8 +146,9 @@ static const struct UsbDevDone dev_done =
|
|||
.read = UsbHostRead,
|
||||
};
|
||||
|
||||
static void UsbHostTask(void* parameter)
|
||||
static void UsbHostTask(void *parameter)
|
||||
{
|
||||
usb_host_init(&usb_app_instance, &usb_app_host, &USBH_MSC_cb, &USR_cb);
|
||||
while (1) {
|
||||
usb_host_mainprocess(&usb_app_instance, &usb_app_host);
|
||||
}
|
||||
|
@ -191,7 +211,6 @@ static int BoardUsbDevBend(void)
|
|||
int HwUsbHostInit(void)
|
||||
{
|
||||
x_err_t ret = EOK;
|
||||
int32 usb_host_task = 0;
|
||||
|
||||
static struct UsbBus usb_bus;
|
||||
memset(&usb_bus, 0, sizeof(struct UsbBus));
|
||||
|
@ -199,8 +218,6 @@ int HwUsbHostInit(void)
|
|||
static struct UsbDriver usb_driver;
|
||||
memset(&usb_driver, 0, sizeof(struct UsbDriver));
|
||||
|
||||
usb_host_init(&usb_app_instance, &usb_app_host, &USBH_MSC_cb, &USR_cb);
|
||||
|
||||
ret = BoardUsbBusInit(&usb_bus, &usb_driver);
|
||||
if (EOK != ret) {
|
||||
KPrintf("BoardUsbBusInit error ret %u\n", ret);
|
||||
|
@ -213,15 +230,6 @@ int HwUsbHostInit(void)
|
|||
return ERROR;
|
||||
}
|
||||
|
||||
usb_host_task = KTaskCreate("usbh", UsbHostTask, NONE,
|
||||
USB_HOST_STACK_SIZE, 8);
|
||||
if(usb_host_task < 0) {
|
||||
KPrintf("usb_host_task create failed ...%s %d.\n", __FUNCTION__, __LINE__);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
StartupKTask(usb_host_task);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -74,10 +74,6 @@ void usb_bsp_init(usb_core_instance *pdev)
|
|||
{
|
||||
stc_gpio_init_t stcGpioCfg;
|
||||
|
||||
/* SysTick configuration */
|
||||
(void)SysTick_Init(1000U);
|
||||
NVIC_SetPriority(SysTick_IRQn, DDL_IRQ_PRIO_14);
|
||||
|
||||
/* USB clock source configurate */
|
||||
CLK_SetUSBClockSrc(CLK_USBCLK_SYSCLK_DIV5);
|
||||
|
||||
|
@ -88,11 +84,6 @@ void usb_bsp_init(usb_core_instance *pdev)
|
|||
(void)GPIO_Init(USB_DM_PORT, USB_DM_PIN, &stcGpioCfg);
|
||||
(void)GPIO_Init(USB_DP_PORT, USB_DP_PIN, &stcGpioCfg);
|
||||
|
||||
// stcGpioInit.u16PinState = PIN_STAT_RST;
|
||||
// stcGpioInit.u16PinDir = PIN_DIR_OUT;
|
||||
// (void)GPIO_Init(USB_DRVVBUS_PORT, USB_DRVVBUS_PIN, &stcGpioInit);
|
||||
// GPIO_SetPins(USB_DRVVBUS_PORT, USB_DRVVBUS_PIN);
|
||||
|
||||
GPIO_SetFunc(USB_DRVVBUS_PORT, USB_DRVVBUS_PIN, GPIO_FUNC_10); /* VBUS */
|
||||
|
||||
FCG_Fcg1PeriphClockCmd(FCG1_PERIPH_USBFS, ENABLE);
|
||||
|
@ -133,7 +124,7 @@ void usb_udelay(const uint32_t usec)
|
|||
|
||||
void usb_mdelay(const uint32_t msec)
|
||||
{
|
||||
SysTick_Delay(msec);
|
||||
usb_udelay(msec * 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -141,7 +132,7 @@ void usb_mdelay(const uint32_t msec)
|
|||
* @param [in] pdev device instance
|
||||
* @retval None
|
||||
*/
|
||||
void usb_bsp_cfgvbus(LL_USB_TypeDef *USBx)
|
||||
void usb_bsp_cfgvbus(LL_USB_TypeDef *USBx)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ void usb_host_deinit(usb_core_instance *pdev, USBH_HOST *phost)
|
|||
* @param [in] phost host state set
|
||||
* @retval None
|
||||
*/
|
||||
int usb_host_mainprocess(usb_core_instance *pdev, USBH_HOST *phost)
|
||||
void usb_host_mainprocess(usb_core_instance *pdev, USBH_HOST *phost)
|
||||
{
|
||||
__IO HOST_STATUS tmp_status;
|
||||
tmp_status = HSTATUS_FAIL;
|
||||
|
@ -193,8 +193,6 @@ int usb_host_mainprocess(usb_core_instance *pdev, USBH_HOST *phost)
|
|||
} else {
|
||||
;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -73,7 +73,7 @@ extern void usb_host_init(usb_core_instance *pdev,
|
|||
usb_host_class_callback_func *class_cbk,
|
||||
usb_host_user_callback_func *user_cbk);
|
||||
extern void usb_host_deinit(usb_core_instance *pdev, USBH_HOST *phost);
|
||||
extern int usb_host_mainprocess(usb_core_instance *pdev, USBH_HOST *phost);
|
||||
extern void usb_host_mainprocess(usb_core_instance *pdev, USBH_HOST *phost);
|
||||
extern void usb_host_errorprocess(USBH_HOST *phost, HOST_STATUS errType);
|
||||
|
||||
/**
|
||||
|
|
|
@ -105,6 +105,7 @@ usb_host_user_callback_func USR_cb = {
|
|||
/*******************************************************************************
|
||||
* Local function prototypes ('static')
|
||||
******************************************************************************/
|
||||
static int usb_connect_status = 0;
|
||||
|
||||
/*******************************************************************************
|
||||
* Local variable definitions ('static')
|
||||
|
@ -125,7 +126,7 @@ void host_user_init(void)
|
|||
|
||||
if (startup == 0U) {
|
||||
startup = 1U;
|
||||
KPrintf("USB Host library v2.1.0 started\r\n");
|
||||
//KPrintf("USB Host library v2.1.0 started\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,7 +138,6 @@ void host_user_init(void)
|
|||
void host_user_devattached(void)
|
||||
{
|
||||
KPrintf("USB device attached\r\n");
|
||||
UsbMountFileSystem();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -158,6 +158,7 @@ void host_user_unrecoverederror(void)
|
|||
void host_user_devdisconn(void)
|
||||
{
|
||||
KPrintf("USB device disconnect\r\n");
|
||||
usb_connect_status = 0;
|
||||
UsbUnmountFileSystem();
|
||||
}
|
||||
|
||||
|
@ -307,6 +308,12 @@ void host_user_overcurrent(void)
|
|||
*/
|
||||
int host_user_msc_app(void)
|
||||
{
|
||||
if (0 == usb_connect_status) {
|
||||
KPrintf("ready to mount file system\n");
|
||||
UsbMountFileSystem();
|
||||
usb_connect_status = 1;
|
||||
}
|
||||
|
||||
return ((int)0);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue