|
35 | 35 |
|
36 | 36 | #endif |
37 | 37 |
|
38 | | -//#include "fsdev_common.h" |
39 | | - |
40 | | -//--------------------------------------------------------------------+ |
41 | | -// |
42 | | -//--------------------------------------------------------------------+ |
43 | | - |
44 | | -#if (CFG_TUSB_MCU == OPT_MCU_AT32F403A_407) || (CFG_TUSB_MCU == OPT_MCU_AT32F413) |
45 | | -static const IRQn_Type fsdev_irq[] = { |
46 | | - USBFS_H_CAN1_TX_IRQn, |
47 | | - USBFS_L_CAN1_RX0_IRQn, |
48 | | - USBFSWakeUp_IRQn |
49 | | -}; |
50 | | -enum { FSDEV_IRQ_NUM = TU_ARRAY_SIZE(fsdev_irq) }; |
51 | | - |
52 | | -#else |
53 | | - #error "Unsupported MCU" |
54 | | -#endif |
55 | | - |
56 | | -void dcd_int_enable(uint8_t rhport) { |
57 | | - (void)rhport; |
58 | | - #if (CFG_TUSB_MCU == OPT_MCU_AT32F403A_407) || (CFG_TUSB_MCU == OPT_MCU_AT32F413) |
59 | | - // AT32F403A/407 devices allow to remap the USB interrupt vectors from |
60 | | - // shared USB/CAN IRQs to separate CAN and USB IRQs. |
61 | | - // This dynamically checks if this remap is active to enable the right IRQs. |
62 | | - if (CRM->intmap_bit.usbintmap) { |
63 | | - NVIC_DisableIRQ(USBFS_MAPH_IRQn); |
64 | | - NVIC_DisableIRQ(USBFS_MAPL_IRQn); |
65 | | - NVIC_DisableIRQ(USBFSWakeUp_IRQn); |
66 | | - } else |
67 | | - #endif |
68 | | - { |
69 | | - for(uint8_t i=0; i < FSDEV_IRQ_NUM; i++) { |
70 | | - NVIC_EnableIRQ(fsdev_irq[i]); |
71 | | - } |
72 | | - } |
73 | | -} |
74 | | - |
75 | | -void dcd_int_disable(uint8_t rhport) { |
76 | | - (void)rhport; |
77 | | - #if (CFG_TUSB_MCU == OPT_MCU_AT32F403A_407) || (CFG_TUSB_MCU == OPT_MCU_AT32F413) |
78 | | - // AT32F403A/407 devices allow to remap the USB interrupt vectors from |
79 | | - // shared USB/CAN IRQs to separate CAN and USB IRQs. |
80 | | - // This dynamically checks if this remap is active to enable the right IRQs. |
81 | | - if (CRM->intmap_bit.usbintmap) { |
82 | | - NVIC_DisableIRQ(USBFS_MAPH_IRQn); |
83 | | - NVIC_DisableIRQ(USBFS_MAPL_IRQn); |
84 | | - NVIC_DisableIRQ(USBFSWakeUp_IRQn); |
85 | | - } else |
86 | | - #endif |
87 | | - { |
88 | | - for(uint8_t i=0; i < FSDEV_IRQ_NUM; i++) { |
89 | | - NVIC_DisableIRQ(fsdev_irq[i]); |
90 | | - } |
91 | | - } |
92 | | -} |
93 | | - |
94 | | -void dcd_disconnect(uint8_t rhport) { |
95 | | - (void) rhport; |
96 | | - /* disable usb phy */ |
97 | | - //USB->ctrl_bit.disusb = TRUE; |
98 | | - *(int *)(0x40000000+0x5C00+0x40) |= (1<<1); |
99 | | - *(int *)(0x40000000+0x5C00+0x60) |= (1<<1); |
100 | | - /* D+ 1.5k pull-up disable */ |
101 | | - //USB->cfg_bit.puo = TRUE; |
102 | | -} |
103 | | - |
104 | | -void dcd_connect(uint8_t rhport) { |
105 | | - (void) rhport; |
106 | | - /* enable usb phy */ |
107 | | - //USB->ctrl_bit.disusb = 0; |
108 | | - *(int *)(0x40000000+0x5C00+0x40) &= ~(1<<1); |
109 | | - *(int *)(0x40000000+0x5C00+0x60) &= ~(1<<1); |
110 | | - /* Dp 1.5k pull-up enable */ |
111 | | - //USB->cfg_bit.puo = 0; |
112 | | -} |
113 | | - |
114 | 38 | #define FSDEV_PMA_SIZE (512u) |
115 | 39 | #define FSDEV_REG_BASE (APB1PERIPH_BASE + 0x00005C00UL) |
116 | 40 | #define FSDEV_PMA_BASE (APB1PERIPH_BASE + 0x00006000UL) |
@@ -221,4 +145,76 @@ void dcd_connect(uint8_t rhport) { |
221 | 145 | #define USB_EPRX_DTOG2 ((uint16_t)0x2000U) /*!< EndPoint RX Data TOGgle bit1 */ |
222 | 146 | #define USB_EPRX_DTOGMASK (USB_EPRX_STAT|USB_EPREG_MASK) |
223 | 147 |
|
| 148 | +#include "fsdev_type.h" |
| 149 | + |
| 150 | +//--------------------------------------------------------------------+ |
| 151 | +// |
| 152 | +//--------------------------------------------------------------------+ |
| 153 | + |
| 154 | +#if (CFG_TUSB_MCU == OPT_MCU_AT32F403A_407) || (CFG_TUSB_MCU == OPT_MCU_AT32F413) |
| 155 | +static const IRQn_Type fsdev_irq[] = { |
| 156 | + USBFS_H_CAN1_TX_IRQn, |
| 157 | + USBFS_L_CAN1_RX0_IRQn, |
| 158 | + USBFSWakeUp_IRQn |
| 159 | +}; |
| 160 | +enum { FSDEV_IRQ_NUM = TU_ARRAY_SIZE(fsdev_irq) }; |
| 161 | + |
| 162 | +#else |
| 163 | + #error "Unsupported MCU" |
| 164 | +#endif |
| 165 | + |
| 166 | +void dcd_int_enable(uint8_t rhport) { |
| 167 | + (void)rhport; |
| 168 | + #if (CFG_TUSB_MCU == OPT_MCU_AT32F403A_407) || (CFG_TUSB_MCU == OPT_MCU_AT32F413) |
| 169 | + // AT32F403A/407 devices allow to remap the USB interrupt vectors from |
| 170 | + // shared USB/CAN IRQs to separate CAN and USB IRQs. |
| 171 | + // This dynamically checks if this remap is active to enable the right IRQs. |
| 172 | + if (CRM->intmap_bit.usbintmap) { |
| 173 | + NVIC_DisableIRQ(USBFS_MAPH_IRQn); |
| 174 | + NVIC_DisableIRQ(USBFS_MAPL_IRQn); |
| 175 | + NVIC_DisableIRQ(USBFSWakeUp_IRQn); |
| 176 | + } else |
| 177 | + #endif |
| 178 | + { |
| 179 | + for(uint8_t i=0; i < FSDEV_IRQ_NUM; i++) { |
| 180 | + NVIC_EnableIRQ(fsdev_irq[i]); |
| 181 | + } |
| 182 | + } |
| 183 | +} |
| 184 | + |
| 185 | +void dcd_int_disable(uint8_t rhport) { |
| 186 | + (void)rhport; |
| 187 | + #if (CFG_TUSB_MCU == OPT_MCU_AT32F403A_407) || (CFG_TUSB_MCU == OPT_MCU_AT32F413) |
| 188 | + // AT32F403A/407 devices allow to remap the USB interrupt vectors from |
| 189 | + // shared USB/CAN IRQs to separate CAN and USB IRQs. |
| 190 | + // This dynamically checks if this remap is active to enable the right IRQs. |
| 191 | + if (CRM->intmap_bit.usbintmap) { |
| 192 | + NVIC_DisableIRQ(USBFS_MAPH_IRQn); |
| 193 | + NVIC_DisableIRQ(USBFS_MAPL_IRQn); |
| 194 | + NVIC_DisableIRQ(USBFSWakeUp_IRQn); |
| 195 | + } else |
| 196 | + #endif |
| 197 | + { |
| 198 | + for(uint8_t i=0; i < FSDEV_IRQ_NUM; i++) { |
| 199 | + NVIC_DisableIRQ(fsdev_irq[i]); |
| 200 | + } |
| 201 | + } |
| 202 | +} |
| 203 | + |
| 204 | +void dcd_disconnect(uint8_t rhport) { |
| 205 | + (void) rhport; |
| 206 | + /* disable usb phy */ |
| 207 | + FSDEV_REG->CNTR |= USB_CNTR_PDWN; |
| 208 | + /* D+ 1.5k pull-up disable, USB->cfg_bit.puo = TRUE; */ |
| 209 | + *(uint32_t *)(FSDEV_REG_BASE+0x60) |= (1u<<1); |
| 210 | +} |
| 211 | + |
| 212 | +void dcd_connect(uint8_t rhport) { |
| 213 | + (void) rhport; |
| 214 | + /* enable usb phy */ |
| 215 | + FSDEV_REG->CNTR &= ~USB_CNTR_PDWN; |
| 216 | + /* Dp 1.5k pull-up enable, USB->cfg_bit.puo = 0; */ |
| 217 | + *(uint32_t *)(FSDEV_REG_BASE+0x60) &= ~(1u<<1); |
| 218 | +} |
| 219 | + |
224 | 220 | #endif |
0 commit comments