Keil settings for Panda II

Hello, In order to use Keil MDK compiler for pandaII : I follow the tutorial for RLPLite http://wiki.tinyclr.com/index.php?title=RLPLite_Demo

I would like to setup the linker to correct values, but I am not sure how to correctly fill them for pandaII, since the tutorial provides adress for Hydra :

More, I chose the device NXP->LPC2387 (instead of Atmel->AT91SAM9RL64 as in the tutorial)
According to the linker script provided with RLP exemple with yagarto

MEMORY
{
  SDRAM (wx) : ORIGIN = 0x40000440, LENGTH = 0x000027FC
}

My guess is that the R/O Base is 0x40000440
But so what is the R/W Base?
Are there other things I should modify in this tutorial to use Keil with panda II ?

Rgds

i was just about to post the exact same question.

it seems that we have lot in commom. Do you participate to eurobot too?

For the Hydra, RLP has a 1 MB RLP region and we split the R/O Base and the R/W Base right in half. You could do something similar by splitting the length of 0x27FC in half to 0x13FE and add it to the base of 0x40000440 to get 0x4000183E as the R/W Base. You can adjust the R/O Base size to match what you need based on your code requirements meaning that you can adjust the ratio between the R/O and R/W bases.

1 Like

Thanks a lot Aron.
Indeed, adresses should be aligned on 4bytes values : so R/W base should be 0x4000183C for ex.
How can we figure how much R/O space we need? (I guess, but I am not sure splitting in two equal parts should be OK for my needs)

Determining the size of the R/O size is dependent on the application itself. The only suggestion I can give is to look at the map file that is created after the compile and look for the R/O region to see how much memory is used for that region then adjust the R/O base size accordingly.

1 Like

Aron->Yes, the end of the .map file helps a lot :

I have a new issue on my way to use keil on panda :
At the moment I only know how to generate .bin files with Keil.
And I only know how to manage .elf files with RLP on panda …
My goal is to save memory, so I guess the best way should be to manage .bin on panda firmware… I probably miss something but it seems to me that it is only possible with RLPLite and not RLP?

Edit : I see that keil generated axf files, wich should be used as regular .elf . source : http://www.tinyclr.com/forum/topic?id=7156

Pacman->Glad that this topics helps you too. No, I am not participatingt to eurobot .

The *.axf file that is created is the same as an *.elf file. Try to plug in that file even if you need to rename it *.elf but first try it as an *.axf.

For now, I did not sucess to get it work with the original .axf file neither if i rename ut in .elf file. I get an unmanaged exception in GHIElectronics.NETMF.Native.dll when calling RLP.InitializeBSSRegion(elf_file); (code always the same that was working previously with yagarto compiler)
this code


 public static void Main()
        {

      
        //Init RLP
           int ret = 0;
            RLP.Enable();
            RLP.Unlock("C.............. ");
            Debug.GC(true);
            byte[] elf_file = Resources.GetBytes(Resources.BinaryResources.RLP);
            if (elf_file == null)
            {
                Debug.Print("Echec de chargement du fichier binaire");
                return;
            }
            RLP.LoadELF(elf_file);
            RLP.InitializeBSSRegion(elf_file); //exception HERE
            RLP.Procedure PID_c;
            PID_c = RLP.GetProcedure(elf_file, "PID_c");
 // We don't need this anymore
            elf_file = null;
            Debug.GC(true);

}

produces this error :

[quote]
#### Exception System.Exception - 0xffffffff (1) ####
#### Message:
#### GHIElectronics.NETMF.Native.RLP::FindSymbol [IP: 0000] ####
#### GHIElectronics.NETMF.Native.RLP::InitializeBSSRegion [IP: 0006] ####
#### GHIElectronics.NETMF.Native.RLP::InitializeBSSRegion [IP: 000a] ####
#### PrecellysV3Panda.Program::Main [IP: 0037] ####
Une exception de première chance de type ‘System.Exception’ s’est produite dans GHIElectronics.NETMF.Native.dll
Une exception non gérée du type ‘System.Exception’ s’est produite dans GHIElectronics.NETMF.Native.dll [/quote]

I try to comment the InitializeBSSRegion (wich means BSS region will not be reset to zero) and then I get a similar error when calling the GetProcedure function…
PID_c = RLP.GetProcedure(elf_file, “PID_c”);

->I suspect that RLP functions don’t find what they want find in my .axf / .elf file, but I have no vision on what they are looking for…and I am not able to load functions directly from their hex address with RLP in the same way as GetProcedure from RLPLite… Is it possible to use those RLPLite-like features on Panda?

->I am (unsucessfully for now) looking around the keil compiler options and trying to understand how binary files are parsed by InitializeBSSRegion function…

Correct. Not sure how you can rename your regions in keil so the easiest option is to comment this out and not to use pre-initialized variable.

For example:


// this is no good
int i=5;// don't pre initialize any variables.
void Foo()
{
 if(i = ?something?)
    do something
}

// this is good
int i;
void Foo()
{
  i=5;//initialize when code runs
}

Yes Gus, but if I comment //RLP.InitializeBSSRegion(elf_file); I get a similar exception
on RLP.GetProcedure

[quote] #### Exception System.Exception - 0xffffffff (1) ####
#### Message:
#### GHIElectronics.NETMF.Native.RLP::GetProcedureAddress_Helper [IP: 0000] ####
#### GHIElectronics.NETMF.Native.RLP::GetProcedure [IP: 0005] ####
[/quote]

Here is the C# code:


            RLP.Enable();
            RLP.Unlock("C...............");
            Debug.GC(true);
            //byte[] elf_file = Resources.GetBytes(Resources.BinaryResources.RLP_PID);
            byte[] elf_file = Resources.GetBytes(Resources.BinaryResources.RLP);
            if (elf_file == null)
            {
                Debug.Print("Echec de chargement du fichier binaire");
                return;
            }

            RLP.LoadELF(elf_file);
            //RLP.InitializeBSSRegion(elf_file);
            RLP.Procedure testProcedure_c;
            testProcedure_c = RLP.GetProcedure(elf_file, "RLP_MemSet"); //exception HERE

=>The problem is that in the file generated by keil compiler, if I remove debug infos, the .axf file does NOT include the name of the function , so RLP functions RLP.GetProcedure(elf_file, “function_name”); can’t magically get the procedure if I don’t give the adress!!!
With .elf generated with yagarto it works function name is present in the .elf file
With .axf generated with keil and debug options compiled, it works function name is present un the .axf file, but this file is biggest than the one generated by yagarto !!! (and why a want to use keil is for decreasing this size of file)

The C code from RLPLite tutoral (link at startup of this topic), with “int notinit = 123;” commented:


//////////////////////////////////////////////
// Copyright (c) GHI Electronics
/////////////////////////////////////////////
 
//////////////////////////////////////
// Important note: Global variables are not initialized
// For example, this variable below does not have 123 in it. It contains a random number.
//int notinit = 123;
/////////////////////////////////////
 
 #include "string.h"
 
int RLP_MemSet(void* par0, int * par1, unsigned char * par2)
{											
	int i=0;
 
	// the passed arguments	 /////
	unsigned char * ByteArray = par0;
	unsigned int length = par1[0];
	unsigned char value = par2[0];
	//////////////////////////////
 
 
	for(i=0;i<length;i++)
	{
		 ByteArray[i] = value;
	}
 
 
 
	return i;	
}
 
 
int RLP_MemSetStdLib(void* par0, int * par1, unsigned char * par2)
{
	// the passed arguments	 /////
	unsigned char * ByteArray = par0;
	unsigned int length = par1[0];
	unsigned char value = par2[0];
	//////////////////////////////
 
 
	memset(	ByteArray, value, length);
 
	return length;
}

int main()
{
	int i;

	unsigned char data[50];
	int value[1]={0x55};
	unsigned char length[1]= {50};

	i = RLP_MemSet(data, value, length);
	i = RLP_MemSetStdLib(data, value, length);

	while(1);
}

Interesting! Please let us know if you figured out keil so we can add some notes to docs.

I get some progress whith unchecking the “debug information” box and forcing the linker (but not ASM neither C++ compiler ) to add debug informations with --debug flag (wich overwrites the --nodebug automatically added by µvision keil interface)

I think it is not yet the good solution because the debug infos certainly include a lot of unnecessary data (file is big compared to the one generated with yagarto)… I look for the right linker options just providing the info that I need…
Indeed, using the .bin file wich is extremely reduced in size should definitively be the best approach. Is it really not possible to do that with PandaII? (uising RLPLite features?)

With this tip, my .axf file go from 6028 bytes to 3576

-“debug info” box unchecked : .elf file is 1408 bytes (NOT working)
-“debug info” box checked (ASM and C++ and Linker debug options enabled) : .axf file is 6028bytes(working)
-“debug info” box unchecked and --debug flag added on linker : .afx file is 3576 bytes(working)
-“debug info” box unchecked and --debug flag added on linker: .bin file is 208 bytes(NOT working)
-same code compiled with yagarto : .elf file is 945 bytes (working)

I am a bit disapointed because the .axf files generated with keil are always bigger than the ones generated with yagarto, even with uLib optimisation…
Indeed, I am currently searching in linker documentation the appropriate option : http://www.keil.com/support/man/docs/armlink/armlink_CIHJEAFC.htm
If someone has some experience with linkers and the options, I would appreciate any help, beacause I don’t want to test every option!

Pacman-> Did you get some success with Keil and Panda?

Okay, I am really disapointed with my 32k-limited experience : I probably miss something but I am totally unable to take benefit of this tool compared to yagarto since all .elf /.afx files generated with keil are bigger than with yagarto, or unusable with RLP…

My original goal was to reduce the size of .elf files generated from yagarto toolchain. My conclusions are that:
-Only .bin give smaller files, but we can’t use them with RLP on Panda…
-A simple (then good) solution to reduce size is to keeping yagarto but using the strip utility (provided with yagarto) after build process should decrease the size of .elf file (in my case 945 to 919 bytes and 10352 to 7474bytes !!!)

If someone figured out how to use properly Keil MDK with panda, I am highly interested. For my part, I continue to work with yagarto…

Edit : I have some hope to reduce size again : I could strip with yagarto tools the .afx generated by keil to remove unusefull debug info…but during stripping I get the warning
"allocated section `ER_RW’ not in segment" and functions are not working correctly…

For uVision4 did you manually change the optimization level? That level is set on the C/C++ tab on the Options for Target dialog box. The options are at the center of the box.

Yes, I have tried -O0 to -O3 and the size is changing but always too big.

Indeedn with biggest code, the results with my Keil setup (7940bytes) are quite similar (but bigger) to yagarto (7474bytes)
The issue is that I don’t find how to keep the essential info in the .axf file without keeping the --debug flag on link.

i have not been able to make it working with Keil so i m now working with the RLP Visual Studio template.