ATmega168

Hello! I adapted demo for ATmega168, changing in "static void prvSetupTimerInterrupt( void )" at file "port.c", the "TIMSK" for "TIMSK1". It build and work, however I want to start a new program and I can’t leave file "serial/serial.c" to build, because if I don’t build it, I get following the error: Linking: main.elf avr-gcc -mmcu=atmega168 -I. -D GCC_MEGA_AVR -I. -I../../Source/include -I../Comm on/include -g -Os -fsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wextra -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wsign- compare -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wmissing-de clarations -Wunused -Wa,-adhlns=main.o  -std=gnu99 main.o ParTest/ParTest.o   — output main.elf -Wl,-Map=main.map,–cref -lm main.o: In function `main’: C:UsersjpintoDocuments1_projectos90-auto_formacaoFreeRTOSV4.6.1DemoAVR_ ATmega168_GCC-AVR/main.c:40: undefined reference to `xTaskCreate’ C:UsersjpintoDocuments1_projectos90-auto_formacaoFreeRTOSV4.6.1DemoAVR_ ATmega168_GCC-AVR/main.c:42: undefined reference to `vTaskStartScheduler’ main.o: In function `vFlashLED’: C:UsersjpintoDocuments1_projectos90-auto_formacaoFreeRTOSV4.6.1DemoAVR_ ATmega168_GCC-AVR/main.c:76: undefined reference to `xTaskGetTickCount’ C:UsersjpintoDocuments1_projectos90-auto_formacaoFreeRTOSV4.6.1DemoAVR_ ATmega168_GCC-AVR/main.c:77: undefined reference to `vTaskDelayUntil’ C:UsersjpintoDocuments1_projectos90-auto_formacaoFreeRTOSV4.6.1DemoAVR_ ATmega168_GCC-AVR/main.c:84: undefined reference to `xTaskGetTickCount’ C:UsersjpintoDocuments1_projectos90-auto_formacaoFreeRTOSV4.6.1DemoAVR_ ATmega168_GCC-AVR/main.c:85: undefined reference to `vTaskDelayUntil’ ParTest/ParTest.o: In function `vParTestToggleLED’: ParTest/ParTest.c:110: undefined reference to `vTaskSuspendAll’ ParTest/ParTest.c:123: undefined reference to `xTaskResumeAll’ ParTest/ParTest.o: In function `vParTestSetLED’: ParTest/ParTest.c:84: undefined reference to `vTaskSuspendAll’ ParTest/ParTest.c:98: undefined reference to `xTaskResumeAll’ make: *** [main.elf] Error 1 I want to convince my chief that FreeRTOS is good for our projects, first I must show him a LED toggle and the size of program code and data code. Thank you. JP Casainho from Portugal – www.Casainho.net

ATmega168

My "main.c" file: #include <stdlib.h> #include <avr/wdt.h> #ifdef GCC_MEGA_AVR     /* EEPROM routines used only with the WinAVR compiler. */     #include <avr/eeprom.h> #endif /* Scheduler include files. */ #include "FreeRTOS.h" #include "task.h" #include "croutine.h" #include "queue.h" /* Priority definitions for the tasks. */ #define mainFlashLED_TASK_PRIORITY            ( tskIDLE_PRIORITY + 1 ) /* * The tasks functions. */ static void vFlashLED( void *pvParameters ); /* * The idle hook is used to scheduler co-routines. */ void vApplicationIdleHook( void ); /*———————————————————–*/ portSHORT main( void ) {     DDRB = 0b00000001;        DDRC = 0b00000001;        /* Create the tasks. */     xTaskCreate(vFlashLED, "LED", configMINIMAL_STACK_SIZE, NULL, mainFlashLED_TASK_PRIORITY, NULL);     vTaskStartScheduler();     return 0; } /*———————————————————–*/ void vApplicationIdleHook( void ) {     wdt_reset(); } static void vFlashLED( void *pvParameters ) { /* The parameters are not used. */ ( void ) pvParameters; portTickType xLastWakeTime; const portTickType xFreq_ligado = 100; const portTickType xFreq_desligado = 400;     /* Cycle for ever. */     for( ;; )     {         // Initialise the xLastWakeTime variable with the current time.         xLastWakeTime = xTaskGetTickCount();         vTaskDelayUntil( &xLastWakeTime, xFreq_desligado );         PORTB |= (1<<0);         PORTC |= (1<<0);         // Initialise the xLastWakeTime variable with the current time.         xLastWakeTime = xTaskGetTickCount();         vTaskDelayUntil( &xLastWakeTime, xFreq_ligado );         PORTB &= ~(1<<0);         PORTC &= ~(1<<0);     } }

ATmega168

The errors listed here make it look like you have removed task.c from your makefile.  task.c is one of the core components and must be included. I would suggest the following approach to converting the existing demo to your hardware. 1) Modify partest.c so that it accesses the correct port pins to flash LED’s on whichever hardware you are using. 2) Modify the prvSetupTimerInterrupt to install a timer that does nothing but flash an LED so you can guarantee that your timer configuration is working.  You don’t want any enter/exit critical calls in partest if you call the partest functions from the timer interrupt.  This stage is done before making any use of FreeRTOS.org, so is to be done in a simple ‘hello world’ type project. 3) Once you have the LEDs and timer interrupt working you can start with FreeRTOS.org.  In the standard demo, main.c, comment out the creation of all tasks so that only the hardware setup and starting of the scheduler remain within main(). void main( void ) { ____vParTestInitialise(); ____vTaskStartScheduler(); } 4) Create a task as follows: void vFlashTest( void *pvParameters ) { ____for(;;) ____{ ________vTaskDelay( 500 ); ________vParTestToggleLED( 0 ); ____} } This will toggle LED 0 every 500 ticks. 5) Add the following line to main(), just before the scheduler starts. xTaskCreate( vFlashTest, "f", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL ); You should then have the simplest program that creates a single task, with the single task simply flashing an LED.  Take a look at FreeRTOS/Demo/Common/Minimal/Flash.c for an example of how to pass the LED number into the task using the task function parameter, then you can create more than one task from the same code. Regards.

ATmega168

Thanks for your suggestions. I can build with success if I uncomment "serial.c" on "makefile" however the final code is this: Size after: main.elf  : section            size      addr .data                74   8388864 .text              9410         0 .bss               1667   8388938 .stab               888         0 .stabstr            113         0 .debug_aranges      448         0 .debug_pubnames    1838         0 .debug_info       10299         0 .debug_abbrev      3552         0 .debug_line       13334         0 .debug_frame       1536         0 .debug_str         4743         0 .debug_loc         5406         0 .debug_ranges        24         0 Total             53332 Errors: none -——- end ——– 9410 bytes of program memory? is to much? I think so and that is because I am build unnecessary files, right? – and it flashes the LED ok, at the right times, I saw on oscilloscope :-) If I "make clean" and after "make", the result is this one – without "serial.c": C:UsersjpintoDocuments1_projectos90-auto_formacaoFreeRTOSV4.6.1DemoAVR_ ATmega168_GCC-AVR>make set -e; avr-gcc -MM -mmcu=atmega168 -I. -D GCC_MEGA_AVR -I. -I../../Source/inclu de -I../Common/include -g -Os -fsigned-char -funsigned-bitfields -fpack-struct – fshort-enums -Wall -Wextra -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-a lign -Wsign-compare -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wunused -Wa,-adhlns=ParTest/ParTest.lst  -std=gnu99 ParT est/ParTest.c         | sed ‘s,\(.*\)\.o[ :]*,1.o 1.d : ,g’ > ParTest/ParTest.d;         [ -s ParTest/ParTest.d ] || rm -f ParTest/ParTest.d set -e; avr-gcc -MM -mmcu=atmega168 -I. -D GCC_MEGA_AVR -I. -I../../Source/inclu de -I../Common/include -g -Os -fsigned-char -funsigned-bitfields -fpack-struct – fshort-enums -Wall -Wextra -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-a lign -Wsign-compare -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wunused -Wa,-adhlns=main.lst  -std=gnu99 main.c         | sed ‘s,\(.*\)\.o[ :]*,1.o 1.d : ,g’ > main.d;         [ -s main.d ] || rm -f main.d -——- begin ——– avr-gcc (GCC) 4.1.2 (WinAVR 20070525) Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions.  There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Compiling: main.c avr-gcc -c -mmcu=atmega168 -I. -D GCC_MEGA_AVR -I. -I../../Source/include -I../C ommon/include -g -Os -fsigned-char -funsigned-bitfields -fpack-struct -fshort-en ums -Wall -Wextra -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wsi gn-compare -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wmissing -declarations -Wunused -Wa,-adhlns=main.lst  -std=gnu99 main.c -o main.o main.c: In function ‘main’: main.c:40: warning: pointer targets in passing argument 2 of ‘xTaskCreate’ diffe r in signedness Compiling: ParTest/ParTest.c avr-gcc -c -mmcu=atmega168 -I. -D GCC_MEGA_AVR -I. -I../../Source/include -I../C ommon/include -g -Os -fsigned-char -funsigned-bitfields -fpack-struct -fshort-en ums -Wall -Wextra -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wsi gn-compare -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wmissing -declarations -Wunused -Wa,-adhlns=ParTest/ParTest.lst  -std=gnu99 ParTest/ParTe st.c -o ParTest/ParTest.o Linking: main.elf avr-gcc -mmcu=atmega168 -I. -D GCC_MEGA_AVR -I. -I../../Source/include -I../Comm on/include -g -Os -fsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wextra -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wsign- compare -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wmissing-de clarations -Wunused -Wa,-adhlns=main.o  -std=gnu99 main.o ParTest/ParTest.o   — output main.elf -Wl,-Map=main.map,–cref -lm main.o: In function `main’: C:UsersjpintoDocuments1_projectos90-auto_formacaoFreeRTOSV4.6.1DemoAVR_ ATmega168_GCC-AVR/main.c:40: undefined reference to `xTaskCreate’ C:UsersjpintoDocuments1_projectos90-auto_formacaoFreeRTOSV4.6.1DemoAVR_ ATmega168_GCC-AVR/main.c:42: undefined reference to `vTaskStartScheduler’ main.o: In function `vFlashLED’: C:UsersjpintoDocuments1_projectos90-auto_formacaoFreeRTOSV4.6.1DemoAVR_ ATmega168_GCC-AVR/main.c:76: undefined reference to `xTaskGetTickCount’ C:UsersjpintoDocuments1_projectos90-auto_formacaoFreeRTOSV4.6.1DemoAVR_ ATmega168_GCC-AVR/main.c:77: undefined reference to `vTaskDelayUntil’ C:UsersjpintoDocuments1_projectos90-auto_formacaoFreeRTOSV4.6.1DemoAVR_ ATmega168_GCC-AVR/main.c:84: undefined reference to `xTaskGetTickCount’ C:UsersjpintoDocuments1_projectos90-auto_formacaoFreeRTOSV4.6.1DemoAVR_ ATmega168_GCC-AVR/main.c:85: undefined reference to `vTaskDelayUntil’ ParTest/ParTest.o: In function `vParTestToggleLED’: ParTest/ParTest.c:110: undefined reference to `vTaskSuspendAll’ ParTest/ParTest.c:123: undefined reference to `xTaskResumeAll’ ParTest/ParTest.o: In function `vParTestSetLED’: ParTest/ParTest.c:84: undefined reference to `vTaskSuspendAll’ ParTest/ParTest.c:98: undefined reference to `xTaskResumeAll’ make: *** [main.elf] Error 1 C:UsersjpintoDocuments1_projectos90-auto_formacaoFreeRTOSV4.6.1DemoAVR_ ATmega168_GCC-AVR> And here is a portion of "makefile", showing "task.c": # List C source files here. (C dependencies are automatically generated.) DEMO_DIR = ../Common/Minimal SOURCE_DIR = ../../Source PORT_DIR = ../../Source/portable/GCC/ATMega168 SRC    = main.c ParTest/ParTest.c #serial/serial.c regtest.c $(SOURCE_DIR)/tasks.c $(SOURCE_DIR)/queue.c $(SOURCE_DIR)/list.c $(SOURCE_DIR)/croutine.c $(SOURCE_DIR)/portable/MemMang/heap_1.c $(PORT_DIR)/port.c $(DEMO_DIR)/crflash.c $(DEMO_DIR)/integer.c $(DEMO_DIR)/PollQ.c $(DEMO_DIR)/comtest.c Can you help? I would suggest a wiki style system and a forum for FreeRTOS – people could share this adaptations from microcontroler to microcontroler. Thank you.

ATmega168

RC = main.c ParTest/ParTest.c #serial/serial.c   <<<<<<< BAD regtest.c $(SOURCE_DIR)/tasks.c $(SOURCE_DIR)/queue.c etc. you can not do it this way.  Delete the whole line RC = main.c ParTest/ParTest.c regtest.c $(SOURCE_DIR)/tasks.c $(SOURCE_DIR)/queue.c etc.

ATmega168

In your makefile, you have commented out a line in the middle of the list of files to build.  The files after the comment line will probably not be included in the build.  This can be seen from your compiler output.  I think this is the problem. You can removed all the $(DEMO_DIR) files provided you do not create of check the demos within main.c. Regards.

ATmega168

Size after: main.elf  : section            size      addr .data                10   8388864 .text              3360         0 .bss               1585   8388874 .stab               888         0 .stabstr            113         0 .debug_aranges      160         0 .debug_pubnames     776         0 .debug_info        4055         0 .debug_abbrev      1421         0 .debug_line        4359         0 .debug_frame        624         0 .debug_str         2133         0 .debug_loc         1869         0 .debug_ranges        24         0 Total             21377 Errors: none -——- end ——– # List C source files here. (C dependencies are automatically generated.) DEMO_DIR = ../Common/Minimal SOURCE_DIR = ../../Source PORT_DIR = ../../Source/portable/GCC/ATMega168 SRC    = main.c $(SOURCE_DIR)/tasks.c $(SOURCE_DIR)/list.c $(SOURCE_DIR)/portable/MemMang/heap_1.c $(PORT_DIR)/port.c Is the 3360 bytes of program memory ok, for this "main.c" file – optimization OPT = s? – I think is a lot, just for this function of toggle LEDs.. however I don’t have experience with RTOS systems… – I would apreciate your opinion about this size of program memorie since I know that will be important for decide to use this RTOS or not. Thank you.

ATmega168

The size seems about as expected.  You might be able to trim some off by setting some of the values in FreeRTOSConfig.h to 0 to exclude certain API functions. Regards.

ATmega168

Thank you. I already managed "FreeRTOSConfig.h" :-) My chief says that is ok the size and that overhead could be ok for some of ours applications :-) See you and continue your good work :-) :-)