element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Embedded and Microcontrollers
  • Technologies
  • More
Embedded and Microcontrollers
Blog Renesas RX65 Envision Kit - part 12: RAM Use with GCC ToolChain
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Embedded and Microcontrollers to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 3 Jan 2020 5:46 PM Date Created
  • Views 3436 views
  • Likes 6 likes
  • Comments 14 comments
  • rx65n
  • gcc
  • renesas
  • linker
Related
Recommended

Renesas RX65 Envision Kit - part 12: RAM Use with GCC ToolChain

Jan Cumps
Jan Cumps
3 Jan 2020

Goal: This post tries to explain what objects are placed where in RAM when using the GCC toolchain.

It's intended as self-documentation. When using the LCD, you need large continuous chunks of memory for the frame buffers.

Memory is limited on controllers. Continuous large blocks even more so.

To be able to reserve these buffers, it's useful to understand where the linker places code, data, stacks and housekeeping blocks.

Knowing their position and size - and knowing if you can move things without side effects - are the hooks to eek out maximum available memory for buffers and custom logic.

image

Not a goal of this post:  Explain the non-RAM ranges or how to try and save data or code size during development.

 

RX65N RAM

 

The controller has two RAM ranges.

 

on-chip RAMSize (bytes)Start addressEnd address
Standard RAM

0x00040000 / 262144

0x000000000x0003FFFF
Expansion RAM

0x00060000 / 393216

0x008000000x0085FFFF
Total RAM0x000A0000 / 655360

 

The first range is available on all RX65N devices. The Expansion RAM is dependent on the particular device.

The R5F565NEDDFB on the Envision kit has the full 640K.

image

source: ammended memory map from the Renesas RX65N datasheet

 

640K is plenty. However, because the memory is not continuous, reserving two 130560130560 blocks (the buffer size for a 480 wide * 272 high * 2 bytes for colour) will need proper care.

It's not a desperate situation image - 2 blocks fit in the expansion RAM. But for a larger display, they wouldn't.

 

What Goes to RAM

 

The objects that will go to RAM are:

  • the start address and top pointer of the heap
  • the two stacks (istack for interrupts, ustack for user)
  • data (yours and that from linked in libraries)
  • Dynamically allocated memory will go to the heap. The heap in this controller is of a fixed size in this RAM region and grows up towards its tail.

 

image

image: the Smart Configurator in e2 studio: define the istack, ustack and heap sizes

 

The linker command file and related assembler file generated by the project wizard and the Smart Configurator place all of that in the Standard RAM area.

 

The Linker Memory Areas

 

The GCC linker command file is where you define what is placed where by the link and load process.

You define what blocks of memory are available, where they are located and the size (if your controller supports it, also if you can read/write/execute in that area). You can also use it to define blocks that aren't available.

Then you define what parts of your code go to those areas.

Typically, you have memory regions, output + input sections and assignments.

  • region: an area of memory. It has address and size.
  • output section: a container that can be filled with code or data, and that's placed within a region, either at the next available address or at a fixed point
  • input section: a named container, belonging to an output section, where that GCC toolchain assign code and data to. It's complex image but your variables and code will be assigned to a particular input section.
    Input sections are then placed within the output section they are assigned to.

You could think of input sections as data that's inputted (gathered) into the output section. The output sections are then outputted (placed) to memory regions.

Assignments are labels that are internally used by the toolchain, but also available to you if you want to assign a memory area to a particular address without hardcoding that address in your code.

 

For our controller, the memory areas are:

image

image: The 4 ranges defined in the linker file

 

I'm ignoring OFS and ROM in this post. (just for info: your code goes to ROM (flash) and is executed from there)

The RAM and RAM2 blocks are the standard and expansion RAM. This is our focus.

note: the loader file generated by e2 studio's project wizard has a bug. It places expansion ram on ox0008000 instead of 0x00800000. Fix that manually after generating a project.

 

View What's Where in RAM

 

Eclipse has a graphical editor that helps you lay out the memory and its use. That includes a graphic overview of the memory.

 

image

image: the Eclipse linker file viewer

 

That will give you an overview of how the linker will place objects. What it will not show is the complete picture with the stacks allocated.

To see that, you can use the GCC linker's map file, and the handy AMAP viewer.

 

image

image: AMAP viewer showing the sections in a Renesas RX65N GCC map file

 

The map file is generated during the build process, so you need a compilable program (I just created a empty Renesas C program for the GCC toolchain, with Smart Configurator support).

The advantage is that it has factual data about how much space is taken by runtime library data, stacks, data, and their exact locations.

 

Objects Placed in RAM

 

As seen earlier, all objects that go to RAM are placed in the standard RAM area by the default linker script. RAM2 is not used by default. So the linker will not place anything in expansion RAM.

The standard RAM region has a number of output sections. Some consecutive, some at a fixed address:

image

image: output sections assigned to standard RAM

 

The tree board startup sections (r_bsp_*) are placed on fixed addresses. All the rest are placed where the linker sees fit within the RAM region.

A good explanation is available from wikipedia.

  • .data contains initialised global and static variables, and the heap start and end points.
  • .gcc_exec contains nothing
  • .bss contains the uninitialised global and static variables and the heap.
  • the stacks contain values pushed on the stack, such as parameters and variables declared within a function.
    They have a fixed size set in the startup assembler code. They are set to NOLOAD so won't be initialised.
  • .r_bsp_NULL, I believe is used for the board upbring code. It reserves 100 bytes.
    For some reason it's not visible in the AMAP viewer but it's the area between end of .bss and start of the stacks. It's content is copied from a ROM address at startup.

 

For a program built without debug information, yet without optimisation, here's the content of the RAM region:

 

image

image: extract from the AMAP tool showing RAM region objects.

 

I did a first attempt in fixing LCD buffers at a fixed free spot in Renesas RX65 Envision Kit - part 10: Reserve LCD Frame Buffer in Expansion RAM with GCC.

That was done with the knowledge that the expansion RAM was unused.

With the info of this post at hand, I should be able to come up with a good strategy to allocate buffers for the LCD display in standard RAM too...

  • Sign in to reply

Top Comments

  • Andrew J
    Andrew J over 5 years ago +2
    For the LCD ram buffers, it’s worth bearing in mind that when using emWin, you will want two of these buffers (i.e. 2 x 261,120 bytes) to operate the screen without flickering, depending upon the frequency…
  • Jan Cumps
    Jan Cumps over 5 years ago +1
    Eclipse has a reasonable good map viewer too: You can open it via Window -> Show View -> Other -> Memory usage. It 'll load the map file of the currently active build configuration. A particularly useful…
  • Jan Cumps
    Jan Cumps over 5 years ago in reply to Andrew J +1
    Andrew J wrote: For the LCD ram buffers, it’s worth bearing in mind that when using emWin, you will want two of these buffers (i.e. 2 x 261,120 bytes) to operate the screen without flickering, ... Did…
Parents
  • Andrew J
    Andrew J over 5 years ago

    For the LCD ram buffers, it’s worth bearing in mind that when using emWin, you will want two of these buffers (i.e. 2 x 261,120 bytes) to operate the screen without flickering, depending upon the frequency of changes to the screen your app makes.  Without using multi-buffering, I found that the screen was not satisfactorily usable with emWin.  See post 7 of my review.  The alternative is to time the screen updates yourself based on vsync, something I didn’t try!

     

    These are really useful follow up posts, thanks.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 5 years ago in reply to Andrew J

    Andrew J  wrote:

     

    For the LCD ram buffers, it’s worth bearing in mind that when using emWin, you will want two of these buffers (i.e. 2 x 261,120 bytes) to operate the screen without flickering, ...

    Did you get that buffer size from documentation?

     

    I tried to understand the emWin and LCDConfig code and there it says, as size per buffer:

    BYTES_PER_LINE = (16 * 480) / 8 = 960

    LINE_OFFSET = ((960 + 63) / 64) * 64 = 960

    BYTES_PER_BUFFER = 960 * 272 = 130560 see later  261120

     

    I'll try my code (https://www.element14.com/community/groups/embedded/blog/2020/01/02/renesas-rx65-envision-kit-part-11-port-emwin-to-gcc-… ) with the bigger buffer and see if that works ...

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Andrew J
    Andrew J over 5 years ago in reply to Jan Cumps

    Yes, from the emWin documentation - page 1034 gives the size calculation per buffer (XSIZE * YSIZE * BitsPerPixel) / 8.  In LCDConf.c (at least in mine!) it has:

     

    //

    // Physical display size

    //

    #define XSIZE_PHYS 480

    #define YSIZE_PHYS 272

     

    //

    // Color depth

    //

    #define BITS_PER_PIXEL 16  // Allowed values: 1, 4, 8, 16, 32

    ....

      #define NUM_BUFFERS      2

     

    so (480 * 272 * 16) / 8 = 261120 per buffer

     

    The only line to change in LCDConf.c should be that #define to set the number of buffers.

     

    It's worth reading through chapter 23 in that manual as it explains it pretty well and covers what to do if you can't use consecutive memory blocks.  Whether the manual buffer size calc is correct, or the calculation in LCDConf.c is I don't actually know!  TBH when I used multi-buffering I didn't need to do anything in terms of memory configuration as it worked without it.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 5 years ago in reply to Andrew J

    The standard examples that use the CC-RX toolchain have two buffers reserved .

    One buffer in the standard memory, starting at 0x100. No size given, but nothing else is put in that memory

    One in the expansion memory, starting at 0x00800000. They start loading any other data after 0x00840000. There are no guardrails though.

    I could try to do the same size in my code, just to test it out ...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • Jan Cumps
    Jan Cumps over 5 years ago in reply to Andrew J

    The standard examples that use the CC-RX toolchain have two buffers reserved .

    One buffer in the standard memory, starting at 0x100. No size given, but nothing else is put in that memory

    One in the expansion memory, starting at 0x00800000. They start loading any other data after 0x00840000. There are no guardrails though.

    I could try to do the same size in my code, just to test it out ...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube