Internal oscilator bluepill blink example arduino ide - Page 1
Forum section: electronics / general

author: marce002
author_rank: Regular Contributor
timestamp: September 19, 2024, 12:50:31 pm
content: Hello!Im new to mcu like this generic bluepill stm32f103c8, using arduino ide 2.3.2, I need to make a mod to this simple blink program to use theinternal clock (hsi oscilator)but i have not found how to be able to do it,it is now working HSE fine in my arduino ide environment with my stlink v2 upload method.. not with HSI.what would you change or add to the code, to use the int clock in a bluepill? i have remove the crystal from the board.Code:HardwareSerial my_serial_name(USART3, PB10, PB11);#define pinLED PC13void setup() {my_serial_name.begin(9600); // on PB11 PB10pinMode(pinLED, OUTPUT);}void loop() {digitalWrite(pinLED, HIGH); // turn the LED on (HIGH is the voltage level)delay(2000); // wait for a seconddigitalWrite(pinLED, LOW); // turn the LED off by making the voltage LOWdelay(1000);my_serial_name.println("La verdad es que anda");}

author: radiolistener
author_rank: Super Contributor
timestamp: September 19, 2024, 01:32:47 pm
content: The STM32F103C8T6 uses the internal oscillator by default after a reset, so no additional configuration is required in this case.If you want to use an external oscillator, follow these steps:1) Configure the external oscillator and the relevant multipliers and dividers for different system blocks.2) Enable the external oscillator.3) Wait for the external oscillator to stabilize.4) Switch the system clock source to the external oscillator.Refer to the datasheet for detailed instructions, or use STM32CubeMX to configure it visually, generate the initialization code, and review what changes were made.If you are using the Arduino startup library, it may reconfigure the clock source. In that case, check the library code.

author: MasterT
author_rank: Frequent Contributor
timestamp: September 19, 2024, 02:11:37 pm
content: In the arduino IDE clock tree defined in (example F4, change to you board)~/.arduino15/packages/STMicroelectronics/hardware/stm32/2.6.0/variants/STM32F4xx/F446R(C-E)T/variant_NUCLEO_F446RE.cppfunction is: WEAK void SystemClock_Config(void) {}As you can see it's "WEAK", so you free to make a copy, change configuration to HSI (CubeMX in help), than place this copy inside arduino sketch (I use separate tab) and call SystemClock_Config(void) {} from setup.Having a local copy saves time if mod required, don't have to navigate all way down to variant_XXX.cppCode:void setup(){Serial.begin(115200);in_String.reserve(200);Serial.print(F("\n\n\tSketch: pwm_dacFS_4c."));Serial.print(F("\t Date: 17 July 2024"));//SystemClock_Config(); <<---Serial.print(F("\n\tSys_clock: "));Serial.print(((uint32_t) SystemCoreClock /(float) 1000000.0), 3);Serial.print(F(" MHz."));

author: marce002
author_rank: Regular Contributor
timestamp: September 19, 2024, 02:42:58 pm
content: thks, but I HAVE only this:C:\Users\Ux410u\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2022.9.26\variants\generic_stm32f103cand no file has inside a definition for SystemClock_Configboard.cpppins_arduino.hvariant.hboardidwirish

author: MasterT
author_rank: Frequent Contributor
timestamp: September 19, 2024, 03:07:51 pm
content: I'm using official ST arduino core, and I just check it has in variants Blue-Pill:https://github.com/stm32duino/Arduino_Core_STM32/blob/main/variants/STM32F1xx/F103C8T_F103CB(T-U)/variant_PILL_F103Cx.cppSome "Getting Started" installation tutorials, scroll page downhttps://github.com/stm32duino/Arduino_Core_STM32#boards-available

author: marce002
author_rank: Regular Contributor
timestamp: September 19, 2024, 03:54:17 pm
content: sorry but i need to use STLINK v2 to upload, and the only wa to do this is usinghttps://dan.drown.org/stm32duino/package_STM32duino_index.jsonand was compiling ok

author: marce002
author_rank: Regular Contributor
timestamp: September 19, 2024, 05:26:56 pm
content: so any chance to make it work with HSI and this library? i mean if I use your libs i cant upload with stlink option.