메인 콘텐츠로 건너뛰기
Knowledgebase
Home
Renesas Korea

(E8a) How to assign variables to internal/external expansion or buffer RAM?

Latest Updated:04/01/2006

Question:

Please tell me how I can assign variables to internal expansion RAM or buffer RAM.
Also, I would like to know how to assign them to external expansion ROM or RAM.

Answer:

Each device includes multiple memory areas, some of which are used for specific purposes such as internal expansion RAM or buffer RAM. Both ROM and RAM can also be expanded externally.
When using a C compiler to create a program, certain variables and code are sometimes assigned to some of these memory areas.

In such cases, the following steps can be used to assign variables or code to memory.
Basically, there are only two steps:

  1. Enter a #pragma section directive before the declaration of the variable or code in order to change the section name of the variable or code to be assigned.
    When assigning to several segments, enter a #pragma section directive for each segment name before declaring the variable.
  2. Use a link directive to link the segments described above to specific addresses.


Two examples are described below.


Example 1: Assigning variables to the uPD780058Y's internal RAM areas

In this example, the following variables and segment names are assumed as those to be assigned to different types of memory.

  Memory type                Size        Address       Variable name   Segment name
-----------------------------------------------------------------------------------------
(1) Internal high-speed RAM  1 Kbyte    (FB00 to FE1F)  a, b, c        @@DATA (default)
    saddr area                          (FE20 to FEFF)  x, y, z        @@DATA (default)
(2) Buffer RAM               32 bytes   (FAC0 to FADF)  serbuf[32]     BUFSEG
(3) Internal expansion RAM   1 Kbyte    (F400 to F7FF)  extdbuf[1024]  EXTDSEG 


The ordinary source code includes a definition of the variable to be assigned to internal high-speed RAM. When sreg is declared, it is assigned to the saddr area.

main.c

extern char serbuf[32];
extern char extdbuf[1024];

int a, b, c;
sreg int x, y, z;

void main()
{

} 


In the source code shown below, if #pragma section is not at the start, the CC78K cannot directly output a REL file. Instead, an ASM file is output, and "output assembler source file" is set to ON by the data.c compiler option (-a).

data.c

#pragma section @@DATA BUFSEG
char serbuf[32];

#pragma section @@DATA EXTDSEG
char extdbuf[1024];


Create a link directive.
Specify this link directive by the linker option (-d linkdir.dr). In the Project Manager, this can be specified in the "other" part of the linker option settings.

linkdir.dr

merge   BUFSEG  : =LRAM          (a)
merge   EXTDSEG : =IXRAM         (b)

(a) The BUFSEG segment is assigned to the buffer RAM area. "LRAM" is the name of the memory area defined in buffer RAM (32 bytes).

(b) The EXTDSEG segment is assigned to the internal expansion RAM area.
"IXRAM" is the name of the memory area defined in the internal expansion RAM area (1 Kbyte).

For further description of these defined memory area names, see the device file documentation.
This description is found under "default link directive information."
If you cannot find this description, see "MEMORY = XXX" in the description of link map files.

Since variables a, b, c, x, y, and z are assigned to the default area, they do not have to be specified.

Examine the link map file in the build results to confirm whether or not variables have been assigned to memory as intended.
(Specify "ON" for "Output public symbol list" by setting the linker option (-kp).)

s0l.map

*** Public symbol list ***

MODULE    ATTR       VALUE    NAME
(Other symbols are omitted)
main      ADDR       FB78H    _a
main      ADDR       FB7AH    _b
main      ADDR       FB7CH    _c

main      ADDR       FE20H    _x
main      ADDR       FE22H    _y
main      ADDR       FE24H    _z

data2     ADDR       F400H    _extdbuf
data1     ADDR       FAC0H    _serbuf 

 


Example 2: Connecting external ROM or RAM to the uPD780056Y and assigning code and variables.

The memory types and the variables, codes, and segment names assumed to be assigned to memory are listed below. Hexadecimal files are output separately to internal ROM and external ROM.

  Memory type          Size       Address      Variable name    Segment name
  -------------------------------------------------------------------------------
  (1)Internal ROM     48 Kbytes (0000 to BFFF)   main()         @@CODE
  (2)External ROM      4 Kbytes (C000 to CFFF)   sub()          GROMSEG
  (3)External RAM      1 Kbyte  (D000 to D3FF)   gaibubuf[1024] GRAMSEG 


Variables assigned to internal ROM are defined in the ordinary source code.

main.c

void sub();

void main()
{
   sub();
} 


Functions assigned to external ROM are described in source code that starts with a #pragma section.

sub.c

#pragma section @@CODE GROMSEG

extern char gaibubuf[1024];

void  sub()
{
    gaibubuf[1] = 123;
} 


Functions assigned to external RAM are described in source code that starts with a #pragma section.

data.c

#pragma section @@DATA GRAMSEG
char gaibubuf[1024]; 


The next step is to create a link directive.
Specify this link directive via the linker option (-d linkdir.dr).
In the Project Manager, this can be specified in the "other" part of the linker option settings.

linkdir.dr

memory  GAIROM : (0C000H,1000H) /EX1          (a)
memory  GAIRAM : (0D000H,0400H)               (b)

merge   GROMSEG  : =GAIROM /EX1               (c)
merge   GRAMSEG  : =GAIRAM                    (d)
(a) Defines the external ROM area.
The memory area name "GAIROM" is assigned to the external ROM area from 0C000H to 1000H (4 KB).
By defining a memory space as /EX1 separate from internal ROM, separate hexadecimal files can be output.
 
(b) Defines the external RAM area.
The memory area name "GAIRAM" is assigned to the external RAM area from 0D000H to 0400H (1 KB).
 
(c) Assigns the GROMSEG segment to the external ROM space.
Here also, the target memory space is a separate space as /EX1.
 
(d) Assigns the GRAMSEG segment to the external RAM space.
 

A link map file in the build results can be checked to confirm whether or not memory assignments have occurred as intended.
(Specify "ON" for "Output public symbol list" by setting the linker option (-kp).

s0l.map

*** Public symbol list ***

MODULE    ATTR       VALUE    NAME
(Other symbols are omitted)
main      ADDR       0111H    _main
sub       ADDR       C000H    _sub
data      ADDR       D000H    _gaibubuf 


This is a hexadecimal file for the internal ROM. (Start-up routine and main.c)

main.hex

:0200000080007E
:1000800061D0EE1C20FE9AEC001000000354FB032C
:1000900040FB0344FB400342FB1058FB0356FB1696
:1000A00080001478FBC6EA8000AD0687958684FA46
:1000B000F41678FBC6EA78FBAD06A1009786FAF441
:1000C0001680001420FEC6EA8000AD06879586845F
:1000D000FAF41620FEC6EA20FEAD06A1009786FAC5
:1000E000F49A11011000009AED00FAFEAF0240FBF5
:1000F0003061013027D667616EAD129696B7C6CAD9
:1001000000FBD68730AE01B69A0F01FAE9FAFE314C
:010110009856
:040111009A00C0AFE1
:00000001FF 


This is a hexadecimal file for the external ROM. (sub.c)

main.H1

:06C00000A17B9E01D0AF00
:00000001FF 

 

Suitable Products
78K0/Dx
78K0/Fx
78K0/Ix
78K0/Kx
78K0/Lx
UPD78F07xx
UPD7800xx
UPD7802xx
UPD7803xx
UPD7807xx
UPD7808xx
UPD7809xx
UPD780xx
UPD78F8025
78K0/VAN ASCP