2011-12-09 05:39 AM
Hi,
I want to measure the clock of my stm32f225rg chip. I am doing it by toggling the bit of gpio port B and checking using scope. Rather than using the routines in the standard peripheral library, I am programming the registers directly. The routine for toggling is below. while (1) { GPIOB->BSRRL = GPIO_Pin_15; // Set GPIOB->BSRRH = GPIO_Pin_15; // ReSet GPIOB->BSRRL = GPIO_Pin_15; // Set GPIOB->BSRRH = GPIO_Pin_15; // ReSet GPIOB->BSRRL = GPIO_Pin_15; // Set GPIOB->BSRRH = GPIO_Pin_15; // ReSet GPIOB->BSRRL = GPIO_Pin_15; // Set GPIOB->BSRRH = GPIO_Pin_15; // ReSet GPIOB->BSRRL = GPIO_Pin_15; // Set GPIOB->BSRRH = GPIO_Pin_15; // ReSet GPIOB->BSRRL = GPIO_Pin_15; // Set Delay(200); GPIOB->BSRRH = GPIO_Pin_15; // ReSet Delay(200); } The toggling can be observed in the scope, but I find the on and off times different. Though the number of instructions for the bitset and bitreset are 4 it seems bitset is using 5 clock cycles and bitreset 4. Any help would be appreciated.2011-12-09 07:11 AM
The GPIO unit is on the APB bus, and behind a write buffer, figure at least 4 cycles. Toggling the pins in this fashion is awfully inefficient. Performance might be different if you use 32-bit writes, and code this in assembler.
Use a TIMer to generate signals with predictable duty cycles. Use the MCO pin to measure CPU frequency. Run code from RAM to avoid unpredictable behaviour of the flash controller/cache.