Showing posts with label IAR. Show all posts
Showing posts with label IAR. Show all posts

September 18, 2014

Project generator - building exported project

The build feature has been implemented in the last 2 days aka ProjectBuilder. This allows to build exported projects, which is useful for automated testing.

The building is currently supported for all tools there (IAR, uVision, Makefile), but IAR still has one bug, does not generate any output eventhough builds without errors.

Want to share with you, that I am currently adding CoIDE (only export, as it does not support building via command line). Should be completed this week.

Anyone out there using the project generator? What tool would you like to see there ? Eclipse? LPCExpresso? Kinetis Design Studio?

The real example is here https://github.com/0xc0170/project_generator_mbed_examples, using mbed SDK. I replaced mbed library by mbed SDK submodule, to stay up to date.
The example repository shows how are records written and how to use it with your own files (blinky demo).

August 29, 2014

Project generator - wiki pages on github

I am currently writing wiki pages for the project generator. If you are interested in the project, read it and provide feedback.
The link Project generator - Wiki pages [github.com/0xc0170/project_generator/wiki]

I am going to merge IAR options once I finish and test them, currently implementation on the branch. It takes longer time than uVision, as IAR has many separate options.
I finished the release of v0.1 this week, created a new tasks for v0.2.

My focus in the v0.2 will be on documentation, stabilize uVision, IAR and creating one generic Makefile for GCC toolchains.

March 30, 2013

Dynamic initialization C++ in IAR

I've been running my demo application only in KEIL for few days which I believe was huge mistake which reflected on me on Friday. When I finally run it in IAR. Once it loaded, first object's method ended up in a default isr handler with the hard fault. My debug session started. First problem I found, was one function was overwritting memory, that one was simple to catch once I found out which memory and what object is located right before overwritten data. Second one was a bit tougher to find out.

I decided to move local user-type objects to a global scope, which means before an application hits main function, global objects must be initialized. No problem with KEIL, but IAR did not do it.

This is quote from EWARM Development Guide (IAR) [3] which is quite comprehensive manual to understand many options it offers through command line options. But it does not provide details which might be handy.
When using the IAR C/C++ compiler and the standard library, C++ dynamic
initialization is handled automatically.


I though all right, how to track it down and see if dynamic allocation is really executed. Let's check map file of my application:

INIT TABLE
          Address     Size
          -------     ----
Zero (__iar_zero_init3)
    1 destination range, total size 0x2a7:
          0x1ffff420  0x2a7
Extra (__iar_cstart_call_ctors)

And here's ENTRY LIST of our interest:

__call_ctors            0x00004775   0x18  Code  Gb  cppinit.o [4]
__iar_cstart_call_ctors
                        0x00004ae5   0x20  Code  Gb  cmain_call_ctors.o [7]

A problem is, they are not invoked, startup function just takes care regular things (copying initialized data from ROM to RAM, .bss data, vector table). There's nothing with dynamic initialization. I placed breakpoint inside __call_ctors and it surprisingly was not reached. How to invoke __call_ctors function? What's it declaration? Exactly this details is not in any documentation provided in IAR doc folder (at least I was not able to find it there). Only one link on google was relevant, let's test it.

extern void * __iar_cstart_call_ctors(void *ptr);

No linker errors, correct declaration. Only one parameter, what it should be? The linker created following sections which are the one we are looking for (more info find in section C++ DYNAMIC INITIALIZATION [3] :

.init_array$$Base       0x00004d58          --   Gb  - Linker created -
.init_array$$Limit      0x00004d5c          --   Gb  - Linker created -
 
SHT$$INIT_ARRAY$$Base   0x00004d58          --   Gb  - Linker created -
SHT$$INIT_ARRAY$$Limit  0x00004d5c          --   Gb  - Linker created -
SHT$$PREINIT_ARRAY$$Base
                        0x00004d58          --   Gb  - Linker created -
SHT$$PREINIT_ARRAY$$Limit
                        0x00004d58          --   Gb  - Linker created -

Each section (INIT_ARRAY, PRE_INIT_ARRAY) contain array of pointers to initialization functions. [2] Let's invoke it in the end of an application's startup with a following line:

void *cpp_init = __section_begin(".init_array");
__iar_cstart_call_ctors(cpp_init);

That calls __call_ctors which initializes all global dynamic objects. Thus application works. An unanswered question is why it was not invoked automatically? I hope I'll come with an answer soon :)

References:
[1] cmain.s [http://code.google.com/p/sdp-firmwares]
[2] System V Application Binary Interface [sco.com/developers/gabi]
[3] EWARM Development Guide - IAR installation folder/arm/doc or online

March 24, 2013

Stack usage for ARM Cortex-M

I'll present how I used one of the methods to measure stack usage, not using any plugin, just debugger and memory window.

Methods to use:
1. IDE plugins (usually compiler and linker do the job)
2. Fill pattern (add small assembly routine in startup)
3. Take an address of the stack pointer in the main function, and in the most nested function (for a simple application usable)


IAR stack plugin [www.iar.com]
This document is targeted to IAR stack plugin. Although this did not work for the MCU I debugged.

Stack and Heap [www.iar.com]
What's stack, heap, methods explained briefly how to calculate stack usage in IAR. Methods applicable for other IDE's as well, not limited to IAR only.

Stack use in C and C++ [www.keil.com]
How to obtain stack usage in KEIL using callgraph (option --callgraph).
Here's callgraph output which I found on the internet, not needed to share mine:
Keil callgraph - an example [ftp.analog.com/pub/MicroConverter]

Using indirect calls (function pointers) make this method unreliable, same for IAR stack plugin, where it can be added #pragma calls, but what if an application using another library, that's too much changes to do, more simple approach is in a following paragraph presented, a filling memory for a stack with a pattern and show how low it gets.

KEIL stack initialize routine [www.keil.com/forum]
Stack initialization routine, which I only accustomed to Thumb-2. Here's the code used on Cortex-M0. Label __user_initial_stackheap is located in assembly file for your board. Just run your application for a while and check the memory window to obtain the lowest address of the last character of your pattern (in our case it's AA (char values)). Calculate the subtraction which gives your application stack usage.

__user_initial_stackheap
    LDR     R0, =Stack_Mem
    LDR     R1, =Stack_Size           
    LDR     R2, =0xAAAAAAAA
fill             
    STR     R2, [R0]
    ADDS    R0,#4
    SUBS    R1,#4                     
    BNE     fill

This also can be added in assembly file which is used in IAR or any other IDE, just replace Stack_Mem symbol (beginning of the stack) and Stack_Size (size of the stack).

January 2, 2013

IAR eclipse plugin (bookmark)

I was suprised when I read today IAR integrated eclipse plugin. Fully integrated IAR C-spy debugger. More information on IAR website.