Blue Pill clock define
Posted: Wed Feb 26, 2020 9:59 pm
Using Arduino IDE how can I set Blue Pill cpu clock to 1 MHz, for example?
Everything relating to using STM32 boards with the Arduino IDE and alternatives
https://www.stm32duino.com/
Code: Select all
extern "C" void SystemClock_Config(void) {...}
great! so i can set it so easy to...whatever i want.fpiSTM wrote: Fri Mar 13, 2020 9:35 am As it is a weak, you can redefine it at sketch levelCode: Select all
extern "C" void SystemClock_Config(void) {...}
Dis you try to do it yourself using STM32CubeMX ?Renato wrote: Tue May 26, 2020 12:09 am Please, show a short SystemClock_Config example when I want 2 MHz cpu clock, with internal RC oscilator HSI 16 MHz.
Thanks
Code: Select all
RCC_OscInitStruct.HSIState = RCC_HSI_ON; /** 16 MHz */
RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV8; /** 2 MHz ahed */
Code: Select all
extern "C" void SystemClock_Config(void)
void setup() {
.....
}
void loop() {
SystemClock_Config()
....
}
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
/** Configure the main internal regulator output voltage
*/
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV8;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
/** Initializes the peripherals clocks
*/
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_ADC;
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1;
PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
}
So, I supose that Arduino IDE find this information in specific folder.stas2z wrote: Tue May 26, 2020 10:58 pm Yes, you need whole SystemClock_Config from cube, and don't call it from loop or from anywhere else, it will be called at preinit