If you need to toggle a pin on STM32 micro controller as fast as possible the code bellow will help you achieve that.
void main()
{
unsigned long *ptr;
unsigned long val = 2;
unsigned long val1 = 2ul << 16;
GPIO_Config(&GPIOB_BASE, _GPIO_PINMASK_1, _GPIO_CFG_DIGITAL_OUTPUT |
_GPIO_CFG_SPEED_MAX | _GPIO_CFG_OTYPE_PP | _GPIO_CFG_PULL_NO);
ptr = (unsigned long *)&GPIOB_BSRR;
while(1)
{
*ptr = val;
*ptr = val1;
*ptr = val;
*ptr = val1;
}
}
