如何解决使用PlatformIOArduino从内部振荡器运行STM32F103吗?
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:
#---------------------------------------------------------------------------------------------------
#Array
Save.array <- array(data = 0,dim= c(23,33935,16),dimnames = list(row.names,column.names,matrix.names))
column.names <- seq(1:33935)
row.names <- seq(1:23)
matrix.names <- c(components.vek) #Components are: O3,CO,Temperature,...
list.components <- as.list(components11.vek)
#---------------------------------------------------------------------------------------------------
# Loop
i <- 1
j <- 1
k <- 1
for (i in c(components.vek)) {
for (j in c(Save.array)) {
Speicher.array <- assign(paste0(i,".subset"),subset(mytable,component == i))
if Speicher.array[i,j,k] <- i == 33935
i+1
}
}
解决方法
我在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`
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。