Example code for RX65N Envision dev board with GCC RX compiler

There seems to be little example code around for the RX65N Envision kit in general, and even less when using the GCC-RX compiler. I've seen a request or two here for a simple hello world type application. The example app that Renesas supplies for this board using their compiler is complicated and tied in to Emwin, so I've put together a much simpler one for anyone who's interested. It has touch screen and LCD drivers incorporated, all using direct register access, but neatly abstracted away into a simple API. The app reads touch screen coordinates and plots a box on the screen displaying the touch point screen coordinate inside it as text. The main function is effectively this...

system_clock_config();
touch_init();
lcd_init();

lcd_filled_rectangle(0, 0, 480, 272, RED);

while (true)
{
    touched = touch_get_point(&x, &y);
    if (touched)
    {
        if (x < 450 && y < 240)
        {
            lcd_filled_rectangle(x, y, 30, 32, BLACK);
            itoa(x, text, 10);
            lcd_string(x, y, text, WHITE);
            itoa(y, text, 10);
            lcd_string(x, y + 16, text, WHITE);
        }
    }
}

Colours parameters to the lcd_* functions are in 24 bit (RGB888) format even though the display uses 16 bit (RGB565) format and are downsized in the functions. I know this is inefficient, but in demo code it's more intuitive to deal with RGB888 format colours.

I've created an e2studio project (version 7.2.0) and the GCC RX version used is 4.8.4.201803-GNURX. All the project files and source are in in the EnvisionDemo1 folder in github here...

https://github.com/miniwinwm/RenesasEnvisionGCC

If anyone finds this useful I'll do some more examples projects. I also have it working using the cc-rx compiler if anyone is interested in that.

  • This example demonstrates the DTC in conjunction with the serial port SCI9 available on the Envision Kit's Pmod connector (CN14).

    The serial port is set up in asynchronous mode (19200, 8, N, 1) using no flow control or error handling. Interrupts are enabled for transmit, transmit end and receive. Two DTC channels are created linked to interrupts 102 and 103 for Rx and Tx for SCI9. These DTC channels intercept the interrupt requests and perform data transfer autonomously, only reaching the interrupt handlers' code after the configured number of bytes have been transferred. When a Tx interrupt is serviced the transmit end interrupt is enabled to detect when transmission of the last byte has been completed.

    Although only 2 DTC channels are used space is allocated for an array of 256 DTC vectors and slots 102 and 103 contain pointers to the configuration structures for these 2 channels. In this example the DTC vector array is located at the top of the RX65N's extended RAM at address 0x0085FC00. This is after both the display buffers used in EnvisionDemo3.

    To position the vector array at this location the generated linker script .ld file needs amending. In the MEMORY list at the top where RAM, ROMS and OFS regions are defined a new region needs adding:


        ERAM : ORIGIN = 0x800000, LENGTH = 0x60000

    In the SECTIONS list a new section needs adding like this:

        .dtc_vectors 0x0085FC00: AT(0x0085FC00)
        {
            KEEP(*(.dtc_vectors))
        } > ERAM

    To define the array in C source to be located at this address a GCC __attribute needs to be used when declaring the array like this:

        static volatile uint32_t __attribute__((section(".dtc_vectors"))) dtc_vectors[256];

    Looking in the .map file after linking shows that this array is at the required address:

        .dtc_vectors 0x0085fc00 0x400 ./src/serial_dtc.o


    When the example is run and connected to a serial terminal the code does an endless loop of writing and reading fixed sized packets of data to/from the serial port.

  • Hi Gerald
    I might try your suggestion as an alternative. The rest of read and write that are not stdin, stdout or stderr could link to the FatFS example I did earlier so that the standard C file handling library is available, although other functions would need diverting as well, like seek. I guess read and write are part of the standard library somewhere in its depths, so the GCC flags would have to be changed to -fno-builtin-read and -fno-builtin-write.
    John
  • John,

    One thing I discovered when implementing those read and write functions is that the console I/O can use up a lot of stack. I ended up just dropping in 2KB to get printf to work with some minimal formatting, but not sure yet what an optimal size is.

    I haven't checked, but I think maybe those low level stream I/O functions may be declared as 'weak' in the GCC library, because the compiler doesn't complain when I add the user defined versions. As you say it would be nice to implement the full set of low level calls for full file support. This would permit using C's stream I/O high level calls for everything.

    I have done this under CC-RX a few years ago, linking in the FatFS file system and a SPI MMC memory driver, so maybe it's time to port it over to GCC.

    -Gerald
  • Hi!

    You are really good at this, i hope one day get as good as you are. can you help with a project i'm working on, i have an envision kit RX65N and need to communicate with EK RA2A1 through serial communication, do you know how to do it? or where i can learn. Thanks!

  • Hi

    Firstly, I haven't used RX processors for 3 years now, so I have forgotten most of what I knew.

    You don't say which compiler you are using. If you are using CC-RX you can use their FIT modules for which there are many examples and good documentation from Renesas. My examples use the free GCC-RX compiler, and there are few examples for that compiler and no drivers, which is why I made the examples that I posted about in this thread. These GCC-RX examples all go direct to registers. That's not something you have to do if you use the FIT modules. What does your project require? 

    If you are using CC-RX you don't have to use the FIT modules, you can go direct to registers using that compiler as well. If you wish to do this then my GCC-RX example code should compile although you will have to make new project files for the different compiler.

    My example project number 18 demonstrates the use of a serial port. You may be able to use this code. My example uses the DTC which complicates things a bit and is not necessary if you want to do simple synchronous serial coms. The DTC is similar to DMA for peripherals - you give the controller a block of data and let it get on with transferring it byte by byte in hardware - it gives you an interrupt when it's done.

  • Hi, thank you for your time Slight smile

    My project basically consists on communicating one EK RA2A1 which is connected to a load cell, then the information from the reading transmit through serial ports to the envision kit RX65N and display the measure on a HMI. I'm new with all of this and learning on the go, but i think i'm using GCC-RX (that's what it shows when creating a new project). I'll check the example you mention but if you have more documentation or examples would be great too. Again thank you for your time.