Information wants to be free...

GR-KURUMI Makefiles for Linux

Here's some follow-up information on the GR-KURUMI microcontroller reference board mentioned in the previous article.

On the official Gadget Renesas pages you can find an online editor and compiler refered to as the "Web Compiler", but in case you want to build the sources on your own Linux box then some more work is required.

First of all, download and build the RL78 GCC toolchain. Follow this advice.

Second, you will need the linker script, crt0 and header files which are specific for the RL78. I got this from the Gadget Renesas Web Compiler by downloading an example project.

Finally, here is an example of a simplified Makefile, based around compiling the source file "led.c" into the binary file "led.bin", which can be flashed:

TOOL_PATH:=/path/to/RL78-Toolchain/prefix/bin

CFLAGS = -c -Os -ffunction-sections -fdata-sections -I. -Icommon
LDFLAGS = -Wl,--gc-sections -nostartfiles

led.bin: led.elf
	$(TOOL_PATH)/rl78-elf-objcopy -O binary $^ $@

led.elf: led.o crt0.o
	$(TOOL_PATH)/rl78-elf-gcc $(LDFLAGS) -T common/rl78_R5F100GJAFB.ld $^ -o $@

crt0.o: common/crt0.S
	$(TOOL_PATH)/rl78-elf-gcc $(CFLAGS) $^ -o $@

led.o: led.c
	$(TOOL_PATH)/rl78-elf-gcc $(CFLAGS) $^ -o $@

.PHONY: clean
clean:
	rm -f *.o *.elf *.bin
          


Here is the led.c example, which I have mostly just copied from the Internet and not written myself:

#include <iodefine.h>
#include <iodefine_ext.h>

#define LED_CYAN_PIN    PM1.BIT.bit7
#define LED_MAGENTA_PIN PM5.BIT.bit1
#define LED_YELLOW_PIN  PM5.BIT.bit0
#define LED_CYAN        P1.BIT.bit7
#define LED_MAGENTA     P5.BIT.bit1
#define LED_YELLOW      P5.BIT.bit0

__attribute__((interrupt))
void wdti_handler(void)
{
}

__attribute__((interrupt))
void it_handler(void)
{   
    LED_CYAN    ^= 1;
    LED_MAGENTA = 0;
    LED_YELLOW  ^= 1;
}

void main(void)
{
  asm("di");

  LED_CYAN_PIN    = 0;
  LED_MAGENTA_PIN = 0;
  LED_YELLOW_PIN  = 0;

  LED_CYAN    = 0;
  LED_MAGENTA = 0;
  LED_YELLOW  = 0;

  /* Setup clocks */                                      
  CMC.cmc = 0x11U; /* Enable XT1, disable X1 */
  CSC.csc = 0x80U; /* Start XT1 */
  CKC.ckc = 0x00U;

  /* Interval timer */
  OSMC.osmc = 0x80U;  /* Supply fsub to Interval Timer */
  RTCEN = 1;
  ITMK  = 1; /* Disable interrupt... */
  ITPR0 = 0; /* High pri... */
  ITPR1 = 0;
  ITMC.itmc = 0x8FFFU; /* 270ms... */
  ITIF = 0; /* interrupt request flag... */
  ITMK = 0; /* Enable interrupt... */

  asm("ei"); /* Enable interrupts */

  for(;;)
  {
    asm("stop"); /* STOP mode. */
  }
}
          


Topic: Configuration, by Kjetil @ 23/09-2017, Article Link