1. RL78开发环境
Renesas RL78系列芯片开发可能使用CS+和e2studio进行开发,CS+是瑞萨一套传统的开发环境,可以使用CC-RL编译器,界面使用习惯比较适合单片机开发者;e2studio是基于eclipse的一套开发环境,可以使用CC-RL编译器,也可以使用GCC编译器,集成了一系列插件,如代码提示等eclipse强大的功能,缺点是eclipse是基于Java的,所示运行有点慢。
2. CC-RL C编译器注意事项
CC-RL是官方的编译器,也支持部分C99功能,我总结了一些使用时应该需要注意的地方。
2.1 使用printf函数
一般大型一点的程序,我们都习惯使用printf来调试,可以使用CC-RL中实现的printf,而不需要自己写,配合可变参数宏( __VA_ARGS__ )使用还是很方便的。使用printf需要重写putchar函数:
To change stdout, replace this function. Note that replacing the putchar function will also change stderr. To change the output destination of stderr to something other than stdout, replace the perror function.
#include <stdio.h>
int __far putchar(int c);可使用的函数有以下几个:
#include <stdio.h>
int __far printf(const char __far *format, ...); (C99)
int __far printf(const char __far * restrict format, ...); (C99) [V1.07 or later]
int __far printf_tiny(const char __far *format, ...);(C90)
int __far printf_tiny(const char __far * restrict format, ...); (C99) [V1.07 or later]printf_tiny is a simplified version of printf. When macro__PRINTF_TINY__is defined before the -D option or stdio.h is included, the function call of printf is replaced with printf_tiny. The following restrictions apply to conversion specifications of printf_tiny.
(1)Flag
-, +, or space cannot be specified.
(2)Field width
A negative field width "*" cannot be specified.
(3)Precision
Cannot be specified.
(4)Size
ll, j, z, t, or L cannot be specified.
(5)Type specification character
f, F, e, E, g, or G cannot be specified.
也就是说如果你定义了__PRINTF_TINY__,printf会被printf_tiny取代。
2.2 结构体的字节对齐
新版本编译器可以使用以下语法设置结构体按字节对齐:
#pragma pack
struct s1 {
char a;
int b; // The number of alignment is set to 1.
} st1;
#pragma unpack
struct s2 {
char a;
int b; // The number of alignment is not set to 1.
} st2;2.3 self RAM
self RAM是RL78特有的,使用EEL或FSL库需保留self RAM, 需要设置linker 选项 -SELF,这样能指定self RAM只作为EEL或FSL所用,不会和其它变量有冲突。
-This option disables allocation of a section to the self RAM area.
-The STACK_ADDR_START symbol andSTACK_ADDR_END symbol are set except for in the saddr area.
可以在CC-RL的linker配置中设置:

2.4 大小端
Flash内数据是以小端模式储存,例如0x1234,则低地址放0x34,高地址放0x12。
2.5 数据变量绝对定位的方法
- 通过伪指令指定变量地址
先使用#pragma address指定地址,然后定义变量;变量定义时不允许初始化;const变量不能使用此方法。
#pragma address (io=0x0ffe00)
int io;2.6 程序绝对定位的方法
- 定位const变量(使用伪指令)
#pragma section const ver
const char *version = "v1.0";然后指定段名为“ver_n”的地址即可;
- 定位const变量(使用汇编)
FW_INFO_ADDR .EQU 0x4000 ;信息存放地址
FW_INFO .CSEG AT FW_INFO_ADDR
.DB 'v', '1', '.', '0' ;固件版本- 定位函数
#pragma section text abc
void func(void)
{
__nop();
}然后指定段名为“abc_n”的地址即可。
2.7 汇编嵌入
#pragma inline_asm func
void func(int x)
{
movw !_a, ax
}3. 总结
以前的都基本上可以在C编译器的Help找得到,这里总结的都是基于CC-RL的编译器的,注意与旧版本编译器CA78K0R并不兼容。