arduino - 使用 PlatformIO (Arduino) 从内部振荡器运行 STM32F103?

标签 arduino stm32 platformio

如何将 STM32F103C8 配置为使用内部 RC 振荡器/HSI 和 PLL 运行,即无需外部晶体振荡器(如“蓝色药丸”板上所示)并使用 PlatformIO 中的 Arduino 框架?

platformio.ini:

[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
#board = genericSTM32F103C8
#board_build.mcu = stm32f103c8t6
#board_build.f_cpu = 72000000L

framework = arduino
lib_deps = olikraus/U8g2 @ ^2.28.7

upload_protocol = stlink

最佳答案

我在 PlatformIO 目录中进行了一些挖掘。

以下路径适用于“通用”:

  • C:\Users\<user>\.platformio\platforms\ststm32\boards\genericSTM32F103C8.json
  • C:\Users\<user>\.platformio\packages\framework-arduinoststm32\variants\Generic_F103Cx\variant.cpp

定义您自己的系统时钟配置,例如你的main.cpp :

void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct;
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
  RCC_PeriphCLKInitTypeDef PeriphClkInit;

  /* Initializes the CPU, AHB and APB busses clocks */
  // RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  // RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  // RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  // RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
    while (1);
  }

  /* Initializes the CPU, AHB and APB busses clocks */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
                                | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) {
    while (1);
  }

  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC ;
  PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6;
  PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5;
  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
    while (1);
  }
}

ini 是:

[env:bluepill_f103c8]
platform = ststm32
board = genericSTM32F103C8
framework = arduino
upload_protocol = stlink
lib_deps = olikraus/U8g2 @ ^2.28.7

我建议重命名 env以避免混淆。

我尚未验证实际时钟速度。


它应以 36 MHz (8 MHz/2*9) 运行。然后ini需要`board_build.f_cpu = 36000000L`

关于arduino - 使用 PlatformIO (Arduino) 从内部振荡器运行 STM32F103?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64646976/

相关文章:

java - Android 中通过蓝牙发送数据

c++ - ESP8266WiFi.h : No such file or directory

c++ - PlatformIO 的范围问题(?)

stm32F4 pwm 输入捕捉高频信号约。 2兆赫?

c - MPU6050 - 自平衡机器人的陀螺仪倾角测量?

c - 在函数 2D DMA 中传递地址

c - ESP32 无法连接到 MQTT 代理 : mqtt_client: Error network response

python - 树莓派 : issue communicating via I2C

node.js - Webduino 从 curl 而不是从 Node 接收 POST 参数

arduino - 在使用 nointerrupts() 函数时,新的中断是否会排队并在 Interrupts() 之后执行?