Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

reallocate main program

Posted by jonathan on April 1, 2009
Hi all,

We use Freertos on an ARM7 (SAM7S from ATMEL) and we have somting that work pretty well. First we have developped an bootloader. try some in house code on the sam7s and all works fine. But if I try to use the sample from freertos, the program hangs when it's not located to 0 in flash. IF I test the program and place it to address 0, everythings work. If I put an offset in the linker file, The program start but as soon as the task is started, the program hang and the Watchdog reset the CPU.

I have use the sample sam7x sample file for GCC.

Does anyone here have try to offset an Freertos project ? We have us ucos/II in the past without any problem . I have some problem finding what cause this kind of things.

regards

jonathan

RE: reallocate main program

Posted by Adam Turowski on April 2, 2009
The beginning of ARM memory is occupied by reset/exceptions vectors. They have to be always there because CPU is forced to executes the code from there when reset/exception occurs. Please check first if these vectors placed at 0x00000 address after you have made your offset.

Best regards,
Adam

RE: reallocate main program

Posted by jonathan on April 2, 2009
HI,

This is what i conclude. The SWI handler is the problem I think. I need to be able to put this in RAM. When we use ucos/II, we don't have this problem because they don't use this SWI interrupt.

Now we try to figure out how to get the SWI handler remaped to RAM.

If someone have done this and would liek to share their startup asm file, ld + makefile, I'll appreciate.

Jonathan

RE: reallocate main program

Posted by Adam Turowski on April 2, 2009
I am using this kind of assembly file:

/*==============================================*/
/* exceptions and interrupt vectors table setup */
/*==============================================*/
.section .startup,"ax"
.arm
.align 0

b start /* jump from here just after reset */
b vUndefinedInstructionException
b vPortYieldProcessor /* used for manual calling SWI instruction to call the scheduler and task yielding */
b vPrefetchAbortException
b vDataAbortException
b vReservedException
ldr pc,[pc, # -0xF20] /* jump to the interrupt exception handler address given in AIC register*/
b vFiqException

This is setting up exception/reset vector table in section called ".startup". In linker script I simply put this section where it belongs:

MEMORY
{
FLASH : ORIGIN = 0x0, LENGTH = 256K
RAM : ORIGIN = 0x200000, LENGTH = 64K /* length of RAM */
}

__ram_end__ = RAM_ORIGIN + RAM_SIZE;

SECTIONS
{
/* setup TEXT section */
. = 0;
__text_beg__ = .;
startup :
{
*(.startup)
} > FLASH

Of course you can hardcode this section origin address in assembly, but I prefer to have that control in linker file.

Hope that helps.

Regards,
Adam

RE: reallocate main program

Posted by jonathan on April 2, 2009
HI Adam,

This is very interesting.

With this setup, you can have your vector in flash, but the vector a realocated in the linker script ? I see that in you ld script, you have you startup section to addr 0, but if I change the FLASH ORIGIN to 0x1780 for exemple, the startup section will be place at 0x1780 ?

am I wrong ?


Jonathan

RE: reallocate main program

Posted by Adam Turowski on April 2, 2009
Yes, if you change FLASH origin, the section .startup address will change accordingly. Please enable and check your *.map file generated during linking stage for all needed information.

RE: reallocate main program

Posted by incrediball on April 7, 2009
The problem with a bootloader is that it defines the default vector table and you would need to get the bootloader interrupt handling to relay all the interrupts through to the main program. This is messy, may not support all of the interrupt types (e.g. SWI in your case) and adds latency to the interrupt handling. To use get around this problem modify your main program so:

1. Define your ROM or FLASH sector at 0x00100000 plus the size of the bootloader sector. For example if you reserve 4K for the bootloader (this corresponds to the first lockable page on the AT91SAM7S64) then define it at 0x00101000.

Note that the flash memory on the AT91SAM7S is really located at 0x00100000 so doing this is not a trick. This memory is only mirrored to 0x00000000 by default.

2. Locate your vector table at 0x00200000, for example:

/* Exception vectors located at 0x00200000. These are re-mapped to 0x00000000 by the re-map command */
/* Note that undf, pabt, dabt just execute a null loop. */

.section.vectors
_vectors:
b./* 0x00 reset - not used since the processor has already reset when it re-maps the memory */
b./* 0x04 undef */
ldrpc, _swi_ram/* 0x08 swi */
b./* 0x0C pabt */
b./* 0x10 dabt */
nop/* 0x14 rsvd */
ldrpc, [pc,#-0xF20]/* 0x18 irq - load PC with the interrupt vector in AT91C_BASE_AIC->AIC_IVR */
ldrpc, [pc,#-0xF20]/* 0x1c fiq - load PC with the interrupt vector in AT91C_BASE_AIC->AIC_FVR */
_swi_ram:.word vPortYieldProcessor


You will need to modify your linker script to tell the linker to put the vectors section first in the RAM.

3. Perform a remap command as soon as the main program starts up. This mirrors the vector table defined at 0x00200000 to 0x00000000 thus replacing the vector table defined by the bootloader.


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




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists