6. Launch e2 studio and create the application (Azure RTOS)
6.1. create the Renesas CC-RX C/C++ Executable Project
In this section, we will outline the necessary steps to build an application based on Azure. While many steps overlap with those outlined in Section 4, we will focus primarily on the differences.
Follow steps 1 through 4 as outlined in the previous section Section 4.
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)
Azure RTOS
Target Board: CK-RX65N

Figure 52 Azure RX Project
Follow steps 6 through 11 as outlined in the previous section Section 4.
Step 12 - We will add the GPIO driver FIT module (instead of the PORT Module).

Figure 53 Add GPIO driver component Azure RTOS
Step 13
Below an overview of the necessary FIT modules to built the Azure RTOS application.

Figure 54 FIT modules to built the Azure RTOS application
Step 14 - Add the BLE thread. Click on azuretos_object and then Tasks tab. When using Azure RTOS ensure the heap 4 size is set to a minimum of 2K bytes. Here we set to 2048 bytes

Figure 55 BLE Thread config Azure
Step 15 - Ensure the BSP heap size is set to at least 2K bytes.

Figure 56 BSP heap size Azure RTOS
Step 16 - Update the clock tree as it shown in Figure 26 and then Generate code for your project.

Figure 57 Azure RTOS project generate code
6.2. 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 17
Add a call to
app_main
to theble_thread_entry.c
file. underscr/rtos_skeleton
/* New Thread entry function */
extern void app_main(void);
void ble_thread_entry(ULONG entry_input)
{
/* TODO: add your own code here */
app_main();
while (1)
{
tx_thread_sleep (1);
}
}
Note
In this step, first, you need to ensure that the file qe_gen\ble\app_main.c
has been generated.
The QE profile generation process remains identical to what was described in Section 4.2. There are no differences in this aspect between building a bare metal application and one based on Azure RTOS.
Step 18
- In the file qe_gen/ble/app_main.c
, Add include for r_gpio_rx_if.h
/******************************************************************************
User file includes
*******************************************************************************/
/* Start user code for file includes. Do not edit comment generated here */
#include "r_gpio_rx_if.h"
/* End user code. Do not edit comment generated here */
Step 19
- 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())
{
R_GPIO_PinDirectionSet(GPIO_PORT_B_PIN_7, GPIO_DIRECTION_OUTPUT);
R_GPIO_PinWrite(GPIO_PORT_B_PIN_7, GPIO_LEVEL_HIGH);
}
else
{
R_GPIO_PinDirectionSet(GPIO_PORT_2_PIN_5, GPIO_DIRECTION_OUTPUT);
R_GPIO_PinWrite(GPIO_PORT_2_PIN_5, GPIO_LEVEL_LOW);
}
Step 20
- Update the evkioctrls_cb()
callback as below:
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 */
uint8_t Level;
R_GPIO_PinDirectionSet(GPIO_PORT_2_PIN_2, GPIO_DIRECTION_OUTPUT);
/* End user code. Do not edit comment generated here */
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)
{
R_GPIO_PinWrite(GPIO_PORT_2_PIN_2, GPIO_LEVEL_HIGH);
}
else
{
R_GPIO_PinWrite(GPIO_PORT_2_PIN_2, GPIO_LEVEL_LOW);
}
}
break;
case BLE_EVKIOCTRLS_EVENT_LEDCTRL_READ_REQ:
if (BLE_SUCCESS == result)
{
Level = R_GPIO_PinRead(GPIO_PORT_2_PIN_2);
R_BLE_EVKIOCTRLS_SetLedctrl(&Level);
}
break;
default:
break;
/* End user code. Do not edit comment generated here */
}
}
Step 21
- Under src
update the tx_application_define
function in demo_thread.c
as below to tx_application_define_user ();
extern void tx_application_define_user (void);
/* Define what the initial system looks like. */
void tx_application_define(void *first_unused_memory)
{
/* Initialize user thread */
tx_application_define_user ();
}