Getting Started With Renesas RA Family/FSP - Part 2 RTT Viewer

by Panos_V in Circuits > Microcontrollers

17 Views, 0 Favorites, 0 Comments

Getting Started With Renesas RA Family/FSP - Part 2 RTT Viewer

Part2.JPG

This intructable walks through using the Part 1 example project and the RTT Viewer. This tool serves as console interface, letting both displaying output messages from your application and sends input from your PC to your MCU, in real time.


Compared to the traditional/boring method of using a UART serial terminal for debugging and monitoring, RTT offers a faster and more efficient alternative, using the existing debug interface.


Although I recommend you to follow my Getting Started collection from the beginning, you can still jump right in if you’re already somewhat familiar with e2 studio and FSP

Supplies

While this tutorial works with any Renesas RA microcontroller, we'll be walking through the steps using the Evaluation Kit for RA6M4 as our example.


Download the Segger J-link RTT Viewer from this link.

Import the Project From Part 1

Untitled.png

Follow this git link and download the project from part 1.

Next, click Import>Rename & Import Existing C/C++ Project into Workspace(cause we want to give a differnet name).

Now, we have a new identical project, ready to add some new features




Add the RTT Files

Screenshot_1.png

Now, you just create a new folder under the src, called SEGGER_RTT. Then, import the files attached on this step, apart from the common_utils.h which should be placed on level higher.

These files include the basic RTT functions we will use on this intructable.

Getting deep into these functions is not necessary, since we demonstrate the the very basic usage. For more details regarding the API, refer to this.


RTT Functions

Screenshot_2.png

Let’s take a look at what’s inside common_utils.h.

Here you’ll find:

  1. Macro definitions for initializing RTT
  2. Banner messages that we’ll display in the RTT Viewer
  3. Helper functions for printing messages or errors
  4. And a simple error trap

These utilities make it easy to send and receive text through RTT, basically giving us a “printf-style” console over the debug link!

Integrate RTT in Hal_entry.c

Now let’s make use of our new RTT utilities inside the hal_entry.c file.

Open your project’s hal_entry.c and add the following include near the top:

#include "common_utils.h"

This allows us to use the APP_PRINT, APP_ERR_PRINT, and APP_ERR_TRAP macros defined in common_utils.h.

These macros make it super easy to send messages directly to the RTT Viewer, no need for printf() or UART setup!

Next, inside your hal_entry() function, let’s print a welcome banner when the program starts:

void hal_entry(void)
{
/* TODO: add your own code here */
fsp_err_t status=FSP_SUCCESS;
/* Display project banner */
APP_PRINT(BANNER_1);
APP_PRINT(BANNER_2);
APP_PRINT(BANNER_3, EP_VERSION);
APP_PRINT(BANNER_4, FSP_VERSION_MAJOR, FSP_VERSION_MINOR, FSP_VERSION_PATCH);
APP_PRINT(BANNER_5);
/* Initialize and start the timer */
status=R_GPT_Open(&coolTimer_ctrl, &coolTimer_cfg);
APP_ERR_TRAP(status);
status = R_GPT_Start (&coolTimer_ctrl);
APP_ERR_TRAP(status);
APP_PRINT("\r\nTimer started successfully!\r\n");

while (1)
{ /* Wait for interrupt */
__WFI();
}
#if BSP_TZ_SECURE_BUILD
/* Enter non-secure code */
R_BSP_NonSecureEnter();
#endif
}

Let’s make our LED timer callback print something each time it runs. this will show that RTT works even during interrupts.

Update your coolTimerCallback() like this:


/* Callback function */
void coolTimerCallback(timer_callback_args_t *p_args)
{
/* Print a message each time the timer fires */
APP_PRINT("Running...\r\n");

FSP_PARAMETER_NOT_USED(p_args);

static bsp_io_level_t level = BSP_IO_LEVEL_LOW;
R_IOPORT_PinWrite(&g_ioport_ctrl, LED1, level);
level = (level) ? BSP_IO_LEVEL_LOW : BSP_IO_LEVEL_HIGH;
}

Now, every time the timer toggles the LED, you’ll also see “Running…” printed in the RTT Viewer in real time!

Connect RTT Viewer

Screenshot_3.png

Build and flash the project to your RA board (e.g., RA6M4).

Keep your debugger connected, RTT communicates through it.

Launch J-link RTT Viewer

Go to

File→ Connect or F2

and then in the RTT Viewer Configuration window, set the following options:

  1. Connection: USB
  2. J-Link Device: your connected board (e.g. R7FA6M4AF)
  3. Force go on connect: Enabled
  4. Interface: SWD
  5. Speed: Auto or 4000 kHz
  6. RTT Control Block: Search Range

Select as range 0x20000000 0x8000

This range tells RTT Viewer to look for the RTT control block in the MCU’s RAM area, where SEGGER RTT usually places it.

This tells RTT Viewer to look for the RTT control block within the first 32 kB of SRAM, which is where many compilers place the _SEGGER_RTT variable by default.

Once configured, click OK to connect. RTT Viewer will automatically open the console and start listening for messages.


Sending Input Back

RTT also allows input from the PC to the MCU, not just output.

For example, you could check if a key is pressed and read it like this:

/* Wait for user input */
APP_PRINT("\r\nType any key in RTT Viewer to continue...\r\n");

char input[1];

/* --- BLOCKING WAIT LOOP --- */
while (1)
{
if (APP_CHECK_DATA)
{
APP_READ(input);
APP_PRINT("\r\nYou pressed: %c\r\n", input[0]);
break; // exit loop after first key press
}
}
APP_PRINT("\r\nContinuing program...\r\n");

Try adding this before the timer initialization. When you type a character in the RTT Viewer input window, your MCU will echo it back just instantly!

Build, Flash, and Watch the Magic

Screenshot_4.png
Screenshot_5.png

Now go ahead and:

  1. Build your project (Ctrl+B)
  2. Debug or run it with the RTT Viewer open
  3. Press a key to continue the program
  4. Watch the live logs appear in the console

RTT gives you a real-time, cable-free debugging console, and you can even use it alongside breakpoints and live variable watching in e² studio.