Compiling FreeRTOS 9.0.0 for Atmel SAMD20

josaed wrote on Friday, June 23, 2017:

Hi,

I have a problem when compiling FreeRTOS for an Atmel SAMD20 microcontroller. I’ve modified the SetupTimerInterrupt with the attribute weak in the port.c file.

static void vPortSetupTimerInterrupt( void );

__attribute__(( weak )) void vPortSetupTimerInterrupt( void )
{
	/* Configure SysTick to interrupt at the requested rate. */
	*(portNVIC_SYSTICK_VAL)  = 0; /* Load the SysTick Counter Value */
	*(portNVIC_SYSTICK_LOAD) = ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL;
	*(portNVIC_SYSTICK_CTRL) = portNVIC_SYSTICK_CLK | portNVIC_SYSTICK_INT | portNVIC_SYSTICK_ENABLE;
}

In other file of my source code I have the actual implementation.

void vPortSetupTimerInterrupt(void)
{
	// Struct for configuring TC
	struct tc_config tcconf;
	// Set up configuration values
	tc_get_config_defaults(&tcconf);
	tcconf.counter_size    = TC_COUNTER_SIZE_32BIT;
	tcconf.run_in_standby  = true;
	tcconf.clock_prescaler = TC_CLOCK_PRESCALER_DIV1;
	tcconf.wave_generation = TC_WAVE_GENERATION_MATCH_FREQ;

	// Initialize the TC
	tc_init(&tc, TICK_TC, &tcconf);

	// Register and enable callback for freeRTOS tick handler
	tc_register_callback(&tc, (tc_callback_t) xPortSysTickHandler, TC_CALLBACK_CC_CHANNEL0);
	tc_enable_callback(&tc, TC_CALLBACK_CC_CHANNEL0);

	// Set top value equal to one os tick
	tc_set_top_value(&tc, TIMER_RELOAD_VALUE_ONE_TICK);

	// Enable the timer
	tc_enable(&tc);
}

The output of the compiler is the following:

		Building file: ../src/ASF/thirdparty/freertos/freertos-9.0.0/Source/portable/GCC/ARM_CM0/port.c
		Invoking: ARM/GNU C Compiler : 6.2.1
		In file included from ../src/ASF/thirdparty/freertos/freertos-9.0.0/Source/include/FreeRTOS.h:98:0,
		                 from ../src/ASF/thirdparty/freertos/freertos-9.0.0/Source/portable/GCC/ARM_CM0/port.c:75:
C:\Users\jose.gonzalez\Desktop\documents\4_Microcontroller\Atmel_workspace\UC_FPGA_board\FreeRTOS_Temp_SM_test\src\config\FreeRTOSConfig.h(120,49): warning: redundant redeclaration of 'PendSV_Handler' [-Wredundant-decls]
		 #define xPortPendSVHandler                      PendSV_Handler
		                                                 ^
C:\Users\jose.gonzalez\Desktop\documents\4_Microcontroller\Atmel_workspace\UC_FPGA_board\FreeRTOS_Temp_SM_test\src\ASF\thirdparty\freertos\freertos-9.0.0\Source\portable\GCC\ARM_CM0\port.c(116,6): info: in expansion of macro 'xPortPendSVHandler'
		 void xPortPendSVHandler( void ) __attribute__ (( naked ));
		      ^```
		In file included from ../src/ASF/sam0/utils/cmsis/samd20/include/samd20.h:76:0,
		                 from ../src/ASF/sam0/utils/header_files/io.h:58,
		                 from ../src/ASF/sam0/utils/compiler.h:65,
		                 from ../src/ASF/sam0/drivers/system/clock/gclk.h:55,
		                 from ../src/config/FreeRTOSConfig.h:52,
		                 from ../src/ASF/thirdparty/freertos/freertos-9.0.0/Source/include/FreeRTOS.h:98,
		                 from ../src/ASF/thirdparty/freertos/freertos-9.0.0/Source/portable/GCC/ARM_CM0/port.c:75:
C:\Users\jose.gonzalez\Desktop\documents\4_Microcontroller\Atmel_workspace\UC_FPGA_board\FreeRTOS_Temp_SM_test\src\ASF\sam0\utils\cmsis\samd20\include\samd20g18.h(184,6): info: previous declaration of 'PendSV_Handler' was here
		 void PendSV_Handler              ( void );
		      ^```
		In file included from ../src/ASF/thirdparty/freertos/freertos-9.0.0/Source/include/FreeRTOS.h:98:0,
		                 from ../src/ASF/thirdparty/freertos/freertos-9.0.0/Source/portable/GCC/ARM_CM0/port.c:75:
C:\Users\jose.gonzalez\Desktop\documents\4_Microcontroller\Atmel_workspace\UC_FPGA_board\FreeRTOS_Temp_SM_test\src\config\FreeRTOSConfig.h(119,49): warning: redundant redeclaration of 'SVC_Handler' [-Wredundant-decls]
		 #define vPortSVCHandler                         SVC_Handler
		                                                 ^
C:\Users\jose.gonzalez\Desktop\documents\4_Microcontroller\Atmel_workspace\UC_FPGA_board\FreeRTOS_Temp_SM_test\src\ASF\thirdparty\freertos\freertos-9.0.0\Source\portable\GCC\ARM_CM0\port.c(118,6): info: in expansion of macro 'vPortSVCHandler'
		 void vPortSVCHandler( void );
		      ^```
		"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-toolchain\bin\arm-none-eabi-gcc.exe"  -x c -mthumb -D__SAMD20G18__ -DDEBUG -DTC_ASYNC=true -D__SAMD20G18__ -DBOARD=USER_BOARD -DARM_MATH_CM0PLUS=true -D__FREERTOS__ -DI2C_MASTER_CALLBACK_MODE=true -DSYSTICK_MODE  -I"../src/ASF/common/boards" -I"../src/ASF/sam0/utils" -I"../src/ASF/sam0/utils/header_files" -I"../src/ASF/sam0/utils/preprocessor" -I"../src/ASF/thirdparty/CMSIS/Include" -I"../src/ASF/thirdparty/CMSIS/Lib/GCC" -I"../src/ASF/common/utils" -I"../src/ASF/sam0/utils/cmsis/samd20/include" -I"../src/ASF/sam0/utils/cmsis/samd20/source" -I"../src/ASF/sam0/drivers/system" -I"../src/ASF/sam0/drivers/system/clock/clock_samd20" -I"../src/ASF/sam0/drivers/system/clock" -I"../src/ASF/sam0/drivers/system/interrupt" -I"../src/ASF/sam0/drivers/system/interrupt/system_interrupt_samd20" -I"../src/ASF/sam0/drivers/system/pinmux" -I"../src/ASF/sam0/drivers/system/power" -I"../src/ASF/sam0/drivers/system/power/power_sam_d_r_h" -I"../src/ASF/sam0/drivers/system/reset" -I"../src/ASF/sam0/drivers/system/reset/reset_sam_d_r_h" -I"../src/ASF/common2/boards/user_board" -I"../src/ASF/thirdparty/freertos/freertos-9.0.0/Source/include" -I"../src/ASF/thirdparty/freertos/freertos-9.0.0/Source/portable/GCC/ARM_CM0" -I"../src" -I"../src/config" -I"../src/ASF/sam0/drivers/sercom" -I"../src/ASF/sam0/drivers/sercom/i2c" -I"../src/ASF/sam0/drivers/sercom/i2c/i2c_samd20" -I"../src/ASF/sam0/drivers/port" -I"../src/ASF/sam0/drivers/tc" -I"../src/ASF/sam0/drivers/tc/tc_sam_d_r_h" -I"../src/AED/APP_tasks" -I"../src/AED/i2c" -I"../src/AED/Callbacks" -I"../src/AED/GPIO" -I"../src/AED/FMC_state_machine" -I"../src/AED/Linked_list"  -O0 -fdata-sections -ffunction-sections -mlong-calls -g3 -Wall -mcpu=cortex-m0plus -c -pipe -fno-strict-aliasing -Wall -Wstrict-prototypes -Wmissing-prototypes -Werror-implicit-function-declaration -Wpointer-arith -std=gnu99 -ffunction-sections -fdata-sections -Wchar-subscripts -Wcomment -Wformat=2 -Wimplicit-int -Wmain -Wparentheses -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs -Wunused -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef -Wshadow -Wbad-function-cast -Wwrite-strings -Wsign-compare -Waggregate-return  -Wmissing-declarations -Wformat -Wmissing-format-attribute -Wno-deprecated-declarations -Wpacked -Wredundant-decls -Wnested-externs -Wlong-long -Wunreachable-code -Wcast-align --param max-inline-insns-single=500 -MD -MP -MF "src/ASF/thirdparty/freertos/freertos-9.0.0/Source/portable/GCC/ARM_CM0/port.d" -MT"src/ASF/thirdparty/freertos/freertos-9.0.0/Source/portable/GCC/ARM_CM0/port.d" -MT"src/ASF/thirdparty/freertos/freertos-9.0.0/Source/portable/GCC/ARM_CM0/port.o"   -o "src/ASF/thirdparty/freertos/freertos-9.0.0/Source/portable/GCC/ARM_CM0/port.o" "../src/ASF/thirdparty/freertos/freertos-9.0.0/Source/portable/GCC/ARM_CM0/port.c" 
C:\Users\jose.gonzalez\Desktop\documents\4_Microcontroller\Atmel_workspace\UC_FPGA_board\FreeRTOS_Temp_SM_test\Debug\Makefile(444,1): error: recipe for target 'src/ASF/thirdparty/freertos/freertos-9.0.0/Source/portable/GCC/ARM_CM0/port.o' failed
		In file included from ../src/ASF/sam0/utils/cmsis/samd20/include/samd20.h:76:0,
		                 from ../src/ASF/sam0/utils/header_files/io.h:58,
		                 from ../src/ASF/sam0/utils/compiler.h:65,
		                 from ../src/ASF/sam0/drivers/system/clock/gclk.h:55,
		                 from ../src/config/FreeRTOSConfig.h:52,
		                 from ../src/ASF/thirdparty/freertos/freertos-9.0.0/Source/include/FreeRTOS.h:98,
		                 from ../src/ASF/thirdparty/freertos/freertos-9.0.0/Source/portable/GCC/ARM_CM0/port.c:75:
C:\Users\jose.gonzalez\Desktop\documents\4_Microcontroller\Atmel_workspace\UC_FPGA_board\FreeRTOS_Temp_SM_test\src\ASF\sam0\utils\cmsis\samd20\include\samd20g18.h(183,6): info: previous declaration of 'SVC_Handler' was here
		 void SVC_Handler                 ( void );
		      ^```
C:\Users\jose.gonzalez\Desktop\documents\4_Microcontroller\Atmel_workspace\UC_FPGA_board\FreeRTOS_Temp_SM_test\src\ASF\thirdparty\freertos\freertos-9.0.0\Source\portable\GCC\ARM_CM0\port.c(371,1): error: in function_and_variable_visibility, at ipa-visibility.c:596
		 }
		 ^
		Please submit a full bug report,
		with preprocessed source if appropriate.
		See <http://gcc.gnu.org/bugs.html> for instructions.
		make: *** [src/ASF/thirdparty/freertos/freertos-9.0.0/Source/portable/GCC/ARM_CM0/port.o] Error 1
		make: *** Waiting for unfinished jobs....

I have other project with FreeRTOS v8.0.1. and it works. Unfortunately I need the new version, Any help would be welcome.

Thanks in advance,
Jose

rtel wrote on Saturday, June 24, 2017:

I can see the compiler seems to crash and think it has a bug, but I
can’t see what the error it is reporting in the source code is (only
warnings).

heinbali01 wrote on Saturday, June 24, 2017:

Just 2 guesses: what does the compiler do when you comment-out the original vPortSetupTimerInterrupt() function?
And what if you leave out -Wredundant-decls ( an option that gave me head-aches ) ?