This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

cc2540 changing code_start on xcl linker file

Hi everybody,

As I posted in another thread (cc2540 place file in specific memory location), I am making a bootloader based on the SBL. I currently have a complete program with works perfectly when using the 'ti_51ew_cc2540b.xcl' file. Then I try moving _CODE_START to another location to give some space to the bootloader; say I move it to 0x0800 as in the provided example.

I recompiled and start debugging but, for any reason, the code gets corrupted in some point and the IDATA and XDATA stacks get filled completely.

I suspect something related with the low power modes, because I can debug the code until the 'halSetSleepMode' function. Maybe it is related with the fact that this piece of code must be located in the SLEEP_CODE address and 4-byte aligned, but I am not sure.

I am completely stucked with this and I see no ray of light regarding this issue.

If anyone could give me a piece of advise I will be very grateful.

Regards,

Javier Ruiz

  • Hello,

    I would take a look at util/UBL .xcl file for example of multi page bootloader.  Or BIM which supports Image A and Image B.  The start of all programs has to be on page 0, so this is why there are some limitations.limitations has multi page USB boot loader.

    BR,

    -Greg

  • Hi GregS,

    Thank you for your answer. I have been playing around with SBL.cxl file as a starting point. I also used 'ti_51ew_cc2540b.xcl' for my program (it works perfectly with it) and modified it so 'CODE_START' is moved to the new address.
    I have also tested the proposed 'cc254x_f256_sbl.xcl' with the same result.
    As I suspect something related with the ISR vectors, I change offsets in the 'sbl_ivec.s51', but although I think now this is OK, the result is the same, the program restarts over and over (I have already implemented a control to check if the binary is correctly downloaded and this part is working fine).

    By the way, is it possible to debug the original program when we make the change in the 'CODE_START'? I am asking this because if I leave 'CODE_START' at 0 it works fine, but when I move it, my original code starts resetting in the same way it does after the bootloader download it to Flash.

    I am really frustrated with this, so any new advice will be really grateful.

    Regards,

    Javier Ruiz

  • I have seen that the INTVEC table for the displaced code is not quite right, I mean, I have checked the LJMP's and there are pointing to wrong locations. So, it is normal that my code resets or do whatever strange things...

    So, my question now is: How I can change the INTVEC to point to the right locations? (I know this is made automatically by the compiler/linker when using code beginning at address 0x000, but I have no idea in how to tell it that I want all the code, and the INTVECs displaced).

    Regards

  • Forget it, INTVEC is OK, but interrupts are not working... I am lost....

  • Hi Javier,

    There will be 2 .xcl files involved, one for bootloader and one for image you are loading. There are SBL specific (,xcl)  files you should use which are in projects/common directory. I would start by getting SBL code to work.

    BR,

    -Greg

  • For bootloader, do not use interrupts. The examples are polling based.

    BR,

    -Greg

  • Hi,

    Finally, I managed to resolve this issue. I will put the solution so anyone with the same problem can try this solution.

    There were several things involved: First, as I guessed, the interrupts were not properly propagating from the bootloader to my code. The SBL has a file called 'sbl_ivec.s51' where we can find the INTVEC table with jumps to the main code. You have to adjust the 'OFFSET' here to the corresponding offset you set for your main code. The problem with this table is that if any of the interrupts is used by the bootloader itself, the jump is overwritten and the isr routine from the bootloader is linked, instead of those from the main code. So I had to add a couple of lines in the 'usbirqHandler' function (usb_interrupt.c), there, I checked for a valid code and if it exists I simply jump to the main code usb ISR.

    Don't forget to change the linker files so the CODE_START in the main program starts in your chosen address. Then,  change the SBL xcl to match this address.

    The other problem I had to solve was a bug in my code: nothing to say here :)

    Hope this helps.

    Regards

    Javier Ruiz

  • Hi Javier,

    I am having the same problem - I am trying to have a boot loader and main code which both use the usb interrupt.

    Can you write the code you added to usbirqHandler to check and jump if needed?

    thanks,

    Nir.