Page 1 of 1

GPIO Mapping from libopencm3 to ChibiOS

Posted: Tue Jul 22, 2014 12:16 am
by hkerner
Hi there,

I originally had my application using lipopencm3 instead of the HAL (I am testing out using both) and am simply trying to blink an LED. I have the STM32F417IG LQFP176 and am trying to manipulate pin PA1. This works perfectly fine with libopencm3 when I reference it as (GPIOA, GPIO1), but doesn't work with the HAL when I reference it as (GPIOA, GPIO_PIN1).

Code: Select all

static WORKING_AREA(wa_blink_thread, 128);
static msg_t blink_thread(void *arg) {

  (void)arg;
  chRegSetThreadName("blinker");
  while (TRUE) {
    palSetPad(GPIOA, GPIOA_PIN1);
    chThdSleepMilliseconds(500);
    palClearPad(GPIOA, GPIOA_PIN1);
    chThdSleepMilliseconds(500);
  }
  return 0;
}

int main(void) {
  halInit();
  chSysInit();
  palSetPadMode(GPIOA, GPIOA_PIN1, PAL_MODE_ALTERNATE(2));
  palClearPad(GPIOA, GPIOA_PIN1);
  chThdCreateStatic(wa_blink_thread, sizeof(wa_blink_thread), NORMALPRIO, blink_thread, NULL);
  while (TRUE) {
    // do nothing
    chThdSleepMilliseconds(1000);
  }
}


And here I believe I have the correct board configuration in board.mk:

Code: Select all

# List of all the board related files.
BOARDSRC = ${CHIBIOS}/boards/ST_STM32F4_DISCOVERY/board.c

# Required include directories
BOARDINC = ${CHIBIOS}/boards/ST_STM32F4_DISCOVERY


Should I not be referencing A1 as (GPIOA, GPIOA_PIN1)? Perhaps there is a different mapping? Any help appreciated.

Re: GPIO Mapping from libopencm3 to ChibiOS

Posted: Tue Jul 22, 2014 7:59 am
by Giovanni
Is the pin configured as output? by default they are all inputs with pull-up.

Giovanni

Re: GPIO Mapping from libopencm3 to ChibiOS

Posted: Wed Jul 23, 2014 1:39 am
by hkerner
Huh... I guess I needed to do:

Code: Select all

  palSetPadMode(GPIOA, 1, PAL_MODE_OUTPUT_PUSHPULL);


rather than:

Code: Select all

palSetPadMode(GPIOA, 1, PAL_MODE_ALTERNATE(2));


Thank you!

Re: GPIO Mapping from libopencm3 to ChibiOS

Posted: Wed Jul 23, 2014 8:27 am
by Giovanni
Correct :)

Giovanni