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.

MSP430F5438A: Custom UART bootloader

Other Parts Discussed in Thread: MSP430F5438A, MSP430F5438

Hi together,

I want to implement a custom bootloader based on my application UART on MSP430F5438A but I'm very new to that. I'm using IAR as IDE. I already looked through the AppNotes SLAU319, SLAA450 and SLAA600 and also was reading a lot of different posts concerning this topic. But somehow, I'm not sure how to start properly.

My app is comunicating with the connected master via UART A1. This is also the only connection to the 'outer world' and therefore has to be used to update the appcode. I learned so far, that in 5438A the BSL code can be changed, where my first question comes along: If I'm changing the code in the BSL memory section and this code is faulty, will I destroy my device or can I change/debug this part of code?

The TI based BSL is activated with a certain bit pattern, but I want my bootloader to automatically run at start up and wait for an update commando or, after a time out, jump to the start of the app. In this case, the reset vector has to point to the first bootloader address (0x1000). Is that right?

 Preferable I would write the bootloader code in C, but I figured out, if using C there is some initial code which can lead to some troubles. In that case I don't hesitate to write that code in assembly.

That's how I would start:

- Creating a new project and not placing the bootloader code in the app project

- State that the code should be placed in the BSL section of the controller

- Initialize the device and program the protocol

- If an update should be done, performing a mass erase

- Copy the received code into the code memory

- Check code (e.g CRC)

- Copy interrupt table to RAM (If so, do I have to make some changes in my app code?)

- Jump to the start of the app

Do you think this can work? Maybe someone can provide more informations concerning this topic?

Any help appreciated!

  • Hey S.L.,

    is the forum specialist for those things - knows everything about JTAG/BSL/SBW/USB/...
    ...and is now pinged. No guarantee, but maybe you're lucky.

    Dennis
  • Yes, I made CDC BSL with AES for MSP430F550x, but don't know about UART BSL for older devices like MSP430F5438 (A and non-A), and what is the story about JTAG fuse there.
  • Thanks for trying to help to both of you!

    zrno soli, maybe you know an IAR source for a very minimalistic bootloader? All I found was for CCS and with a lot of features..
    But for having a good starting point, a very minimalistic example would be the best. Once I understood the logic behind the basic steps, I can improve my bootloader on my own ;)
  • To remove any chance for device lockup, I done complete development (assembler) inside main flash area, not in BSL. After reset/start BSL was copied to RAM and executed from there. When I was completely sure, that everything is working OK, program was relocated (by source #define) and flashed inside BSL area. It is original, not related to any TI example, and interrupts are not used.

    Except TI BSL examples, there are also some others, open source, for example...

    http://forum.43oh.com/topic/3661-1k-serial-gdb-bootloader/

  • Hi zrno soli,

    thanks for your advices! I have now written my bootloader code and so far it works (erasing bank B and writing new data collected via UART).

    At the moment it is located at address 0x5c00 as standard code.As second approach I created a segment "-Z(CODE)BOOTLOADER=45000-45BFF" in the linker file where I want to move my code.

    Can you tell me how to move my code into this section? And how to change the reset vector so that it points to the address 0x45000?

    Edit: I programmed the bootloader in C!

  • My is written in assembler, so I can't help you much regarding relocating (I guess) C code to BSL area. There is no vector table, and stack is not used at all. At start complete BSL is copied from flash (any location) to RAM, and BSL is executed from RAM (block write is used for flashing).

  • As it seems that writting bootloader code in C is more complicated than a assembly one, I translated my C code into assembly code.
    I think I read somewhere, that if I dont use interrupts in the bootloader code, I dont have to relocate the interrupt vectors. In that case:
    - What means not using: Don't even enable the interrupts?
    - Is polling the interrupt flag possible?

    Thx!
  • With CDC BSL, USB interrupt vector table is big. I didn't made precise calculation, but for sure removing interrupts will increase free space (regarding 2 KByte total). For testing USB flags is used infinitive loop. There are some jump tables, but code is without subroutine call / ret, stack is not used. For switch between test version (main flash), and final (BSL area) I used #define TEST, and here is part of code...

            #ifndef TEST
            org 01000h
            #else
            org 0C000h
            #endif

    Entry   jmp Begin    ; 01000h
            ...          ; 01002h

    Protect ; Protects the BSL memory and protects the SYS module
            ...
            reta
            
            ; It is already aligned to 017F0h so next org is not used

            ;#ifndef TEST
            ;org 017F0h
            ;#endif

            dw 0FFFFh        ; 017F0h
            dw Protect       ; 017F2h  Addr of first instruction in the BSL protect function
            dw 03CA5h        ; 017F4h  Unlock Signature 0x3CA5 indicate a correctly programmed BSL
            dw 0C35Ah        ; 01F76h  Unlock Signature 0xC35A indicate a correctly programmed BSL
            dw 0FFFFh        ; 017F8h  Reserved
            dw Entry         ; 017FAh  Addr of first instruction to be executed on BSL invoke
            dw 0FFFFh        ; 017FCh  JTAG Key
            dw 0FFFFh        ; 017FEh  JTAG Key

            #ifdef TEST
            org 0FFFEh
            dw Begin
            #endif

**Attention** This is a public forum