undefined reference to `palEnableLineEvent'

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
AnSc
Posts: 17
Joined: Tue Mar 29, 2022 4:16 pm
Has thanked: 1 time
Been thanked: 2 times

undefined reference to `palEnableLineEvent'

Postby AnSc » Wed May 11, 2022 3:53 pm

Hi,

I wanted to implement this method for event based reading buttons from this article: https://www.playembedded.org/blog/buttons-stm32/

However, I get the error

Code: Select all

undefined reference to `palEnableLineEvent'


I did set #define HAL_USE_PAL TRUE in halconf.h

I can see the definition of it in C:\ChibiStudio\chibios2111\os\hal\include\hal_pal.h

and I did #include "hal.h" in my source file.

What am I missing? I'm using a STM32F103 if that makes any difference.

Code: Select all

/** this file contains buttons related code */

#include "ch.h"
#include "hal.h"
#include "board.h"

void button_cb(void *arg){
  (void)arg;
  if(palReadLine(LINE_BUTTON_A) == PAL_HIGH){ // rising edge starts timer
    startTimeA = chVTGetSystemTimeX();
  }
  else { // falling edge reads timer and desides if clicked or long press
    if(chVTIsSystemTimeWithinX(startTimeA, startTimeA + TIME_MS2I(LONGPRESSEDMS))){
      // short pressed
      active.A = CLICKED;
    }
    else { // long press
      active.A = LONGPRESSED;
    }
  }
  if(palReadLine(LINE_BUTTON_B) == PAL_HIGH){ // rising edge starts timer
    startTimeB = chVTGetSystemTimeX();
  }
  else { // falling edge reads timer and desides if clicked or long press
    if(chVTIsSystemTimeWithinX(startTimeB, startTimeB + TIME_MS2I(LONGPRESSEDMS))){
      // short pressed
      active.B = CLICKED;
    }
    else { // long press
      active.B = LONGPRESSED;
    }
  }
  if(palReadLine(LINE_BUTTON_L) == PAL_HIGH){ // rising edge starts timer
    startTimeL = chVTGetSystemTimeX();
  }
  else { // falling edge reads timer and desides if clicked or long press
    if(chVTIsSystemTimeWithinX(startTimeL, startTimeL + TIME_MS2I(LONGPRESSEDMS))){
      // short pressed
      active.L = CLICKED;
    }
    else { // long press
      active.L = LONGPRESSED;
    }
  }
  if(palReadLine(LINE_BUTTON_R) == PAL_HIGH){ // rising edge starts timer
    startTimeR = chVTGetSystemTimeX();
  }
  else { // falling edge reads timer and desides if clicked or long press
    if(chVTIsSystemTimeWithinX(startTimeR, startTimeR + TIME_MS2I(LONGPRESSEDMS))){
      // short pressed
      active.R = CLICKED;
    }
    else { // long press
      active.R = LONGPRESSED;
    }
  }
  if(palReadLine(LINE_BUTTON_ROT) == PAL_HIGH){ // rising edge starts timer
    startTimeRot = chVTGetSystemTimeX();
  }
  else { // falling edge reads timer and desides if clicked or long press
    if(chVTIsSystemTimeWithinX(startTimeRot, startTimeRot + TIME_MS2I(LONGPRESSEDMS))){
      // short pressed
      active.ROT = CLICKED;
    }
    else { // long press
      active.ROT = LONGPRESSED;
    }
  }

}

/** set up the buttons */
void buttonInit(void){
  palEnableLineEvent(LINE_BUTTON_A,   PAL_EVENT_MODE_BOTH_EDGES);
  palEnableLineEvent(LINE_BUTTON_B,   PAL_EVENT_MODE_BOTH_EDGES);
  palEnableLineEvent(LINE_BUTTON_L,   PAL_EVENT_MODE_BOTH_EDGES);
  palEnableLineEvent(LINE_BUTTON_R,   PAL_EVENT_MODE_BOTH_EDGES);
  palEnableLineEvent(LINE_BUTTON_ROT, PAL_EVENT_MODE_BOTH_EDGES);

  palSetLineCallback(LINE_BUTTON_A,   button_cb, NULL);
  palSetLineCallback(LINE_BUTTON_B,   button_cb, NULL);
  palSetLineCallback(LINE_BUTTON_L,   button_cb, NULL);
  palSetLineCallback(LINE_BUTTON_R,   button_cb, NULL);
  palSetLineCallback(LINE_BUTTON_ROT, button_cb, NULL);
}

User avatar
Giovanni
Site Admin
Posts: 14057
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 990 times
Been thanked: 839 times
Contact:

Re: undefined reference to `palEnableLineEvent'

Postby Giovanni » Wed May 11, 2022 4:25 pm

Hi,

In halconf.h you also need to set:

#define PAL_USE_CALLBACKS TRUE
#define PAL_USE_WAIT FALSE

Giovanni

AnSc
Posts: 17
Joined: Tue Mar 29, 2022 4:16 pm
Has thanked: 1 time
Been thanked: 2 times

Re: undefined reference to `palEnableLineEvent'

Postby AnSc » Wed May 11, 2022 4:51 pm

Thanks a lot. :D
Somehow I missed this information in the article.
It's right there… :roll:


Return to “ChibiOS/HAL”

Who is online

Users browsing this forum: No registered users and 1 guest