cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F042K6 - USB Library too big for device?

PP11
Associate II

 

Hello everyone,

 

I am using the STM32F042K6 for a small project where I don't have much space. Therefore, I rely on the small package and the "crystal-less USB" function. The hardware arrived today, but unfortunately, I had to realize that the USB library seems to be too large for the chip. I created a new, empty project in CUBE IDE, with only I2C and USB (COM PORT) enabled, and I get the following error message:

 

"c:\st\stm32cubeide_.2.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.200.202301161003\tools\arm-none-eabi\bin\ld.exe: Test_Project.elf section .data' will not fit in region FLASH'
 
c:\st\stm32cubeide_1.2.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.200.202301161003\tools\arm-none-eabi\bin\ld.exe: region `FLASH' overflowed by 12 bytes"

 

 

This is quite frustrating when it is advertised and then doesn't work "out of the box." What can I do?
 
Best regards,
Paul

 

1 ACCEPTED SOLUTION

Accepted Solutions

Looks like the CDC is using a lot of RAM. If you change the buffer from 1024 to 512, then it will fit.

  • Hopefully you don't have much user code especially RAM or you'll run into the same issue.
  • You'll have to work with a smaller buffer. Hopefully you don't need to transfer large amount of data.

 

KarlYamashita_0-1725485197999.png

KarlYamashita_1-1725485246307.png

 

If smoke escapes your device, put the smoke back in. It'll still work as a conversation piece. If you find my answers useful, click the Accept as Solution button so that way others can see the solution.

View solution in original post

9 REPLIES 9
Andrew Neil
Evangelist III

What optimisation setting are you using?

Are there configuration options on the library to reduce its memory footprint (presumably, at the cost of functionality and/or performance)?

Pavel A.
Evangelist III

You need only 12 bytes to fit. Try to optimize. Section .data is initialized data copied to flash. Is there a large array or struct mostly filled with zeros? 

 

Karl Yamashita
Lead III

I have a project that uses the USB CDC code, CAN drivers, along with my code and the code fits just fine. You didn't mention what YOUR code is doing that is generating code larger than the flash memory.

What you should have done was use a larger flash memory and write your code first. Then you can determine if you can go with a lower memory chip afterwards. 

You can look into the STM32F072 with more flash memory, which I believe is a drop in replacement.

If smoke escapes your device, put the smoke back in. It'll still work as a conversation piece. If you find my answers useful, click the Accept as Solution button so that way others can see the solution.
PP11
Associate II

@Andrew Neil : What optimisation setting are you using? 

I did not change anything in the default settings, but I will have a look on it. Thank you!

@Andrew Neil :Are there configuration options on the library to reduce its memory footprint (presumably, at the cost of functionality and/or performance)?

I changed the size of some buffers, but I doesnt work. 


@Pavel A. You need only 12 bytes to fit. 


Yes, but I have not a single line of user code in this configuration. I think I can optimize the 12 byte, but then I still have no space for my user code. 

 

@Karl Yamashita I have a project that uses the USB CDC code 
With the F042K6 (LQPF32, 32K Flash, 8K RAM and only CAN OR USB, both is not possible on this device)?

@Karl Yamashita You can look into the STM32F072 with more flash memory,


Not available in LQPF32.... next LQPF32 is F303 but it requiere a crystal for usb. 

Thanks for your answers! 

 

The STM32F042C6 has the same flash memory size as the K6.

Can you upload your IOC file?

If smoke escapes your device, put the smoke back in. It'll still work as a conversation piece. If you find my answers useful, click the Accept as Solution button so that way others can see the solution.

Sure, here it is. Brand new Project, no user code, only USB and I2C activated. 


@PP11 wrote:

@Andrew Neil : What optimisation setting are you using? 

I did not change anything in the default settings,


Then likely it's NO optimisation - so definitely start by adjusting that!

And a big +1 to @Karl Yamashita's suggestion to start developing on a bigger device - it's far easier to find optimisations in something that does build than in something that doesn't.

When it does build, you will have  a map file to look at to see where all the code space is going.

 


@PP11 wrote:

I changed the size of some buffers, but I doesn't work. 


Buffers would be in RAM - so unlikely to affect Flash use.

Looks like the CDC is using a lot of RAM. If you change the buffer from 1024 to 512, then it will fit.

  • Hopefully you don't have much user code especially RAM or you'll run into the same issue.
  • You'll have to work with a smaller buffer. Hopefully you don't need to transfer large amount of data.

 

KarlYamashita_0-1725485197999.png

KarlYamashita_1-1725485246307.png

 

If smoke escapes your device, put the smoke back in. It'll still work as a conversation piece. If you find my answers useful, click the Accept as Solution button so that way others can see the solution.

Hey Karl, 

the optimization settings and lowering the buffer size does work, thanks for your help!

Greetings Paul