PlatformIO Community

How to HSI stm32f103C8 and big memory usage

hello and a happy new year to all first :slight_smile:

after some package struggling i got my code compiling for a bare STM32f103C8 but i want to run it on the internal HSI. i use Arduino Framework and after some research i found that i need to add or change some code anywere for using HSI instead of external crystal. i´ve soldered the chip with some other components on a pcb with 4pin ST LINK Header and without a crystal.

platformio ini:

[env:genericSTM32F103C8]
platform = ststm32
board = genericSTM32F103C8
framework = arduino

also iam asking myself why the chip uses a lot of memory while nothing really happened in code… please look on the image

is there another core that uses lesser start memory?
thanks for any help

thanks for any help

So the first thing to find out is which of the two STM32 you’re using (mapple or stm32 provided one). The board’s JSON file says

So the board speed setup is in

So you just have to define USE_HSI_CLOCK. Do that by adding

build_flags = -D USE_HSI_CLOCK

to the platformio.ini. That should be it and the board should be choosing the HSI & 72MHz configuration.

Note that this makes it impossibles to use the USB interface is it needs the HSE to generate a stable 48MHz for the USB system.

You may also try to use board = bluepill_f103c8.json to use the STM32 core (https://github.com/platformio/platform-ststm32/blob/master/boards/bluepill_f103c8.json).

Well that’s just the thing with frameworks. Lots of boiler-plate code is compiled, even though your code just uses the GPIO and PWM (aka timers) on the board. You can generate .map files (Generate a .map file) and look at them using http://www.sikorskiy.net/prj/amap/ to know which exact file / function / object is taking up which memory.

max, thank you!!

so with the generic stuff in the platformio ini the code run on the chip.

now i switch the content in the ini to:

[env:bluepill_f103c8]
platform = ststm32@~4.5.0
board = bluepill_f103c8
framework = arduino

build_flags = -D USE_HSI_CLOCK

the ~4.5.0 addition is necessary for configure pin as PWM - > pinMode(xyz, PWM)

i got this compiler message:

then i thought the project needs some dedicated files, so i start a new project with bluepillf103C8. i then click on build and upload but the compiler give me the same problems cuz the project before. the compiler isnt in the new project. i can also close the wrong project from the workspace but it doesnt compile the right project … whats going wrong here? i´ve also killed all terminal, press clean … no change at all :frowning:

then on the bluePill project i removed @~4.5.0 and changed the pinMode PWM definition to OUTPUT and compiling works. i´ve uploaded it to the chip but it doenst run cuz the HSI occurs not to be enabled. if i go to the OSC pin with my probe it starts to run but with very low speed.

I’m not quiet believing that PWM is unavailble for after 4.5.0, it should just be accessed differently? You should always try to use the latest version of everything.

Now you’re using a different board with a different STM32 core (the stm32 implementation), there the flag USE_HSI_CLOCK has no effect, The right way to overwrite the weak function used for clock initialization, as seen here

So you have to write in your main.cpp code a function

extern "C" { /* must use C-linkage */
void SystemClock_Config(void)
{
   //init code here
}
}

Additionally you need lib_archive = no in the platformio.ini to make weak linking work.

The initialization code for the clock can be generated by using STM32CubeMX (https://www.st.com/en/development-tools/stm32cubemx.html). Start a new project for the STM32F103C8T6, go to the clock tree setup, select HSI and as input and 72MHz as the main CPU frequency, then let CubeMX solve for the PLL parameters. Then export the project and look at the src folder, a file in there will have the needed function for the clock setup.

1 Like

i really really thank you max!! i´ve got it to run :slight_smile:

two things stay:

  1. there are task errors. look at output …
  2. under PROBLEMS wrong definitions of closed files are showed

how do i get rid of these

i´ll post working code and setup in a little while

Could you provide a screenshot and relevant log if there is?

sorry for the delay, wasnt at the workbench for 2 weeks.

so now iam back and here i have a screenshot:

it appears on every project iam working on. dont know how to fix this.
i´ve tried updateing all my stuff but getting thousand compiler warnings now cuz BOOLEAN:

also you see the two upper entries:
these are including errors from a completely other project iam not in.

ok, the thing with the “boolean” only appears if i choose bluePill in the platformio.ini
tried with genericSTM32… it disappear