Self Bootloader

Discussion in 'Embedded Systems and Microcontrollers' started by bctang, Nov 1, 2008.

  1. bctang

    Thread Starter Member

    Sep 5, 2004
    26
    0
    Hi,

    Currently i have success download the hex data to SRAM and running the program. Now I would like to save the CODE data on external eeprom whenever power is ON will automatically download the data to SRAM and start running the program without manualy set the /EA to GND.

    I have found this method 8051 von Neumann Memory ( http://www.keil.com/download/docs/192.asp ). I'm not sure this method will solve the problem not.

    void main (void)
    { load_vonNeumann_memory (); // Load VN memory
    ((void (code *) (void)) 0xE000) (); // Call function in VN memory
    while (1) // Loop Forever { }
    }

    May i know this load_vonNeumann_memory (); function will be the bootloader portion? Download the hex data to SRAM. The next ((void (code *) (void)) 0xE000) (); function will be the external CODE execution start at 0xE000 address. Am i rite?

    I have tested but no work. May be is the "Options for Target" Off-chip Code Memory and Off-chip Xdata memory setting is wrong.
    Let say, my application code define is :-
    Off-chip Code Memory: start = 0x0000, size = 0x4FFF
    Off-chip Xdata memory: start = 0x5000, size = 0xAFFF
    I'm using 2 32kB SRAM.

    How can i do the setting on the 8051 von Neumann Memory?
    If this method can't make it. Is there any other method to run the external code without doing the /EA to GND setting?

    Thank you.
     
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
  3. bctang

    Thread Starter Member

    Sep 5, 2004
    26
    0
    Hi,

    Thank for your information. I'm understand how the does Von Neumann architecture work. A single block of memory may mapped to act as both data and program memory.

    On my circuit side the /RD and /PSEN is connected to one AND gate, the output will connected to SRAM /OE.

    So, i would like to run my uC external memory as Von Neumann architecture. How can i define the memory size?

    Currently, I have one program will write to external memory. The size configurate is
    Off-chip Code Memory: start = 0x0000, size = 0x4FFF
    Off-chip Xdata memory: start = 0x5000, size = 0xAFFF

    So, my CODE size will be is 0x5000, and the Xdata size is AFFF.

    How can i make use of this 8051 von Neumann Memory method to access my external memory?

    I reallize when i apply this ((void (code *) (void)) 0x0000) (); function on bootloader. The function is point to the code address 0x0000. So, whenever the function is point the coding will start with at main() function again. Look like reset the coding.

    Please guide me....

    Thank you.
     
    Last edited: Nov 1, 2008
  4. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    Your external memory is just memory - the 8051 sees it as a string of adresses.

    The division of memory into code and data storage is entirely up to the programmer. It's a matter of setting up storage, like arrays for data structures in C, or reserving blocks of memory addresses in assembler. Usage of memory is just a matter of not letting the data block overwrite the code block.

    The alternative to the Von Nneumann memory moded is the Harvard Architecture, which uses separate memory for data and code. A number of modern microcontrollers are made with this arrangement.
     
  5. bctang

    Thread Starter Member

    Sep 5, 2004
    26
    0
    Hi,

    Ya, thank for your explanation. now i have very clear picture on it.

    I have do alot of testing. Bellow show the setting that i tested.
    Internal code - LJMP 8003H, External code - Interrupt vector & STARTUP.A51 line-125 = 0x8000
    Internal code - LJMP 8003H, External code - Interrupt vector & STARTUP.A51 line-125 = 0x8003
    Internal code - LJMP 8000H, External code - Interrupt vector & STARTUP.A51 line-125 = 0x8000

    Code ( (Unknown Language)):
    1.  
    2. void runprog(void)
    3. {
    4. #pragma asm
    5. ljmp 8000H
    6. #pragma endasm
    7. }
    8.  
    Now i'm using above function to jump to the address 8000h after bootloader.

    Why still can't work?
    Is it the circuit is wrong!!

    Thank you
     
  6. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    Do you actually have memory at 8000h? How much memory do you have in the system?
     
  7. bctang

    Thread Starter Member

    Sep 5, 2004
    26
    0
    Hi,

    The attached is the circuit.
    Yes, I have two 32kb SRAM. But another thing is if i loader the code address at 0x0000 or 0x8000. It will working fine. Like other address 0x2000 or 0xE000 wouldn't work. This is /EA to GND condition.
    When the address start at 0x8000 is work on /EA to Vcc condition is fine. I use this address and /EA to GND condition, after the bootloader will LJMP 0x8000. It no work. I wonder why :confused: Is it the circuit problem?

    I have done alot of testing.

    Test1:
    I have write a simple prints "Hello" message in external code. Just test a simple serial interface on Hyperterminal and try to set the Code range, Xdata range, Start-up address and interrupt vector address.
    Code ( (Unknown Language)):
    1. void main(void){
    2.    // SerialInit;
    3.    while(1){
    4.    // prints("Hello");
    5.   }
    6. }
    7.  
    Above is the code will be write into SRAM. The code will start loaded at 0x2000. The setting is
    Off-chip Code memory:- Start=0x2000 Size=0x5FFF
    Off-chip Xdata memory:- Start=0x6000 Size=0x9FFF
    Interrupt vectors at address: 0x2000
    Un-tick "Use Memory Layout from Target Dialog" at BL51 Locate tab
    STARTUP.A51 line-125 CSEG AT 0x2000

    Test2:
    Code ( (Unknown Language)):
    1. void main(void){
    2.    // Bootloader;
    3.    // RunExternalProg; LJMP 0x2000
    4.    while(1);
    5. }
    6.  
    or
    Test3:
    Code ( (Unknown Language)):
    1. void INT0ISR() interrupt 0 {
    2. #pragma asm
    3.    LJMP 2000H
    4. #pragma endasm
    5. }
    6. void main(void){
    7.    // Bootloader;
    8.    while(1);
    9. }
    10.  
    Above is the code will be burn into uC. The Interrupt vectors address is 0x0000 and the STARTUP.A51 line-125 CSEG AT 0x0000
    After the RunExternalPrgo function will do nothing already.
    May i know do we need to sett the address offset add the +3 (LJMP 0x2003) or any?

    Test4:
    I have write a jump function on mcu. This function can be retrace back the data back after loading the code before jump to 0x2000. The data downloaded in external ram is nice. The result same as .hex file.

    Test5:
    And i have writing directly the hand coded code function on mcu also. Using hand coded change the address. It is more flexible and easy to do testing.

    Another concern, regarding the Serial code. I have using serial intterrupt will it cause any problem?

    I have do alot of testing but still can't find the problem. :(

    Thank you.
     
    • cct.pdf
      File size:
      20.5 KB
      Views:
      19
    Last edited: Nov 5, 2008
  8. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    Can you do something like writing a bit pattern to memory and then are you able to read it back?
     
  9. bctang

    Thread Starter Member

    Sep 5, 2004
    26
    0
    Yes, I can able to read back all the data. But i rendom eye check. The bootloader will stop download when received this hex code.
    Code ( (Unknown Language)):
    1.  
    2. :00000001FF
    3.  
    The hex code show the internal SRAM data. It is read back from SRAM. The higher data was the last data downloaded into the SRAM.

    I can running the external code in /EA to GND condition will display out the "Hello" message but the Interrupt Vector address must be this 2 address, either 0x0000 or 0x8000. Other address will not work. I also don't know why.

    Now i have a concern about the STARTUP.A51 on bootloader and xcode. On the bootloader side the Interrupt Vector address is 0x0000 and the xcode interrupt vector address is 0x2000. I'm worry when we create xcode hex file, also create code for reset address and other interrupt locations. When running two STARTUP.A51 in between will it cause any problem?

    I have do some testing, the picture show the result:

    I remove the startup.A51 from the bootloader and the external code.

    Test1:
    Interrupt vectors at 0x2000. When i hand coded 2000 (22000000 is hyperterminal echo) on h/t, the bootloader code still running (running internal code) which mean it still allow me to key in interrupt vectors again. Once i key 0x2001, it will hang there already. I think the code is start using external code already but not comeout any "Hello" message on screen.
    After that i need to reset the uC again then become normal.
    This test1 show if the Interrupt vectors offset to 1 (at 0x2001) it will jump to external code. Other address will still running in bootloader code.

    Test2:
    Interrupt vectors at 0x9000. The situation is run opposition way. If the Interrupt vectors offset to 1(at 0x9001) it will looking bootloader code. Other address will hanging in somewhere else then need to press reset to run it like normal.

    From this testing can we get any sign?

    Thank you.
     
    Last edited: Nov 6, 2008
Loading...