cancel
Showing results for 
Search instead for 
Did you mean: 

RCC frequency differences between MX generated code and standard library code at 48Hz

ittyBitty
Associate

Working in the MX and with a PicoScope, I measured some square waves looking to see how the MX generated code compared to the standard library code in loop time. I was changing frequency using the 8Hz HSI through the PLL multiplier.  I found that with the MX generate code:

HAL_GPIO_TogglePin(LED_1_GPIO_Port, LED_1_Pin);
HAL_GPIO_WritePin(LED_1_GPIO_Port, LED_1_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(LED_1_GPIO_Port, LED_1_Pin, GPIO_PIN_SET);

The toggle at 48Hz was slower(2.5micro seconds) than at 32 Hz(1.9micro seconds). WritePin was also slower: 48Hz at 2.3 microseconds, to 1.7 microseconds at 32Hz

 

Using this standard library code, 48Hz was faster than 32Hz, as expected:


DigWrite_GPIOC(4, 1);
DigWrite_GPIOC(4, 0);

(3.9microseconds at 48Hz, and 2.2 microseconds at 32Hz)


GPIOC->BSRR = 0x0010;
GPIOC->BRR = 0x0010;

(392ns at 48Hz, 332ns at 32Hz)

 

This was all done in the MX through the PLL at 8Hz by 6 divided by 1 for 48Hz, and 8Hz by 4 divided by 1 for 32 Hz.

The standard library functions were used in the HAL generated code body, as were the HAL generated functions. 

Has anyone else has experienced this?

Thanks!

2 REPLIES 2
ittyBitty
Associate

Sorry.....MHz, not Hz.

TDK
Guru

What chip? HSI has a /2 divisor on at least some F0 chips, didn't see that mentioned.

Weird. It should scale with clock speed. Did you verify clock settings using MCO out or something else?

> GPIOC->BRR = 0x0010;

This isn't a valid statement. Makes me wonder how you're compiling.

> Sorry.....MHz, not Hz.

You can edit your post. Click the down arrow at the top-right of your post.

If you feel a post has answered your question, please click "Accept as Solution".