cancel
Showing results for 
Search instead for 
Did you mean: 

How to fix Undefined reference to `arm_pid_init_q31', error?

karlis
Associate II
Posted on December 30, 2017 at 13:21

Hi, everyone!

I am trying to implement PID controller from arm_math library. I use this code as kind of example for this 

https://stm32f4-discovery.net/2014/11/project-03-stm32f4xx-pid-controller/

  

I am getting error - Undefined reference to `arm_pid_init_q31',

There is nothing much regarding PID in my code, I copied only lines regarding PID.

&sharpinclude <arm_math.h>

&sharpdefine PID_PARAM_KP 10 /* Proporcional */

&sharpdefine PID_PARAM_KI 10 /* Integral */

&sharpdefine PID_PARAM_KD 10 /* Derivative */

uint32_t PID_ERROR;

arm_pid_instance_q31 PID;

PID.Kp = PID_PARAM_KP; /* Proporcional */

PID.Ki = PID_PARAM_KI; /* Integral */

PID.Kd = PID_PARAM_KD; /* Derivative */

arm_pid_init_q31(&PID, 1);

while(1)

{

output_voltage_mv = (3300*VOUT * 21) / 4096;

PID_ERROR = Vreg - output_voltage_mv;

duty_cycle = arm_pid_q31(&PID, PID_ERROR);

}

Can any help please?

#pid #arm_math
8 REPLIES 8
Posted on December 30, 2017 at 15:25

Error suggests you need to add the library file to your project, or add in the source files from the library.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Zt Liu
Senior III
Posted on January 02, 2018 at 11:17

If using keil, you may need to enable your CMSIS-DSP pack.

Good luck!

Zt.

Posted on January 03, 2018 at 12:51

But I have included arm_math.h and this arm_pid_init_q31 is defined in arm_math.h....

I do not understand why shouldn't it work. If arm_math would not be accessable for project I would get error about that.

Posted on January 03, 2018 at 13:12

karlis77 wrote:

But I have included arm_math.h and thisarm_pid_init_q31 is defined (sic?) in arm_math.h....

Are you sure it's actually defined there ...?

https://community.st.com/0D50X00009XkWruSAF

Posted on January 03, 2018 at 13:43

I think I am. When I click Go to Definition it opens arm_math.h and shows me this.

0690X00000604EzQAI.jpg
Posted on January 03, 2018 at 13:58

Ha - that's Keil being sloppy with their terminology!

>:(

That is just a function prototype - it is not a definition - it is just a declaration.

See: C-FAQ 

http://c-faq.com/decl/decldef.html

 

So, as in the previously-linked forum thread, you need to also include the .c source file which provides the actual definition (ie, the implementation) of that function ...

EDIT

To be fair,  I think that Eclipse is equally sloppy with this.

Posted on January 03, 2018 at 14:09

Ok, thank you!

I searched for .c file and found that there is \STM32H7xxxx\CMSIS_HAL\DSP\Source\ControllerFunction\

arm_pid_init_q31.c

So I included it in my code and now I can build it. 

I do not know much about this stuff, but I was wondering why it wasn't included in arm_math.h

Posted on January 03, 2018 at 14:12

karlis77 wrote:

I do not know much about this stuff, but I was wondering why it wasn't included in arm_math.h

As noted in the other thread, it is standard 'C' programming stuff - not specific to Keil or ST or even embedded.

It is explained in the linked FAQ.