gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 08:39:13 26 4
gpt4 key购买 nike

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

  • https://docs.platformio.org/en/latest/boards/ststm32/bluepill_f103c8.html
  • https://docs.platformio.org/en/latest/boards/ststm32/genericSTM32F103C8.html
  • https://docs.platformio.org/en/latest/frameworks/arduino.html

  • 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/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com