Linker Error using STM32F4 & FreeRTOS

groufosse wrote on Monday, June 02, 2014:


I believe I have followed the steps to integrate FreeRTOS into my STM32F4 project, but getting a link error.
I modified the startup file for EWARM (IAR) and added the declarations there:
EXTERN xPortPendSVHandler
EXTERN xPortSysTickHandler
EXTERN vPortSVCHandler

Also change further below in the __vector_table:
DCD vPortSVCHandler ; SVCall Handler
DCD DebugMon_Handler ; Debug Monitor Handler
DCD 0 ; Reserved
DCD xPortPendSVHandler ; PendSV Handler
DCD xPortSysTickHandler ; SysTick Handler

I have the file “FreeRTOSConfig.h” in my local include directory and it’s in the compiler’s preprocessor path. Still, I get this link error:

Error[Li005]: no definition for “vPortSVCHandler” [referenced from C:\Users\rds\Documents\IAR Embedded Workbench\ADC2\Projects\EWARM\ADC2 Configuration\Obj\startup_stm32f407xx.o]

Can someone please provide some insight on this…?

Thank you.

rtel wrote on Tuesday, June 03, 2014:

I’m not sure why that would be as it looks ok.

The other option would be to keep the linker script exactly as delivered by IAR, then add the following lines into FreeRTOSConfig.h to effectively change the names of the FreeRTOS handlers:

#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
#define xPortSysTickHandler SysTick_Handler

Richard Barry.

markwrichardson wrote on Tuesday, June 03, 2014:

In my assembler, I have to use an assembly directive ‘XREF’ to cast a variable as public. They are private by default. Also, my C/ASM environment use different variable names as seen by the linker. All C variable have an underscore ‘_’ before the name. So, if I want to use an assembly variable or function from C I have to name it in assembly starting with an underscore and drop it in the C code.

groufosse wrote on Tuesday, June 03, 2014:

Thanks for the help. Richard, your suggestion worked and it now compiles and links correctly.

Now a further question regarding systick. In my code, I had a basic ADC configuration in a loop reading an input, which was working OK.

Now, I’ve added in (under IAR) the FreeRTOS 8 folder and all required files, and it builds OK. I still have the same main.c file, of which I’ve included:

#include “FreeRTOS.h”
#include “task.h”
#include “semphr.h”

But I have NOT actually added any FreeRTOS tasks, statements or variables. However, it appears the basic ADC operation is no longer working correctly. I had a simple for loop running the ADC 50 times in the call “HAL_ADC_PollForConversion”, which was previously working fine. Now, it now runs exactly 3 times and then freezes (I havea printf stament in the loop). I don’t want to yet add a task or start the scheduler until I understand what is now happening.

Any suggestions as to what has happened, and why the ADC is behaving this way, especially without any FreeRTOS operating code yet added?

Thanks again for any assistance.

groufosse wrote on Tuesday, June 03, 2014:

Hi all,

I’ve figured out where the problem is…there isn’t. It’s now working OK.
For whatever reason (maybe someone can explain why) that, until I placed the reading of the adc withing a task and launched the scheduler, it doesn’t operate correctly. I suspect this has something to do with systick?


rtel wrote on Tuesday, June 03, 2014:

Glad its working for you.

I don’t know why you would get the issue you described, but here are some possibilities:

  • Your printf function is using semi-hosting, which uses the SVC function, but now you have a FreeRTOS handler on that function.

  • You conversion routine was somehow using SysTick for delays between polling, but SysTick is now hooked into something else.


groufosse wrote on Tuesday, June 03, 2014:

Thanks again for the advice and prompt replies !!!