update stm32f4 usb_dc with synopsys

This commit is contained in:
sakumisu
2022-01-10 22:12:54 +08:00
parent abee382c88
commit 6180db5d8a
5 changed files with 197 additions and 106 deletions

View File

@@ -62,7 +62,6 @@ static void MX_USART1_UART_Init(void);
/* USER CODE BEGIN 0 */ /* USER CODE BEGIN 0 */
int fputc(int ch, FILE *f) int fputc(int ch, FILE *f)
{ {
HAL_UART_Transmit(&huart1,(uint8_t*)&ch,1,1000); HAL_UART_Transmit(&huart1,(uint8_t*)&ch,1,1000);
return ch; return ch;
} }
@@ -163,7 +162,6 @@ void usbd_cdc_acm_out(uint8_t ep)
uint8_t data[64]; uint8_t data[64];
uint32_t read_byte; uint32_t read_byte;
usbd_ep_read(ep,data,64,&read_byte); usbd_ep_read(ep,data,64,&read_byte);
printf("out\r\n");
printf("read len:%d\r\n",read_byte); printf("read len:%d\r\n",read_byte);
usbd_ep_read(ep,NULL,0,NULL); usbd_ep_read(ep,NULL,0,NULL);
} }
@@ -183,7 +181,49 @@ usbd_endpoint_t cdc_in_ep = {
.ep_cb = usbd_cdc_acm_in .ep_cb = usbd_cdc_acm_in
}; };
void usb_dc_low_level_init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN USB_OTG_HS_MspInit 0 */
/* USER CODE END USB_OTG_HS_MspInit 0 */
__HAL_RCC_GPIOB_CLK_ENABLE();
/**USB_OTG_HS GPIO Configuration
PB14 ------> USB_OTG_HS_DM
PB15 ------> USB_OTG_HS_DP
*/
GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF12_OTG_HS_FS;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* Peripheral clock enable */
__HAL_RCC_USB_OTG_HS_CLK_ENABLE();
/* USB_OTG_HS interrupt Init */
HAL_NVIC_SetPriority(OTG_HS_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(OTG_HS_IRQn);
}
extern void usb_dc_init(void); extern void usb_dc_init(void);
volatile uint8_t dtr_enable = 0;
void usbd_cdc_acm_set_dtr(bool dtr)
{
if(dtr)
{
dtr_enable = 1;
}
else
{
dtr_enable = 0;
}
}
/* USER CODE END 0 */ /* USER CODE END 0 */
/** /**
@@ -214,7 +254,6 @@ int main(void)
/* Initialize all configured peripherals */ /* Initialize all configured peripherals */
MX_GPIO_Init(); MX_GPIO_Init();
MX_USB_OTG_HS_PCD_Init();
MX_USART1_UART_Init(); MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */ /* USER CODE BEGIN 2 */
usbd_desc_register(cdc_descriptor); usbd_desc_register(cdc_descriptor);
@@ -234,9 +273,12 @@ int main(void)
/* USER CODE END WHILE */ /* USER CODE END WHILE */
/* USER CODE BEGIN 3 */ /* USER CODE BEGIN 3 */
uint8_t data_buffer[10] = { 0x31, 0x32, 0x33, 0x34, 0x35, 0x31, 0x32, 0x33, 0x34, 0x35 }; if(dtr_enable)
usbd_ep_write(CDC_IN_EP, data_buffer, 10, NULL); {
HAL_Delay(500); uint8_t data_buffer[10] = { 0x31, 0x32, 0x33, 0x34, 0x35, 0x31, 0x32, 0x33, 0x34, 0x35 };
usbd_ep_write(CDC_IN_EP, data_buffer, 10, NULL);
HAL_Delay(500);
}
} }
/* USER CODE END 3 */ /* USER CODE END 3 */
} }

View File

@@ -202,44 +202,44 @@ void SysTick_Handler(void)
/** /**
* @brief This function handles USB On The Go HS End Point 1 Out global interrupt. * @brief This function handles USB On The Go HS End Point 1 Out global interrupt.
*/ */
void OTG_HS_EP1_OUT_IRQHandler(void) //void OTG_HS_EP1_OUT_IRQHandler(void)
{ //{
/* USER CODE BEGIN OTG_HS_EP1_OUT_IRQn 0 */ // /* USER CODE BEGIN OTG_HS_EP1_OUT_IRQn 0 */
/* USER CODE END OTG_HS_EP1_OUT_IRQn 0 */ // /* USER CODE END OTG_HS_EP1_OUT_IRQn 0 */
HAL_PCD_IRQHandler(&hpcd_USB_OTG_HS); // HAL_PCD_IRQHandler(&hpcd_USB_OTG_HS);
/* USER CODE BEGIN OTG_HS_EP1_OUT_IRQn 1 */ // /* USER CODE BEGIN OTG_HS_EP1_OUT_IRQn 1 */
/* USER CODE END OTG_HS_EP1_OUT_IRQn 1 */ // /* USER CODE END OTG_HS_EP1_OUT_IRQn 1 */
} //}
/** ///**
* @brief This function handles USB On The Go HS End Point 1 In global interrupt. // * @brief This function handles USB On The Go HS End Point 1 In global interrupt.
*/ // */
void OTG_HS_EP1_IN_IRQHandler(void) //void OTG_HS_EP1_IN_IRQHandler(void)
{ //{
/* USER CODE BEGIN OTG_HS_EP1_IN_IRQn 0 */ // /* USER CODE BEGIN OTG_HS_EP1_IN_IRQn 0 */
/* USER CODE END OTG_HS_EP1_IN_IRQn 0 */ // /* USER CODE END OTG_HS_EP1_IN_IRQn 0 */
HAL_PCD_IRQHandler(&hpcd_USB_OTG_HS); // HAL_PCD_IRQHandler(&hpcd_USB_OTG_HS);
/* USER CODE BEGIN OTG_HS_EP1_IN_IRQn 1 */ // /* USER CODE BEGIN OTG_HS_EP1_IN_IRQn 1 */
/* USER CODE END OTG_HS_EP1_IN_IRQn 1 */ // /* USER CODE END OTG_HS_EP1_IN_IRQn 1 */
} //}
/** ///**
* @brief This function handles USB On The Go HS global interrupt. // * @brief This function handles USB On The Go HS global interrupt.
*/ // */
void OTG_HS_IRQHandler(void) //void OTG_HS_IRQHandler(void)
{ //{
/* USER CODE BEGIN OTG_HS_IRQn 0 */ // /* USER CODE BEGIN OTG_HS_IRQn 0 */
/* USER CODE END OTG_HS_IRQn 0 */ // /* USER CODE END OTG_HS_IRQn 0 */
HAL_PCD_IRQHandler(&hpcd_USB_OTG_HS); // HAL_PCD_IRQHandler(&hpcd_USB_OTG_HS);
/* USER CODE BEGIN OTG_HS_IRQn 1 */ // /* USER CODE BEGIN OTG_HS_IRQn 1 */
/* USER CODE END OTG_HS_IRQn 1 */ // /* USER CODE END OTG_HS_IRQn 1 */
} //}
/* USER CODE BEGIN 1 */ /* USER CODE BEGIN 1 */

View File

@@ -103,7 +103,7 @@
<bEvRecOn>1</bEvRecOn> <bEvRecOn>1</bEvRecOn>
<bSchkAxf>0</bSchkAxf> <bSchkAxf>0</bSchkAxf>
<bTchkAxf>0</bTchkAxf> <bTchkAxf>0</bTchkAxf>
<nTsel>3</nTsel> <nTsel>6</nTsel>
<sDll></sDll> <sDll></sDll>
<sDllPa></sDllPa> <sDllPa></sDllPa>
<sDlgDll></sDlgDll> <sDlgDll></sDlgDll>
@@ -114,9 +114,29 @@
<tDlgDll></tDlgDll> <tDlgDll></tDlgDll>
<tDlgPa></tDlgPa> <tDlgPa></tDlgPa>
<tIfile></tIfile> <tIfile></tIfile>
<pMon>BIN\CMSIS_AGDI.dll</pMon> <pMon>STLink\ST-LINKIII-KEIL_SWO.dll</pMon>
</DebugOpt> </DebugOpt>
<TargetDriverDllRegistry> <TargetDriverDllRegistry>
<SetRegEntry>
<Number>0</Number>
<Key>ARMRTXEVENTFLAGS</Key>
<Name>-L70 -Z18 -C0 -M0 -T1</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
<Key>DLGTARM</Key>
<Name>(1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(1012=-1,-1,-1,-1,0)</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
<Key>ARMDBGFLAGS</Key>
<Name></Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
<Key>DLGUARM</Key>
<Name>(105=-1,-1,-1,-1,0)</Name>
</SetRegEntry>
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
<Key>CMSIS_AGDI</Key> <Key>CMSIS_AGDI</Key>
@@ -130,10 +150,43 @@
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
<Key>ST-LINKIII-KEIL_SWO</Key> <Key>ST-LINKIII-KEIL_SWO</Key>
<Name>-U-O142 -O2254 -S0 -C0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC800 -FN1 -FF0STM32F4xx_1024.FLM -FS08000000 -FL0100000 -FP0($$Device:STM32F429IGTx$CMSIS\Flash\STM32F4xx_1024.FLM)</Name> <Name>-U066EFF555453774987091527 -O2287 -SF4000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(2BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC800 -FN1 -FF0STM32F4xx_1024.FLM -FS08000000 -FL0100000 -FP0($$Device:STM32F429IGTx$CMSIS\Flash\STM32F4xx_1024.FLM)</Name>
</SetRegEntry> </SetRegEntry>
</TargetDriverDllRegistry> </TargetDriverDllRegistry>
<Breakpoint/> <Breakpoint>
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>526</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>..\..\..\..\port\synopsys\usb_dc_synopsys.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
<Bp>
<Number>1</Number>
<Type>0</Type>
<LineNumber>529</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>..\..\..\..\port\synopsys\usb_dc_synopsys.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
</Breakpoint>
<Tracepoint> <Tracepoint>
<THDelay>0</THDelay> <THDelay>0</THDelay>
</Tracepoint> </Tracepoint>
@@ -178,10 +231,10 @@
<pMultCmdsp></pMultCmdsp> <pMultCmdsp></pMultCmdsp>
<DebugDescription> <DebugDescription>
<Enable>1</Enable> <Enable>1</Enable>
<EnableFlashSeq>1</EnableFlashSeq> <EnableFlashSeq>0</EnableFlashSeq>
<EnableLog>0</EnableLog> <EnableLog>0</EnableLog>
<Protocol>2</Protocol> <Protocol>2</Protocol>
<DbgClock>10000000</DbgClock> <DbgClock>4000000</DbgClock>
</DebugDescription> </DebugDescription>
</TargetOption> </TargetOption>
</Target> </Target>
@@ -476,7 +529,7 @@
<GroupNumber>3</GroupNumber> <GroupNumber>3</GroupNumber>
<FileNumber>23</FileNumber> <FileNumber>23</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c</PathWithFileName> <PathWithFileName>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c</PathWithFileName>
@@ -543,8 +596,8 @@
<tvExp>0</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>..\..\..\..\port\stm32\usb_dc_hal.c</PathWithFileName> <PathWithFileName>..\..\..\..\port\synopsys\usb_dc_synopsys.c</PathWithFileName>
<FilenameWithoutPath>usb_dc_hal.c</FilenameWithoutPath> <FilenameWithoutPath>usb_dc_synopsys.c</FilenameWithoutPath>
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
<bShared>0</bShared> <bShared>0</bShared>
</File> </File>

View File

@@ -338,7 +338,7 @@
<v6Rtti>0</v6Rtti> <v6Rtti>0</v6Rtti>
<VariousControls> <VariousControls>
<MiscControls></MiscControls> <MiscControls></MiscControls>
<Define>USE_HAL_DRIVER,STM32F429xx,STM32F4</Define> <Define>USE_HAL_DRIVER,STM32F429xx,CONFIG_USB_HS_IN_FULL</Define>
<Undefine></Undefine> <Undefine></Undefine>
<IncludePath>../Core/Inc; ../Drivers/STM32F4xx_HAL_Driver/Inc; ../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy; ../Drivers/CMSIS/Device/ST/STM32F4xx/Include; ../Drivers/CMSIS/Include; ..\..\..\..\class\cdc; ..\..\..\..\core; ..\..\..\..\common; ..\..\..\..\class\winusb</IncludePath> <IncludePath>../Core/Inc; ../Drivers/STM32F4xx_HAL_Driver/Inc; ../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy; ../Drivers/CMSIS/Device/ST/STM32F4xx/Include; ../Drivers/CMSIS/Include; ..\..\..\..\class\cdc; ..\..\..\..\core; ..\..\..\..\common; ..\..\..\..\class\winusb</IncludePath>
</VariousControls> </VariousControls>
@@ -586,9 +586,9 @@
<FilePath>..\..\..\..\class\cdc\usbd_cdc.c</FilePath> <FilePath>..\..\..\..\class\cdc\usbd_cdc.c</FilePath>
</File> </File>
<File> <File>
<FileName>usb_dc_hal.c</FileName> <FileName>usb_dc_synopsys.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\..\..\port\stm32\usb_dc_hal.c</FilePath> <FilePath>..\..\..\..\port\synopsys\usb_dc_synopsys.c</FilePath>
</File> </File>
</Files> </Files>
</Group> </Group>

View File

@@ -17,24 +17,27 @@
#define USBD_IRQHandler OTG_HS_IRQHandler #define USBD_IRQHandler OTG_HS_IRQHandler
#endif #endif
#ifndef USB_RAM_SIZE #ifndef USB_NUM_BIDIR_ENDPOINTS
#define USB_RAM_SIZE 4096 #define USB_NUM_BIDIR_ENDPOINTS 6 /* define with minimum value*/
#endif
#ifndef USB_RAM_SIZE
#define USB_RAM_SIZE 4096 /* define with minimum value*/
#endif #endif
#define USB_INSTANCE USB_OTG_HS
#else #else
#ifndef USBD_IRQHandler #ifndef USBD_IRQHandler
#define USBD_IRQHandler OTG_FS_IRQHandler #define USBD_IRQHandler OTG_FS_IRQHandler
#endif #endif
#ifndef USB_RAM_SIZE
#define USB_RAM_SIZE 1280
#endif
#endif
#ifndef USB_NUM_BIDIR_ENDPOINTS #ifndef USB_NUM_BIDIR_ENDPOINTS
#define USB_NUM_BIDIR_ENDPOINTS 6 #define USB_NUM_BIDIR_ENDPOINTS 4 /* define with minimum value*/
#endif
#ifndef USB_RAM_SIZE
#define USB_RAM_SIZE 1280 /* define with minimum value*/
#endif
#endif #endif
#if defined(CONFIG_USB_HS) || defined(CONFIG_USB_HS_IN_FULL) #if defined(CONFIG_USB_HS) || defined(CONFIG_USB_HS_IN_FULL)
@@ -60,25 +63,16 @@
#ifndef CONFIG_USB_TX5_FIFO_SIZE #ifndef CONFIG_USB_TX5_FIFO_SIZE
#define CONFIG_USB_TX5_FIFO_SIZE (256U) #define CONFIG_USB_TX5_FIFO_SIZE (256U)
#endif #endif
#ifndef CONFIG_USB_TX6_FIFO_SIZE
#define CONFIG_USB_TX6_FIFO_SIZE (256U)
#endif
#ifndef CONFIG_USB_TX7_FIFO_SIZE
#define CONFIG_USB_TX7_FIFO_SIZE (256U)
#endif
#ifndef CONFIG_USB_TX8_FIFO_SIZE
#define CONFIG_USB_TX8_FIFO_SIZE (192U)
#endif
#else #else
/*FIFO sizes in bytes (total available memory for FIFOs is 1.25kB)*/ /*FIFO sizes in bytes (total available memory for FIFOs is 1.25kB)*/
#ifndef CONFIG_USB_RX_FIFO_SIZE #ifndef CONFIG_USB_RX_FIFO_SIZE
#define CONFIG_USB_RX_FIFO_SIZE (640U) #define CONFIG_USB_RX_FIFO_SIZE (640U)
#endif #endif
#ifndef CONFIG_USB_TX0_FIFO_SIZE #ifndef CONFIG_USB_TX0_FIFO_SIZE
#define CONFIG_USB_TX0_FIFO_SIZE (160U) #define CONFIG_USB_TX0_FIFO_SIZE (64U)
#endif #endif
#ifndef CONFIG_USB_TX1_FIFO_SIZE #ifndef CONFIG_USB_TX1_FIFO_SIZE
#define CONFIG_USB_TX1_FIFO_SIZE (160U) #define CONFIG_USB_TX1_FIFO_SIZE (256U)
#endif #endif
#ifndef CONFIG_USB_TX2_FIFO_SIZE #ifndef CONFIG_USB_TX2_FIFO_SIZE
#define CONFIG_USB_TX2_FIFO_SIZE (160U) #define CONFIG_USB_TX2_FIFO_SIZE (160U)
@@ -86,9 +80,6 @@
#ifndef CONFIG_USB_TX3_FIFO_SIZE #ifndef CONFIG_USB_TX3_FIFO_SIZE
#define CONFIG_USB_TX3_FIFO_SIZE (160U) #define CONFIG_USB_TX3_FIFO_SIZE (160U)
#endif #endif
#ifndef CONFIG_USB_TX4_FIFO_SIZE
#define CONFIG_USB_TX4_FIFO_SIZE (160U)
#endif
#endif #endif
#ifndef CONFIG_USB_TURNAROUND_TIME #ifndef CONFIG_USB_TURNAROUND_TIME
@@ -161,16 +152,9 @@ int usb_dc_init(void)
#else #else
/* Select FS Embedded PHY */ /* Select FS Embedded PHY */
USBx->GUSBCFG |= USB_OTG_GUSBCFG_PHYSEL; USBx->GUSBCFG |= USB_OTG_GUSBCFG_PHYSEL;
// if (cfg.battery_charging_enable == 0U)
// {
/* Activate the USB Transceiver */ /* Activate the USB Transceiver */
USBx->GCCFG |= USB_OTG_GCCFG_PWRDWN; USBx->GCCFG |= USB_OTG_GCCFG_PWRDWN;
// }
// else
// {
// /* Deactivate the USB Transceiver */
// USBx->GCCFG &= ~(USB_OTG_GCCFG_PWRDWN);
// }
#endif #endif
/* Reset after a PHY select and set Host mode */ /* Reset after a PHY select and set Host mode */
@@ -201,23 +185,18 @@ int usb_dc_init(void)
USBx->DIEPTXF[i] = 0U; USBx->DIEPTXF[i] = 0U;
} }
/* VBUS Sensing setup */ #if 1 /* To fix vbus sensing disable*/
// if (cfg.vbus_sensing_enable == 0U)
// {
/* Deactivate VBUS Sensing B */ /* Deactivate VBUS Sensing B */
USBx->GCCFG &= ~USB_OTG_GCCFG_VBDEN; USBx->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
/* B-peripheral session valid override enable */ /* B-peripheral session valid override enable */
USBx->GOTGCTL |= USB_OTG_GOTGCTL_BVALOEN; USBx->GOTGCTL |= USB_OTG_GOTGCTL_BVALOEN;
USBx->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL; USBx->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL;
// } #else
// else USBx->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS;
// { USBx->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN;
// /* Enable HW VBUS sensing */ USBx->GCCFG &= ~USB_OTG_GCCFG_VBUSASEN;
// USBx->GCCFG |= USB_OTG_GCCFG_VBDEN; #endif
// }
//
/* Restart the Phy Clock */ /* Restart the Phy Clock */
USBx_PCGCCTL = 0U; USBx_PCGCCTL = 0U;
@@ -226,6 +205,8 @@ int usb_dc_init(void)
#if defined(CONFIG_USB_HS) #if defined(CONFIG_USB_HS)
/* Set Core speed to High speed mode */ /* Set Core speed to High speed mode */
USBx_DEVICE->DCFG |= USB_OTG_SPEED_HIGH; USBx_DEVICE->DCFG |= USB_OTG_SPEED_HIGH;
#elif defined(CONFIG_USB_HS_IN_FULL)
USBx_DEVICE->DCFG |= USB_OTG_SPEED_HIGH_IN_FULL;
#else #else
USBx_DEVICE->DCFG |= USB_OTG_SPEED_FULL; USBx_DEVICE->DCFG |= USB_OTG_SPEED_FULL;
#endif #endif
@@ -277,15 +258,27 @@ int usb_dc_init(void)
USBx->GINTMSK |= USB_OTG_GINTMSK_USBSUSPM | USB_OTG_GINTMSK_USBRST | USB_OTG_GINTMSK_ENUMDNEM | USBx->GINTMSK |= USB_OTG_GINTMSK_USBSUSPM | USB_OTG_GINTMSK_USBRST | USB_OTG_GINTMSK_ENUMDNEM |
USB_OTG_GINTMSK_OEPINT | USB_OTG_GINTMSK_IEPINT | USB_OTG_GINTMSK_RXFLVLM | USB_OTG_GINTMSK_OEPINT | USB_OTG_GINTMSK_IEPINT | USB_OTG_GINTMSK_RXFLVLM |
USB_OTG_GINTMSK_WUIM; USB_OTG_GINTMSK_WUIM;
#if 0
USBx->GINTMSK |= USB_OTG_GINTMSK_SOFM;
#endif
USBx_DEVICE->DOEPMSK = USB_OTG_DOEPMSK_STUPM | USB_OTG_DOEPMSK_XFRCM;
USBx_DEVICE->DIEPMSK = USB_OTG_DIEPMSK_XFRCM;
USBx->GRXFSIZ = (CONFIG_USB_RX_FIFO_SIZE / 4); USBx->GRXFSIZ = (CONFIG_USB_RX_FIFO_SIZE / 4);
#if defined(CONFIG_USB_HS) || defined(CONFIG_USB_HS_IN_FULL)
usb_set_txfifo(USBx, 0, CONFIG_USB_TX0_FIFO_SIZE / 4); usb_set_txfifo(USBx, 0, CONFIG_USB_TX0_FIFO_SIZE / 4);
usb_set_txfifo(USBx, 1, CONFIG_USB_TX1_FIFO_SIZE / 4); usb_set_txfifo(USBx, 1, CONFIG_USB_TX1_FIFO_SIZE / 4);
usb_set_txfifo(USBx, 2, CONFIG_USB_TX2_FIFO_SIZE / 4); usb_set_txfifo(USBx, 2, CONFIG_USB_TX2_FIFO_SIZE / 4);
usb_set_txfifo(USBx, 3, CONFIG_USB_TX3_FIFO_SIZE / 4); usb_set_txfifo(USBx, 3, CONFIG_USB_TX3_FIFO_SIZE / 4);
usb_set_txfifo(USBx, 4, CONFIG_USB_TX4_FIFO_SIZE / 4); usb_set_txfifo(USBx, 4, CONFIG_USB_TX4_FIFO_SIZE / 4);
usb_set_txfifo(USBx, 5, CONFIG_USB_TX5_FIFO_SIZE / 4);
#else
usb_set_txfifo(USBx, 0, CONFIG_USB_TX0_FIFO_SIZE / 4);
usb_set_txfifo(USBx, 1, CONFIG_USB_TX1_FIFO_SIZE / 4);
usb_set_txfifo(USBx, 2, CONFIG_USB_TX2_FIFO_SIZE / 4);
usb_set_txfifo(USBx, 3, CONFIG_USB_TX3_FIFO_SIZE / 4);
#endif
USBx->GAHBCFG |= USB_OTG_GAHBCFG_GINT; USBx->GAHBCFG |= USB_OTG_GAHBCFG_GINT;
USBx_DEVICE->DCTL &= ~USB_OTG_DCTL_SDIS; USBx_DEVICE->DCTL &= ~USB_OTG_DCTL_SDIS;
@@ -298,6 +291,22 @@ void usb_dc_deinit(void)
uint32_t USBx_BASE = (uint32_t)USBx; uint32_t USBx_BASE = (uint32_t)USBx;
usb_dc_low_level_deinit(); usb_dc_low_level_deinit();
/* Clear Pending interrupt */
for (uint8_t i = 0U; i < 15U; i++) {
USBx_INEP(i)->DIEPINT = 0xFB7FU;
USBx_OUTEP(i)->DOEPINT = 0xFB7FU;
}
/* Clear interrupt masks */
USBx_DEVICE->DIEPMSK = 0U;
USBx_DEVICE->DOEPMSK = 0U;
USBx_DEVICE->DAINTMSK = 0U;
/* Flush the FIFO */
usb_flush_txfifo(USBx, 0x10U);
usb_flush_rxfifo(USBx);
USBx_DEVICE->DCTL |= USB_OTG_DCTL_SDIS;
} }
int usbd_set_address(const uint8_t addr) int usbd_set_address(const uint8_t addr)
@@ -346,13 +355,6 @@ int usbd_ep_open(const struct usbd_endpoint_cfg *ep_cfg)
} }
int usbd_ep_close(const uint8_t ep) int usbd_ep_close(const uint8_t ep)
{ {
USB_OTG_GlobalTypeDef *USBx = usb_dc_cfg.Instance;
uint32_t USBx_BASE = (uint32_t)USBx;
uint8_t ep_idx = USB_EP_GET_IDX(ep);
if (USB_EP_DIR_IS_OUT(ep)) {
} else {
}
return 0; return 0;
} }
int usbd_ep_set_stall(const uint8_t ep) int usbd_ep_set_stall(const uint8_t ep)
@@ -617,12 +619,6 @@ void USBD_IRQHandler(void)
} }
USBx_DEVICE->DAINTMSK |= 0x10001U; USBx_DEVICE->DAINTMSK |= 0x10001U;
USBx_DEVICE->DOEPMSK |= USB_OTG_DOEPMSK_STUPM |
USB_OTG_DOEPMSK_XFRCM;
USBx_DEVICE->DIEPMSK |= USB_OTG_DIEPMSK_TOM |
USB_OTG_DIEPMSK_XFRCM;
USBx_OUTEP(0U)->DOEPTSIZ = 0U; USBx_OUTEP(0U)->DOEPTSIZ = 0U;
USBx_OUTEP(0U)->DOEPTSIZ |= (USB_OTG_DOEPTSIZ_PKTCNT & (1U << 19)); USBx_OUTEP(0U)->DOEPTSIZ |= (USB_OTG_DOEPTSIZ_PKTCNT & (1U << 19));
USBx_OUTEP(0U)->DOEPTSIZ |= (3U * 8U); USBx_OUTEP(0U)->DOEPTSIZ |= (3U * 8U);