Skip to main content
Visitor II
May 12, 2005
Question

32 Byte Boot Code

  • May 12, 2005
  • 3 replies
  • 895 views
Posted on May 12, 2005 at 20:52

32 Byte Boot Code

    This topic has been closed for replies.

    3 replies

    Visitor II
    May 11, 2005
    Posted on May 11, 2005 at 18:01

    Having a hard time writing an F276 boot loader that is <= 32 bytes. Want to simply copy data from BSL (serial port) into RAM and then run the newly loaded code. Using Keil compiler with optimizations maxed. Smallest I get is 34 bytes! Any help?

    Visitor II
    May 12, 2005
    Posted on May 12, 2005 at 09:08

    Are you trying to write it in C? If so, my advice is to try to write directly in ASM. If you want to move some data in XRAM you should enable it setting XPEN in the SYSCON register, XPERCON contains already a config with XRAM1 enabled. Then using some register, you should implement a small cycle to get data from S0RBUF and move it into your location (stored in a register). The cycle test a leght or a final location. To jump to your location, you can push the address into the stack and at the end use a RET instruction or use a JUMPS.. Anyway 32 bytes are enough to implement all.

    For example:

    BSET XPEN ;if you want to use XRAM1 2bytes

    MOV R0,#0xAABB ;start address to be chosen, it could be an IRAM address. 4 bytes

    loop: JNB S0RIR,loop ;4bytes

    MOVB [R0],S0RBUF ;4bytes

    BCLR S0RIR ;2bytes

    CMPI1 R0,#0xCCDD ;end address,4bytes

    JMPR cc_NE,loop ;2bytes

    JMPS 0,0xAABB ;4bytes jump to target code

    It should be working, maybe there are stupid errors but it's only my quick start point. You can adapt it to use other segment or to do something else. It is 26 bytes.

    Visitor II
    May 12, 2005
    Posted on May 12, 2005 at 20:52

    Yeah - finally got one small enough by doing it straight in ASM. Thanks for the reply! Man, one would like to think a good compiler could optimize something that simple, but I guess not!!!