cancel
Showing results for 
Search instead for 
Did you mean: 

Time taken to change USB state

Nico3
Senior

I am running USB in Mass Storage host mode. On connecting the device, USB FLASH stick, it takes around 20 seconds to change the Appli_Sate from APPLICATION_START to APPLICATION_READY in usb_host.c file. 

It is normal ? Can the time be reduced ?

 

 

 

Thanks

11 REPLIES 11

Thanks @AScha.3 

I had HAL_Delay(500) ; after MX_USB_HOST_Process(). I removed that and now state is changing in ms time...So the problem is solved. 

Anyway how MX_USB_HOST_Process() works still confuses me. The whole USB connection process is blocking mode or interrupt mode still a mystery for me.

@AScha.3 May you please share part of code where you run swd + DWT counter..

Jo,

first - in main:

 

volatile uint32_t *DWT_CONTROL = (uint32_t *)0xE0001000;		// speed test: DWT addresses of registers
volatile uint32_t *DWT_CYCCNT = (uint32_t *)0xE0001004;

 

 

then, to use it:

 

			*DWT_CYCCNT = 0;									// clear counter
			*DWT_CONTROL = *DWT_CONTROL | 1 ; 					// start cycle counter
...
...


    	count = *DWT_CYCCNT;									// number of cycles stored in count variable
    	printf("%ld ns USB mounted  \n", count * 5);			// SWV ITM print

 

count * 5 = ns here, because core at 200MHz ; count is in cpu cycles, so adjust ...to get us or ns .

+

You have swd running ?

This is a bit tricky ...

to print you need just this, at end of main , i put before /*user...4*/ :

 

int __io_putchar(int ch)
{
    ITM_SendChar(ch);
    return (ch);
}

/* USER CODE END 4 */

 

Then set swo in debug settings and your cpu clk (otherwise - no work.)

Then start it in debug session, see :

https://community.st.com/t5/stm32cubeide-mcus/enable-swo-on-cubeide-1-12-1-board-used-nucleo-h755zi/m-p/569369#M18733

If you feel a post has answered your question, please click "Accept as Solution".