4. Launch e2 studio and create the application (Baremetal)
4.1. create the Renesas CC-RX C/C++ Executable Project
If you have not yet installed the QE BLE Tool you can do that now by following these Instructions.
Step 1 Launch e2 studio.
e2 studio can be launched from the Windows start menu. If you have multiple versions of e2 studio installed, please make sure to launch the version of e2 studio that is specified in the prerequisites section. In the Eclipse Launcher window, specify the destination for the new workspace. It is recommended to keep the path simple and avoid using spaces.

Figure 7 Eclipse Launcher window
Step 2 - Click Launch to start e2 studio in the specified path. When prompted, log into your My Renesas account or click Cancel to dismiss the pop up window asking for permission to log and report usage (it will remain disabled). Select No when prompted for setting up a password hint. - The welcome screen may show inside the new workspace. It can be dismissed by clicking on the Hide button in the top-right corner.

Figure 8 Hide button in the top-right corner
Step 3 - Go to File -> New and select C/C++ Project. - In the new project wizard window, select Renesas CC-RX C/C++ Executable Project and click Next

Figure 9 Renesas CC-RX C/C++ Executable Project
Step 4 - Specify a project name and Click Next.

Figure 10 Project name
Step 5 - Create a new e2 studio project with the following settings and then click next
Renesas CC-RX C/C++ Executable Project
Project name: (Arbitrary)
RTOS: None (for Baremetal), FreeRTOS (kernel only) or Azure RTOS
Target Board: CK-RX65N
Warning
Below are the steps to build a bare metal application. The steps for integrating FreeRTOS or Azure RTOS are outlined in section Section 5.1 and Section 6.1 respectively.

Figure 11 Baremetal RX Project
Step 6 - Check Use Smart Configurator and click the Finish button..

Figure 12 Smart Configurator
Step 7 - You may get Board Data File update pup up window, select Next and download the up to date FIT Module.

Figure 13 Board Data File update

Figure 14 new FIT module download
Step 8 - The project configuration is compelete. Select Components tab in the Smart Configurator perspective

Figure 15 Project created
Step 9 - Click Add component button to add the FIT module to the list of components in New Component window.

Figure 16 Add component
Step 10 - Select the BLE FIT module added and click Finish button on the window.

Figure 17 Add BLE Fit Module
Step 11 - Make sure the FIT module is added. Enable the Boot from Host feature. Select 1-Wire-UART

Figure 18 BLE Fit Module added
Warning
Enable the option to boot DA14531 from host MCU through 1-Wire UART (disabled by default)
The DA14531 Pmod™ module will be connected on the Pmod™ 1 of the CK-RX65N dev kit, when considering to Use another MCU, all the steps that we mentioned earlier are the same, you just need to correctly configure the Reset PIN for the Pmod™ on that Dev kit
Step 12 - Add other FIT modules to serve the sample app

Figure 19 Add PORT Fit Module
Step 13 - Under Drivers –> Communications select r_sci_rx (Serial Communications Interface) and set the following configurations for UART. Support for channel 1 is included by default, set to NOT and include support for channel 6 instead.

Figure 20 Include Channel 6

Figure 21 Channel 6 TX/RX buffers configuration

Figure 22 Channel 6 TX/RX Pins selection
Step 14 - Next step is to configure the GPIO Port Settings. Select Config_Port under Drivers –> I/O Ports and select PORT2 and PORTB These are for LED toogling used by the application.

Figure 23 GPIO Ports setting’
Step 15 - Select PORT2 tab for configuration.

Figure 24 GPIO Ports 2 setting
Step 16 - Select PORTB tab for configuration.

Figure 25 GPIO Ports B setting
Step 17 - In this example, the high-speed on-chip oscillator (HOCO) is used as a reference clock, clock tree need to be updated as follow, disable main clock and Sub clock.

Figure 26 HOCO used as a reference clock
Step 18
- Click Generate Code button to add the FIT module and its dependencies in smc_gen
folder, click Proceed.

Figure 27 smc_gen folder updated with dependencies after code generated
4.2. Profile development with QE for BLE
This section describes how to design QE for BLE profile. QE for BLE can be used to design GATT profiles as well as to configure GAP roles and parameters for Bluetooth LE. With the QE profile configurator you can set up your device name and enable broadcasting.
Step 19 - From the menu bar select Renesas Views -> Renesas QE and then R_BLE_Custom Profile RA, RE, RX (QE) option.

Figure 28 QE BLE
Step 20 - Set the Project to the name of your project and set the Module type to DA1453x.

Figure 29 QE BLE module Configuration
Important
You may note that there already exist a couple of services. These are descriptive services that exist in most commercial profiles.
The R_BLE Custom Profile RX (QE) view has 3 main tabs:
The Profile tab allows the creation of your profile. Many of the SIG adopted profiles and services are present here, as well as the ability to generate custom ones.
The Peripheral tab allows you to easily view and change what data is transmitted in your advertising packets and scan responses. These are values exposed when the device acts as a Peripheral.
The Central tab allows you to set your scan and connection parameters, as well as scan filters. These values are used when the device is acting as a Central.
Step 21
Go to the Peripheral tab indicated below. Here you can change what data the connectable advertising packets contain. Since we will not be using the device as a central, we will disregard the central tab.
Step 22 - Click the check box beside Local Name to enable it. - Then click Local Name itself, this will open the settings for the element. - Enter a name that is unique to your application, for example: DA14531-RX-BLE - Select Advertising Parameter and set the Slow Advertising Interval to 100.0ms.

Figure 30 Peripheral tab Configuration
4.3. QE GATT Profile
This section describes how to use the QE profile configurator to set up your SIG profile and generate the necessary source code.
Step 23 - In the QE tool, click back to the Profile tab. - You will notice the GAP service defaults to have both Server and Client configurations active, but the GATT service has a red X on it as shown in Figure 29. Since we will be using the device as a GATT server, you will need to enable this option for the GATT Service. - Click the GATT Service to select it, then click the Customize button in the panel to the right. - Note that this will rename the service to GATT Service2. Delete the number 2 and check the box for Server above the name. You will notice the error symbol goes away.

Figure 31 GATT service Enabled
Step 24
To add a new service. Highlight the profile by clicking the cyan Profile button, then click the green plus above it.

Figure 32 Add GATT service
Important
Next, you can add some of the profiles and services that have been adopted by the Bluetooth Special Interest Group (SIG). In this document we will select “Add Service” as we want to add service that has been already been defined

Figure 33 Select Add service
Select Immediate Alert Service

Figure 34 Immediate Alert Service

Figure 35 Immediate Alert Service Added
When you click to customize, you will be prompted to enter in all the necessary information for your service.
Step 25 - Rename the service “CK-RX65N IO Control” and give it the abbreviation “evkioctrl” so we can easily identify this in our code.
Important
Note that a UUID is already pre-generated, you may change this if you wish but for now we will go ahead and accept whatever was randomly generated.
When you have completed the service configuration, verify it looks similar to below:

Figure 36 IO control service
Step 26
Now we will edit our characteristics to the service we just created. click the yellow “C”. In the Properties box check the Read and Write boxes. This is so we can allow the client (our phone) to retrieve and set these values.
Set the Name to “LED Control”, the Abbreviation to “ledctrl”, the Properties to Read and Write.
Ensure DBSize is 1 as we will be using a 1-byte container to hold this value.
As our value will be initialized to 0, ensure Value is set to 0x00. At this point verify your screen looks as below:

Figure 37 Alert Level characteristics
Step 27 - Save the changes and then select Generate Code, necessary Include files will be added to the project

Figure 38 QE BLE generate code
Once complete, the generated files should be listed in the console

Figure 39 QE BLE code generation console
4.4. Source Code Modifications
This section steps through adding an application layer to the code generated by the smart configurator. The code we will insert is simple but would be the foundation for building out your entire project.
Step 28
- Add a call to app_main
to the file src[Project name].c CK_RX65N_DA14531.c
file.
/***********************************************************************
*
* FILE : CK_RX65N_DA14531.c
* DATE : 2024-04-08
* DESCRIPTION : Main Program
*
* NOTE:THIS IS A TYPICAL EXAMPLE.
*
***********************************************************************/
#include "r_smc_entry.h"
extern void app_main(void);
void main(void);
void main(void)
{
app_main();
while(1)
{
R_BSP_SoftwareDelay(1000, BSP_DELAY_MILLISECS);
}
}
Note
In this step, first, you need to ensure that the file qe_gen\ble\app_main.c
has been generated.
Step 29
- In the file qe_gen/ble/app_main.c
, add the following macros:
/******************************************************************************
User macro definitions
*******************************************************************************/
/* Start user code for macro definitions. Do not edit comment generated here */
#define GPIO_PORT(x, y) ((PORT##x.PODR.BIT.B##y))
/* End user code. Do not edit comment generated here */
Step 30
- Update the ble_init()
in the app_main
function as below, this will toggle the Red LED on the DA14531 PMOD when BLE and profiles are Initialized.
/* Initialize BLE and profiles */
if (BLE_SUCCESS == ble_init())
{
GPIO_PORT(B, 7) = 1;
GPIO_PORT(2, 2) = 1;
GPIO_PORT(2, 5) = 1;
}
else
{
GPIO_PORT(2, 5) = 0;
}
Important
The API file, in our case r_ble_evkioctrls.h
, contains all the functions and enums
necessary to interface with and control a GATT service. In this case the file provides the
interface for our Target Board IO control (abbreviation evkioctrls) service.
This file will be broken down into separate sections for each of the services characteristics, and one additional section for enumerations and generic functions.
Since this characteristic is enabled only for read and write it’s functions are pretty simple. There is a get function and a set function. These allow an interface with the characteristic value in the database.
Step 31
- The only callback we are interested in at this time is evkioctrls_cb()
, locate this function (around line 358). The other callbacks are very useful for understanding what events are happening inside the BLE stack, although they are beyond the scope of this document. Modify the callback function to have the following code in qe_gen/ble/app_main.c
static void evkioctrls_cb(uint16_t type, ble_status_t result, st_ble_servs_evt_data_t *p_data)
{
/* Hint: Input common process of callback function such as variable definitions */
/* Start user code for RX65N IO Control Server callback function common process. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
uint8_t Level;
switch(type)
{
/* Hint: Add cases of RX65N IO Control server events defined in e_ble_evkioctrls_event_t */
/* Start user code for RX65N IO Control Server callback function event process. Do not edit comment generated here */
case BLE_EVKIOCTRLS_EVENT_LEDCTRL_WRITE_REQ:
if (BLE_SUCCESS == result)
{
Level = *(uint8_t *)p_data->p_param;
if(Level == 0x00)
{
GPIO_PORT(2, 2) = 1;
}
else
{
GPIO_PORT(2, 2) = 0;
}
}
break;
case BLE_EVKIOCTRLS_EVENT_LEDCTRL_READ_REQ:
if (BLE_SUCCESS == result)
{
Level = GPIO_PORT(2, 2);
R_BLE_EVKIOCTRLS_SetLedctrl(&Level);
}
break;
default:
break;
/* End user code. Do not edit comment generated here */
}
}
4.5. Building and running the application
Step 32
Now that the application is complete, you can build and run it on the CK-RX65N board.
Press the “hammer” icon to start building the project

Figure 40 Build the application
The toolchain will report compilation and build status to the console pane in the lower-right corner of e2 studio. When the build has completed, it should confirm that there are zero errors.
Warning
when you compile the project the compiler reports some warnings, You may ignore them. Some callbacks are not updated and they are beyond the scope of this document.

Figure 41 Build the application console
Create and select the project debug configuration, Press the “bug” icon.

Figure 42 Create the debug configuration

Figure 43 Select the debug configuration
The application is now ready to be programmed and run on the CK-RX65N board. Press debug to begin the debug session.

Figure 44 Run the debug configuration
e2 studio will perform flash programming routines and prompt to switch to Debug perspective. Select the check box by Remember my decision and click Switch. LED5 near the debug USB port will blink while programming.
The debug session is now started, and the application is paused at its entry function
PowerON_Reset_PC
. Click the Resume button or press F8 on the keyboard to start the application.