Skip to main content
Knowledgebase
Home
Renesas Electronics America - Knowledgebase

How can I both the areas of R8C Family MCUs, such as the R8C/2A to 2D?

Latest Updated:10/16/2008

Question:

The RAM area in some R8C Family MCUs, such as the R8C/2A to 2D, is divided into two areas. How can I use both of these areas?

Answer:

M16C Family and R8C Family compilers do not have a function that automatically assigns variables to both RAM areas. In addition, variables cannot be assigned to both RAM areas by changing the startup program. The user must assign the variables to one of the RAM areas by declaring them accordingly in the user source program.

Some R8C family products embed the normal RAM (referred to herein as RAM-A) from address 400h as well as an additional RAM (referred to herein as RAM-B) from address 3000h. When an MCU embeds two discontinuous RAM areas, variables to be assigned to RAM-B must be declared in a new section (memory allocation is done in section units) in the user source program. This newly declared section is assigned to address 3000h.

First, determine which variable will be assigned to which RAM area. Then, change the section name for the variables to be assigned to RAM-B. The section name should be changed using #pragma section in the variable declaration portion of the source program.

The following shows an example in which variables a and d are assigned to RAM-A and variables b and c are assigned to RAM-B. In this example, RAM-A section has default section bss, and RAM-B has section bss2 (arbitrary name). Note how the section for variables b and c are changed to bss2 in the #pragma section below. This example assumes the use of M16C compiler version V.5.43 or later.

Example:

int       a; 		// Variable “a” belongs to section bss_NE
#pragma 	section bss bss2 	// Change default section from bss to bss2
int       b; 		// Variable “b” belongs to section bss2_NE
char     c; 		// Variable “c“ belongs to section bss2_NO
#pragma 	section bss bss 	// Return default to section bss
char     d; 		// Variable “d”belongs to section bss_NO

Please refer to 2.2.3 Customizing for NC30 Memory Mapping in the compiler manual for more details concerning section names

The last bss2 sections (bss2_NE, bss2_NO) declared are assigned to address 3000h. Make these assignments using Method (a) or (b) as follows:

(a) Set bss2 in linker -ORDER option
Assign sections bss2_NE and bss2_NO to address 3000h in the settings in linker -ORDER option.

Example:

-ORDER bss2_NE=03000,bss2_NO


(b) Add bss2 to startup program sect30.inc
Section names can be changed by making corrections to assembler startup program sect30.inc. Add the following five lines to the end of the sect30.inc file (make sure you add them to the immediately before .end which is end of the file.)

Example:

.section bss2_NE,DATA
.org 3000H
bss2_NE_top:
.section bss2_NO,DATA
bss2_NO_top:

You can also zero clear sections bss2_NE and bss2_NO by adding the following process to the startup file.

When using C startup:
Add the following two lines to the initsct.c file to zero clear sections bss2_NE and bss2_NO.

void initsct(void)
{
sclear("bss_SE","data","align");
:
// add new sections
// bss_clear("new section name");
sclear("bss2_NE","data","align");         //     Add
sclear("bss2_NO","data","noalign");     //     Add


When using Assembler startup:
Add the following two lines to the ncrt.a30 file to zero clear sections bss2_NE and bss2_NO. However, make sure you assign sections bss2_NE and bss2_NO using Method (b) above.

;-------------------------------------------------
; bss zero clear
;-------------------------------------------------

N_BZERO 	bss_SE_top,bss_SE
	
N_BZERO 	bss_SO_top,bss_SO
	
N_BZERO 	bss_NE_top,bss_NE
	
N_BZERO 	bss_NO_top,bss_NO
	
N_BZERO 	bss2_NE_top,bss2_NE 	; Add

N_BZERO 	bss2_NO_top,bss2_NO 	; Add
Suitable Products
C/C++ Compiler Package for M16C Series and R8C Family [M3T-NC30WA]