Closed nopnop2002 closed 1 year ago
genericSTM32F103VB/VC/VD/VE
The clock frequency is set to 64MHz instead of 72MHz.
Board maps to variant
And https://github.com/stm32duino/Arduino_Core_STM32/tree/main/variants/STM32F1xx/F103V8(H-T)_F103VB(H-I-T) only has one clock code in generic_clock.c. If the USB communication is enabled, it clocks the CPU by HSI / 2 12, with HSI = 8MHz, that is 48 Mhz (USB peripheral needs a 48MHz source and that can be achieved easily with that), else, by HSI / 2 16 = 64MHz.
If you have a high-speed crystal (HSE) on the board, you can achieve the full frequency, which is what PlatformIO always lists. It does not account for default clock init code of different frameworks. To do this, you have to place a function in your firmware, e.g. in the src/main.cpp
file, with
extern "C" void SystemClock_Config(void)
{
// clock init code here
}
and that inner code can e.g. be generated with STM32CubeMX's clock configurator tool.
I did another test using a bluepill board and same code.
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[platformio]
default_envs = bluepill_f103c8
[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = arduino
F_CPU show 72000000
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[platformio]
default_envs = genericSTM32F103CB
[env:genericSTM32F103CB]
platform = ststm32
board = genericSTM32F103CB
framework = arduino
F_CPU show 64000000
#include <Arduino.h>
//HardwareSerial Serial1(USART1);
HardwareSerial Serial2(USART2);
HardwareSerial Serial3(USART3);
#define BAUDRATE 115200
void setup() {
Serial3.begin(BAUDRATE); Serial3.println("serial 3"); // PB10/PC5
Serial2.begin(BAUDRATE); Serial2.println("serial 2"); // PA2/PA3
Serial1.begin(BAUDRATE); Serial1.println("serial 1"); // PA9/PA10
/* Serial.begin(BAUDRATE); */
Serial.println("serial (same as 1)");
Serial.println("*****");
}
void loop() {
Serial3.println("serial 3");
Serial3.println(F_CPU);
Serial2.println("serial 2");
Serial2.println(F_CPU);
Serial1.println("serial 1");
Serial1.println(F_CPU);
Serial.println("serial (same as 1)");
Serial.println("*****");
delay(1000);
}
board = bluepill_f103c8
shows F_CPU = 72000000 because its clock code configures it to do so, HSE (=8MHz) / 1 * 9 = 72 MHz.
board = genericSTM32F103C8
shows F_CPU = 64000000 because its clock code configures it to do so, HSI (=8MHz) / 2 * 16 = 64 MHz.
Choosing different board
values will select different variants in the STM32Duino core, which can all have their own clock init code. This is all okay. Specifically, generic* boards don't make assumptions about having a HSE crystal, so they use HSI, which can't achieve the full speed. Known hardware like the Bluepill uses the HSE, because it's on a bluepill.
@maxgerhardt
Thank you for the commentary.
I would like to keep this issues open for others.
@maxgerhardt
Do you think 72Mhz on this list should be changed?
No, because that's the maximum frequency of the chip. People can still use board = genericSTM32F103C8
and achieve 72MHz if they add the clock init code. And the chip supports more frameworks (stm32cube, cmsis, mbed-os, ...), all of which can have a different default frequency. Without doing anything in CMSIS for example, clock frequency is just HSI = 8MHz. Stating the frequency in the table as 8MHz there would be very misleading.
@maxgerhardt
I got it.
The board manifest contains maximum chip frequency that has nothing to do with specific particular settings.
Configuration
Operating system: Linux (ubuntu)
PlatformIO Version (
platformio --version
): PlatformIO Core, version 5.2.5Description of problem
I built with this variant.
genericSTM32F103VB/VC/VD/VE
The clock frequency is set to 64MHz instead of 72MHz.
Is this the correct behavior?
If problems with PlatformIO Build System:
The content of
platformio.ini
:Source file to reproduce issue: