You can refer to the previous setup steps here.
- Install the RL78 T04-FDL Library you have previously downloaded. During the installation, select to install for the IAR Compiler v2.10 (or later) on the project folder (
$PROJ_DIR$
). The installer will create a folder namedFDL\IAR_210
(or similar).
-
In the IDE, go to the Project → Options → Linker → Config → Linker configuration file.
-
Tick Override default and select the corresponding trio_lnk<device>.icf for the target device in use. In this example, we are using the R5F104LEA target, so the trio_lnkR5F104xE.icf will be selected:
$PROJ_DIR$\ewrl78-linker-config-flashlibs\trio_lnkR5F104xE.icf
-
In the same configuration tab, append
__RESERVE_T04_FDL=1
to the Configuration file symbol definition, as below:
- In Linker → Library → Additional libraries, add the following line:
$PROJ_DIR$\FDL\IAR_210\lib\pfdl.a
- In C/C++ Compiler → Preprocessor → Additional include directories, add the following 2 lines:
$PROJ_DIR$\applilet3_src
$PROJ_DIR$\FDL\IAR_210\lib
Note Each target device has its own memory reservation requirements. In order to get the best out of the trio configurations, please choose the appropriate
trio_lnk<device>.icf
linker configuration for the actual device you are using in your project, directly from the repository you cloned inside the project's directory ($PROJ_DIR$\ewrl78-linker-config-flashlibs
).
Now it is time to update the application with this example source code below that exercises some of the library's capabilities.
- Open the
Renesas_AP\cg_src\r_main.c
and insert the pico FDL headers between the generated comment guards for the "user code for include", as below:
...
/* Start user code for include. Do not edit comment generated here */
/* Pico FDL headers */
#include "pfdl.h"
#include "pfdl_types.h"
/* End user code. Do not edit comment generated here */
#include "r_cg_userdefine.h"
...
- In the Global variables and functions section add the
WriteString[]
andReadString[]
global arrays between the comment guards, as below:
/********************************...**
Global variables and functions
*********************************...**/
/* Start user code for global. Do not edit comment generated here */
#define STRING_SZ 16
pfdl_u08 WriteString[STRING_SZ] = "0123456789ABCDEF";
pfdl_u08 ReadString[STRING_SZ];
/* End user code. Do not edit comment generated here */
- Replace the original
main()
function with the following code snippet:
void main(void)
{
R_MAIN_UserInit();
/* Start user code. Do not edit comment generated here */
/* pico FDL local vars */
pfdl_descriptor_t PFDL_descriptor;
pfdl_request_t PFDL_request;
pfdl_status_t PFDL_status;
/* Open the pico FDL */
PFDL_descriptor.fx_MHz_u08 = 32;
PFDL_descriptor.wide_voltage_mode_u08 = 0;
PFDL_Open (&PFDL_descriptor);
/* Check if the Data Flash region is blank */
PFDL_request.index_u16 = 0x0000; // Rel. 16-bit addr @ 0xF1000
PFDL_request.command_enu = PFDL_CMD_BLANKCHECK_BYTES;
PFDL_request.bytecount_u16 = STRING_SZ;
PFDL_status = PFDL_Execute(&PFDL_request);
while (PFDL_BUSY == PFDL_status)
{
PFDL_status = PFDL_Handler();
}
/* If not empty, erase the entire Data Flash block (1KB) */
if (PFDL_OK != PFDL_status)
{
PFDL_request.index_u16 = 0; // Block number @0xF1000
PFDL_request.command_enu = PFDL_CMD_ERASE_BLOCK;
PFDL_request.bytecount_u16 = 0x0000U;
PFDL_status = PFDL_Execute(&PFDL_request);
while (PFDL_BUSY == PFDL_status)
{
PFDL_status = PFDL_Handler();
}
}
/* Write "WriteString" to the Data Flash */
if (PFDL_OK == PFDL_status)
{
PFDL_request.index_u16 = 0x0000; // Rel. 16-bit addr @0xF1000
PFDL_request.command_enu = PFDL_CMD_WRITE_BYTES;
PFDL_request.data_pu08 = WriteString;
PFDL_request.bytecount_u16 = STRING_SZ;
PFDL_status = PFDL_Execute(&PFDL_request);
while (PFDL_BUSY == PFDL_status)
{
PFDL_status = PFDL_Handler();
}
}
/* Performs internal verify operation to check data retention */
if (PFDL_OK == PFDL_status)
{
PFDL_request.index_u16 = 0x0000; // Rel. 16-bit addr @0xF1000
PFDL_request.command_enu = PFDL_CMD_IVERIFY_BYTES;
PFDL_request.bytecount_u16 = STRING_SZ;
PFDL_status = PFDL_Execute(&PFDL_request);
while (PFDL_BUSY == PFDL_status)
{
PFDL_status = PFDL_Handler();
}
}
/* Read the Data Flash, store into "ReadString" */
if (PFDL_OK == PFDL_status)
{
PFDL_request.index_u16 = 0x0000; // Rel. 16-bit addr @0xF1000
PFDL_request.command_enu = PFDL_CMD_READ_BYTES;
PFDL_request.data_pu08 = ReadString ;
PFDL_request.bytecount_u16 = STRING_SZ;
PFDL_status = PFDL_Execute(&PFDL_request);
while (PFDL_BUSY == PFDL_status)
{
PFDL_status = PFDL_Handler();
}
}
/* Close the pico FDL */
PFDL_Close();
/* The infinite loop */
for (;;)
{
}
/* End user code. Do not edit comment generated here */
}
-
Go to the Project Options, General Options → Target → Device and choose the desired part number.
-
In the project options, Debugger → Setup → Driver and choose the emulator you have. Typically TK, E1 or E2 Lite depending on the emulator in use.
-
Start a new C-SPY debugging session by choosing Project → Download and Debug. If necessary, choose the right Power supply voltage for the Target system in the Emulator Hardware Setup window. In this case, as the LVD was set to
3.63V
, the choosen voltage was5V
. -
Tick the Erase flash before next ID check checkbox.
-
Click OK to close the Hardware Setup window.
-
By default, C-SPY will execute the application until it reaches a breakpoint in the beginning of the
main()
function. Insert a breakpoint near thePFDL_Close()
call in the end of themain()
function. -
Activate the Watch window by selecting View → Watch → Watch1. This window will allow you to add expressions to watch the contents of global variables.
-
<Click to add>
ReadString
andWriteString
. -
Hit Go (F5) on the Debug toolbar.
-
In the Watch1 window, verify if the contents of the variables
ReadString
andWriteString
match.
Note The data written into the Data Flash can also be directly seen by activating the Memory Window. In this case, select View → Memory → Memory1 and Go to the address
0xF1000
. This will take the Memory1 window straight to the Data Flash initial address.