Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

problems porting FreeRTOS on AVR atmega328p

Posted by glb on October 21, 2009
I'M trying to get my first run with FreeRTOS on AVR chips.
I have an atmega328p, which is very similar to atmega323. I'm testing on the stk500v2 board.
According to the documentation, I'm making small changes in port.c, resume with a diff :
`diff ./Source/portable/GCC/ATMega323/port.c ...
416c416
< ucLowByte = TIMSK;
> ucLowByte = TIMSK1;
418c418
< TIMSK = ucLowByte;
> TIMSK1 = ucLowByte;`
I see some errors in the test code due to serial port differences, so I change some ref :
`103c103
< ucByte = UCSRB;
> ucByte = UCSR0B;
105c105
< UCSRB = ucByte;
> UCSR0B = ucByte;
113c113
< ucInByte = UCSRB;
> ucInByte = UCSR0B;
115c115
< UCSRB = ucInByte;
> UCSR0B = ucInByte;
136c136
< UBRRL = ucByte;
> UBRR0L = ucByte;
140c140
< UBRRH = ucByte;
> UBRR0H = ucByte;
144c144
< UCSRB = ( serRX_INT_ENABLE | serRX_ENABLE | serTX_ENABLE );
> UCSR0B = ( serRX_INT_ENABLE | serRX_ENABLE | serTX_ENABLE );
147c147
< UCSRC = ( serUCSRC_SELECT | serEIGHT_DATA_BITS );
> UCSR0C = ( serUCSRC_SELECT | serEIGHT_DATA_BITS );
206c206
< ucByte = UCSRB;
> ucByte = UCSR0B;
208c208
< UCSRB = ucByte;
> UCSR0B = ucByte;
222c222
< cChar = UDR;
> cChar = UDR0;
240c240
< UDR = cChar;
> UDR0 = cChar;`
After that, I can compile the demo :
`Size after:
rtosdemo.elf :
section size addr
.data 80 8388864
.text 9880 0
.bss 1665 8388944
.stab 32016 0
.stabstr 15741 0
Total 59382
Errors: none
-------- end --------`
But after uploading the code, It doesn't work... no led flashing or signal on serial port.
Does anyone experiencing such problem? I don't see what other difference between m323/3328 I have to code.

RE: problems porting FreeRTOS on AVR atmega328p

Posted by glb on October 21, 2009
oups... sorry for the "code" section

RE: problems porting FreeRTOS on AVR atmega328p

Posted by MEdwards on October 22, 2009
I cannot read the posted code, but can you say some more about what happens when you try running the application? How far does the code get?

RE: problems porting FreeRTOS on AVR atmega328p

Posted by glb on October 22, 2009
Here is the FreeRTOS/Source/portable/GCC/ATMega323/port.c diff
416c416
< ucLowByte = TIMSK;
---
> ucLowByte = TIMSK1;
418c418
< TIMSK = ucLowByte;
---
> TIMSK1 = ucLowByte;

RE: problems porting FreeRTOS on AVR atmega328p

Posted by glb on October 22, 2009
FreeRTOS/Source/portable/GCC/ATMega323/port.c
416c416
&lt; ucLowByte = TIMSK;
---
$gt; ucLowByte = TIMSK1;
418c418
&lt; TIMSK = ucLowByte;
---
&gt; TIMSK1 = ucLowByte;

RE: problems porting FreeRTOS on AVR atmega328p

Posted by glb on October 22, 2009
`
FreeRTOS/Source/portable/GCC/ATMega323/port.c
416c416
< ucLowByte = TIMSK;
---
> ucLowByte = TIMSK1;
418c418
< TIMSK = ucLowByte;
---
> TIMSK1 = ucLowByte;
`

RE: problems porting FreeRTOS on AVR atmega328p

Posted by glb on October 22, 2009
FreeRTOS/Source/portable/GCC/ATMega323/port.c :
416c416
< ucLowByte = TIMSK;
> ucLowByte = TIMSK1;
418c418
< TIMSK = ucLowByte;
> TIMSK1 = ucLowByte;

RE: problems porting FreeRTOS on AVR atmega328p

Posted by glb on October 22, 2009
Sorry for the post I'm not good with the post language.

At the end, the port.c and serial.c mod to compile the demo for atmega328.
When I re-start after program the chip, nothing is happend, no led flashing, no data on serial spare port...

FreeRTOS/Source/portable/GCC/ATMega323/port.c :
416c416
< ucLowByte = TIMSK;
> ucLowByte = TIMSK1;
418c418
< TIMSK = ucLowByte;
> TIMSK1 = ucLowByte;

FreeRTOS/Demo/AVR_ATMega323_WinAVR/serial/serial.c :
103c103
< ucByte = UCSRB;
> ucByte = UCSR0B;
105c105
< UCSRB = ucByte;
> UCSR0B = ucByte;
113c113
< ucInByte = UCSRB;
> ucInByte = UCSR0B;
115c115
< UCSRB = ucInByte;
> UCSR0B = ucInByte;
136c136
< UBRRL = ucByte;
> UBRR0L = ucByte;
140c140
< UBRRH = ucByte;
> UBRR0H = ucByte;
144c144
< UCSRB = ( serRX_INT_ENABLE | serRX_ENABLE | serTX_ENABLE );
> UCSR0B = ( serRX_INT_ENABLE | serRX_ENABLE | serTX_ENABLE );
147c147
< UCSRC = ( serUCSRC_SELECT | serEIGHT_DATA_BITS );
> UCSR0C = ( serUCSRC_SELECT | serEIGHT_DATA_BITS );
206c206
< ucByte = UCSRB;
> ucByte = UCSR0B;
208c208
< UCSRB = ucByte;
> UCSR0B = ucByte;
222c222
< cChar = UDR;
> cChar = UDR0;
240c240
< UDR = cChar;
> UDR0 = cChar;

RE: problems porting FreeRTOS on AVR atmega328p

Posted by glb on October 22, 2009
Sorry for the post I'm not good with the post language.

At the end, the port.c and serial.c mod to compile the demo for atmega328.
When I re-start after program the chip, nothing is happend, no led flashing, no data on serial spare port...

FreeRTOS/Source/portable/GCC/ATMega323/port.c :
416c416
< ucLowByte = TIMSK;
> ucLowByte = TIMSK1;
418c418
< TIMSK = ucLowByte;
> TIMSK1 = ucLowByte;

FreeRTOS/Demo/AVR_ATMega323_WinAVR/serial/serial.c :
103c103
< ucByte = UCSRB;
> ucByte = UCSR0B;
105c105
< UCSRB = ucByte;
> UCSR0B = ucByte;
113c113
< ucInByte = UCSRB;
> ucInByte = UCSR0B;
115c115
< UCSRB = ucInByte;
> UCSR0B = ucInByte;
136c136
< UBRRL = ucByte;
> UBRR0L = ucByte;
140c140
< UBRRH = ucByte;
> UBRR0H = ucByte;
144c144
< UCSRB = ( serRX_INT_ENABLE | serRX_ENABLE | serTX_ENABLE );
> UCSR0B = ( serRX_INT_ENABLE | serRX_ENABLE | serTX_ENABLE );
147c147
< UCSRC = ( serUCSRC_SELECT | serEIGHT_DATA_BITS );
> UCSR0C = ( serUCSRC_SELECT | serEIGHT_DATA_BITS );
206c206
< ucByte = UCSRB;
> ucByte = UCSR0B;
208c208
< UCSRB = ucByte;
> UCSR0B = ucByte;
222c222
< cChar = UDR;
> cChar = UDR0;
240c240
< UDR = cChar;
> UDR0 = cChar;


RE: problems porting FreeRTOS on AVR atmega328p

Posted by glb on October 22, 2009
I just try with an another AVR, atmega32. I just change the makefile parameters, and it works (3 blinking leds + 2 serial port transmission leds) ! So I can exclude a problem on the stk500 and harware config.

I recheck the atmega328 spec, but I don't fine where the problem come from.

RE: problems porting FreeRTOS on AVR atmega328p

Posted by kd5uwl on October 24, 2009
Did you check these items at the top of port.c:

/* Hardware constants for timer 1. */
#define portCLEAR_COUNTER_ON_MATCH ( ( unsigned portCHAR ) 0x08 )
#define portPRESCALE_64 ( ( unsigned portCHAR ) 0x03 )
#define portCLOCK_PRESCALER ( ( unsigned portLONG ) 64 )
#define portCOMPARE_MATCH_A_INTERRUPT_ENABLE ( ( unsigned portCHAR ) 0x02 )

These are what worked on my 1284p. Point is, you may need to check these. I don't know that this is right, just something else to check.

kd5uwl

RE: problems porting FreeRTOS on AVR atmega328p

Posted by glb on October 25, 2009
That's right, the interrupt comparator enable bit is not the same. And the interrupt vector name is not same. The final "port.c" is here. There is also problems with the serial port, but with the relevant tasks commented in main.c, it works.

diff -r FreeRTOS/Source/portable/GCC/ATMega323/port.c ...
80c80
< #define portCOMPARE_MATCH_A_INTERRUPT_ENABLE( ( unsigned char ) 0x10 )
> #define portCOMPARE_MATCH_A_INTERRUPT_ENABLE( ( unsigned char ) 0x02 )
416c416
< ucLowByte = TIMSK;
> ucLowByte = TIMSK1;
418c418
< TIMSK = ucLowByte;
> TIMSK1 = ucLowByte;
429,430c429,430
< void SIG_OUTPUT_COMPARE1A( void ) __attribute__ ( ( signal, naked ) );
< void SIG_OUTPUT_COMPARE1A( void )
> void TIMER1_COMPA_vect( void ) __attribute__ ( ( signal, naked ) );
> void TIMER1_COMPA_vect( void )


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner