Jump to content
Sign in to follow this  
Maccle

Why am i unable to place code in custom ROM (SECRET_IROM1 )section?

Recommended Posts

Posted (edited)

I am trying to place a variable named secret_key at location 0x08002000 in STM32Nucleo-board which has STM32L476RG(www.kynix.com/Parts/158001/STM32L476RGT6.html) on board with 1MB flash.

Question 1: Why am i unable to place code in custom ROM (SECRET_IROM1 )section?
Question 2: What is the mistake i am doing?

I am still newbie to Linker topic.

I am able to do it(still do not undestnad, why other RO section also follows my new address of secret_key variable) if i define the address which is in the default section for RO in the scatter file. If i create a new section, mapping is not happening. I can see the address assigned as expected but the value of the secret_key is not visible at that location.

below image shows what happens when i declare the address out of range from the default section.

Code section where variable is declared:

unsigned long long int array4[6]={0};
unsigned long long int array[6]={12};

unsigned long long int arra2[4] = {0x1111111111111111,0x2222222222222222,0x3333333333333333,0x4444444444444444};
const long secret_key[3] __attribute__((section(".ARM.__at_0x8001800"))) = {0xABABABAB,0xCDCDCDCD, 0xEFEFEFEF};
extern int addsum(int, int);

int main()
       {
    long long int array3[100] = {1,2,3,4,5,6,7};
    array[1] = arra2[1] - array[0]+array3[1]*2+array3[2]*2+addsum(array[1],array[2])+array4[2]+(int)secret_key[0];
    while(1);
}

Memory map below:

dxqSA.jpg

 

Scatter file contents below:

; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************

LR_IROM1 0x08000000 0x00100000  {    ; load region size_region
  ER_IROM1 0x08000000 0x00002000  {  ; load address = execution address
   *.o (RESET, +First)
   *(InRoot$$Sections)
   .ANY (+RO)
  }

  SECRET_IROM1 0x08002000 0x00000030  {  ; load address = execution address
  *(.ARM.__at_0x8001800) ; secret key
  }

  RW_IRAM1 0x20000000 0x00000100  {  ; RW data
   project2.o (+RW)
   }

  RW_IRAM2 0x20000100 0x00000100  {  ; RW data
   project2.o (+ZI)
   }

  RW_IRAM3 0x20000200 0x00000300  {  ; RW data
   project.o (+ZI)   
  }

  RW_IRAM4 0x20000500 0x00000200  {  ; RW data
   project.o (+RW)   
  }

  RW_IRAM5 0x20000700 0x00001000  {  ; RW data
   .ANY (+RW,+ZI)   
  }
}

Second case: where it doesn't work

Code here:

unsigned long long int array4[6]={0};
unsigned long long int array[6]={12};

unsigned long long int arra2[4] = {0x1111111111111111,0x2222222222222222,0x3333333333333333,0x4444444444444444};
const long secret_key[3] __attribute__((section(".ARM.__at_0x8002100"))) = {0xABABABAB,0xCDCDCDCD, 0xEFEFEFEF};
extern int addsum(int, int);

int main()
       {
    long long int array3[100] = {1,2,3,4,5,6,7};
    array[1] = arra2[1] - array[0]+array3[1]*2+array3[2]*2+addsum(array[1],array[2])+array4[2]+(int)secret_key[0];
    while(1);
}

associated scatter file here:

; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************

LR_IROM1 0x08000000 0x00100000  {    ; load region size_region
  ER_IROM1 0x08000000 0x00001800  {  ; load address = execution address
   *.o (RESET, +First)
   *(InRoot$$Sections)
   .ANY (+RO)
  }

  SECRET_IROM1 0x08002100 0x00000030  {  ; load address = execution address
  *(.ARM.__at_0x8002100) ; secret key
  }

  RW_IRAM1 0x20000000 0x00000100  {  ; RW data
   project2.o (+RW)
   }

  RW_IRAM2 0x20000100 0x00000100  {  ; RW data
   project2.o (+ZI)
   }

  RW_IRAM3 0x20000200 0x00000300  {  ; RW data
   project.o (+ZI)   
  }

  RW_IRAM4 0x20000500 0x00000200  {  ; RW data
   project.o (+RW)   
  }

  RW_IRAM5 0x20000700 0x00001000  {  ; RW data
   .ANY (+RW,+ZI)   
  }
}

memory map below:

DXDex.jpg

Edited by Maccle

Share this post


Link to post
Share on other sites

Why is the high byte of the address 08? According to that page it's only a 1 Megabit flash on that microcontroller which = 128K which would have a highest possible address of 1FFFF.

 

(not real big on C programming here so it might not be your problem)

Share this post


Link to post
Share on other sites

I should have thought of that... and it looks like his code does consider that base address. Likely boot time code might be location fixed, generally it's higher level stuff that's relocatable.

 

I would also assume there should be PC based emulation available so you'd not needlessly have to reflash every time you want a trivial change during development.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×