Loading...
 
Skip to main content

System Workbench for STM32


Importing Cube example programs: F7-discovery

Ok, so I looked over your git project (Thank you!) and compared your .ioc and my .ioc, for default projects. I text diffed with pspad and the only real differences are the project names.

So, your ioc project says to set up the RCC with 168MHz, and what actually happens in your main.c in the SystemClock_Config() function, is the following:

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLM = 10;
RCC_OscInitStruct.PLL.PLLN = 210;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 2;
HAL_RCC_OscConfig(&RCC_OscInitStruct);

I have that as well. So from the above, we can see it uses the high speed internal oscillator, divides the 16MHz by 10, multiplies 210 to give 336 and divides by two to give the final 168MHz sys clock. Same with mine.

What I've done since is set the clocks to use the external crystals and used 25M / 25, *400, final div by 2 to give a 200MHz sys clock, set up in the nice graphical clock config page in cube MX. 😊

So, in my main.c:

/* USER CODE BEGIN 2 */
RCC->DCKCFGR1 |= RCC_DCKCFGR1_TIMPRE;
RCC->APB1ENR |= RCC_APB1ENR_TIM7EN;
TIM7->PSC = 10000;
TIM7->ARR = 10000; // 10k * 10k = 100M == twice a second @ 200MHz
TIM7->DIER = 1;
TIM7->CNT = 0;

NVIC_EnableIRQ(TIM7_IRQn);

TIM7->CR1 = 1;

So just set the timer prescale bit RCC_DCKCFGR1_TIMPRE in the (Direct?) clock config register, to ensure timers get 200MHz sys clock, not APB1, then configure your timer to interrupt and obviously code your interrupt routine as well to indicate / do something.

All the above was basically to check the clock config was right and peripherals working / dubuggable and running at the desired speed. Another 16MHz is for another time maybe 😉

I've yet to test the maths capabilities wrt cache and clk speed. Maybe this has gone a bit OT but I'll put details in a fresh post and report back...