2016-08-16 04:29 AM
Hello,
I want to read/write files on a usb stick in my application and I already have generated a project with the help of ST32CubeMX for my Nucleo-F746ZG board. The configuration in CubeMX is: -USB_OTG_FS, Host_Only -Mass Storage Host Class -FATFs: USB Disk My application follows this sequence: 1. read/write file on usb stick 2. disable usb operation. I do that, because otherwise the global usb_otg interrupt (OTG_FS_IRQHandler) would slow down step 3 (processing). 3. processing 4. enable usb operation 5. read/write file on usb stick Note: During all steps, the usb stick is connected to the STM32F7. Step 1 works, but after disabling and enabling the usb operation, the usb stick seems to be disconnected and I cannot read/write to the file in step 5. I tried to disalbe/enable the operation with USBH_Start and USBH_Stop. Here is my test application, that shall demonstrate the issue:/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_TIM6_Init();
MX_SPI1_Init();
MX_TIM1_Init();
MX_I2C1_Init();
MX_I2C2_Init();
MX_FATFS_Init();
MX_USB_HOST_Init();
MX_CRC_Init();
//stop/start test
volatile uint32_t cnt = 0;
while(1)
{
MX_USB_HOST_Process();
if (Appli_state == APPLICATION_READY)
{
MX_USB_HOST_Stop();
MX_USB_HOST_Start();
cnt++;
}
}
Note: MX_USB_HOST_Start/Stop are wrapper functions for USBH_Start/Stop.
Appli_state is APPLICATION_READY only once. After Stop/Start was executed, Appli_state remains in APPLICATION_DISCONNECT.
My thoughts:
-I´m not sure if USBH_Start/Stop are the right API calls for my use case.
-Maybe I should re-initialize the whole usb module + drivers
Any ideas what is happening?
2016-08-16 05:29 AM
To call USBH_Stop just because you do not want any interrupts seems a bit harsh to me.
Try and just disable the interrupt (NVIC) and enable it again. Or you can just set a flag when the interrupt is called, so when it is 0, it will just skip the function call inside the interrupt.