Page 1 of 1

Beginners - Blinking LED

Posted: Wed Jun 11, 2014 10:56 am
by Juzujka
Code sample for blinking LED

Here is example for
  • creating thread
  • IO pin toggle
Example uses STM32VL discovery
board.h considers

Code: Select all

...
/*
 * Port C setup.
 * Everything input with pull-up except:
 * PC8  - Push-pull output (LED4), initially low state.
 * PC9  - Push-pull output (LED3), initially low state.
 */
#define VAL_GPIOCCRL            0x88888888      /*  PC7...PC0 */
#define VAL_GPIOCCRH            0x88888833      /* PC15...PC8 */
#define VAL_GPIOCODR            0xFFFFFCFF
...


main.c

Code: Select all

#include <ch.h>
#include <hal.h>
#include <stm32f10x.h>
#include <chtypes.h>
#include <chmsg.h>

static WORKING_AREA(wa_blinker, 128);
static msg_t blinker(void *arg) {
  (void)arg;
  chRegSetThreadName("blinker");
  while (!chThdShouldTerminate()) {
    palTogglePad(GPIOC, GPIOC_LED3);
    chThdSleepMilliseconds(500);
  }
  return 0;
}
int main(void) {
  halInit();
  chSysInit();

  chThdCreateStatic(wa_blinker, sizeof(wa_blinker), NORMALPRIO, blinker, NULL);
  while (!chThdShouldTerminate()) {
    chThdSleepMilliseconds(500);
  }
  return 0;
}

Re: Beginners - Blinking LED

Posted: Sun Jun 22, 2014 1:20 am
by Tectu
Thank you for sharing.
Probably you should add some information about the ChibiOS/RT version you are using. Comparing to the current /demos and /testhal this seems to be "old" code.


~ Tectu