I'm evaluating the Renesas RX65N MCU EV Kit.

In this post,  I make the emWin libraries work with the GCC toolchain

an emWin widget with the GCC toolchain


Renesas CC-RX Dependencies


The emWin that's available for the Renesas RX family can be built with the GCC Toolchain, but there are changes needed

  • a CC-RX construct is used to call the NOP() machine instruction.
  • a compile time definition needs to be set.
  • a different emWin library needs to be linked in.
  • take care that code and data are not overlapping the fixed drawing buffer areas.


These steps are easy, but it took me a good day to figure everything out.

In particular the memory location of the buffers was tricky to find out. The firmware crashes when you use the default locations for code and data. More in the Memory Management section below.


I've attached the completely configured project at the end of this post. If you're stuck following the instructions, you can use that known-working archive as a start point.


Create GCC Project and Configure Peripherals


Start off with an empty GCC project. Follow the instructions of the Create the Project section of part 2a: Blinky with GCC Toolchain.

Then open the Smart Configurator file and start setting up the hardware:


  1. Set Board and Configure Board Startup
    On the Board tab, set EnvisionRX65N as the active board.
    Then have a look at the r_bsp module in the Components tab. The default settings are OK for this project.
  2. add r_dma_rx module, keep the defaults
  3. add r_gpio_rx, also keep defaults
  4. add r_sci_iic_rx. This module is the i2c peripheral that will talk to the touch screen on i2c channel 6.
    Set these attributes:
    MCU CH6: supported
    IIC bitrate for CH6: 38400
    Interrupt Priority for CH6: Level 2
    Digital Noise Filter for CH6: Enable
    Noise Filter Setting Register for CH6: clock / 1
    i2c mode register 1 for CH6: 18
    Software Bus Busy counter: 1000
    Setting port : Include Port Setting
    SCI6: check
    SSCL6 pin: check
    SSDA6 pin: check
  5. add r_glcdc_rc, then set:
  6. add r_cmt_rx and accept default attributes.


Save the configuration file and click the Generate Code button.

It's good to try to build and run the project at this time, just to confirm that all is working.


Add emWin dependencies and Example Program.


When you installed (unzipped) emWin for the RX family, it created an example project subfolder called emWin_RX65N.

Grab these emWIN folders and copy them into your project's ./src folder (accept overwrite when asked):

  • Config
  • drw_2d
  • GUI

Also create an Application folder under ./src.


Download the Segger emWin Tutorial example source.

Unzip that examples archive, then copy the file WIDGET_ButtonRound.c to the Application folder you just created in e2 studio.


Adapt your main() code so that the Segger example is called:


#include "GUI.h"
#include "Pin.h"
#include "DIALOG.h"

void MainTask(void);

void main(void) {


Add a port folder under ./src, and create a machine.h file with the below contents:



#define nop()                            __asm("nop")

#endif /* PORT_MACHINE_H_ */


GCC has a different way of calling the nop machine instruction. The construct above takes care that a GCC compatible definition is available, without having to change emWin sources.


Don't build yet, there are project settings that need to be done...



The license file in the package is somewhat fuzzy. It says you can only build PC projects.

The licensee (YOU) will receive the software as object code and some tools in executable code from SEGGER.

YOU may use the code for evaluation purposes only. You may not use or port the software on another platform other than a PC, use, port or embed it in a product or for any commercial purposes without entering a separate License Agreement.

The Renesas and Segger websites however say that it's free for commercial use with Renesas products:



GUI development tools:

- emWin by Segger is free of charge


Please create your free user account to download the full package for your commercial application design



Configure GCC Project Settings


There's a significant number of includes to add, and a macro definition:


In the emWin version licensed for this evaluation kit, most of the logic comes as a precompiled library. We have to link it in (there's a dedicated one for GCC).

First add the library path to the user defined archives directory. The lib is located in the ./src/GUI folder you copied over from emWin's example earlier.

Then add the emWinLib to the user defined libraries.



Try to build the project. It should be successful.

You can try to run it too, but it will fail at the GUI_Init() call, because that will overwrite part of our code in RAM with graphic data. Fixed in the next section...


Memory Mangement


The RX libraries define two buffers on fixed memory addresses.

Renesas has configured the CC-RX linker settings to not use these sections for code. We'll have to do the same for the GCC linker file.


note: In the prevous post I've documented how to use a structured approach to guard the buffers. In this post I'm not using it.

I'm using Renesas approach with fixed addresses and telling the loader to load all code and data after the 2nd buffer in expanded RAM.

In a next post I'll convert this to structured memory sections, but that requires changing some example code. I tried to avoid that in this first post.


The CC-RX example starts loading user code at address 0x00840000.

The two buffers are in 2 fixed areas of the RAM, at the start of the standard and expansion RAM blocks.

This construct is in ./config/LCDConfig.c.


*       Static data
static const U32 _aBufferPTR[] = {
  0x00000100,  // Begin of On-Chip RAM
  0x00800000   // Begin of Expansion RAM


Renesas has given 0x00840000 as the safe address to start (giving all standard RAM and 0x40000 bytes of expansion RAM to the graphic library as buffer).

The total expansion size is 0x60000. That leaves 0x20000 for code and data.

The easiest way to explain that to GCC's linker is as such in the linker file:



Now build the project again, then execute it.

You will get a dialog window with 5 controls. You can freely drag the dialog across the screen.

The button on the right side is the custom widget. Standard, it behaves as a normal button.

Press the callback button on the left and it turns into a custom round one. You can change its attributes by pressing the other buttons on the left screen part.

Check how it behaves by clicking on it...


Related blog
part 1: Create an Empty Project
part 2a: Blinky with GCC Toolchain
part 2b: Blinky with Timer and Interrupt
part 3: Port an example from Renesas toolchain to GCC
part 4a: Low Power - Sleep
part 4b: Low Power - Software Standby
4c todo: power mode 3
4d todo: power mode 4
part 5: DAC
part 6: Software SHA
part 7: Blinky with FreeRTOS
part 8: DMA
part 9: UART
part 10: Reserve LCD Frame Buffer in Expansion RAM with GCC
part 11: port emWIN to GCC and run an LCD Widget
Renesas RX65N MCU EV Kit - Review
Andrew Johnson's blog series
Renesas Envision Kit RPBRX65N Roadtest