cancel
Showing results for 
Search instead for 
Did you mean: 

where can i put the common code

x_
Associate II
Posted on December 02, 2004 at 22:14

where can i put the common code

6 REPLIES 6
x_
Associate II
Posted on May 17, 2011 at 12:03

hello:

we're doing a redesign of an existing environment and are planning to make full use of the uPSD3234 memory system. But I got problems with implementing the mem.map.

We have a IAP to load main application, which should use the address 0--3fff of code memory, and the rs0 and csiop needs 200--3ff && 2000--3fff of data space. So where to put my common code of the banked program? Shouldn't it put at the address of 0--7fff? But the space is already used by IAP or rs0&&csiop? Is that all right?

jdaniel
Associate II
Posted on May 17, 2011 at 12:03

sunvin,

The easiest way to do this would be to map secondary flash into the lower memory space (say 0-7FFF) and then have main flash banked in the upper 32kB. All your common code (including the routines for whatever IAP you need to perform) would go in the lower 32kB, and the banked and updatable stuff would go in the upper 32kB.

x_
Associate II
Posted on May 17, 2011 at 12:04

Hi, phase426,

Here is the memory map we would use:

1. memory map at boot-up

Program Space:

0000-1FFF bootloader program which could update main program, Part1

2000-3FFF bootloader program which could update main program, Part2

4000-7FFF nothing

Data Space:

0000--3FFF Regs/RAM,csiop, PSD SRAM and so on, all pages

4000--7FFF nothing

8000--FFFF main program code, part0--part7 to page0--page7 respectively

2. main program code changes from data space to program space

Program Space:

0000-1FFF bootloader program which could update main program, Part1

2000-3FFF bootloader program which could update main program, Part2

4000-7FFF nothing

8000--FFFF main program code, part0--part7 to page0--page7 respectively

Data Space:

0000--3FFF Regs/RAM,csiop, PSD SRAM and so on, all pages

4000--7FFF nothing

3. main program begins to execute, main program replaces bootloader

Program Space:

0000-7FFF main program part0, which should load main program, failed here

page0 8000-9FFF bootloader program which could update main program, Part1

page0 A000-BFFF bootloader program which could update main program, Part2

page0 4000-7FFF nothing

8000-FFFF main program code, part1--part7 to page1--page7 respectively

Data Space:

0000--3FFF Regs/RAM,csiop, PSD SRAM and so on, all pages

4000--7FFF nothing

In the former program, we are not using the code bank. We use a fixed address to restart the main program when we change the PAGE register to make the bootloader changing to main program. But this time, when we use the code bank, we can't relocate the main program properly. After change the PAGE register value, the program fly away! Where has him gone, flying with beauty angel?

Thank you.

x_
Associate II
Posted on May 17, 2011 at 12:04

We find it hard to relocate main application, that means the right page is selected but not reset as we respected.

We use the code: ((void (code *)(void))0x0)();

and locate both at IAP and main application at the fixed same address

jdaniel
Associate II
Posted on May 17, 2011 at 12:04

Sunvin,

I struggled with trying to do this for a while, but here's what I do in my code.

The file STARTUP.A51 (and specifically the routine C_C51STARTUP) is located to the exact same address in both main flash and secondary flash. Also, the code in both areas is IDENTICAL. On startup, I check for a code in ram. If it's present, then I stay on the secondary flash page and run my IAP routines. If it's NOT present, then I check a special status bit in the flash to see if the application there is marked as ''good.'' If it is, I modify the VM and page register and ''jump'' to that page. (This moves my main flash from 8000 to 0000 just like you're doing). From there, code execution continues and the main program is executed.

The big trick is that this startup function must be exactly identical up to the point where the page swap happens. It's hard to describe in detail, but hopefully you'll get the general idea.

Also note that using this method caused me to have to have two entirely separate projects and applications in Keil C and load them into the separate memory spaces.

x_
Associate II
Posted on May 17, 2011 at 12:04

Hi, phase426:

We are requiring two entirely separate projects definitely. Perhaps we should use STARTUP.A51 to located program start address instead of the method i described above. Thanks a lot. I think i can solve the problem for you having done it with code banks. Thank you again.