How to use STM32F0 onboard led with Arduino IDE?

I have found this example on how to use onboard led

  int t;                                        // timer
  RCC->CR |= 0x1;                               // set HSI
  RCC->AHBENR 1 = RCC_AHBENR_GPIOAEN;           // enable gpio port A
  GPIOA->MODER |= GPIO_MODER_MODER4_0;          // PA4 as input
  GPIOA->OTYPER &= ~GPIO_OTYPER_OT_4;           // output push-pull PA4
  GPIOA->OSPEEDR &= ~GPIO_OSPEEDER_OSPEEDR4_0;  // low speed PA4
  GPIOA->PUPDR |= GPIO_PUPDR_PUPDR4_0;          // set pull-up mode PA4
  while (1) {
    GPIOA->ODR |= GPIO_ODR_4;  // led ON at PA4
    t = 57500;
    while (t > 0) t--;          // countdown
    GPIOA->ODR &= -GPIO_ODR_4;  // led OFF at PA4
    t = 57500;
    while (t > 0) t--;  // countdown
  }

But has been written for Keil-MDK and doesn't work on Arduino IDE (it isn''t even able to recognize ~ on some lines ).
What is the correct way to use it on Arduino IDE?

STM32F0 is an MCU, it doesn't identify a single board layout. If your board is supported by the STM32 core you're using you can blink it this way:


void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, LOW);
  delay(100);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(100);
}
1 Like

Thank you it works.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.