Thanks for your reply, sir.
I follow your guide and check my design carefully.
First, the external clock frequency on PCB is 32MHz indeed, I confirmed that with an oscilloscope.
And I enabled “Master Clock Output 1” feature, and STM32 output main clock through PA8, I measured this pin with an oscilloscope, it was 32MHz.
Whether I use HSE or HSI, I make sure the system runs at 32MHz, I measured “Master Clock Output 1” with an oscilloscope, it was 32MHz, there was no doubt.
Then I go to check HAL_GPIO_WritePin() function, it checks parameters validation, then operates registers directly.
The last point you mentioned, I checked again, No Optimization Enabled.
This is a very tiny code project to output a fixed frequency wave. What’s going on? Did I miss something? This really confused me.
Then My colleagues suggested me to update STM32CubeIDE to latest version.
The version I’m using is V1.14.1, the latest version on ST.com is V1.15.1,
After I eliminated old version and updated to the latest version, nothing changed, I still can’t get a correct consequence.
Does anyone do me a favor?