cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX config question

hmc
Associate III
Posted on February 23, 2018 at 22:56

Hello,

There are 2 things I do not understand about my Nucleo-FRM32F042K6 project (attached take1.ioc).  As you can see, I turned off everything except the SWD and USB.

0690X00000609gvQAA.png 

I want to use the HSI48 for USB, and run everything else off the HSI, without the PLL.  In Mr. Noviello's ''Mastering STM32'' book section 10.1.2 Configuraing Clock Tree Using CubeMX, he uses 8 MHz for APB1 peripheral clock just like I did, but my CubeMX marks the box as red.  So far, I haven't found an explanation.

0690X00000609MIQAY.png

And why does CubeMX want to generate GPIO code, when I am not using any GPIO?

0690X00000609nzQAA.png

Thanks for reading!

5 REPLIES 5
Posted on February 23, 2018 at 23:19

You checked: 'set All pins as analog' in code generator option - that's why all unused pins are configured

Posted on February 23, 2018 at 23:42

It seems that the dependency is on USB - when you disable USB the 8MHz on APB1 is accepted.

Cannot find any relevant limitation in the datasheet.

Posted on February 23, 2018 at 23:53

Thanks for the quick reply Bogdan,

So is it cheaper to choose HSI48 into the clock mux (SW) and divide by 4 to run everything at 12 MHz, or to turn on PLL to generate a 16 MHz from 8 MHz?  The power consumption calculator doesn't have an option for HSI48 into the clock mux...

Pavel A.
Evangelist III
Posted on February 24, 2018 at 02:00

So is it cheaper to choose HSI48 into the clock mux (SW) 

Select in the Cube menu 'Reset' (PCLK1 will become red) then select 'Resolve' and it will automagically find solution.

The PCLK1 in the initial state is red not because of USB (the USB clock Mux is shown below) but because PCKL1 should be > 10 MHz and it was 8.

HSI48 is the internal on-chip source that you get for free.

If you want lower system clock than 48 MHz, try to enter lower values in rectangles with blue frames and resolve again.

And why does CubeMX want to generate GPIO code, when I am not using any GPIO?

Even if you have not defined custom GPIOs , CubeMX creates setup code for pins used by various functions such as USB and for unused pins.

-- pa

Posted on February 25, 2018 at 04:26

Thanks for the response, Pavel.  My question might not have been clear; let me try again.

STM32F042 can indeed generate the 48 MHz internally--HSI48.  But it also has 8 MHz HSI and PLL (like many other STM32F devices).  A question naturally arises: is it better use HSI to generate every clock in the system?  From the data sheet, it seems that the HSI quality is not good enough for USB FS, so one MUST use HSI48 for USB comm.  In THAT case then, one wonders: is it better to feed HSI48 to the APB and the MCU, or to still use the HSI?  From the behavior of the CubeMX that I observe and answer above, it seems that the USB peripheral needs a minimum of 12 MHz clock on the APB, IN ADDITION to the HSI48 (although I still don't know why the USB peripheral couldn't just divide the input HSI48 by 4 and work independently of the APB1 clock).  At this point, it seems I have 2 choices for the APB1 clock generation:

  1. HSI --> PLL
  2. HSI48 --> divider

I don't know how to infer which route is more energy efficient from the data sheet.  Sorry if I am just ignorant of something that should perhaps be obvious.

Thanks for reading!