To use the USB host on the S3A7 make sure the USBF DIP switch on the Top board in Off. Then to register the USBFS peripheral as a host controller :- #include "ux_api.h" #include "ux_host_class_cdc_acm.h" #include "ux_hcd_synergy.h" /* Initialize USBX. Memory */ ux_system_initialize((CHAR *) g_usb_memory, sizeof(g_usb_memory), UX_NULL, 0); /* The code below is required for installing the host portion of USBX */ status = ux_host_stack_initialize(demo_host_change_function); if (status != UX_SUCCESS) { return; } /* Register all the host class drivers for this USBX implementation. */ status = ux_host_stack_class_register(_ux_system_host_class_cdc_acm_name, _ux_host_class_cdc_acm_entry); if (status != UX_SUCCESS) { return; } /* Register all the USB host controllers available in this system */ status = ux_host_stack_hcd_register((UCHAR *)"DK-S3A7", _ux_hcd_synergy_initialize, R_USBFS_BASE, UX_SYNERGY_CONTROLLER_S3A7); if (status != UX_SUCCESS) { return; } /* Port 4_7 needs to be high to enable USB VBUS */ g_ioport.p_api- pinCfg(IOPORT_PORT_04_PIN_07, IOPORT_CFG_PORT_DIRECTION_OUTPUT); g_ioport.p_api- pinWrite(IOPORT_PORT_04_PIN_07, IOPORT_LEVEL_HIGH); Then the host change function (this is registered with the host stack in the call ux_host_stack_initialize(demo_host_change_function); ), which notifies you of a USB change (insertion or removal) is :- UINT demo_host_change_function(ULONG event, UX_HOST_CLASS * class, VOID * instance) { UINT status; UX_HOST_CLASS *cdc_acm_host_class; /* Check if there is a device insertion. */ if (UX_DEVICE_INSERTION == event) { /* Get the storage class. */ status = ux_host_stack_class_get(_ux_system_host_class_cdc_acm_name, &cdc_acm_host_class); if (UX_SUCCESS != status) { return(status); } /* Check if we got a CDC ACM class device. */ if (cdc_acm_host_class == class) { g_cdc_acm = (UX_HOST_CLASS_CDC_ACM *) instance; } } /* Check if some device is removed. */ else if(UX_DEVICE_REMOVAL == event) { g_cdc_acm = (UX_HOST_CLASS_CDC_ACM *) NULL; } else { /* Default case, nothing to do */ } return(UX_SUCCESS); } Then to use the CDC ACM, e.g. for a write :- if (NULL != g_cdc_acm) { status = ux_host_class_cdc_acm_write(g_cdc_acm, (UCHAR *)&message, length, &actual_length); if (UX_SUCCESS != status) { while(1); } }
↧