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

Re: STM32F103RCT6 on li-ion for a week

Post by razvitm »

Eureka!
I am running the STM32F103RCT6 at 4MHz and current consumption dropped to 8mA.
I replaced the external 8MHz crystal with a 4MHz one.
I modified the file:
c:\Users\Razvan\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2020.3.13\variants\generic_stm32f103r\wirish\boards_setup.cpp
Added
" #elif F_CPU==4000000
#define BOARD_RCC_PLLMUL RCC_PLLMUL_2"
And modified the file:
c:\Users\Razvan\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2020.3.13\boards.txt
Modified:
genericSTM32F103R.menu.cpu_speed.speed_48mhz.build.f_cpu=4000000L

So that the compiler knows the core is running at 4MHz so all the timings are correct.

Also in the arduino sketch I had to include the following code to disable the PLL and feed the external clock directly to the core.
#include <boards.h>
#include <libmaple/libmaple_types.h>
#include <libmaple/flash.h>
#include <libmaple/nvic.h>
#include <libmaple/systick.h>
#include "boards_private.h"

void setup() {
setup_clocks();
}
static void setup_clocks(void) {
// Turn on HSI. We'll switch to and run off of this while we're
// setting up the main PLL.
rcc_turn_on_clk(RCC_CLK_HSI);

// Turn off and reset the clock subsystems we'll be using, as well
// as the clock security subsystem (CSS). Note that resetting CFGR
// to its default value of 0 implies a switch to HSI for SYSCLK.
RCC_BASE->CFGR = 0x00000000;
rcc_disable_css();
rcc_turn_off_clk(RCC_CLK_PLL);
rcc_turn_off_clk(RCC_CLK_HSE);
wirish::priv::board_reset_pll();
// Clear clock readiness interrupt flags and turn off clock
// readiness interrupts.
RCC_BASE->CIR = 0x00000000;

//disable PLL
RCC_BASE->CR &= ~(1<<24);

#if !USE_HSI_CLOCK
// Enable HSE, and wait until it's ready.
rcc_turn_on_clk(RCC_CLK_HSE);
while (!rcc_is_clk_ready(RCC_CLK_HSE))
;
#endif

// Finally, switch to the HSE as the main clock source.
rcc_switch_sysclk(RCC_CLKSRC_HSE);
}

I'm also using the Serial1 at 115200 baudrate with the core running at 4MHz and I get 0.6% error which is below 3% meaning I'll have no problem communicating with sensors on this baudrate. With the Atmega2560 at 8MHz this was impossible due to the fact that it divides by 2 a lot before the clock reaches the UART and so 115200 at 8MHz is impossible with the Mega.
Post Reply

Return to “General discussion”