2023-12-11 02:40 AM
The MCU is STM32G031J6 on a STM32G0316-DISCO board.
The maximum software pin toggling speed I am able to achieve is about 0.7 us.
It looks a bit slow for a M0+ running at 48 mhz.
Looking at listing file, there is no library overhead (I am using LL).
Can someone shed some light on this?
Solved! Go to Solution.
2023-12-11 11:21 AM
Solved, thank you all.
My bad. Inexperienced with Stm32Cube, I was always flashing the MCU with the Debug build.
Attached there are the listing of the main loop and the output.
2023-12-11 04:02 AM
> running at 48 mhz
Milli-hecto-z? ;)
Does it indeed run at 48MHz? Read out and check/post content of relevant RCC registers.
> Looking at listing file
Show.
JW
2023-12-11 04:14 AM
Yes, it does indeed run at 48 mhz, I checked it with a scope on pin 5, configured as MCO.
I have not the listing at hand, I'll post it as soon as I can.
2023-12-11 04:22 AM
what optimizer setting you have? try -O2
2023-12-11 04:25 AM
Speed depends on how efficiently you write to registers, whether you RMW to ODR or write patterns to BSRR
Normally for high speed you'd use a TIM in toggle mode, rather than saturate the MCU with bus traffic to the AHB/APB, which realistically is going to take at least 4 machine cycles.
For speed critical output perhaps a RAM based pattern buffer and TIM+DMA+GPIO to drive between 1 and 16 pins in a single GPIO Bank
2023-12-11 04:50 AM
>the MCU with bus traffic to the AHB/APB, which realistically is going to take at least 4 machine cycles.
As far as I know, this MCU features the 'single cycle' IOPORT.
2023-12-11 05:01 AM - edited 2023-12-11 05:28 AM
Not sure what you mean by "toggling" since you didn't show the actual code. The HAL_GPIO_Toggle routine has some errors/inefficiencies. The optimal routine should be this:
static inline void TogglePin(GPIO_TypeDef *port, uint16_t msk)
{
port->BSRR = msk << 16 | (~port->ODR & msk);
}
In contrast, the HAL routine is not declared as static inline, so it must be really called (which takes few instruction cycles) and there is an extra, unnecessary logic AND operation in it.
2023-12-11 08:12 AM
btw
i just tested an H563 , 250MHz , -O2 ; APB bus at 250M , pin speed : very high;
makes 4 ns at the pin ! (with: GPIOB->BSRR = GPIO_PIN_0; )
2023-12-11 11:21 AM