C
Create a Renesas e2 Studio project
This topic provides you step-by-step instructions to create a Renesas e2 studio project, and integrate the Qt for MCUs static library.
The following instructions guide you through the complete process:
- Launch e2 studio and create a new project for RA6M3G using File > New > Renesas C/C++ Project > Renesas RA.
- Select C++ as the project language and click Next.
- Select Executable and FreeRTOS and click Next.
- Select FreeRTOS - Minimal – Static Allocation as the project template. Follow the wizard and complete the steps to create the project.
- Configure the FSP Stacks as described in the Renesas RA6M3G FSP configuration topic.
- Import the following sources and headers from
<QT_INSTALL_DIR>/QtMCUs/<QUL_VERSION>/platform
into the project:boards/renesas/ek-ra6m3g-common
all.cpp
and.h
filesboards/renesas/ek-ra6m3g-freertos/platform_os.cpp
boards/renesas/ek-ra6m3g-freertos/platform_time.cpp
common/platform.cpp
common/singlepointtoucheventqueue.cpp
common/freertos/freertosqueue.cpp
common/freertos/mem_info.cpp
common/freertos/mem-freertos.cpp
common/freertos/mem-freertos-default.cpp
As a result, you should have a directory named platform in your project, containing the sources for Qt Quick Ultralite RA6M3G FreeRTOS platform port.
- Open C/C++ Project Settings. Right-click on the project in the Project Explorer and choose Properties from the context menu to make the following changes:
- Navigate to C/C++ General > Paths and Symbols > Source Location and add platform/boards/renesas/ek-ra6m3g-common to the project's source locations list.
- Add <your-Qt-Creator-project-build-folder>/<Release|Debug|MinSizeRel> and <Qt-install-dir>/QtMCUs/<QUL-version>/include to the C++ include directories list under C/C++ General > Paths and Symbols > Includes. Select the Add to all configurations and Add to all languages options.
- Add the following libraries to the C/C++ Build > Settings > Tool Settings > GNU Arm Cross C++ Linker > Libraries list:
- <your-Qt-Creator-project-build-folder>/<Release|Debug|MinSizeRel>/lib<your-GUI-app>.a
- Add the following from
<Qt-install-dir>/QtMCUs/<QUL-version>/lib
:libMonotypeUnicode_cortex-m4-hf-fpv4-sp-d16_Windows_armgcc _MinSizeRel.a
libQulMonotypeUnicodeEngineShaperDisabled_cortex-m4-hf-fpv4 -sp-d16_Windows_armgcc_MinSizeRel.a
libQulPNGDecoderLodePNG_cortex-m4-hf-fpv4-sp-d16 _Windows_armgcc_MinSizeRel.a
libQulCore_cortex-m4-hf-fpv4-sp-d16_Windows_armgcc_MinSizeRel.a
- Set the C++ language standard to GNU ISO 2014 C++ under C/C++ Build > Settings > Tool Settings > Gnu Arm Cross C++ Compiler > Optimization. Select the Do not use exceptions, Do not use RTTI, and Do not use thread-safe statics options.
Note: Apply these settings to all project configurations.
- Add the following preprocessor definitions under `C/C++ Build > Settings > Tool Settings > GNU Arm Cross C++ Compiler`:
QUL_PLATFORM_DEFAULT_TEXT_CACHE_ENABLED=0
QUL_PLATFORM_DEFAULT_NUM_FRAMES_TO_PRESERVE_ASSETS=0
QUL_PLATFORM_DEFAULT_TEXT_CACHE_SIZE=24*1024
QUL_PLATFORM_REQUIRED_PIXEL_WIDTH_ALIGNMENT=1
QUL_PLATFORM_REQUIRED_IMAGE_ALIGNMENT=1
QUL_PLATFORM_DEFAULT_RESOURCE_PIXEL_FORMAT_ALPHA=ARGB8888
QUL_PLATFORM_DEFAULT_RESOURCE_PIXEL_FORMAT_OPAQUE=RGB565
QUL_COLOR_DEPTH=16
- Add
ucHeap=__HeapBase
preprocessor definition under C/C++ Build > Settings > Tool Settings > GNU Arm Cross C Compiler.Note: This enables FreeRTOS use the heap that is usually reserved for
std malloc
. Ensure that your project does not usestd mallocs
or relocate FreeRTOS heap. The current RA6 FreeRTOS platform port uses FreeRTOSpvPortMalloc()
, so it needs a sizable portion of RAM to work. You can change this behavior by overriding the functions in platform/mem-freertos.cpp.
- Edit script/fsp.ld and append the following code:
QulModuleResourceData : { . = ALIGN(4); __qspi_flash_start__ = .; *(QulModuleResourceData) } > QSPI_FLASH QulFontResourceData : { . = ALIGN(4); *(QulFontResourceData) } > QSPI_FLASH QulResourceData : { . = ALIGN(4); *(QulResourceData) . = ALIGN(4); __qspi_flash_end__ = .; } > QSPI_FLASH
- Edit platform/boards/renesas/ek-ra6m3g-common/platform_ek-ra6m3g.cpp to remove the
R_BSP_WarmStart()
function definition. This function is already defined in the src/hal_entry.cpp file generated by the IDE. - Edit src/hal_entry.cpp to insert the following code in the
R_BSP_WarmStart()
function definition. It enables the S1 button on the board.R_ICU_ExternalIrqOpen(&g_S1_irq_ctrl, &g_S1_irq_cfg); R_ICU_ExternalIrqEnable(&g_S1_irq_ctrl);
Note: This code should be inside the
BSP_WARM_START_POST_C
if block, right afterR_IOPORT_Open()
. - Edit qul_thread_entry.cpp and replace the existing code with the following:
/****************************************************************************** ** ** Copyright (C) 2022 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Quick Ultralite module. ** ** $QT_BEGIN_LICENSE:COMM$ ** ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see http://www.qt.io/terms-conditions. For further ** information use the contact form at http://www.qt.io/contact-us. ** ** $QT_END_LICENSE$ ** ******************************************************************************/ #include "qul_thread.h" #include "qul_run.h" void qul_thread_entry(void *pvParameters) { FSP_PARAMETER_NOT_USED(pvParameters); qul_run(); } static bool ledEvent = false; void sendCommandToAppThread(bool led1Status) { ledEvent = led1Status; xQueueSend(g_app_queue, &ledEvent, 0); }
The
qul_thread_entry()
function ensures that it gives the thread to Qt Quick Ultralite. The UI code calls thesendCommandToAppThread()
function to postled1Status
tog_app_queue
, and turn on or turn off the blue LED. - Edit app_thread_entry.cpp to replace the code with the following:
/****************************************************************************** ** ** Copyright (C) 2022 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Quick Ultralite module. ** ** $QT_BEGIN_LICENSE:COMM$ ** ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see http://www.qt.io/terms-conditions. For further ** information use the contact form at http://www.qt.io/contact-us. ** ** $QT_END_LICENSE$ ** ******************************************************************************/ #include "app_thread.h" extern void sendToUI(bool led1Data); void app_thread_entry(void *pvParameters) { FSP_PARAMETER_NOT_USED(pvParameters); bool led1State; while (true) { // Wait for an event from the user interface if (pdTRUE == xQueueReceive(g_app_queue, (void *) &led1State, portMAX_DELAY)) { bsp_io_level_t level; level = led1State ? BSP_IO_LEVEL_HIGH : BSP_IO_LEVEL_LOW; R_BSP_PinAccessEnable(); R_BSP_PinWrite(BSP_IO_PORT_04_PIN_03, level); // blue LED on EK-RA6M3 R_BSP_PinAccessDisable(); sendToUI(led1State); } } } static bool led1Level = false; extern "C" void s1_irq_callback(external_irq_callback_args_t *p_args) { FSP_PARAMETER_NOT_USED(p_args); R_BSP_PinAccessEnable(); uint32_t level = R_BSP_PinRead(BSP_IO_PORT_04_PIN_03); // blue LED on EK-RA6M3 R_BSP_PinAccessDisable(); led1Level = !(level & 0x01); xQueueSendFromISR(g_app_queue, &led1Level, NULL); }
The first line declares
sendToUI
extern symbol, which you defined while developing the application backend.Next, the
app_thread_entry()
function uses a simple while loop, waiting for an item ong_app_queue
. When it finds an item (abool
value) on the queue, it toggles (on/off) the blue LED1 based on the item value. Finally, it sends the change notification to the UI thread.The last function is the callback for s1 interrupt defined in the FSP configuration. It checks the LED1 status and adds the inverse value to the
g_app_queue
, to toggle the LED1 depending on its previous state.
Your application is now ready. Build and flash it to the RA6M3G board to test that everything works as intended. Next, you can try experimenting with the code. For example, configure an interrupt for the S2 button and implement a callback to toggle LED2 and update the LED's status in the UI.
Available under certain Qt licenses.
Find out more.