Author Topic: Internal oscilator bluepill blink example arduino ide  (Read 641 times)

0 Members and 1 Guest are viewing this topic.

Offline marce002Topic starter

  • Regular Contributor
  • *
  • Posts: 53
  • Country: ar
Internal oscilator bluepill blink example arduino ide
« on: September 19, 2024, 12:50:31 pm »
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 the internal 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: [Select]
HardwareSerial my_serial_name(USART3, PB10, PB11);
#define pinLED PC13
void setup() {
my_serial_name.begin(9600); // on PB11 PB10
 pinMode(pinLED, OUTPUT);
}

void loop() {
digitalWrite(pinLED, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(2000);              // wait for a second
  digitalWrite(pinLED, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);     
my_serial_name.println("La verdad es que anda");
}
 

Offline radiolistener

  • Super Contributor
  • ***
  • Posts: 4054
  • Country: ua
Re: Internal oscilator bluepill blink example arduino ide
« Reply #1 on: September 19, 2024, 01:32:47 pm »
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.
« Last Edit: September 19, 2024, 01:35:12 pm by radiolistener »
 

Offline MasterT

  • Frequent Contributor
  • **
  • Posts: 833
  • Country: ca
Re: Internal oscilator bluepill blink example arduino ide
« Reply #2 on: September 19, 2024, 02:11:37 pm »
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.cpp

function 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.cpp
Code: [Select]
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."));


 

Offline marce002Topic starter

  • Regular Contributor
  • *
  • Posts: 53
  • Country: ar
Re: Internal oscilator bluepill blink example arduino ide
« Reply #3 on: September 19, 2024, 02:42:58 pm »
thks, but I HAVE only this:


C:\Users\Ux410u\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2022.9.26\variants\generic_stm32f103c

and no file has inside a definition for SystemClock_Config

board.cpp
pins_arduino.h
variant.h
board
id
wirish




 

Offline MasterT

  • Frequent Contributor
  • **
  • Posts: 833
  • Country: ca
Re: Internal oscilator bluepill blink example arduino ide
« Reply #4 on: September 19, 2024, 03:07:51 pm »
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.cpp

Some "Getting Started" installation tutorials, scroll page down
https://github.com/stm32duino/Arduino_Core_STM32#boards-available
 

Offline marce002Topic starter

  • Regular Contributor
  • *
  • Posts: 53
  • Country: ar
Re: Internal oscilator bluepill blink example arduino ide
« Reply #5 on: September 19, 2024, 03:54:17 pm »
sorry but i need to use STLINK v2 to upload, and the only wa to do this is using

https://dan.drown.org/stm32duino/package_STM32duino_index.json

and was compiling ok

 

Offline marce002Topic starter

  • Regular Contributor
  • *
  • Posts: 53
  • Country: ar
Re: Internal oscilator bluepill blink example arduino ide
« Reply #6 on: September 19, 2024, 05:26:56 pm »
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.

« Last Edit: September 19, 2024, 05:41:49 pm by marce002 »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf