STM32F103RCT6 on li-ion for a week

Post here all questions related to LibMaple core if you can't find a relevant section!
razvitm
Posts: 38
Joined: Sat Apr 11, 2020 12:35 pm

STM32F103RCT6 on li-ion for a week

Post by razvitm »

Hello, this is my first post here.
I was using the arduino mega until recently but want to switch to the STM32F103RC because of the 5 serial ports.
The project has to run on li-ion 18650 cell for a week, so I have to reduce the clock from 72MHz down to 8MHz.
I have found that in the \stm32duino\hardware\STM32F1\2020.3.13\boards.txt file, if I edit the line 607 so it becomes:
"genericSTM32F103R.menu.cpu_speed.speed_48mhz.build.f_cpu=16000000L" instead of
"genericSTM32F103R.menu.cpu_speed.speed_48mhz.build.f_cpu=48000000L"
The MCU clock is changed to 16MHz and current consumption for a simple blinky sketch drops from 44mA at 72MHz to 17mA at 16MHz.
But still the 17mA is too much because I have other sensors that are powered by the same li-ion cell and I need to further reduce the MCU clock.
However. In the datasheet, the PLL multiplier cannot be set lower than 2, so if the external crystal is 8MHz, then with the current external crystal, the minimum frequency is 16MHz.
The question is, if I replace the external crystal with a 4MHz one, what files do I need to modify in the stm32duino folder to tell the IDE that the frequency is 8MHz now, so all the timings are correct?
razvitm
Posts: 38
Joined: Sat Apr 11, 2020 12:35 pm

Re: STM32F103RCT6 on li-ion for a week

Post by razvitm »

For example, I can use the Arduino Mega boards with different crystals because we have the Mega Core that allows the use of a bunch of different frequency crystals. I would like to be able to do the same with STM32 in arduino.

Later edit:

I found a file in which the PLL multipliers are defined based on the desired CPU clock
c:\Users\lenovo\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2020.3.13\variants\generic_stm32f103r\wirish\boards_setup.cpp

If I replace the external crystal oscillator with a 4MHz one, and in the above mentioned file I double all the RCC_PLLMUL, would I get correct timings?
So the #defines become
#if F_CPU==128000000
#define BOARD_RCC_PLLMUL RCC_PLLMUL_32
#elif F_CPU==72000000
#define BOARD_RCC_PLLMUL RCC_PLLMUL_18
#elif F_CPU==48000000
#define BOARD_RCC_PLLMUL RCC_PLLMUL_12
#elif F_CPU==16000000
#define BOARD_RCC_PLLMUL RCC_PLLMUL_4
#endif
User avatar
Pito
Posts: 94
Joined: Tue Dec 24, 2019 1:53 pm

Re: STM32F103RCT6 on li-ion for a week

Post by Pito »

44mA at 72MHz is too much, imho.
25-30mA is something I would buy..
What is the board like? Any LEDs with 220ohm serial resistors?
You may run stm32 with an external 8MHz crystal without PLL engaged, you have to change the settings, however.
With 8MHz crystal you may get 5mA Idd.
Last edited by Pito on Sat Apr 11, 2020 2:50 pm, edited 1 time in total.
Pukao Hats Cleaning Services Ltd.
razvitm
Posts: 38
Joined: Sat Apr 11, 2020 12:35 pm

Re: STM32F103RCT6 on li-ion for a week

Post by razvitm »

Pito wrote: Sat Apr 11, 2020 2:39 pm 44mA at 72MHz is too much, imho.
20mA is something I would buy..
What is the board like? Any LEDs with 220ohm serial resistors?
You may run stm32 with an external 8MHz crystal without PLL engaged, you have to change the settings, however.
Thank you for answering, can you please guide me on changing the settings to disable the PLL in arduino?
User avatar
Pito
Posts: 94
Joined: Tue Dec 24, 2019 1:53 pm

Re: STM32F103RCT6 on li-ion for a week

Post by Pito »

Which core do you use?
Pukao Hats Cleaning Services Ltd.
razvitm
Posts: 38
Joined: Sat Apr 11, 2020 12:35 pm

Re: STM32F103RCT6 on li-ion for a week

Post by razvitm »

Pito wrote: Sat Apr 11, 2020 2:51 pm Which core do you use?
stm32duino.
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: STM32F103RCT6 on li-ion for a week

Post by stevestrong »

Read this first: https://web.archive.org/web/20190316164 ... f=2&t=3111
and then answer the question:
Which core do you use?
razvitm
Posts: 38
Joined: Sat Apr 11, 2020 12:35 pm

Re: STM32F103RCT6 on li-ion for a week

Post by razvitm »

stevestrong wrote: Sat Apr 11, 2020 3:34 pm Read this first: https://web.archive.org/web/20190316164 ... f=2&t=3111
and then answer the question:
Which core do you use?
I am using:
1. The current STM32F1/F4 core files (Leaflabs-based core) for the latest version of ArduinoIDE for clone boards
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: STM32F103RCT6 on li-ion for a week

Post by stevestrong »

Have a look at these code lines:
https://github.com/rogerclarkmelbourne/ ... #L107-L139,
and change it according to your needs as described in the reference manual RM0008.
ag123
Posts: 1668
Joined: Thu Dec 19, 2019 5:30 am
Answers: 25

Re: STM32F103RCT6 on li-ion for a week

Post by ag123 »

if you can unclock the pheriperials that you don't use, accordingly that could save some power
http://www.emcu.it/STM32/STM32VLDiscove ... eripherals.

those are using HAL codes, but i'd guess if you were to review RM0008 and the core source codes it shouldn't be too difficult to unclock the pheriperials you don't use.
Post Reply

Return to “General discussion”