From 1af0960fe5be9eea0303e5e6987d14eedd948aea Mon Sep 17 00:00:00 2001 From: Dimitris Mantzouranis Date: Sat, 10 Aug 2024 15:33:37 +0300 Subject: [PATCH 1/9] sn32: usb: update registers for max 7+1 endpoints --- os/hal/ports/SN32/LLD/SN32F2xx/USB/sn32_usb.h | 49 ++++++++++--------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/os/hal/ports/SN32/LLD/SN32F2xx/USB/sn32_usb.h b/os/hal/ports/SN32/LLD/SN32F2xx/USB/sn32_usb.h index c5974b06fb..99e4e5644b 100644 --- a/os/hal/ports/SN32/LLD/SN32F2xx/USB/sn32_usb.h +++ b/os/hal/ports/SN32/LLD/SN32F2xx/USB/sn32_usb.h @@ -32,12 +32,12 @@ * @brief Number of the available endpoints. * @details This value does not include the endpoint 0 which is always present. */ -#define HAL_MAX_ENDPOINTS 6 +#define HAL_MAX_ENDPOINTS 7 #if (defined(SN32F240B) || defined(SN32F260)) #define USB_ENDPOINTS_NUMBER 4 #define SN32_USB_PMA_SIZE 256 #elif (defined(SN32F280) || defined(SN32F290)) -#define USB_ENDPOINTS_NUMBER HAL_MAX_ENDPOINTS +#define USB_ENDPOINTS_NUMBER 6 #define SN32_USB_PMA_SIZE 512 #else #error "USB driver not supported in the selected device" @@ -47,30 +47,33 @@ * @brief USB registers block. */ typedef struct { - volatile uint32_t INTEN; /*!< (@ 0x00000000) Offset:0x00 USB Interrupt Enable Register */ - volatile uint32_t INSTS; /*!< (@ 0x00000004) Offset:0x04 USB Interrupt Event Status Register */ - volatile uint32_t INSTSC; /*!< (@ 0x00000008) Offset:0x08 USB Interrupt Event Status Clear Register */ - volatile uint32_t ADDR; /*!< (@ 0x0000000C) Offset:0x0C USB Device Address Register */ - volatile uint32_t CFG; /*!< (@ 0x00000010) Offset:0x10 USB Configuration Register */ - volatile uint32_t SGCTL; /*!< (@ 0x00000014) Offset:0x14 USB Signal Control Register */ - volatile uint32_t EPCTL[HAL_MAX_ENDPOINTS +1]; /*!< (@ 0x00000018) Offset:0x18 USB Endpoint 0-6 Control Registers */ - volatile uint32_t RESERVED[2]; - volatile uint32_t EPTOGGLE; /*!< (@ 0x0000003C) Offset:0x3C USB Endpoint Data Toggle Register */ + volatile uint32_t INTEN; /*!< (@ 0x00000000) Offset:0x00 USB Interrupt Enable Register */ + volatile uint32_t INSTS; /*!< (@ 0x00000004) Offset:0x04 USB Interrupt Event Status Register */ + volatile uint32_t INSTSC; /*!< (@ 0x00000008) Offset:0x08 USB Interrupt Event Status Clear Register */ + volatile uint32_t ADDR; /*!< (@ 0x0000000C) Offset:0x0C USB Device Address Register */ + volatile uint32_t CFG; /*!< (@ 0x00000010) Offset:0x10 USB Configuration Register */ + volatile uint32_t SGCTL; /*!< (@ 0x00000014) Offset:0x14 USB Signal Control Register */ + volatile uint32_t EPCTL[USB_ENDPOINTS_NUMBER +1]; /*!< (@ 0x00000018) Offset:0x18 USB Endpoint 0-7 Control Registers */ + volatile uint32_t RESERVED[HAL_MAX_ENDPOINTS - USB_ENDPOINTS_NUMBER + 1]; + volatile uint32_t EPTOGGLE; /*!< (@ 0x0000003C) Offset:0x3C USB Endpoint Data Toggle Register */ volatile uint32_t RESERVED1[2]; - volatile uint32_t EPBUFOS[HAL_MAX_ENDPOINTS]; /*!< (@ 0x00000048) Offset:0x48 USB Endpoint 1-6 Buffer Offset Registers */ - volatile uint32_t FRMNO; /*!< (@ 0x00000060) Offset:0x60 USB Frame Number Register */ - volatile uint32_t PHYPRM; /*!< (@ 0x00000064) Offset:0x64 USB PHY Parameter Register */ + volatile uint32_t EPBUFOS[USB_ENDPOINTS_NUMBER]; /*!< (@ 0x00000048) Offset:0x48 USB Endpoint 1-7 Buffer Offset Registers */ +#if (USB_ENDPOINTS_NUMBER != HAL_MAX_ENDPOINTS) + volatile uint32_t RESERVED2[HAL_MAX_ENDPOINTS - USB_ENDPOINTS_NUMBER - 1]; +#endif + volatile uint32_t FRMNO; /*!< (@ 0x00000060) Offset:0x60 USB Frame Number Register */ + volatile uint32_t PHYPRM; /*!< (@ 0x00000064) Offset:0x64 USB PHY Parameter Register */ volatile uint32_t RESERVED3; - volatile uint32_t PHYPRM2; /*!< (@ 0x0000006C) Offset:0x6C USB PHY Parameter 2 Register */ - volatile uint32_t PS2CTL; /*!< (@ 0x00000070) Offset:0x70 PS/2 Control Register */ + volatile uint32_t PHYPRM2; /*!< (@ 0x0000006C) Offset:0x6C USB PHY Parameter 2 Register */ + volatile uint32_t PS2CTL; /*!< (@ 0x00000070) Offset:0x70 PS/2 Control Register */ volatile uint32_t RESERVED4; - volatile uint32_t RWADDR; /*!< (@ 0x00000078) Offset:0x78 USB Read/Write Address Register */ - volatile uint32_t RWDATA; /*!< (@ 0x0000007C) Offset:0x7C USB Read/Write Data Register */ - volatile uint32_t RWSTATUS; /*!< (@ 0x00000080) Offset:0x80 USB Read/Write Status Register */ - volatile uint32_t RWADDR2; /*!< (@ 0x00000084) Offset:0x84 USB Read/Write Address Register 2 */ - volatile uint32_t RWDATA2; /*!< (@ 0x00000088) Offset:0x88 USB Read/Write Data Register 2 */ - volatile uint32_t RWSTATUS2; /*!< (@ 0x0000008C) Offset:0x8C USB Read/Write Status Register 2 */ -} sn32_usb_t; /*!< Size = 144 (0x90) */ + volatile uint32_t RWADDR; /*!< (@ 0x00000078) Offset:0x78 USB Read/Write Address Register */ + volatile uint32_t RWDATA; /*!< (@ 0x0000007C) Offset:0x7C USB Read/Write Data Register */ + volatile uint32_t RWSTATUS; /*!< (@ 0x00000080) Offset:0x80 USB Read/Write Status Register */ + volatile uint32_t RWADDR2; /*!< (@ 0x00000084) Offset:0x84 USB Read/Write Address Register 2 */ + volatile uint32_t RWDATA2; /*!< (@ 0x00000088) Offset:0x88 USB Read/Write Data Register 2 */ + volatile uint32_t RWSTATUS2; /*!< (@ 0x0000008C) Offset:0x8C USB Read/Write Status Register 2 */ +} sn32_usb_t; /*!< Size = 144 (0x90) */ /** @} */ From bafbd8459cb6d113b5381a2fa4da027a2320e6c9 Mon Sep 17 00:00:00 2001 From: Dimitris Mantzouranis Date: Sat, 10 Aug 2024 15:59:38 +0300 Subject: [PATCH 2/9] sn32: usb: respect read only registers --- os/hal/ports/SN32/LLD/SN32F2xx/USB/sn32_usb.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/os/hal/ports/SN32/LLD/SN32F2xx/USB/sn32_usb.h b/os/hal/ports/SN32/LLD/SN32F2xx/USB/sn32_usb.h index 99e4e5644b..ad2ca442f8 100644 --- a/os/hal/ports/SN32/LLD/SN32F2xx/USB/sn32_usb.h +++ b/os/hal/ports/SN32/LLD/SN32F2xx/USB/sn32_usb.h @@ -48,25 +48,25 @@ */ typedef struct { volatile uint32_t INTEN; /*!< (@ 0x00000000) Offset:0x00 USB Interrupt Enable Register */ - volatile uint32_t INSTS; /*!< (@ 0x00000004) Offset:0x04 USB Interrupt Event Status Register */ + volatile const uint32_t INSTS; /*!< (@ 0x00000004) Offset:0x04 USB Interrupt Event Status Register */ volatile uint32_t INSTSC; /*!< (@ 0x00000008) Offset:0x08 USB Interrupt Event Status Clear Register */ volatile uint32_t ADDR; /*!< (@ 0x0000000C) Offset:0x0C USB Device Address Register */ volatile uint32_t CFG; /*!< (@ 0x00000010) Offset:0x10 USB Configuration Register */ volatile uint32_t SGCTL; /*!< (@ 0x00000014) Offset:0x14 USB Signal Control Register */ volatile uint32_t EPCTL[USB_ENDPOINTS_NUMBER +1]; /*!< (@ 0x00000018) Offset:0x18 USB Endpoint 0-7 Control Registers */ - volatile uint32_t RESERVED[HAL_MAX_ENDPOINTS - USB_ENDPOINTS_NUMBER + 1]; + volatile const uint32_t RESERVED[HAL_MAX_ENDPOINTS - USB_ENDPOINTS_NUMBER + 1]; volatile uint32_t EPTOGGLE; /*!< (@ 0x0000003C) Offset:0x3C USB Endpoint Data Toggle Register */ - volatile uint32_t RESERVED1[2]; + volatile const uint32_t RESERVED1[2]; volatile uint32_t EPBUFOS[USB_ENDPOINTS_NUMBER]; /*!< (@ 0x00000048) Offset:0x48 USB Endpoint 1-7 Buffer Offset Registers */ #if (USB_ENDPOINTS_NUMBER != HAL_MAX_ENDPOINTS) volatile uint32_t RESERVED2[HAL_MAX_ENDPOINTS - USB_ENDPOINTS_NUMBER - 1]; #endif - volatile uint32_t FRMNO; /*!< (@ 0x00000060) Offset:0x60 USB Frame Number Register */ + volatile const uint32_t FRMNO; /*!< (@ 0x00000060) Offset:0x60 USB Frame Number Register */ volatile uint32_t PHYPRM; /*!< (@ 0x00000064) Offset:0x64 USB PHY Parameter Register */ - volatile uint32_t RESERVED3; + volatile const uint32_t RESERVED3; volatile uint32_t PHYPRM2; /*!< (@ 0x0000006C) Offset:0x6C USB PHY Parameter 2 Register */ volatile uint32_t PS2CTL; /*!< (@ 0x00000070) Offset:0x70 PS/2 Control Register */ - volatile uint32_t RESERVED4; + volatile const uint32_t RESERVED4; volatile uint32_t RWADDR; /*!< (@ 0x00000078) Offset:0x78 USB Read/Write Address Register */ volatile uint32_t RWDATA; /*!< (@ 0x0000007C) Offset:0x7C USB Read/Write Data Register */ volatile uint32_t RWSTATUS; /*!< (@ 0x00000080) Offset:0x80 USB Read/Write Status Register */ From ddd5df1ecd16c688b0ecedd6f0bb3dd9a72df729 Mon Sep 17 00:00:00 2001 From: Dimitris Mantzouranis Date: Sat, 10 Aug 2024 17:11:59 +0300 Subject: [PATCH 3/9] sn32: usb: dynamically handle NAK/ACK EPs Multiple EP number variations between the family. Handle all of them dynamically --- .../ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.c | 25 ++++++++----- os/hal/ports/SN32/LLD/SN32F2xx/USB/sn32_usb.h | 17 ++++++--- os/hal/ports/SN32/LLD/SN32F2xx/USB/usbhw.h | 36 ------------------- 3 files changed, 29 insertions(+), 49 deletions(-) diff --git a/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.c b/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.c index cb6f91c7f1..2655d2ffac 100644 --- a/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.c +++ b/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.c @@ -86,7 +86,7 @@ static const USBEndpointConfig ep0config = { /*===========================================================================*/ /* Driver local variables and types. */ /*===========================================================================*/ - +uint32_t msk_EP_NAK, msk_EP_ACK; /*===========================================================================*/ /* Driver local functions. */ /*===========================================================================*/ @@ -306,7 +306,7 @@ static void usb_lld_serve_interrupt(USBDriver *usbp) { ///////////////////////////////////////////////// /* Device Status Interrupt (EPnACK) */ ///////////////////////////////////////////////// - if (iwIntFlag & (mskEP6_ACK|mskEP5_ACK|mskEP4_ACK|mskEP3_ACK|mskEP2_ACK|mskEP1_ACK)) { + if (iwIntFlag & msk_EP_ACK) { // Determine the interrupting endpoint, direction, and clear the interrupt flag for(usbep_t ep = 1; ep <= USB_MAX_ENDPOINTS; ep++) { if (iwIntFlag & mskEPn_ACK(ep)){ @@ -315,9 +315,8 @@ static void usb_lld_serve_interrupt(USBDriver *usbp) { } } } - if (iwIntFlag & (mskEP6_NAK|mskEP5_NAK|mskEP4_NAK|mskEP3_NAK|mskEP2_NAK|mskEP1_NAK)) { - SN32_USB->INSTSC = (mskEP6_NAK|mskEP5_NAK|mskEP4_NAK|mskEP3_NAK|mskEP2_NAK|mskEP1_NAK); - + if (iwIntFlag & msk_EP_NAK) { + SN32_USB->INSTSC = msk_EP_NAK; } } @@ -470,10 +469,18 @@ void usb_lld_start(USBDriver *usbp) { if (usbp->config->sof_cb != NULL) { SN32_USB->INTEN |= mskUSB_SOF_IE; } - //SN32_USB->INTEN |= (mskEP1_NAK_EN|mskEP2_NAK_EN|mskEP3_NAK_EN|mskEP4_NAK_EN); -#if (USB_ENDPOINTS_NUMBER > 4) - //SN32_USB->INTEN |= (mskEP5_NAK_EN|mskEP6_NAK_EN); -#endif /* (USB_ENDPOINTS_NUMBER > 4) */ + /* Calculate EP ACK, NAK, NAK_EN flags.*/ + msk_EP_NAK = 0; + msk_EP_ACK = 0; + //uint32_t msk_EP_NAK_EN = 0; + for(usbep_t ep = 1; ep <= USB_MAX_ENDPOINTS; ep++) { + msk_EP_NAK |= mskEPn_NAK(ep); + msk_EP_ACK |= mskEPn_ACK(ep); + // msk_EP_NAK_EN |= mskEPn_NAK_EN(ep); + } + /* Enable NAK EP interrupts.*/ + // Disabled for now. + // SN32_USB->INTEN |= msk_EP_NAK_EN; } } diff --git a/os/hal/ports/SN32/LLD/SN32F2xx/USB/sn32_usb.h b/os/hal/ports/SN32/LLD/SN32F2xx/USB/sn32_usb.h index ad2ca442f8..cbaad38d92 100644 --- a/os/hal/ports/SN32/LLD/SN32F2xx/USB/sn32_usb.h +++ b/os/hal/ports/SN32/LLD/SN32F2xx/USB/sn32_usb.h @@ -96,10 +96,19 @@ * @brief Pointer to the USB RAM. */ #define SN32_USBRAM ((sn32_usb_pma_t *)SN32_USBRAM_BASE) -#define mskEPn_NAK(ep) (0x1<<(ep -1)) -#define mskEPn_ACK(ep) (0x1<<(8+(ep-1))) -#define mskEPn_DIR(ep) (0x1<<(ep-1)) -#define mskEPn_DATA_TOGGLE(ep) (0x1<<(ep-1)) +/** + * @brief USB EP handling. + */ +/* USB Interrupt Event Status Bit Definitions */ +#define mskEPn_NAK(ep) (0x1<<(ep -1)) +#define mskEPn_ACK(ep) (0x1<<(8+(ep-1))) +/* USB Configuration Bit Definitions */ +#define mskEPn_DIR(ep) (0x1<<(ep-1)) +/* USB Endpoint Data Toggle Bit Definitions */ +#define mskEPn_DATA_TOGGLE(ep) (0x1<<(ep-1)) +/* USB Interrupt Enable Bit Definitions */ +#define mskEPn_NAK_EN(ep) mskEPn_NAK(ep) +#define mskEPnACK_EN (0x1<EPCTL[ep] = (mskEPn_ENDP_EN|mskEPn_ENDP_STATE_ACK|bBytecnt) diff --git a/os/hal/ports/SN32/LLD/SN32F2xx/USB/usbhw.h b/os/hal/ports/SN32/LLD/SN32F2xx/USB/usbhw.h index 36a2f2e99b..627192d9e9 100644 --- a/os/hal/ports/SN32/LLD/SN32F2xx/USB/usbhw.h +++ b/os/hal/ports/SN32/LLD/SN32F2xx/USB/usbhw.h @@ -5,35 +5,12 @@ #define __USBHW_H__ /* USB Interrupt Enable Bit Definitions */ -#define mskEP1_NAK_EN (0x1<<0) -#define mskEP2_NAK_EN (0x1<<1) -#define mskEP3_NAK_EN (0x1<<2) -#define mskEP4_NAK_EN (0x1<<3) -#define mskEP5_NAK_EN (0x1<<4) -#define mskEP6_NAK_EN (0x1<<5) -#define mskEPnACK_EN (0x1<<6) - #define mskBUSWK_IE (0x1<<28) #define mskUSB_IE (0x1<<29) #define mskUSB_SOF_IE (0x1<<30) #define mskBUS_IE (0x1U<<31) /* USB Interrupt Event Status Bit Definitions */ -#define mskEP1_NAK (0x1<<0) -#define mskEP2_NAK (0x1<<1) -#define mskEP3_NAK (0x1<<2) -#define mskEP4_NAK (0x1<<3) -#define mskEP5_NAK (0x1<<4) -#define mskEP6_NAK (0x1<<5) - -#define mskEP1_ACK (0x1<<8) -#define mskEP2_ACK (0x1<<9) -#define mskEP3_ACK (0x1<<10) -#define mskEP4_ACK (0x1<<11) -#define mskEP5_ACK (0x1<<12) -#define mskEP6_ACK (0x1<<13) - - #define mskERR_TIMEOUT (0x1<<17) #define mskERR_SETUP (0x1<<18) #define mskEP0_OUT_STALL (0x1<<19) @@ -52,13 +29,6 @@ #define mskUADDR (0x7F<<0) /* USB Configuration Bit Definitions */ -#define mskEP1_DIR (0x1<<0) -#define mskEP2_DIR (0x1<<1) -#define mskEP3_DIR (0x1<<2) -#define mskEP4_DIR (0x1<<3) -#define mskEP5_DIR (0x1<<4) -#define mskEP6_DIR (0x1<<5) - #define mskDIS_PDEN (0x1<<26) #define mskESD_EN (0x1<<27) #define mskSIE_EN (0x1<<28) @@ -85,12 +55,6 @@ #define mskEPn_ENDP_STATE_STALL (0x3<<29) #define mskEPn_ENDP_EN (0x1U<<31) -/* USB Endpoint Data Toggle Bit Definitions */ -#define mskEP1_CLEAR_DATA0 (0x1<<0) -#define mskEP2_CLEAR_DATA0 (0x1<<1) -#define mskEP3_CLEAR_DATA0 (0x1<<2) -#define mskEP4_CLEAR_DATA0 (0x1<<3) - /* USB Endpoint n Buffer Offset Bit Definitions */ #define mskEPn_OFFSET (0x1FF<<0) From ec0f1e8f889792f0b65c2a724596b0f65b4ef79e Mon Sep 17 00:00:00 2001 From: Dimitris Mantzouranis Date: Sat, 10 Aug 2024 17:19:14 +0300 Subject: [PATCH 4/9] sn32: usb: add undocumented register bits --- os/hal/ports/SN32/LLD/SN32F2xx/USB/usbhw.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/os/hal/ports/SN32/LLD/SN32F2xx/USB/usbhw.h b/os/hal/ports/SN32/LLD/SN32F2xx/USB/usbhw.h index 627192d9e9..9a26613bea 100644 --- a/os/hal/ports/SN32/LLD/SN32F2xx/USB/usbhw.h +++ b/os/hal/ports/SN32/LLD/SN32F2xx/USB/usbhw.h @@ -29,6 +29,8 @@ #define mskUADDR (0x7F<<0) /* USB Configuration Bit Definitions */ +#define mskVREG33DIS_EN (0x1<<24) +#define mskUSBRAM_EN (0x1<<25) #define mskDIS_PDEN (0x1<<26) #define mskESD_EN (0x1<<27) #define mskSIE_EN (0x1<<28) From bdb8a5b7c690b0c50d8888f238bdbc0e5064753a Mon Sep 17 00:00:00 2001 From: Dimitris Mantzouranis Date: Thu, 13 Jun 2024 01:02:32 +0300 Subject: [PATCH 5/9] sn32: usb: add direct sram access support --- os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.c | 14 ++++++++++++-- os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.h | 7 +++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.c b/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.c index 2655d2ffac..23b572c954 100644 --- a/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.c +++ b/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.c @@ -137,6 +137,11 @@ static void sn32_usb_read_fifo(usbep_t ep, uint8_t *buf, size_t sz, bool intr) { if (off + chunk > sz) chunk = sz - off; +#if (SN32_USB_DIRECT_SRAM == TRUE) + volatile uint32_t *sram; + sram = (volatile uint32_t *)(SN32_USBRAM_BASE + off + ep_offset); + data = *sram; +#else if(intr) { SN32_USB->RWADDR = off + ep_offset; SN32_USB->RWSTATUS = 0x02; @@ -149,7 +154,7 @@ static void sn32_usb_read_fifo(usbep_t ep, uint8_t *buf, size_t sz, bool intr) { while (SN32_USB->RWSTATUS2 & 0x02); data = SN32_USB->RWDATA2; } - +#endif //dest, src, size memcpy(buf, &data, chunk); @@ -180,6 +185,11 @@ static void sn32_usb_write_fifo(usbep_t ep, const uint8_t *buf, size_t sz, bool //dest, src, size memcpy(&data, buf, chunk); +#if (SN32_USB_DIRECT_SRAM == TRUE) + volatile uint32_t *sram; + sram = (volatile uint32_t *)(SN32_USBRAM_BASE + off + ep_offset); + *sram = data; +#else if(intr) { SN32_USB->RWADDR = off + ep_offset; SN32_USB->RWDATA = data; @@ -192,7 +202,7 @@ static void sn32_usb_write_fifo(usbep_t ep, const uint8_t *buf, size_t sz, bool SN32_USB->RWSTATUS2 = 0x01; while (SN32_USB->RWSTATUS2 & 0x01); } - +#endif off += chunk; buf += chunk; } diff --git a/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.h b/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.h index 5226c8f923..a3d8cf8bbe 100644 --- a/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.h +++ b/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.h @@ -83,6 +83,13 @@ #if !defined(SN32_USB_HOST_WAKEUP_DURATION) || defined(__DOXYGEN__) #define SN32_USB_HOST_WAKEUP_DURATION 2 #endif + +/** + * @brief USB driver using SRAM direct. + */ +#if !defined(SN32_USB_DIRECT_SRAM) || defined(__DOXYGEN__) +#define SN32_USB_DIRECT_SRAM FALSE +#endif /** @} */ /*===========================================================================*/ From c761cc414e591bf1dc1cddcf90c772d751ae61d3 Mon Sep 17 00:00:00 2001 From: Dimitris Mantzouranis Date: Sat, 10 Aug 2024 17:30:15 +0300 Subject: [PATCH 6/9] sn32: usb: Update supported chip list and provide configs for SN32F240, SN32F240C --- os/hal/ports/SN32/LLD/SN32F2xx/USB/sn32_usb.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/os/hal/ports/SN32/LLD/SN32F2xx/USB/sn32_usb.h b/os/hal/ports/SN32/LLD/SN32F2xx/USB/sn32_usb.h index cbaad38d92..c1cea76b3b 100644 --- a/os/hal/ports/SN32/LLD/SN32F2xx/USB/sn32_usb.h +++ b/os/hal/ports/SN32/LLD/SN32F2xx/USB/sn32_usb.h @@ -34,13 +34,16 @@ */ #define HAL_MAX_ENDPOINTS 7 #if (defined(SN32F240B) || defined(SN32F260)) -#define USB_ENDPOINTS_NUMBER 4 -#define SN32_USB_PMA_SIZE 256 -#elif (defined(SN32F280) || defined(SN32F290)) -#define USB_ENDPOINTS_NUMBER 6 -#define SN32_USB_PMA_SIZE 512 +# define USB_ENDPOINTS_NUMBER 4 +# define SN32_USB_PMA_SIZE 256 +#elif defined(SN32F240C) +# define USB_ENDPOINTS_NUMBER HAL_MAX_ENDPOINTS +# define SN32_USB_PMA_SIZE 512 +#elif (defined(SN32F240) || defined(SN32F280) || defined(SN32F290)) +# define USB_ENDPOINTS_NUMBER 6 +# define SN32_USB_PMA_SIZE 512 #else -#error "USB driver not supported in the selected device" +# error "USB driver not supported in the selected device" #endif /** From 1651d4a8762117dfb705fb3ecfa6e51f2199891d Mon Sep 17 00:00:00 2001 From: Dimitris Mantzouranis Date: Sat, 10 Aug 2024 17:36:10 +0300 Subject: [PATCH 7/9] sn32: usb: use the vendor provided address mask --- os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.c b/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.c index 23b572c954..a7528960b3 100644 --- a/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.c +++ b/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.c @@ -546,7 +546,7 @@ void usb_lld_reset(USBDriver *usbp) { */ void usb_lld_set_address(USBDriver *usbp) { - SN32_USB->ADDR = usbp->address & 0x7F; + SN32_USB->ADDR = usbp->address & mskUADDR; } /** From 568afac2dbdd6ae91fff3d4379f91334ed657d4f Mon Sep 17 00:00:00 2001 From: Dimitris Mantzouranis Date: Sat, 10 Aug 2024 17:44:08 +0300 Subject: [PATCH 8/9] sn32: usb: add special init for 240 --- os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.c b/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.c index a7528960b3..7f6a6a6851 100644 --- a/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.c +++ b/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.c @@ -460,6 +460,9 @@ void usb_lld_start(USBDriver *usbp) { /* Powers up the transceiver while holding the USB in reset state.*/ SN32_USB->SGCTL = (mskBUS_DRVEN|mskBUS_J_STATE); SN32_USB->CFG = (mskVREG33_EN|mskPHY_EN|mskDPPU_EN|mskSIE_EN|mskESD_EN); +# if defined(SN32F240) + SN32_USB->CFG |= (mskUSBRAM_EN|mskVREG33DIS_EN); +# endif /* Set up hardware configuration.*/ SN32_USB->PHYPRM = 0x80000000; SN32_USB->PHYPRM2 = 0x00004004; From 1b165fc8395d423317de865683fe4a2861a67bff Mon Sep 17 00:00:00 2001 From: Dimitris Mantzouranis Date: Sat, 10 Aug 2024 18:35:34 +0300 Subject: [PATCH 9/9] sn32: usb: prefer UINT32_MAX over hardcoded value --- os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.c b/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.c index 7f6a6a6851..325de22eb0 100644 --- a/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.c +++ b/os/hal/ports/SN32/LLD/SN32F2xx/USB/hal_usb_lld.c @@ -526,7 +526,7 @@ void usb_lld_stop(USBDriver *usbp) { */ void usb_lld_reset(USBDriver *usbp) { /* Post reset initialization.*/ - SN32_USB->INSTSC = (0xFFFFFFFF); + SN32_USB->INSTSC = (UINT32_MAX); /* Set the address to zero during enumeration.*/ usbp->address = 0;