Skip to content

Latest commit

 

History

History
154 lines (117 loc) · 6.78 KB

t01-fsl.md

File metadata and controls

154 lines (117 loc) · 6.78 KB

Project Setup Example for T01-FSL

You can refer to the previous setup steps here.

  • Install the RL78 T01-FSL 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 named FSL\IAR_210 (or similar).

Linker configuration

  • In the IDE, go to the ProjectOptionsLinkerConfigLinker 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_T01_FSL=1 to the Configuration file symbol definition, as below:

T04 Linker Configuration

  • In LinkerLibraryAdditional libraries, add the following line:
$PROJ_DIR$\FSL\IAR_210\lib\fsl.a
  • In C/C++ CompilerPreprocessorAdditional include directories, add the following 2 lines:
$PROJ_DIR$\applilet3_src
$PROJ_DIR$\FSL\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).

Example source code

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 FSL 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 */
/* FSL headers */
#include "fsl.h"
#include "fsl_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 WriteStringFAR[], WriteStringNEAR[] and ReadString[] between the comment guards, as below:
/********************************...**
Global variables and functions
*********************************...**/
/* Start user code for global. Do not edit comment generated here */

#define FSL_BLOCK_SIZE   (0x0400U)

/* Set the FSL BLOCK (1KB) address within the mirror-able region */
#define FSL_BLOCK_ADDR   (0x010000U - 8U*FSL_BLOCK_SIZE)
#define FSL_BLOCK_SLOT   (FSL_BLOCK_ADDR/FSL_BLOCK_SIZE)

/* The FSL BLOCK will be mirrored on the Near Area */ 
#define FSL_BLOCK_ADDR_MIRRORED  (FSL_BLOCK_ADDR | 0xF0000U)

#define STRING_SZ 16
fsl_u08 WriteString[STRING_SZ] = "0123456789ABCDEF";

/* Access the data directly from the Code Flash (24-bit __far address) */
#pragma location = FSL_BLOCK_ADDR
__root __far const fsl_u08 ReadStringFAR[STRING_SZ];

/* Access the data from the Mirror Area (16-bit __near address - more efficient access!) */
#pragma location = FSL_BLOCK_ADDR_MIRRORED
__root __near __no_init fsl_u08 ReadStringNEAR[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 */
    
    /* FSL local vars */
    fsl_descriptor_t FSL_descriptor;
    fsl_write_t      FSL_wr;
    fsl_u08          FSL_status;

    /* Initiate the FSL library */
    FSL_descriptor.fsl_flash_voltage_u08 = 0x00;
    FSL_descriptor.fsl_frequency_u08 = 32;
    FSL_descriptor.fsl_auto_status_check_u08 = 0x01;
    FSL_status = FSL_Init((__far fsl_descriptor_t*)&FSL_descriptor);
    if (FSL_OK != FSL_status)
    {
        while(1);
    }
    FSL_Open();
    FSL_PrepareFunctions();

    /* Erases the FSL_BLOCK_SLOT contents */
    FSL_status = FSL_Erase(FSL_BLOCK_SLOT);
    while (FSL_BUSY == FSL_status)
    {
        FSL_status = FSL_StatusCheck();
    }

    /* Writes "WriteString" to the FSL_BLOCK_ADDR */
    FSL_wr.fsl_data_buffer_p_u08 =  WriteString;
    FSL_wr.fsl_word_count_u08 = STRING_SZ/4; // 32-bit aligned writes
    FSL_wr.fsl_destination_address_u32 = FSL_BLOCK_ADDR;
    FSL_status = FSL_Write(&FSL_wr);
    while (FSL_BUSY == FSL_status)
    {
        FSL_status = FSL_StatusCheck();
    }

    /* Closes the FSL */
    FSL_Close();

    /* The infinite loop */
    for (;;)
    {
    }
    /* End user code. Do not edit comment generated here */
}

Configuring and debugging the project

  • Go to the Project Options, General OptionsTargetDevice and choose the desired part number.

  • In the project options, DebuggerSetupDriver 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 ProjectDownload 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 was 5V.

  • 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 the FSL_Close() call in the end of the main() function.

  • Activate the Watch window by selecting ViewWatchWatch1. This window will allow you to add expressions to watch the contents of global variables.

  • <Click to add> ReadStringNEAR, ReadStringFAR and WriteString.

  • Hit Go (F5) on the Debug toolbar.

  • In the Watch1 window, verify if the contents of the variables ReadString and WriteString match.

Note The data written into the Code Flash can also be directly seen by activating the Memory Window. In this case, select ViewMemoryMemory1 and Go to the address &ReadStringFAR.

T01-FSL Memory1 View

The same data will be also available from the Near Memory (0xF0000-0xFFFFF), which provides a computationally cheaper way of accessing the same data. This area is addressable by 16-bit pointers. Activate a new Memory window by selecting ViewMemoryMemory2 and Go to the address &ReadStringNEAR to visit the Mirrored Data.

T01-FSL Memory2 View

< ICF Trio documentation page