Skip to content

Instantly share code, notes, and snippets.

@csrohit
Last active December 1, 2022 09:03
Show Gist options
  • Save csrohit/ae7176560d56e5f80a40b22e286d223e to your computer and use it in GitHub Desktop.
Save csrohit/ae7176560d56e5f80a40b22e286d223e to your computer and use it in GitHub Desktop.
Gist for supporting article on optimising code size
void ms_delay(int ms)
{
while (ms-- > 0)
{
volatile int x = 1000;
while (x-- > 0)
__asm("nop");
}
}
void unused_delay(int ms)
{
while (ms-- > 0)
{
volatile int x = 10;
while (x-- > 0)
__asm("nop");
}
}
int main(void)
{
RCC->APB2ENR |= RCC_APB2ENR_IOPCEN;
GPIOC->CRH = 0x02 << ((13 - 8) << 2);
while(1){
GPIOC->ODR ^= 1 << 13;
ms_delay(1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment