Skip to main content
Explorer II
September 3, 2024
Solved

STM32F042K6 - USB Library too big for device?

  • September 3, 2024
  • 4 replies
  • 2166 views

 

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

 

    This topic has been closed for replies.
    Best answer by Karl Yamashita

    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

     

    4 replies

    Super User
    September 3, 2024

    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)?

    Super User
    September 3, 2024

    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? 

     

    Graduate II
    September 3, 2024

    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.

    PP11Author
    Explorer II
    September 3, 2024

    @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! 

     

    Graduate II
    September 3, 2024

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

    Can you upload your IOC file?

    PP11Author
    Explorer II
    September 4, 2024

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