GPIO Mapping from libopencm3 to ChibiOS

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
hkerner
Posts: 24
Joined: Tue Jul 22, 2014 12:05 am

GPIO Mapping from libopencm3 to ChibiOS

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: GPIO Mapping from libopencm3 to ChibiOS

Post by Giovanni »

Is the pin configured as output? by default they are all inputs with pull-up.

Giovanni
hkerner
Posts: 24
Joined: Tue Jul 22, 2014 12:05 am

Re: GPIO Mapping from libopencm3 to ChibiOS

Post 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!
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: GPIO Mapping from libopencm3 to ChibiOS

Post by Giovanni »

Correct :)

Giovanni
Post Reply