cancel
Showing results for 
Search instead for 
Did you mean: 

saving power underclocking with USB device mode connected

developer2
Senior
Posted on January 21, 2015 at 14:09

Hi all,

i'm using STM32F407/F417 with 12MHz crystal,

and i would like to save power as possible, because i need to run it on batteries,

i need to have USB connected,

i read in manual that i could underclock ...

please could somebody direct me how to do it and to not loose usb connection ? so exactly: at one moment i need full swing and other moment i need to save power and it's not required to have fast execution,

thanks for all replies ...

12 REPLIES 12
developer2
Senior
Posted on January 23, 2015 at 17:19

Hi all,

so i tried my idea:

RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));

while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS ) != RCC_CFGR_SWS_HSI) {;}

results: usb link seems to be ''not lost'' but it's unresponsive,

maybe too fast IRQs on USB ? first is not replied and comes next ...

does anybody has an idea what can i try ?

is there some possibility to setup USB frame frequency during linked USB ?

EDIT: measured currents ... measurement of the whole device:

stm32f407 not booted ... (BOOT0 pin) ... 144mA (whole device)

stm32f407 booted and USB connected FS core ... 255mA

RCC_SW_HSI ... 214mA but USB unresponsive

so stm32f407 takes at least 111mA and underclocking can save 40mA ...

developer2
Senior
Posted on January 24, 2015 at 12:52

for those who are interested:

so i added :

    RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));

    while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS ) != RCC_CFGR_SWS_HSI) {;}

    FLASH->ACR &= ~(FLASH_ACR_LATENCY_7WS);

and i had to reinit USARTs due to recalculation BRR for debugging for new frequencies of APB,

and i found that there is permanent IRQ without clearing flag:

in Library 2.1.0 19-March-2012 in file usb_dcd_int.c:

in DCD_HandleInEP_ISR:

ep_intr = USB_OTG_ReadDevAllInEPItr(pdev); -- there is always zero, but this line is executed because IRQ came and some flag should be raised,

so there is bug in Library - there is situation that is not fixed and based on this fact there is permanently called IRQ,

raised flag is: EP1: DIEPINT: 00000080 (TXFE: Transmit FIFO empty )

and same situation is when stm32f407 is clocked normally at 168MHz and when ACM viewer on Host is closed and stm32 is trying to send data ...

so i disabled in MSK this flag and stm32 reacts on sent data from Host to STM32 and STM32 is trying to send back reply but Host is not receiving ...

so i think that's useful but there is still some bug in communication in direction STM32 -> Host CDC , when running at 16MHz HSI internal RC and 12MHz external crystal only for USB,

if somebody knows please let me know how to debug & fix ...

Kind regards,

tsuneo
Senior
Posted on January 26, 2015 at 16:03

> in Library 2.1.0 19-March-2012 in file usb_dcd_int.c:

 

> .. > there is situation that is not fixed and based on this fact there is permanently called IRQ

Discussed on this topic,

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flooded%20empty%20FIFO%20interrupts%20still%20make%20USB%20devices%20crawl

> it should be prepared to run ''the job'' anytime after first ''the job''

How quickly should the ''job'' be responded?

To save power on USB device, you may drop the USB connection into Suspend on the host side. But Resume takes a couple of 100ms..

Tsuneo