...change the start address and size of my program in memory?

Comments

12 comments

  • Avatar
    David Patton

    This sounds simple and it is..  The problem is that once you do this your application will no longer run, at least mine won't.  It runs just fine if I don't change the start address and size of the flash..

    0
    Comment actions Permalink
  • Avatar
    Jon Elliott

    David,

    This is probably down to your exception vector table being moved away from the start of memory. This can be a problem on some targets because it means the processor won't be using the correct exception vector table when an exception occurs.

    I believe from previous correspondence that you are using an LPC2378, in this case you need to define the preprocessor definition SRAM_EXCEPTIONS when assembling the startup code (assuming you are using our default startup code) to make it copy the exception vectors to the start of SRAM and map SRAM at address 0x00000000.

    0
    Comment actions Permalink
  • Avatar
    Sam Wong

    I using the NXP LPC2468 and define my program to two part.

    The startup program is locate in 0x0000 and will doing some memory checking for last update then jump to my main code locate in 0x10000 which contain the boatloader, I modify the boatloader memory map to follow:

    <!DOCTYPE Board_Memory_Definition_File>
    <Root name="Philips LPC2468">
      <Processor name="LPC2468">
        <MemorySegment start="0x00010000" size="0x70000" access="ReadOnly" name="FLASH"/>

    .....

    but my boatloader program no response at all, even trigger a LED also cannot.

    I try use keil trial version to do the same thing to verify my start up program, prove that my start up program is no problem. So what should I do for next? I already define the preprocessor definition to "SRAM_EXCEPTIONS". Or I need to change my startup program preprocessor definition?

    0
    Comment actions Permalink
  • Avatar
    Michael Johnson

    Debug it - you can use the Debugger Options | Additional Load File project property to download and debug both the bootloader and the bootloadee.

    0
    Comment actions Permalink
  • Avatar
    Sam Wong

    I using NXP LPC1778 now and create simple bootloader & application as below:

     

    //Bootloader

    //<MemorySegment size="0x2000" access="ReadOnly" start="0x00000000" name="FLASH"/>

    //Preprocessor Definitions to "STARTUP_FROM_RESET"

    #define USER_START_SECTOR_ADDRESS 0x2000
    #define USER_START_SECTOR         2

    unsigned user_code_present(void)
    {
        param_table[IAP_CMD_CODE] = BLANK_CHECK_SECTOR;
        param_table[IAP_PARAM_0] = USER_START_SECTOR;
        param_table[IAP_PARAM_1] = USER_START_SECTOR;
        iap_entry(param_table,result_table);
        if( result_table[IAP_STAT_CODE] == CMD_SUCCESS )
        {
            return (FALSE);
        }
        else
        {
            return (TRUE);
        }
    }

    int main(void)

    {

    RED_LED_ON;

    if( user_code_present() )

    {

    GREEN_LED_ON;

    void (*user_code_entry)(void);
    user_code_entry = (void (*)(void))USER_START_SECTOR_ADDRESS;
    SCB_VTOR_REG = USER_START_SECTOR_ADDRESS & 0x1FFFFF80;

    user_code_entry();

    }

    }

     

    //User Application

    //<MemorySegment size="0x5000" access="ReadOnly" start="0x00002000" name="FLASH"/>

    //Preprocessor Definitions = "SRAM_EXCEPTIONS"

    int main(void)

    {

    RED_LED_OFF;

    GREEN_LED_OFF;

    }

    I verify using flash magic confirm the bootloader jump to my user application, but stop after jump, even the RED LED also not trigger OFF.
    Any mistake on my code? or anything I miss define in compiler?

    0
    Comment actions Permalink
  • Avatar
    Jon Elliott

    Sam,

    On a Cortex-M3 the first address of the vector table is the initial stack pointer value, not code, so jumping to it is a bad idea. See http://infocenter.arm.com/help/topic/com.arm.doc.dui0552a/BABIFJFG.html for more information.

    Regards,

    Jon

    0
    Comment actions Permalink
  • Avatar
    Sam Wong

    Hi Jon,

    Yes, I try to modify the code to

    "user_code_entry = (void (*)(void))(USER_START_SECTOR_ADDRESS+4); //jump to PC"

    or

    "user_code_entry = (void (*)(void))(USER_START_SECTOR_ADDRESS+0x200); //jump out IRQ"

    but fail, therefore I have no idea which parts cause the problem now :(

    Hope you can give me some more guide line. thanks.

    Regards,

    Sam

    0
    Comment actions Permalink
  • Avatar
    Jon Elliott

    Sam,

    Take another look at the link I sent you, offset 4 of the vector table contains the address of the reset entry point, again not executable code. You need to jump to the address stored at this location rather than jumping to it.

    Regards,

    Jon

    0
    Comment actions Permalink
  • Avatar
    Sam Wong

    Hi Jon,

     

    My jump code is write as below:

    //Preprocessor Definitions to "STARTUP_FROM_RESET"
    #define USER_START_SECTOR_ADDRESS 0x2000

    void (*user_code_entry)(void);
    user_code_entry = (void (*)(void))(USER_START_SECTOR_ADDRESS+4); //load value of PC to user_code entry
    SCB_VTOR_REG = USER_START_SECTOR_ADDRESS & 0x1FFFFF80;
    user_code_entry();

    I check both user application hex file and value load to "user_code_entry" on bootloader = 0x2287, this means my execution code are start from address 0x2287 right? But I still cannot start my user application :(

    Beside, I found when debug the "user_code_entry" function, the assembly code show the function will branch indirect (BLX) but not reload the PC, this should be the problem? Or how to modify PC in crosswork?

    BR,

    Sam

    0
    Comment actions Permalink
  • Avatar
    Jon Elliott

    Sam,

    The code 'user_code_entry = (void (*)(void))(USER_START_SECTOR_ADDRESS+4)' will set user_code_entry to 0x2004

    This is fine if your executable code starts at at 0x2004, but as I understand it you have a regular Cortex-M3 vector table at 0x2000 so you need to set user_code_entry to be the value stored at this address.

    Lets add the following typedef to the code to make it clearer:

    typedef void (*entry_t)(void);

    You are doing:

    entry_t user_code_entry;
    user_code_entry = (entry_t)(USER_START_SECTOR_ADDRESS+4);
    user_code_entry();

    You should be doing:

    entry_t user_code_entry;
    user_code_entry = *(entry_t *)(USER_START_SECTOR_ADDRESS+4);
    user_code_entry();

    Jon

    0
    Comment actions Permalink
  • Avatar
    StrahinjaVD
    Hello, I am working with STM32 microcontroller and I am using CrossWorks 2.2. I am trying to make two firmwares: - in-application for programming via UART (application note AN2557) - USB to RS-232 firmware (VirtualComPort, example from user manual UM0424) So I need to relocate USB firmware (example is working when set to 0x8000000). I want to relocate this firmware to 0x8003000. Because of this I import memory map and write: I set with this xml Memory Map File option. I also in main function firtst wrtite: NVIC_SetVectorTable( NVIC_VectTab_FLASH, 0x3000 ); This function is first executed in main function and should notify firmware that vector table is relocated. I just wanted to start USB application, and it is not working. I during debugg see that he is going into interrupt routine, but nothing happens. Also I noticed that sometimes during work he jump to address 0x80000242?! This address is HardFault_Handler when firmware is not relocated. I check my memory map, and it is written that HardFault_Handler is now on 0x80003242. What am I doing wrong?!
    0
    Comment actions Permalink
  • Avatar
    Shyan Jenq

    Hi Jon,

    I am wondering in the memory map file, this particular segment, when I initialized my SRAM where the starting address is 0x98000000, do I need to change/tweak the size  and the access status of it in order to define the memory space availability?

    <MemorySegment start="0x98000000" size="$(EMC_CS2_SIZE:0)" access="$(EMC_CS2_ACCESS:ReadWrite)" name="$(EMC_CS2_NAME:EMC_CS2)"/>

    0
    Comment actions Permalink

Please sign in to leave a comment.