diff --git a/usb/device/targets/TARGET_Freescale/USBPhyHw.h b/usb/device/targets/TARGET_Freescale/USBPhyHw.h index 7bf1fee22f..529cbc7197 100644 --- a/usb/device/targets/TARGET_Freescale/USBPhyHw.h +++ b/usb/device/targets/TARGET_Freescale/USBPhyHw.h @@ -36,7 +36,7 @@ public: virtual void sof_disable(); virtual void set_address(uint8_t address); virtual void remote_wakeup(); - virtual const usb_ep_table_t* endpoint_table(); + virtual const usb_ep_table_t *endpoint_table(); virtual uint32_t ep0_set_max_packet(uint32_t max_packet); virtual void ep0_setup_read_result(uint8_t *buffer, uint32_t size); diff --git a/usb/device/targets/TARGET_Freescale/USBPhy_Kinetis.cpp b/usb/device/targets/TARGET_Freescale/USBPhy_Kinetis.cpp index eae9fb3a4a..34d4ea43d1 100644 --- a/usb/device/targets/TARGET_Freescale/USBPhy_Kinetis.cpp +++ b/usb/device/targets/TARGET_Freescale/USBPhy_Kinetis.cpp @@ -83,7 +83,7 @@ typedef enum { // * as there are ODD and EVEN buffer -> 8*2 bdt MBED_ALIGN(512) BDT bdt[NUMBER_OF_PHYSICAL_ENDPOINTS * 2]; // 512 bytes aligned! -uint8_t * endpoint_buffer[NUMBER_OF_PHYSICAL_ENDPOINTS * 2]; +uint8_t *endpoint_buffer[NUMBER_OF_PHYSICAL_ENDPOINTS * 2]; uint8_t ep0_buffer[2][MAX_PACKET_SIZE_EP0]; uint8_t ep1_buffer[2][MAX_PACKET_SIZE_EP1]; uint8_t ep2_buffer[2][MAX_PACKET_SIZE_EP2]; @@ -96,8 +96,9 @@ static ctrl_xfer_t ctrl_xfer = CTRL_XFER_READY; static uint32_t Data1 = 0x55555555; -static uint32_t frameNumber() { - return((USB0->FRMNUML | (USB0->FRMNUMH << 8)) & 0x07FF); +static uint32_t frameNumber() +{ + return ((USB0->FRMNUML | (USB0->FRMNUMH << 8)) & 0x07FF); } USBPhy *get_usb_phy() @@ -126,11 +127,11 @@ void USBPhyHw::init(USBPhyEvents *events) NVIC_DisableIRQ(USB0_IRQn); #if (defined(FSL_FEATURE_SOC_MPU_COUNT) && (FSL_FEATURE_SOC_MPU_COUNT > 0U)) - MPU->CESR=0; + MPU->CESR = 0; #endif #if (defined(FSL_FEATURE_SOC_SYSMPU_COUNT) && (FSL_FEATURE_SOC_SYSMPU_COUNT > 0U)) - SYSMPU->CESR=0; + SYSMPU->CESR = 0; #endif #if defined(TARGET_KL43Z) || defined(TARGET_K22F) || defined(TARGET_K64F) @@ -150,9 +151,9 @@ void USBPhyHw::init(USBPhyEvents *events) // USB Module Configuration // Set BDT Base Register - USB0->BDTPAGE1 = (uint8_t)((uint32_t)bdt>>8); - USB0->BDTPAGE2 = (uint8_t)((uint32_t)bdt>>16); - USB0->BDTPAGE3 = (uint8_t)((uint32_t)bdt>>24); + USB0->BDTPAGE1 = (uint8_t)((uint32_t)bdt >> 8); + USB0->BDTPAGE2 = (uint8_t)((uint32_t)bdt >> 16); + USB0->BDTPAGE3 = (uint8_t)((uint32_t)bdt >> 24); // Clear interrupt flag USB0->ISTAT = 0xff; @@ -209,7 +210,7 @@ void USBPhyHw::connect() void USBPhyHw::disconnect() { // disable all endpoints to prevent them from nacking when disconnected - for(int i = 0; i < 16; i++) { + for (int i = 0; i < 16; i++) { USB0->ENDPOINT[i].ENDPT = 0x00; } // disable USB @@ -259,7 +260,7 @@ void USBPhyHw::remote_wakeup() #define ALLOW_BULK_OR_INT_ENDPOINTS (USB_EP_ATTR_ALLOW_BULK | USB_EP_ATTR_ALLOW_INT) #define ALLOW_NO_ENDPOINTS 0 -const usb_ep_table_t* USBPhyHw::endpoint_table() +const usb_ep_table_t *USBPhyHw::endpoint_table() { static const usb_ep_table_t endpoint_table = { 1, // No cost per endpoint - everything allocated up front @@ -349,7 +350,7 @@ void USBPhyHw::ep0_write(uint8_t *buffer, uint32_t size) // Prepare for next setup packet endpoint_read_core(EP0OUT, MAX_PACKET_SIZE_EP0); ctrl_xfer = CTRL_XFER_READY; - } + } endpoint_write(EP0IN, buffer, size); // Clear suspend after the setup stage @@ -386,7 +387,7 @@ void USBPhyHw::ep0_stall() bool USBPhyHw::endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type) { uint32_t handshake_flag = 0; - uint8_t * buf; + uint8_t *buf; if (DESC_TO_PHY(endpoint) > NUMBER_OF_PHYSICAL_ENDPOINTS - 1) { return false; @@ -406,21 +407,21 @@ bool USBPhyHw::endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_ // IN endpt -> device to host (TX) if (DESC_EP_IN(endpoint)) { - bdt[EP_BDT_IDX(log_endpoint, TX, ODD )].address = (uint32_t) buf; - bdt[EP_BDT_IDX(log_endpoint, TX, ODD )].info = 0; + bdt[EP_BDT_IDX(log_endpoint, TX, ODD)].address = (uint32_t) buf; + bdt[EP_BDT_IDX(log_endpoint, TX, ODD)].info = 0; bdt[EP_BDT_IDX(log_endpoint, TX, EVEN)].address = 0; USB0->ENDPOINT[log_endpoint].ENDPT |= handshake_flag | // ep handshaking (not if iso endpoint) USB_ENDPT_EPTXEN_MASK; // en TX (IN) tran } // OUT endpt -> host to device (RX) else { - bdt[EP_BDT_IDX(log_endpoint, RX, ODD )].byte_count = max_packet; - bdt[EP_BDT_IDX(log_endpoint, RX, ODD )].address = (uint32_t) buf; - bdt[EP_BDT_IDX(log_endpoint, RX, ODD )].info = BD_DTS_MASK; + bdt[EP_BDT_IDX(log_endpoint, RX, ODD)].byte_count = max_packet; + bdt[EP_BDT_IDX(log_endpoint, RX, ODD)].address = (uint32_t) buf; + bdt[EP_BDT_IDX(log_endpoint, RX, ODD)].info = BD_DTS_MASK; bdt[EP_BDT_IDX(log_endpoint, RX, EVEN)].info = 0; if (log_endpoint == 0) { // Prepare for setup packet - bdt[EP_BDT_IDX(log_endpoint, RX, ODD )].info |= BD_OWN_MASK; + bdt[EP_BDT_IDX(log_endpoint, RX, ODD)].info |= BD_OWN_MASK; } USB0->ENDPOINT[log_endpoint].ENDPT |= handshake_flag | // ep handshaking (not if iso endpoint) USB_ENDPT_EPRXEN_MASK; // en RX (OUT) tran. @@ -466,8 +467,7 @@ bool USBPhyHw::endpoint_read_core(usb_ep_t endpoint, uint32_t max_packet) bdt[idx].byte_count = max_packet; if ((Data1 >> DESC_TO_PHY(endpoint)) & 1) { bdt[idx].info = BD_OWN_MASK | BD_DTS_MASK | BD_DATA01_MASK; - } - else { + } else { bdt[idx].info = BD_OWN_MASK | BD_DTS_MASK; } @@ -491,7 +491,7 @@ bool USBPhyHw::endpoint_read_result_core(usb_ep_t endpoint, uint8_t *data, uint3 { uint32_t n, sz, idx, setup = 0; uint8_t not_iso; - uint8_t * ep_buf; + uint8_t *ep_buf; uint32_t log_endpoint = DESC_TO_LOG(endpoint); @@ -542,7 +542,7 @@ bool USBPhyHw::endpoint_read_result_core(usb_ep_t endpoint, uint8_t *data, uint3 bool USBPhyHw::endpoint_write(usb_ep_t endpoint, uint8_t *data, uint32_t size) { uint32_t idx, n; - uint8_t * ep_buf; + uint8_t *ep_buf; if (DESC_TO_PHY(endpoint) > NUMBER_OF_PHYSICAL_ENDPOINTS - 1) { return false; @@ -588,7 +588,7 @@ void USBPhyHw::process() // reset interrupt if (istat & USB_ISTAT_USBRST_MASK) { // disable all endpt - for(i = 0; i < 16; i++) { + for (i = 0; i < 16; i++) { USB0->ENDPOINT[i].ENDPT = 0x00; } @@ -631,9 +631,10 @@ void USBPhyHw::process() } // stall interrupt - if (istat & 1<<7) { - if (USB0->ENDPOINT[0].ENDPT & USB_ENDPT_EPSTALL_MASK) + if (istat & 1 << 7) { + if (USB0->ENDPOINT[0].ENDPT & USB_ENDPT_EPSTALL_MASK) { USB0->ENDPOINT[0].ENDPT &= ~USB_ENDPT_EPSTALL_MASK; + } USB0->ISTAT = USB_ISTAT_STALL_MASK; } @@ -660,9 +661,9 @@ void USBPhyHw::process() } else { // OUT packet if (rx_en && (TOK_PID((EP_BDT_IDX(num, dir, ev_odd))) == OUT_TOKEN)) { - if (num == 0) + if (num == 0) { events->ep0_out(); - else { + } else { epComplete |= EP(phy_ep); events->out(PHY_TO_DESC(phy_ep)); } @@ -676,8 +677,7 @@ void USBPhyHw::process() USB0->ADDR = addr & 0x7F; set_addr = 0; } - } - else { + } else { epComplete |= EP(phy_ep); events->in(PHY_TO_DESC(phy_ep)); } @@ -688,7 +688,7 @@ void USBPhyHw::process() } // sleep interrupt - if (istat & 1<<4) { + if (istat & 1 << 4) { USB0->ISTAT = USB_ISTAT_SLEEP_MASK; events->suspend(true); } @@ -713,7 +713,8 @@ void USBPhyHw::process() NVIC_EnableIRQ(USB0_IRQn); } -void USBPhyHw::_usbisr(void) { +void USBPhyHw::_usbisr(void) +{ NVIC_DisableIRQ(USB0_IRQn); instance->events->start_process(); } diff --git a/usb/device/targets/TARGET_NXP/USBHAL_LPC17.cpp b/usb/device/targets/TARGET_NXP/USBHAL_LPC17.cpp index fe802b00f5..5f8f60ce91 100644 --- a/usb/device/targets/TARGET_NXP/USBHAL_LPC17.cpp +++ b/usb/device/targets/TARGET_NXP/USBHAL_LPC17.cpp @@ -126,10 +126,10 @@ static USBPhyHw *instance; static uint32_t opStarted; static const usb_ep_t ISO_EPS[] = { - 0x03, 0x83, - 0x06, 0x86, - 0x09, 0x89, - 0x0C, 0x8C + 0x03, 0x83, + 0x06, 0x86, + 0x09, 0x89, + 0x0C, 0x8C }; static void SIECommand(uint32_t command) @@ -171,7 +171,7 @@ static uint8_t SIEgetDeviceStatus(void) return SIEReadData(SIE_CMD_GET_DEVICE_STATUS); } -void SIEsetAddress(uint8_t address, bool enable=true) +void SIEsetAddress(uint8_t address, bool enable = true) { // Write SIE device address register SIECommand(SIE_CMD_SET_ADDRESS); diff --git a/usb/device/targets/TARGET_RENESAS/TARGET_RZ_A1XX/USBPhyHw.h b/usb/device/targets/TARGET_RENESAS/TARGET_RZ_A1XX/USBPhyHw.h index 62d05dc91b..a881c82cf0 100644 --- a/usb/device/targets/TARGET_RENESAS/TARGET_RZ_A1XX/USBPhyHw.h +++ b/usb/device/targets/TARGET_RENESAS/TARGET_RZ_A1XX/USBPhyHw.h @@ -37,7 +37,7 @@ public: virtual void sof_disable(); virtual void set_address(uint8_t address); virtual void remote_wakeup(); - virtual const usb_ep_table_t* endpoint_table(); + virtual const usb_ep_table_t *endpoint_table(); virtual uint32_t ep0_set_max_packet(uint32_t max_packet); virtual void ep0_setup_read_result(uint8_t *buffer, uint32_t size); @@ -59,7 +59,7 @@ public: virtual void process(); private: - #define PIPE_NUM (16) +#define PIPE_NUM (16) typedef struct { bool enable; @@ -76,18 +76,18 @@ private: static void _usbisr(void); void chg_curpipe(uint16_t pipe, uint16_t isel); uint16_t is_set_frdy(uint16_t pipe, uint16_t isel); - uint8_t * read_fifo(uint16_t pipe, uint16_t count, uint8_t *read_p); + uint8_t *read_fifo(uint16_t pipe, uint16_t count, uint8_t *read_p); uint16_t read_data(uint16_t pipe); void fifo_to_buf(uint16_t pipe); - uint8_t * write_fifo(uint16_t pipe, uint16_t count, uint8_t *write_p); + uint8_t *write_fifo(uint16_t pipe, uint16_t count, uint8_t *write_p); uint16_t write_data(uint16_t pipe); void buf_to_fifo(uint16_t pipe); - uint16_t * get_pipectr_reg(uint16_t pipe); - uint16_t * get_pipetre_reg(uint16_t pipe); - uint16_t * get_pipetrn_reg(uint16_t pipe); - uint16_t * get_fifoctr_reg(uint16_t pipe); - uint16_t * get_fifosel_reg(uint16_t pipe); - uint32_t * get_fifo_reg(uint16_t pipe); + uint16_t *get_pipectr_reg(uint16_t pipe); + uint16_t *get_pipetre_reg(uint16_t pipe); + uint16_t *get_pipetrn_reg(uint16_t pipe); + uint16_t *get_fifoctr_reg(uint16_t pipe); + uint16_t *get_fifosel_reg(uint16_t pipe); + uint32_t *get_fifo_reg(uint16_t pipe); uint16_t get_pid(uint16_t pipe); void set_mbw(uint16_t pipe, uint16_t data); void set_pid(uint16_t pipe, uint16_t new_pid); diff --git a/usb/device/targets/TARGET_RENESAS/TARGET_RZ_A1XX/USBPhy_RZ_A1.cpp b/usb/device/targets/TARGET_RENESAS/TARGET_RZ_A1XX/USBPhy_RZ_A1.cpp index e5371f3250..9d6cebaac1 100644 --- a/usb/device/targets/TARGET_RENESAS/TARGET_RZ_A1XX/USBPhy_RZ_A1.cpp +++ b/usb/device/targets/TARGET_RENESAS/TARGET_RZ_A1XX/USBPhy_RZ_A1.cpp @@ -502,11 +502,17 @@ bool USBPhyHw::endpoint_read(usb_ep_t endpoint, uint8_t *data, uint32_t size) /* Set Transaction counter */ p_reg = get_pipetre_reg(pipe); - if (p_reg != NULL) *p_reg |= USB_TRCLR; + if (p_reg != NULL) { + *p_reg |= USB_TRCLR; + } p_reg = get_pipetrn_reg(pipe); - if (p_reg != NULL) *p_reg = trncnt; + if (p_reg != NULL) { + *p_reg = trncnt; + } p_reg = get_pipetre_reg(pipe); - if (p_reg != NULL) *p_reg |= USB_TRENB; + if (p_reg != NULL) { + *p_reg |= USB_TRENB; + } p_reg = get_pipectr_reg(pipe); /* Buffer Clear */ @@ -701,14 +707,12 @@ void USBPhyHw::process() } events->ep0_out(); } - } - else if (((ists0 & USB_BEMP) == USB_BEMP) && ((ests & USB_BEMP0) == USB_BEMP0)) { + } else if (((ists0 & USB_BEMP) == USB_BEMP) && ((ests & USB_BEMP0) == USB_BEMP0)) { /* ==== BEMP PIPE0 ==== */ USB_MX.BEMPSTS = (uint16_t)((~USB_BEMP0) & BEMPSTS_MASK); events->ep0_in(); - } - else if (((ists0 & USB_NRDY) == USB_NRDY) && ((nsts & USB_NRDY0) == USB_NRDY0)) { + } else if (((ists0 & USB_NRDY) == USB_NRDY) && ((nsts & USB_NRDY0) == USB_NRDY0)) { /* ==== NRDY PIPE0 ==== */ USB_MX.NRDYSTS = (uint16_t)((~USB_NRDY0) & NRDYSTS_MASK); /* Non processing. */ @@ -783,8 +787,7 @@ void USBPhyHw::process() } } } - } - else if ((ists0 & USB_BEMP) == USB_BEMP) { + } else if ((ists0 & USB_BEMP) == USB_BEMP) { /* ==== BEMP PIPEx ==== */ USB_MX.BEMPSTS = (uint16_t)((~ests) & BEMPSTS_MASK); @@ -806,8 +809,7 @@ void USBPhyHw::process() } } } - } - else if ((ists0 & USB_NRDY) == USB_NRDY) { + } else if ((ists0 & USB_NRDY) == USB_NRDY) { /* ==== NRDY PIPEx ==== */ USB_MX.NRDYSTS = (uint16_t)((~nsts) & NRDYSTS_MASK); @@ -821,8 +823,7 @@ void USBPhyHw::process() } } } - } - else { + } else { /* Non processing. */ } } @@ -892,7 +893,7 @@ uint16_t USBPhyHw::is_set_frdy(uint16_t pipe, uint16_t isel) return (USB_FIFOERROR); } -uint8_t * USBPhyHw::read_fifo(uint16_t pipe, uint16_t count, uint8_t *read_p) +uint8_t *USBPhyHw::read_fifo(uint16_t pipe, uint16_t count, uint8_t *read_p) { iodefine_reg32_t *p_reg; uint16_t even; @@ -1018,7 +1019,7 @@ void USBPhyHw::fifo_to_buf(uint16_t pipe) } } -uint8_t * USBPhyHw::write_fifo(uint16_t pipe, uint16_t count, uint8_t *write_p) +uint8_t *USBPhyHw::write_fifo(uint16_t pipe, uint16_t count, uint8_t *write_p) { iodefine_reg32_t *p_reg; uint16_t even; @@ -1147,77 +1148,77 @@ void USBPhyHw::buf_to_fifo(uint16_t pipe) } } -uint16_t * USBPhyHw::get_pipectr_reg(uint16_t pipe) +uint16_t *USBPhyHw::get_pipectr_reg(uint16_t pipe) { if (pipe == USB_PIPE0) { - return (uint16_t *)&(USB_MX.DCPCTR); + return (uint16_t *) & (USB_MX.DCPCTR); } else { - return (uint16_t *)&(USB_MX.PIPE1CTR) + (pipe - USB_PIPE1); + return (uint16_t *) & (USB_MX.PIPE1CTR) + (pipe - USB_PIPE1); } } -uint16_t * USBPhyHw::get_pipetre_reg(uint16_t pipe) +uint16_t *USBPhyHw::get_pipetre_reg(uint16_t pipe) { if ((pipe >= USB_PIPE1) && (pipe <= USB_PIPE5)) { - return (uint16_t *)&(USB_MX.PIPE1TRE) + ((pipe - USB_PIPE1) * 2); + return (uint16_t *) & (USB_MX.PIPE1TRE) + ((pipe - USB_PIPE1) * 2); } else if ((pipe >= USB_PIPE9) && (pipe <= USB_PIPE10)) { - return (uint16_t *)&(USB_MX.PIPE9TRE) + ((pipe - USB_PIPE9) * 2); + return (uint16_t *) & (USB_MX.PIPE9TRE) + ((pipe - USB_PIPE9) * 2); } else if ((pipe >= USB_PIPE11) && (pipe <= USB_PIPE15)) { - return (uint16_t *)&(USB_MX.PIPEBTRE) + ((pipe - USB_PIPE11) * 2); + return (uint16_t *) & (USB_MX.PIPEBTRE) + ((pipe - USB_PIPE11) * 2); } else { return NULL; } } -uint16_t * USBPhyHw::get_pipetrn_reg(uint16_t pipe) +uint16_t *USBPhyHw::get_pipetrn_reg(uint16_t pipe) { if ((pipe >= USB_PIPE1) && (pipe <= USB_PIPE5)) { - return (uint16_t *)&(USB_MX.PIPE1TRN) + ((pipe - USB_PIPE1) * 2); + return (uint16_t *) & (USB_MX.PIPE1TRN) + ((pipe - USB_PIPE1) * 2); } else if ((pipe >= USB_PIPE9) && (pipe <= USB_PIPE10)) { - return (uint16_t *)&(USB_MX.PIPE9TRN) + ((pipe - USB_PIPE9) * 2); + return (uint16_t *) & (USB_MX.PIPE9TRN) + ((pipe - USB_PIPE9) * 2); } else if ((pipe >= USB_PIPE11) && (pipe <= USB_PIPE15)) { - return (uint16_t *)&(USB_MX.PIPEBTRN) + ((pipe - USB_PIPE11) * 2); + return (uint16_t *) & (USB_MX.PIPEBTRN) + ((pipe - USB_PIPE11) * 2); } else { return NULL; } } -uint16_t * USBPhyHw::get_fifoctr_reg(uint16_t pipe) +uint16_t *USBPhyHw::get_fifoctr_reg(uint16_t pipe) { uint16_t fifo_use = PIPE2FIFO(pipe); if ((fifo_use & USB_FUNCTION_D0FIFO_USE) == USB_FUNCTION_D0FIFO_USE) { - return (uint16_t *)&(USB_MX.D0FIFOCTR); + return (uint16_t *) & (USB_MX.D0FIFOCTR); } else if ((fifo_use & USB_FUNCTION_D1FIFO_USE) == USB_FUNCTION_D1FIFO_USE) { - return (uint16_t *)&(USB_MX.D1FIFOCTR); + return (uint16_t *) & (USB_MX.D1FIFOCTR); } else { - return (uint16_t *)&(USB_MX.CFIFOCTR); + return (uint16_t *) & (USB_MX.CFIFOCTR); } } -uint16_t * USBPhyHw::get_fifosel_reg(uint16_t pipe) +uint16_t *USBPhyHw::get_fifosel_reg(uint16_t pipe) { uint16_t fifo_use = PIPE2FIFO(pipe); if ((fifo_use & USB_FUNCTION_D0FIFO_USE) == USB_FUNCTION_D0FIFO_USE) { - return (uint16_t *)&(USB_MX.D0FIFOSEL); + return (uint16_t *) & (USB_MX.D0FIFOSEL); } else if ((fifo_use & USB_FUNCTION_D1FIFO_USE) == USB_FUNCTION_D1FIFO_USE) { - return (uint16_t *)&(USB_MX.D1FIFOSEL); + return (uint16_t *) & (USB_MX.D1FIFOSEL); } else { - return (uint16_t *)&(USB_MX.CFIFOSEL); + return (uint16_t *) & (USB_MX.CFIFOSEL); } } -uint32_t * USBPhyHw::get_fifo_reg(uint16_t pipe) +uint32_t *USBPhyHw::get_fifo_reg(uint16_t pipe) { uint16_t fifo_use = PIPE2FIFO(pipe); if ((fifo_use & USB_FUNCTION_D0FIFO_USE) == USB_FUNCTION_D0FIFO_USE) { - return (uint32_t *)&(USB_MX.D0FIFO); + return (uint32_t *) & (USB_MX.D0FIFO); } else if ((fifo_use & USB_FUNCTION_D1FIFO_USE) == USB_FUNCTION_D1FIFO_USE) { - return (uint32_t *)&(USB_MX.D1FIFO); + return (uint32_t *) & (USB_MX.D1FIFO); } else { - return (uint32_t *)&(USB_MX.CFIFO); + return (uint32_t *) & (USB_MX.CFIFO); } } @@ -1259,8 +1260,8 @@ void USBPhyHw::set_pid(uint16_t pipe, uint16_t new_pid) } break; case USB_PID_BUF: - if (((old_pid & USB_PID_STALL) == USB_PID_STALL) || - ((old_pid & USB_PID_STALL2) == USB_PID_STALL2)) { + if (((old_pid & USB_PID_STALL) == USB_PID_STALL) || + ((old_pid & USB_PID_STALL2) == USB_PID_STALL2)) { *p_reg &= (~USB_PID); *p_reg |= USB_PID_NAK; } diff --git a/usb/device/targets/TARGET_RENESAS/TARGET_RZ_A1XX/USBPhy_RZ_A1_Def.h b/usb/device/targets/TARGET_RENESAS/TARGET_RZ_A1XX/USBPhy_RZ_A1_Def.h index cd26180161..5506260e58 100644 --- a/usb/device/targets/TARGET_RENESAS/TARGET_RZ_A1XX/USBPhy_RZ_A1_Def.h +++ b/usb/device/targets/TARGET_RENESAS/TARGET_RZ_A1XX/USBPhy_RZ_A1_Def.h @@ -680,7 +680,7 @@ #define USB_CF_RWUPON (0x20u) /* Remote Wake up ON */ #define USB_CF_RWUPOFF (0x00u) /* Remote Wake up OFF */ - /* Descriptor length Define */ +/* Descriptor length Define */ #define USB_DD_BLENGTH (18u) /* Device Descriptor Length */ #define USB_CD_BLENGTH (9u) /* Configuration Descriptor Length */ #define USB_ID_BLENGTH (9u) /* Interface Descriptor Length */ diff --git a/usb/device/targets/TARGET_STM/USBPhyHw.h b/usb/device/targets/TARGET_STM/USBPhyHw.h index 68c3ccb876..698ebb2355 100644 --- a/usb/device/targets/TARGET_STM/USBPhyHw.h +++ b/usb/device/targets/TARGET_STM/USBPhyHw.h @@ -63,7 +63,7 @@ public: virtual void sof_disable(); virtual void set_address(uint8_t address); virtual void remote_wakeup(); - virtual const usb_ep_table_t* endpoint_table(); + virtual const usb_ep_table_t *endpoint_table(); virtual uint32_t ep0_set_max_packet(uint32_t max_packet); virtual void ep0_setup_read_result(uint8_t *buffer, uint32_t size); diff --git a/usb/device/targets/TARGET_STM/USBPhy_STM32.cpp b/usb/device/targets/TARGET_STM/USBPhy_STM32.cpp index ec2e350fbd..e5ff9c1674 100644 --- a/usb/device/targets/TARGET_STM/USBPhy_STM32.cpp +++ b/usb/device/targets/TARGET_STM/USBPhy_STM32.cpp @@ -42,10 +42,10 @@ #define ENDPOINT_NON_ISO (USB_EP_ATTR_ALLOW_BULK | USB_EP_ATTR_ALLOW_INT) static const uint32_t tx_ep_sizes[NUM_ENDPOINTS] = { - MAX_PACKET_NON_ISO, - MAX_PACKET_NON_ISO, - MAX_PACKET_NON_ISO, - MAX_PACKET_ISO + MAX_PACKET_NON_ISO, + MAX_PACKET_NON_ISO, + MAX_PACKET_NON_ISO, + MAX_PACKET_ISO }; uint32_t HAL_PCDEx_GetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo) @@ -53,8 +53,7 @@ uint32_t HAL_PCDEx_GetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo) uint32_t len; if (fifo == 0) { len = hpcd->Instance->DIEPTXF0_HNPTXFSIZ >> 16; - } - else { + } else { len = hpcd->Instance->DIEPTXF[fifo - 1] >> 16; } return len * 4; @@ -62,7 +61,7 @@ uint32_t HAL_PCDEx_GetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo) void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) { - USBPhyHw *priv=((USBPhyHw *)(hpcd->pData)); + USBPhyHw *priv = ((USBPhyHw *)(hpcd->pData)); USB_OTG_GlobalTypeDef *USBx = hpcd->Instance; if (priv->sof_enabled) { priv->events->sof((USBx_DEVICE->DSTS & USB_OTG_DSTS_FNSOF) >> 8); @@ -72,7 +71,7 @@ void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) /* this call at device reception completion on a Out Enpoint */ void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) { - USBPhyHw *priv=((USBPhyHw *)(hpcd->pData)); + USBPhyHw *priv = ((USBPhyHw *)(hpcd->pData)); uint8_t endpoint = LOG_OUT_TO_EP(epnum); priv->epComplete[EP_TO_IDX(endpoint)] = 1; /* -2 endpoint 0 In out are not in call back list */ @@ -86,7 +85,7 @@ void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) /* this is call at device transmission completion on In endpoint */ void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) { - USBPhyHw *priv=((USBPhyHw *)(hpcd->pData)); + USBPhyHw *priv = ((USBPhyHw *)(hpcd->pData)); uint8_t endpoint = LOG_IN_TO_EP(epnum); priv->epComplete[EP_TO_IDX(endpoint)] = 1; /* -2 endpoint 0 In out are not in call back list */ @@ -99,19 +98,19 @@ void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) /* This is call at device set up reception */ void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) { - USBPhyHw *priv=((USBPhyHw *)(hpcd->pData)); + USBPhyHw *priv = ((USBPhyHw *)(hpcd->pData)); priv->events->ep0_setup(); } void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) { - USBPhyHw *priv=((USBPhyHw *)(hpcd->pData)); + USBPhyHw *priv = ((USBPhyHw *)(hpcd->pData)); priv->events->suspend(1); } void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) { - USBPhyHw *priv=((USBPhyHw *)(hpcd->pData)); + USBPhyHw *priv = ((USBPhyHw *)(hpcd->pData)); priv->events->suspend(0); } @@ -127,15 +126,15 @@ void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) { - USBPhyHw *obj=((USBPhyHw *)(hpcd->pData)); + USBPhyHw *obj = ((USBPhyHw *)(hpcd->pData)); unsigned int i; - for(i=0;iInit.dev_endpoints;i++) { - obj->epComplete[2*i]=0; - HAL_PCD_EP_Close(hpcd,IDX_TO_EP(2*i)); - HAL_PCD_EP_Flush(hpcd,IDX_TO_EP(2*i)); - obj->epComplete[2*i+1]=0; - HAL_PCD_EP_Close(hpcd,IDX_TO_EP(2*i+1)); - HAL_PCD_EP_Flush(hpcd,IDX_TO_EP(2*i+1)); + for (i = 0; i < hpcd->Init.dev_endpoints; i++) { + obj->epComplete[2 * i] = 0; + HAL_PCD_EP_Close(hpcd, IDX_TO_EP(2 * i)); + HAL_PCD_EP_Flush(hpcd, IDX_TO_EP(2 * i)); + obj->epComplete[2 * i + 1] = 0; + HAL_PCD_EP_Close(hpcd, IDX_TO_EP(2 * i + 1)); + HAL_PCD_EP_Flush(hpcd, IDX_TO_EP(2 * i + 1)); } obj->endpoint_add(EP0IN, MAX_PACKET_SIZE_EP0, USB_EP_TYPE_CTRL); @@ -299,7 +298,7 @@ void USBPhyHw::init(USBPhyEvents *events) __HAL_RCC_SYSCFG_CLK_ENABLE(); // Configure PCD and FIFOs - hpcd.pData = (void*)this; + hpcd.pData = (void *)this; hpcd.State = HAL_PCD_STATE_RESET; HAL_PCD_Init(&hpcd); @@ -427,7 +426,7 @@ void USBPhyHw::ep0_setup_read_result(uint8_t *buffer, uint32_t size) size = MAX_PACKET_SIZE_SETUP; } memcpy(buffer, hpcd.Setup, size); - memset(hpcd.Setup,0,MAX_PACKET_SIZE_SETUP); + memset(hpcd.Setup, 0, MAX_PACKET_SIZE_SETUP); } void USBPhyHw::ep0_read(uint8_t *data, uint32_t size) @@ -435,7 +434,7 @@ void USBPhyHw::ep0_read(uint8_t *data, uint32_t size) HAL_StatusTypeDef ret; epComplete[EP_TO_IDX(EP0OUT)] = 2; ret = HAL_PCD_EP_Receive(&hpcd, EP0OUT, data, size > MAX_PACKET_SIZE_EP0 ? MAX_PACKET_SIZE_EP0 : size); - MBED_ASSERT(ret!=HAL_BUSY); + MBED_ASSERT(ret != HAL_BUSY); } uint32_t USBPhyHw::ep0_read_result() @@ -466,12 +465,12 @@ bool USBPhyHw::endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_ * fifos when endpoints are added or removed causes tests to fail. */ if (endpoint & 0x80) { - len = HAL_PCDEx_GetTxFiFo(&hpcd,endpoint & 0x7f); + len = HAL_PCDEx_GetTxFiFo(&hpcd, endpoint & 0x7f); MBED_ASSERT(len >= max_packet); } HAL_StatusTypeDef ret = HAL_PCD_EP_Open(&hpcd, endpoint, max_packet, type); - MBED_ASSERT(ret!=HAL_BUSY); - return (ret == HAL_OK) ? true:false; + MBED_ASSERT(ret != HAL_BUSY); + return (ret == HAL_OK) ? true : false; } void USBPhyHw::endpoint_remove(usb_ep_t endpoint) @@ -484,33 +483,33 @@ void USBPhyHw::endpoint_stall(usb_ep_t endpoint) { HAL_StatusTypeDef ret; ret = HAL_PCD_EP_SetStall(&hpcd, endpoint); - MBED_ASSERT(ret!=HAL_BUSY); + MBED_ASSERT(ret != HAL_BUSY); } void USBPhyHw::endpoint_unstall(usb_ep_t endpoint) { HAL_StatusTypeDef ret; ret = HAL_PCD_EP_ClrStall(&hpcd, endpoint); - MBED_ASSERT(ret!=HAL_BUSY); + MBED_ASSERT(ret != HAL_BUSY); } bool USBPhyHw::endpoint_read(usb_ep_t endpoint, uint8_t *data, uint32_t size) { // clean reception end flag before requesting reception HAL_StatusTypeDef ret = HAL_PCD_EP_Receive(&hpcd, endpoint, data, size); - MBED_ASSERT(ret!=HAL_BUSY); + MBED_ASSERT(ret != HAL_BUSY); return true; } uint32_t USBPhyHw::endpoint_read_result(usb_ep_t endpoint) { - if (epComplete[EP_TO_IDX(endpoint)]==0) { + if (epComplete[EP_TO_IDX(endpoint)] == 0) { /* no reception possible !!! */ return 0; - } else if ((epComplete[EP_TO_IDX(endpoint)]!=1)) { + } else if ((epComplete[EP_TO_IDX(endpoint)] != 1)) { return 0; } - epComplete[EP_TO_IDX(endpoint)]= 0; + epComplete[EP_TO_IDX(endpoint)] = 0; return HAL_PCD_EP_GetRxCount(&hpcd, endpoint);; } @@ -520,9 +519,11 @@ bool USBPhyHw::endpoint_write(usb_ep_t endpoint, uint8_t *data, uint32_t size) // clean transmission end flag before requesting transmission epComplete[EP_TO_IDX(endpoint)] = 2; ret = HAL_PCD_EP_Transmit(&hpcd, endpoint, data, size); - MBED_ASSERT(ret!=HAL_BUSY); + MBED_ASSERT(ret != HAL_BUSY); // update the status - if (ret != HAL_OK) return false; + if (ret != HAL_OK) { + return false; + } // fix me return is too simple return true; } @@ -530,7 +531,7 @@ bool USBPhyHw::endpoint_write(usb_ep_t endpoint, uint8_t *data, uint32_t size) void USBPhyHw::endpoint_abort(usb_ep_t endpoint) { HAL_StatusTypeDef ret = HAL_PCD_EP_Abort(&hpcd, endpoint); - MBED_ASSERT(ret==HAL_OK); + MBED_ASSERT(ret == HAL_OK); } void USBPhyHw::process() @@ -541,7 +542,8 @@ void USBPhyHw::process() NVIC_EnableIRQ(USBHAL_IRQn); } -void USBPhyHw::_usbisr(void) { +void USBPhyHw::_usbisr(void) +{ NVIC_DisableIRQ(USBHAL_IRQn); instance->events->start_process(); } diff --git a/usb/device/targets/TARGET_Template/USBPhyHw.h b/usb/device/targets/TARGET_Template/USBPhyHw.h index 395dc6c63e..1476fa797f 100644 --- a/usb/device/targets/TARGET_Template/USBPhyHw.h +++ b/usb/device/targets/TARGET_Template/USBPhyHw.h @@ -37,7 +37,7 @@ public: virtual void sof_disable(); virtual void set_address(uint8_t address); virtual void remote_wakeup(); - virtual const usb_ep_table_t* endpoint_table(); + virtual const usb_ep_table_t *endpoint_table(); virtual uint32_t ep0_set_max_packet(uint32_t max_packet); virtual void ep0_setup_read_result(uint8_t *buffer, uint32_t size); diff --git a/usb/device/targets/TARGET_Template/USBPhy_template.cpp b/usb/device/targets/TARGET_Template/USBPhy_template.cpp index 28c0a3caa3..fe0d559e61 100644 --- a/usb/device/targets/TARGET_Template/USBPhy_template.cpp +++ b/usb/device/targets/TARGET_Template/USBPhy_template.cpp @@ -304,7 +304,8 @@ void USBPhyHw::process() NVIC_EnableIRQ(USB_IRQn); } -void USBPhyHw::_usbisr(void) { +void USBPhyHw::_usbisr(void) +{ NVIC_DisableIRQ(USB_IRQn); instance->events->start_process(); }