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.

PLEASE HELP: Few questions about BOOTLOADER (UART BSL) on MSP430F5529

Other Parts Discussed in Thread: MSP430F5529, MSP-FET

Hi everyone,


I am doing some stuffs about custom bootloader but I have a problems with it.

I put a LED signalization into BSL_Protect function which is on 0x17F2 memory. In this function I check if BSL sequence was entered.

BSL_Protect
              CLR      	RET_low                  ;lock (keep JTAGLOCK_KEY state)
             
              BIS     	#SYSBSLPE+SYSBSLSIZE0+SYSBSLSIZE1 , &SYSBSLC ; protects BSL
              

              BIS.B   #BIT3, &P7DIR
              BIC.B   #BIT3, &P7OUT

	      BIT     	#SYSBSLIND,&SYSCTL      ;check for BSL start request
              JZ      	BCC2BSL

	      CLR 		SYSCTL
              BIS.B   	#BSL_REQ_APP_CALL, RET_low

              BIS.B   #BIT3, &P7OUT
              MOV.W   #10000, R11
DELAY_LOOP:   
DEC.W R11 JNZ DELAY_LOOP BIC.B #BIT3, &P7OUT BCC2BSL: RETA

As you can see the led MUST blink only if the exact bsl sequence was entered. When I burn the BSL code into MSP430F5529 led did not blink. All right. I enter the BSL entry sequence (hold RST, pulse on TEST, hold TEST, release RST, release TEST) and LED diode blinks. All right - I am into BSL code. BUT I press RST button again and the LED blinks AGAIN!

1. Why? I did not enter the BSL sequence! But If I press TEST button, release TEST button and then I press the RST button the blink is not done. Could someone explain it to me? The led blinks if I power off / power on the my board too.


2. Why R12 register? HOW the R12 register invoked the BSL code or an application code? Is something inside into MSP430 which cannot be seen? After reading a lot of documentation the start-up sentence is like this:

a) Hard reset

b) Check if 03CA5h and 0C35Ah is on the proper location: 0x17F4 and 0x17F6

c) After that the PC is set to 0x17F2 where is jump to BSL_Protect function

d) In the BSL_Protect function is a code which decides if BSL sequence was entered. If yes it sets R12 = 0x0002. If not the R12 = 0x0000

e) NOW WHAT? Now is called RETA instruction but WHERE? Could you please explain me HOW and WHERE the code jumps?

3. In this section:

BSL_Entry_JMP 
              JMP    C_Branch
              JMP    BSL_ACTION0                ;BSL_ACTION0 unused
              JMP    $                          ;BSL_ACTION1 unused
              JMP    $                          ;BSL_ACTION2 unused
              JMP    $                          ;BSL_ACTION3 unused
C_Branch      BR     #_c_int00
              ;JMP    $                          ;BSL_ACTION5 unused 
              ;JMP    $                          ;BSL_ACTION6 unused

How the BSL code could jump to BSL_ACTION0? Why is the example code like this? Or the action0 is not important?

4. My problem is that I burn app code into MCU. I can run the code but after RST is pressed the code do not work anymore. Problem is that I have wrong jump on the RST vector  0xFFFE and 0xFFFF. I found out with reading of MCU memory byt MSP-FET programmer

THANK YOU VERY MUCH.

Best regards,

Maros

;**************************************************************
; BSL SW low level functions
;**************************************************************

    .cdecls C,LIST,"msp430x552x.h"

ARG1 .equ R12
ARG2 .equ R13
ARG3 .equ R14
ARG4 .equ R15

RET_low .equ R12
RET_high .equ r13

 .ref _c_int00
;--------------------------------------------------------------
 .sect ".ZAREA"
;--------------------------------------------------------------
BSL_Entry_JMP 
              JMP    C_Branch
;              JMP    BSL_ACTION0                ;BSL_ACTION0 unused
;              JMP    $                          ;BSL_ACTION1 unused
;              JMP    $                          ;BSL_ACTION2 unused
;              JMP    $                          ;BSL_ACTION3 unused
C_Branch      BR     #_c_int00
              ;JMP    $                          ;BSL_ACTION5 unused 
              ;JMP    $                          ;BSL_ACTION6 unused

 .sect ".ZAREA_CODE"

;**************************************************************
; Name       :BSL_ACTION0
; Function   :BSL Action 0 is a function caller
; Arguments  :r15, Function ID
;                - 0: Get Software ID
;                - 1: Unlock BSL Flash area
; Returns    :r14, Low Word
;            :r15, High Word
;**************************************************************
BSL_ACTION0
              CMP      #0xDEAD, ARG2
              JNE      RETURN_ERROR
              CMP      #0xBEEF, ARG3 
              JNE      RETURN_ERROR                              
              ;CMP      #0x01, ARG1
              ; to do ... comment!
              ;JEQ      BSL_Unprotect          ; 1 == unlock BSL flash area
              ;JEQ      JTAG_Lock
              ;JL       BSL_SW_ID            ; 0 == return SW ID
              ;JL       RETURN_ERROR           ; 0 == return SW ID
              JMP      RETURN_TO_BSL           ; 2 == return to BSL
RETURN_ERROR
              CLR      RET_low
              CLR      RET_high
              RETA                           

;**************************************************************
; Name       :RETURN_TO_BSL
; Function   :Returns to a BSL function after that function has made
;            :an external function call
; Arguments  none
; Returns    :none
;**************************************************************
RETURN_TO_BSL
              POP.W    RET_low                 ; remove first word from return addr
              POP.W    RET_high                ; remove second word from return addr
              
              RETA                             ; should now return to the BSL location

 
;**************************************************************
; Name       :BSL_Protect
; Function   :Protects the BSL memory and protects the SYS module
; Arguments  :none
; Returns    :0 in R12.0 for lock (keep JTAGLOCK_KEY state)
;            :1 in R12.0 for unlock (overwrite JTAGLOCK_KEY) : BSL_REQ_JTAG_OPEN
;            :0 in R12.1 for no appended call
;            :1 in R12.1 for appended call via BSLENTRY : BSL_REQ_APP_CALL
;**************************************************************
BSL_REQ_JTAG_OPEN  .equ  0x0001                  ;Return Value for BSLUNLOCK Function to open JTAG
BSL_REQ_APP_CALL   .equ  0x0002                  ;Return Value for BSLUNLOCK Function to Call BSL again
BSL_Protect
              CLR      	RET_low                  ;lock (keep JTAGLOCK_KEY state)
             
              BIS     	#SYSBSLPE+SYSBSLSIZE0+SYSBSLSIZE1 , &SYSBSLC ; protects BSL
              

              BIS.B   #BIT3, &P7DIR
              BIC.B   #BIT3, &P7OUT

			  BIT     	#SYSBSLIND,&SYSCTL      ;check for BSL start request
              JZ      	BCC2BSL

			  CLR 		SYSCTL
              BIS.B   	#BSL_REQ_APP_CALL, RET_low

              BIS.B   #BIT3, &P7OUT
              mov.w   #10000, R11
DELAY_LOOP:   dec.w   R11
              jnz     DELAY_LOOP
              BIC.B   #BIT3, &P7OUT

BCC2BSL:      RETA



	.sect ".BSLSIG"

                 .word       0xFFFF
BslProtectVecLoc .word       BSL_Protect             ; Do tejto funkcie skoci pri starte programu VZDY.
PBSLSigLoc       .word       03CA5h                  ;1st BSL signature
SBSLSigLoc       .word       0C35Ah                  ;2nd BSL signature
                 .word       0xFFFF
BslEntryLoc      .word       BSL_Entry_JMP           ;BSL_Entry_JMP

PJTAGLOCK_KEY    .word       0xFFFF                  ; Primary Key Location
SJTAGLOCK_KEY    .word       0xFFFF                  ; Secondary Key Location
                                                     ; set default unlock JTAG with option to lock with writting
                                                     ; a value <> 0x0000 or 0xFFFF
.end

  • The MSP430 indeed has boot code that is executed before the BSL or your application code, and that cannot be seen.

    The BSL is run if the reset vector is empty, so I'd guess your BSL code accidentally erased it.

  • Sorry, but I do not understand. Why the BSL is only run IF the reset vector is empty ( 0xFF 0xFF ?). The reset vector cannot be empty because on that vector is jump to my application.

    A really DO NOT understand. So what can I do right now?
  • Not "only"; there are other reasons why the BSL is run.

    But if the BSL is run without the BSL signal, this would be the most obvious explanation.

  • I check my flash code and on the 0xFFFE address is not 0xFFFF so reset vector is not empty.. any idea? Please check my .asm code if its correct or please answer my other question if you could. Thanks!
  • Here is my FLASH image:

    === BSL Flash Memory Segments  0x1000 - 0x17FF ======
    
    
    0x1000: 04 3C FE 3F FF 3F FF 3F   FF 3F 30 40 5A 15 FF FF | .<.?.?.?.?0@Z...
    0x1010: 00 08 08 04 D2 D3 42 02   3D 90 AD DE 04 20 3E 90 | ......B.=.... >.
    0x1020: EF BE 01 20 03 3C 0C 43   0D 43 10 01 E2 D3 42 02 | ... .<.C.C....B.
    0x1030: 3C 41 3D 41 10 01 0C 43   B2 D0 03 80 82 01 D2 D3 | <A=A...C........
    0x1040: 44 02 E2 D3 44 02 E2 C3   42 02 D2 C3 42 02 B2 B0 | D...D...B...B...
    0x1050: 10 00 80 01 01 24 6C D3   10 01 FF FF FF FF FF FF | .....$l.........
    0x1060: FF FF FF FF 6A 14 21 82   82 43 1A 26 B2 40 00 A5 | ....j.!..C.&.@..
    0x1070: 1C 26 B2 40 41 03 00 24   B2 40 A0 01 02 24 B2 40 | .&.@A..$.@...$.@
    0x1080: 33 02 68 01 82 43 60 01   B2 40 40 00 62 01 82 43 | 3.h..C`..@@.b..C
    0x1090: 6A 01 B2 40 3C 20 64 01   B2 40 20 00 42 03 B2 40 | j..@< d..@ .B..@
    0x10A0: 20 02 40 03 F2 40 06 00   0A 02 E2 43 04 02 3E 40 |  .@..@.....C..>@
    0x10B0: 00 02 3F 40 0A 24 1F 53   CF 43 FF FF 1E 83 FB 23 | ..?@.$.S.C.....#
    0x10C0: B2 40 0A 24 04 24 B2 40   0A 24 06 24 82 43 1A 26 | .@.$.$.@.$.$.C.&
    0x10D0: 38 40 3B 00 B2 3C B2 90   A5 A5 1A 26 02 24 6F 42 | 8@;..<.....&.$oB
    0x10E0: 08 3C 82 43 1A 26 0F 18   4D 5D 00 18 4D DC 4D 13 | .<.C.&..M]..M.M.
    0x10F0: 4F 43 1E 42 06 24 CE 48   00 00 1E 42 06 24 CE 4F | OC.B.$.H...B.$.O
    0x1100: 01 00 2C 43 B0 13 9E 14   98 3C CC 0F B0 13 00 14 | ..,C.....<......
    0x1110: 4C 93 05 20 B0 13 A0 12   CF 43 01 00 F2 3F B0 13 | L.. .....C...?..
    0x1120: A0 12 3E 40 05 00 CF 4E   01 00 EB 3F B2 90 A5 A5 | ..>@...N...?....
    0x1130: 1A 26 74 20 92 42 1C 26   44 01 3F 40 40 00 1F 52 | .&t .B.&D.?@@..R
    0x1140: 1C 26 82 4F 40 01 B2 90   05 00 08 24 67 28 81 4C | .&.O@......$g(.L
    0x1150: 00 00 81 4D 02 00 15 42   08 24 25 82 29 42 19 52 | ...M...B.$%.)B.R
    0x1160: 04 24 CE 0C CF 0D 35 B0   00 80 0B 7B 3B E3 CA 05 | .$....5....{;...
    0x1170: 0A 5E 0B 6F 0F 9B 03 28   51 20 0E 9A 4F 2C C6 0E | .^.o...(Q ..O,..
    0x1180: C7 0F 16 F3 07 F3 07 93   2C 20 06 93 2A 20 35 B0 | ........, ..* 5.
    0x1190: 00 80 0C 7C 3C E3 CD 0E   C4 0F 0D 85 04 7C 2D 81 | ...|<........|-.
    0x11A0: 14 71 02 00 34 93 02 20   3D 93 1B 24 B2 90 A5 A5 | .q..4.. =..$....
    0x11B0: 1A 26 12 20 2D 49 B0 13   BC 12 84 4D 00 00 B0 13 | .&. -I.....M....
    0x11C0: BC 12 2D 94 02 20 44 43   01 3C 54 43 92 B3 46 01 | ..-.. DC.<TC..F.
    0x11D0: 04 24 74 40 03 00 01 3C   64 42 29 53 1E 53 0F 63 | .$t@...<dB)S.S.c
    0x11E0: 14 3C B2 90 A5 A5 1A 26   0E 20 6D 49 B0 13 BC 12 | .<.....&. mI....
    0x11F0: C4 4D 00 00 B0 13 BC 12   64 44 4D 94 02 20 44 43 | .M......dDM.. DC
    0x1200: 03 3C 54 43 01 3C 64 42   19 53 44 93 07 20 1E 53 | .<TC.<dB.SD.. .S
    0x1210: 0F 63 0F 9B B8 2B 02 20   0E 9A B5 2B 92 42 1C 26 | .c...+. ...+.B.&
    0x1220: 40 01 B0 13 AE 12 09 3C   B0 13 A0 12 3E 40 07 00 | @......<....>@..
    0x1230: CF 4E 01 00 2C 43 B0 13   9E 14 B0 13 C8 12 5C B3 | .N..,C........\.
    0x1240: FC 27 1F 43 1F 52 04 24   1E 42 04 24 5C 4E 03 00 | .'.C.R.$.B.$\N..
    0x1250: 0D 43 B0 13 02 15 1E 42   04 24 5E 4E 02 00 0C DE | .C.....B.$^N....
    0x1260: B0 13 02 15 6E 4F 0C DE   1E 42 04 24 6E 4E 3E 80 | ....nO...B.$nN>.
    0x1270: 10 00 5C 27 1E 83 49 27   2E 82 03 24 2E 83 2B 27 | ..\'..I'...$..+'
    0x1280: D3 3F 92 42 1C 26 44 01   3F 40 06 00 1F 52 1C 26 | .?.B.&D.?@...R.&
    0x1290: 82 4F 40 01 C2 43 E0 FF   B0 13 AE 12 3B 3F 03 43 | .O@..C......;?.C
    0x12A0: 1F 42 06 24 CF 48 00 00   1F 42 06 24 10 01 3F 40 | .B.$.H...B.$..?@
    0x12B0: 10 00 1F 52 1C 26 82 4F   44 01 10 01 C4 0F 0F 18 | ...R.&.OD.......
    0x12C0: 44 54 00 18 44 DE 10 01   21 83 81 43 00 00 4C 43 | DT..D...!..C..LC
    0x12D0: 0D 43 B2 40 20 89 44 03   92 B3 44 03 FD 27 B2 F0 | .C.@ .D...D..'..
    0x12E0: FE FE 44 03 92 52 02 24   54 03 3E 40 09 00 0F 43 | ..D..R.$T.>@...C
    0x12F0: 92 52 00 24 54 03 92 C3   44 03 92 B3 44 03 FD 27 | .R.$T...D...D..'
    0x1300: 5F 01 B2 B0 00 04 44 03   02 24 3F D0 00 01 1E 83 | _.....D..$?.....
    0x1310: EF 23 4F 4F 0D 93 0D 20   3F 90 80 00 02 20 1D 53 | .#OO... ?.... .S
    0x1320: 5E 3C 7C 40 51 00 B0 13   E6 13 B0 13 F6 13 FD 23 | ^<|@Q..........#
    0x1330: 56 3C 1D 93 51 24 2D 93   33 24 CE 0D 1E 82 08 24 | V<..Q$-.3$.....$
    0x1340: 3E 90 03 00 29 24 2E 92   23 20 4F 4F 8F 10 81 DF | >...)$..# OO....
    0x1350: 00 00 2C 41 B2 43 54 01   82 93 08 24 09 24 3E 40 | ..,A.CT....$.$>@
    0x1360: 0A 24 0F 43 F2 4E 52 01   1F 53 1F 92 08 24 FA 2B | .$.C.NR..S...$.+
    0x1370: 82 9C 54 01 08 24 7C 40   52 00 B0 13 E6 13 B0 13 | ..T..$|@R.......
    0x1380: F6 13 FD 23 2C 3C 4C 43   B0 13 50 14 5C 43 29 3C | ...#,<LC..P.\C)<
    0x1390: CD 4F 07 24 1D 53 23 3C   81 4F 00 00 1D 53 1F 3C | .O.$.S#<.O...S.<
    0x13A0: 4F 4F 8F 10 82 DF 08 24   82 93 08 24 07 20 7C 40 | OO.....$...$. |@
    0x13B0: 53 00 B0 13 E6 13 B0 13   F6 13 FD 23 B2 90 01 02 | S..........#....
    0x13C0: 08 24 07 28 7C 40 54 00   B0 13 E6 13 B0 13 F6 13 | .$.(|@T.........
    0x13D0: FD 23 3D 40 03 00 03 3C   82 4F 08 24 2D 43 4C 93 | .#=@...<.O.$-CL.
    0x13E0: 78 27 21 53 10 01 B0 13   50 14 3E 40 00 02 3F 40 | x'!S....P.>@..?@
    0x13F0: 0A 24 6C 43 10 01 1F 53   CF 43 FF FF 1E 83 10 01 | .$lC...S.C......
    0x1400: 0A 14 31 82 CA 0C CC 01   3D 40 7C 15 3E 40 06 00 | ..1.....=@|.>@..
    0x1410: B0 13 42 15 3D 40 06 00   CC 01 0E 43 7F 4A 7F EC | ..B.=@.....CJ.
    0x1420: 0E DF 1D 83 FB 23 0E 93   03 24 7C 40 05 00 0D 3C | .....#...$|@...<
    0x1430: B1 40 FF 7F 06 00 02 3C   91 83 06 00 91 93 06 00 | .@....<........
    0x1440: FB 37 B2 40 A5 A5 1A 26   4C 43 31 52 0A 16 10 01 | .7.@...&LC1R....
    0x1450: 92 42 50 03 52 03 92 52   00 24 52 03 4C 4C 3C 50 | .BP.R..R.$R.LL<P
    0x1460: 00 02 5C 02 3F 40 00 02   3E 40 0B 00 92 B3 42 03 | ..\.?@..>@....B.
    0x1470: FD 27 92 C3 42 03 92 52   00 24 52 03 B2 D0 80 00 | .'..B..R.$R.....
    0x1480: 42 03 1C B3 04 24 0C EF   B2 F0 7F FF 42 03 5F 01 | B....$.....B._.
    0x1490: 5C 01 1E 83 EB 23 92 B3   42 03 FD 27 10 01 CD 0C | \....#..B..'....
    0x14A0: 7C 40 80 00 B0 13 50 14   B0 13 D6 14 B0 13 50 14 | |@....P.......P.
    0x14B0: B2 43 54 01 1D 93 09 38   3B 40 0A 24 7C 4B C2 4C | .CT....8;@.$|K.L
    0x14C0: 52 01 B0 13 50 14 1D 83   F9 23 1D 42 54 01 B0 13 | R...P....#.BT...
    0x14D0: D6 14 80 00 50 14 4C 4D   B0 13 50 14 CC 0D 8C 10 | ....P.LM..P.....
    0x14E0: 8C 11 4C 4C 10 01 5C 02   0D 6D 5C 02 0D 6D 5C 02 | ..LL..\..m\..m\.
    0x14F0: 0D 6D 5C 02 0D 6D 5C 02   0D 6D 5C 02 0D 6D 5C 02 | .m\..m\..m\..m\.
    0x1500: 0D 6D 5C 02 0D 6D 5C 02   0D 6D 5C 02 0D 6D 5C 02 | .m\..m\..m\..m\.
    0x1510: 0D 6D 5C 02 0D 6D 5C 02   0D 6D 5C 02 0D 6D 5C 02 | .m\..m\..m\..m\.
    0x1520: 0D 6D 10 01 B2 40 80 5A   5C 01 3D 40 4C 57 3F 40 | .m...@.Z\.=@LW?@
    0x1530: 00 1C 03 3C 2F 53 8F 4D   FE FF 0E 41 0F 9E FA 2B | ...</S.M...A...+
    0x1540: 10 01 CF 0C 0E 93 05 24   1F 53 FF 4D FF FF 1E 83 | .......$.S.M....
    0x1550: FB 23 10 01 03 43 FF 3F   10 01 31 40 00 44 00 18 | .#...C.?..1@.D..
    0x1560: F2 40 58 15 0A 26 00 18   F2 40 58 15 0E 26 B0 13 | .@X..&...@X..&..
    0x1570: 24 15 0C 43 B0 13 64 10   B0 13 54 15 AA BB CC DD | $..C..d...T.....
    0x1580: EE FF 04 FF FF FF FF FF   FF FF FF FF FF FF FF FF | ................
    0x1590:       ------- b l a n k ----(all 0xFF)------- 
    
    
    0x17F0: FF FF 36 10 A5 3C 5A C3   FF FF 00 10 FF FF FF FF | ..6..<Z.........
    
    === Information Memory Segments  0x1800 - 0x19FF ======
    
    0x1800:       ------- b l a n k ----(all 0xFF)------- 
    
    
    ========== Main Memory Segments  0x4400 - 0x243FF ======
    
    
    0x4400: 31 40 00 44 00 18 F2 40   58 44 00 24 00 18 F2 40 | 1@.D...@XD.$...@
    0x4410: 58 44 04 24 B0 13 50 44   0C 43 B0 13 22 44 B0 13 | XD.$..PD.C.."D..
    0x4420: 54 44 B2 40 80 5A 5C 01   F2 42 64 02 F2 E2 62 02 | TD.@.Z\..Bd...b.
    0x4430: 3F 40 F3 01 0D 14 3D 40   4A 01 1D 83 FE 23 0D 16 | ?@....=@J....#..
    0x4440: 1F 83 3F 93 F3 27 F6 3F   03 43 32 D0 10 00 FD 3F | ..?..'.?.C2....?
    0x4450: 1C 43 10 01 03 43 FF 3F   10 01 FF FF FF FF FF FF | .C...C.?........
    0x4460:       ------- b l a n k ----(all 0xFF)------- 
    
    
    0xFFF0: FF FF FF FF FF FF FF FF   FF FF FF FF FF FF 5A 15 | ..............Z.
    
    ===== Extended Main Memory Block #1  (0x10000-0x1FFFF) =====
    
    0x10000:       ------- b l a n k ----(all 0xFF)------- 
    
    
    ===== Extended Main Memory Block #2  (0x20000-0x243FF) =====
    
    0x20000:       ------- b l a n k ----(all 0xFF)------- 

    Here is my simple application code:

    @4400
    31 40 00 44 00 18 F2 40 58 44 00 24 00 18 F2 40
    58 44 04 24 B0 13 50 44 0C 43 B0 13 22 44 B0 13
    54 44 B2 40 80 5A 5C 01 F2 42 64 02 F2 E2 62 02
    3F 40 F3 01 0D 14 3D 40 4A 01 1D 83 FE 23 0D 16
    1F 83 3F 93 F3 27 F6 3F 03 43 32 D0 10 00 FD 3F
    1C 43 10 01 03 43 FF 3F 10 01
    @ffd2
    4A 44 4A 44 4A 44 4A 44 4A 44 4A 44 4A 44 4A 44
    4A 44 4A 44 4A 44 4A 44 4A 44 4A 44 4A 44 4A 44
    4A 44 4A 44 4A 44 4A 44 4A 44 4A 44 00 44
    q

    Really do not know why the FFD2 secion is not written into flash memory and why on the reset vector is 5A 15

     

    This is my .asm file:

    ;**************************************************************
    ; BSL SW low level functions
    ;**************************************************************
    
        .cdecls C,LIST,"msp430x552x.h"
    
    ARG1 .equ R12
    ARG2 .equ R13
    ARG3 .equ R14
    ARG4 .equ R15
    
    RET_low .equ R12
    RET_high .equ r13
    
        .ref version_array
        .ref _c_int00
    
        .sect ".ZAREA"
    
    BSL_Entry_JMP JMP    C_Branch                   ; BSL ENTRY AREA
                  JMP    BSL_ACTION0
                  JMP    $                          ;BSL_ACTION1 unused
                  JMP    $                          ;BSL_ACTION2 unused
                  JMP    $                          ;BSL_ACTION3 unused
    C_Branch      BR     #_c_int00                  ;BSL_ACTION4 unused
    
        .sect ".ZAREA_CODE"
    
    BSL_ACTION0:
    
                  BIS.B   #BIT0, &P5OUT
    
                  CMP      #0xDEAD, ARG2
                  JNE      RETURN_ERROR
                  CMP      #0xBEEF, ARG3
                  JNE      RETURN_ERROR
    
                  JMP      RETURN_TO_BSL           ; 2 == return to BSL
    RETURN_ERROR
                  CLR      RET_low
                  CLR      RET_high
                  RETA
    
    RETURN_TO_BSL
    
                  BIS.B   #BIT1, &P5OUT
    
                  POP.W    RET_low                 ; remove first word from return addr
                  POP.W    RET_high                ; remove second word from return addr
    
                  RETA                             ; should now return to the BSL location
    
    ;--------------------------------------------------------------
                   ;BSL Signature Area
    ;--------------------------------------------------------------
         .def BslEntryLoc                             ;location of BSL Entry Address
         .def BslProtectVecLoc                        ;location of BSL_Protect() vector
         .def PBSLSigLoc                              ;location of primary BSL signature
         .def SBSLSigLoc                              ;location of secondary BSL signature
         .def PJTAGLOCK_KEY                           ;location of primary JTAG Lock Key
         .def SJTAGLOCK_KEY                           ;location of secondary JTAG Lock Key
    
         .def BSL_REQ_JTAG_OPEN
         .def BSL_REQ_APP_CALL
     
    ;**************************************************************
    ; Name       :BSL_Protect
    ;**************************************************************
    BSL_REQ_JTAG_OPEN  .equ  0x0001                  ;Return Value for BSLUNLOCK Function to open JTAG
    BSL_REQ_APP_CALL   .equ  0x0002                  ;Return Value for BSLUNLOCK Function to Call BSL again
    
    BSL_Protect
                  CLR      	RET_low                  ;lock (keep JTAGLOCK_KEY state)
                 
                  BIS     	#SYSBSLPE+SYSBSLSIZE0+SYSBSLSIZE1 , &SYSBSLC ; protects BSL
    
                  BIS.B   #BIT0, &P5DIR
                  BIS.B   #BIT1, &P5DIR
    
                  BIC.B   #BIT1, &P5OUT
                  BIC.B   #BIT0, &P5OUT
    
    			  BIT.W     #SYSBSLIND,&SYSCTL      ;check for BSL start request
                  JZ      	BCC2BSL
    
                  BIS.B   	#BSL_REQ_APP_CALL, RET_low
    
    BCC2BSL:
    			  RETA
    
    
    
    	.sect ".BSLSIG"
    
                     .word       0xFFFF
    BslProtectVecLoc .word       BSL_Protect             ; Do tejto funkcie skoci pri starte programu VZDY.
    PBSLSigLoc       .word       03CA5h                  ; 1st BSL signature
    SBSLSigLoc       .word       0C35Ah                  ; 2nd BSL signature
                     .word       0xFFFF
    BslEntryLoc      .word       BSL_Entry_JMP           ; BSL_Entry_JMP
    
    PJTAGLOCK_KEY    .word       0xFFFF                  ; Primary Key Location
    SJTAGLOCK_KEY    .word       0xFFFF                  ; Secondary Key Location
                                                         ; set default unlock JTAG with option to lock with writting
                                                         ; a value <> 0x0000 or 0xFFFF
    .end
    

     

  • Your application looks OK.

    However, it looks as if the interrupt vectors (including the reset vector) were overwritten when you flashed the BSL.
    Show the BSL's output . txt file.
  • OK, this is builded .txt file of my bootloader code:

    @1000
    04 3C FE 3F FF 3F FF 3F FF 3F 30 40 5A 15 
    @1010
    00 08 08 04 D2 D3 42 02 3D 90 AD DE 04 20 3E 90 
    EF BE 01 20 03 3C 0C 43 0D 43 10 01 E2 D3 42 02 
    3C 41 3D 41 10 01 0C 43 B2 D0 03 80 82 01 D2 D3 
    44 02 E2 D3 44 02 E2 C3 42 02 D2 C3 42 02 B2 B0 
    10 00 80 01 01 24 6C D3 10 01 
    @1064
    6A 14 21 82 82 43 1A 26 B2 40 00 A5 1C 26 B2 40 
    41 03 00 24 B2 40 A0 01 02 24 B2 40 33 02 68 01 
    82 43 60 01 B2 40 40 00 62 01 82 43 6A 01 B2 40 
    3C 20 64 01 B2 40 20 00 42 03 B2 40 20 02 40 03 
    F2 40 06 00 0A 02 E2 43 04 02 3E 40 00 02 3F 40 
    0A 24 1F 53 CF 43 FF FF 1E 83 FB 23 B2 40 0A 24 
    04 24 B2 40 0A 24 06 24 82 43 1A 26 38 40 3B 00 
    B2 3C B2 90 A5 A5 1A 26 02 24 6F 42 08 3C 82 43 
    1A 26 0F 18 4D 5D 00 18 4D DC 4D 13 4F 43 1E 42 
    06 24 CE 48 00 00 1E 42 06 24 CE 4F 01 00 2C 43 
    B0 13 9E 14 98 3C CC 0F B0 13 00 14 4C 93 05 20 
    B0 13 A0 12 CF 43 01 00 F2 3F B0 13 A0 12 3E 40 
    05 00 CF 4E 01 00 EB 3F B2 90 A5 A5 1A 26 74 20 
    92 42 1C 26 44 01 3F 40 40 00 1F 52 1C 26 82 4F 
    40 01 B2 90 05 00 08 24 67 28 81 4C 00 00 81 4D 
    02 00 15 42 08 24 25 82 29 42 19 52 04 24 CE 0C 
    CF 0D 35 B0 00 80 0B 7B 3B E3 CA 05 0A 5E 0B 6F 
    0F 9B 03 28 51 20 0E 9A 4F 2C C6 0E C7 0F 16 F3 
    07 F3 07 93 2C 20 06 93 2A 20 35 B0 00 80 0C 7C 
    3C E3 CD 0E C4 0F 0D 85 04 7C 2D 81 14 71 02 00 
    34 93 02 20 3D 93 1B 24 B2 90 A5 A5 1A 26 12 20 
    2D 49 B0 13 BC 12 84 4D 00 00 B0 13 BC 12 2D 94 
    02 20 44 43 01 3C 54 43 92 B3 46 01 04 24 74 40 
    03 00 01 3C 64 42 29 53 1E 53 0F 63 14 3C B2 90 
    A5 A5 1A 26 0E 20 6D 49 B0 13 BC 12 C4 4D 00 00 
    B0 13 BC 12 64 44 4D 94 02 20 44 43 03 3C 54 43 
    01 3C 64 42 19 53 44 93 07 20 1E 53 0F 63 0F 9B 
    B8 2B 02 20 0E 9A B5 2B 92 42 1C 26 40 01 B0 13 
    AE 12 09 3C B0 13 A0 12 3E 40 07 00 CF 4E 01 00 
    2C 43 B0 13 9E 14 B0 13 C8 12 5C B3 FC 27 1F 43 
    1F 52 04 24 1E 42 04 24 5C 4E 03 00 0D 43 B0 13 
    02 15 1E 42 04 24 5E 4E 02 00 0C DE B0 13 02 15 
    6E 4F 0C DE 1E 42 04 24 6E 4E 3E 80 10 00 5C 27 
    1E 83 49 27 2E 82 03 24 2E 83 2B 27 D3 3F 92 42 
    1C 26 44 01 3F 40 06 00 1F 52 1C 26 82 4F 40 01 
    C2 43 E0 FF B0 13 AE 12 3B 3F 03 43 1F 42 06 24 
    CF 48 00 00 1F 42 06 24 10 01 3F 40 10 00 1F 52 
    1C 26 82 4F 44 01 10 01 C4 0F 0F 18 44 54 00 18 
    44 DE 10 01 21 83 81 43 00 00 4C 43 0D 43 B2 40 
    20 89 44 03 92 B3 44 03 FD 27 B2 F0 FE FE 44 03 
    92 52 02 24 54 03 3E 40 09 00 0F 43 92 52 00 24 
    54 03 92 C3 44 03 92 B3 44 03 FD 27 5F 01 B2 B0 
    00 04 44 03 02 24 3F D0 00 01 1E 83 EF 23 4F 4F 
    0D 93 0D 20 3F 90 80 00 02 20 1D 53 5E 3C 7C 40 
    51 00 B0 13 E6 13 B0 13 F6 13 FD 23 56 3C 1D 93 
    51 24 2D 93 33 24 CE 0D 1E 82 08 24 3E 90 03 00 
    29 24 2E 92 23 20 4F 4F 8F 10 81 DF 00 00 2C 41 
    B2 43 54 01 82 93 08 24 09 24 3E 40 0A 24 0F 43 
    F2 4E 52 01 1F 53 1F 92 08 24 FA 2B 82 9C 54 01 
    08 24 7C 40 52 00 B0 13 E6 13 B0 13 F6 13 FD 23 
    2C 3C 4C 43 B0 13 50 14 5C 43 29 3C CD 4F 07 24 
    1D 53 23 3C 81 4F 00 00 1D 53 1F 3C 4F 4F 8F 10 
    82 DF 08 24 82 93 08 24 07 20 7C 40 53 00 B0 13 
    E6 13 B0 13 F6 13 FD 23 B2 90 01 02 08 24 07 28 
    7C 40 54 00 B0 13 E6 13 B0 13 F6 13 FD 23 3D 40 
    03 00 03 3C 82 4F 08 24 2D 43 4C 93 78 27 21 53 
    10 01 B0 13 50 14 3E 40 00 02 3F 40 0A 24 6C 43 
    10 01 1F 53 CF 43 FF FF 1E 83 10 01 0A 14 31 82 
    CA 0C CC 01 3D 40 7C 15 3E 40 06 00 B0 13 42 15 
    3D 40 06 00 CC 01 0E 43 7F 4A 7F EC 0E DF 1D 83 
    FB 23 0E 93 03 24 7C 40 05 00 0D 3C B1 40 FF 7F 
    06 00 02 3C 91 83 06 00 91 93 06 00 FB 37 B2 40 
    A5 A5 1A 26 4C 43 31 52 0A 16 10 01 92 42 50 03 
    52 03 92 52 00 24 52 03 4C 4C 3C 50 00 02 5C 02 
    3F 40 00 02 3E 40 0B 00 92 B3 42 03 FD 27 92 C3 
    42 03 92 52 00 24 52 03 B2 D0 80 00 42 03 1C B3 
    04 24 0C EF B2 F0 7F FF 42 03 5F 01 5C 01 1E 83 
    EB 23 92 B3 42 03 FD 27 10 01 CD 0C 7C 40 80 00 
    B0 13 50 14 B0 13 D6 14 B0 13 50 14 B2 43 54 01 
    1D 93 09 38 3B 40 0A 24 7C 4B C2 4C 52 01 B0 13 
    50 14 1D 83 F9 23 1D 42 54 01 B0 13 D6 14 80 00 
    50 14 4C 4D B0 13 50 14 CC 0D 8C 10 8C 11 4C 4C 
    10 01 5C 02 0D 6D 5C 02 0D 6D 5C 02 0D 6D 5C 02 
    0D 6D 5C 02 0D 6D 5C 02 0D 6D 5C 02 0D 6D 5C 02 
    0D 6D 5C 02 0D 6D 5C 02 0D 6D 5C 02 0D 6D 5C 02 
    0D 6D 5C 02 0D 6D 5C 02 0D 6D 5C 02 0D 6D 10 01 
    B2 40 80 5A 5C 01 3D 40 4C 57 3F 40 00 1C 03 3C 
    2F 53 8F 4D FE FF 0E 41 0F 9E FA 2B 10 01 CF 0C 
    0E 93 05 24 1F 53 FF 4D FF FF 1E 83 FB 23 10 01 
    03 43 FF 3F 10 01 31 40 00 44 00 18 F2 40 58 15 
    0A 26 00 18 F2 40 58 15 0E 26 B0 13 24 15 0C 43 
    B0 13 64 10 B0 13 54 15 AA BB CC DD EE FF 04 
    @17f0
    FF FF 36 10 A5 3C 5A C3 FF FF 00 10 FF FF FF FF 
    @fffe
    5A 15 
    q
    

  • @fffe
    5A 15 

    There's your problem.

    What function is at this address?

  • Hmm, How can I found out it? I looked into .asm list file (.lst) and I cannot see anything. If you look into bootloader .txt code, 5A 15 are last bytes in @1000 section..
  • Ok. I look into .map file in my BSL code and:

    0000155a _c_int00
  • That is the entry point of the C startup code. Do you have a main() function?
  • Yes, of course main() function is included. In the main function is a bootloader code to communicate with PC... That code I downloaded from TI BSL package. This is my link file:

    /******************************************************************************/
    /* lnk_msp430f5438a.cmd - LINKER COMMAND FILE FOR LINKING MSP430F5438A PROGRAMS     */
    /*                                                                            */
    /*   Usage:  lnk430 <obj files...>    -o <out file> -m <map file> lnk.cmd     */
    /*           cl430  <src files...> -z -o <out file> -m <map file> lnk.cmd     */
    /*                                                                            */
    /*----------------------------------------------------------------------------*/
    /* These linker options are for command line linking only.  For IDE linking,  */
    /* you should set your linker options in Project Properties                   */
    /* -c                                               LINK USING C CONVENTIONS  */
    /* -stack  0x0100                                   SOFTWARE STACK SIZE       */
    /* -heap   0x0100                                   HEAP AREA SIZE            */
    /*                                                                            */
    /*----------------------------------------------------------------------------*/
    
    
    /****************************************************************************/
    /* SPECIFY THE SYSTEM MEMORY MAP                                            */
    /****************************************************************************/
    
    /*BSL Specific Memory Locations*/
    
    
    MEMORY
    {
        SFR                     : origin = 0x0000, length = 0x0010
        PERIPHERALS_8BIT        : origin = 0x0010, length = 0x00F0
        PERIPHERALS_16BIT       : origin = 0x0100, length = 0x0100
    
        /*RAM                     : origin = 0x1C00, length = 0x4000*/
    
        RAM                     : origin = 0x2400, length = 0x2000
        USBRAM                  : origin = 0x1C00, length = 0x0800
    
        INFOA                   : origin = 0x1980, length = 0x0080
        INFOB                   : origin = 0x1900, length = 0x0080
        INFOC                   : origin = 0x1880, length = 0x0080
        INFOD                   : origin = 0x1800, length = 0x0080
    
        ZAREA              		: origin = 0x1000, length = 0x0010
        BSL430_VERSION          : origin = 0x1010, length = 0x0004
        ZAREA_CODE          	: origin = 0x1014, length = 0x0050
        FLASH                   : origin = 0x1064, length = 0x078C
        BSLSIG              	: origin = 0x17F0, length = 0x0010
    
        INT00                   : origin = 0xFF80, length = 0x0002
        INT01                   : origin = 0xFF82, length = 0x0002
        INT02                   : origin = 0xFF84, length = 0x0002
        INT03                   : origin = 0xFF86, length = 0x0002
        INT04                   : origin = 0xFF88, length = 0x0002
        INT05                   : origin = 0xFF8A, length = 0x0002
        INT06                   : origin = 0xFF8C, length = 0x0002
        INT07                   : origin = 0xFF8E, length = 0x0002
        INT08                   : origin = 0xFF90, length = 0x0002
        INT09                   : origin = 0xFF92, length = 0x0002
        INT10                   : origin = 0xFF94, length = 0x0002
        INT11                   : origin = 0xFF96, length = 0x0002
        INT12                   : origin = 0xFF98, length = 0x0002
        INT13                   : origin = 0xFF9A, length = 0x0002
        INT14                   : origin = 0xFF9C, length = 0x0002
        INT15                   : origin = 0xFF9E, length = 0x0002
        INT16                   : origin = 0xFFA0, length = 0x0002
        INT17                   : origin = 0xFFA2, length = 0x0002
        INT18                   : origin = 0xFFA4, length = 0x0002
        INT19                   : origin = 0xFFA6, length = 0x0002
        INT20                   : origin = 0xFFA8, length = 0x0002
        INT21                   : origin = 0xFFAA, length = 0x0002
        INT22                   : origin = 0xFFAC, length = 0x0002
        INT23                   : origin = 0xFFAE, length = 0x0002
        INT24                   : origin = 0xFFB0, length = 0x0002
        INT25                   : origin = 0xFFB2, length = 0x0002
        INT26                   : origin = 0xFFB4, length = 0x0002
        INT27                   : origin = 0xFFB6, length = 0x0002
        INT28                   : origin = 0xFFB8, length = 0x0002
        INT29                   : origin = 0xFFBA, length = 0x0002
        INT30                   : origin = 0xFFBC, length = 0x0002
        INT31                   : origin = 0xFFBE, length = 0x0002
        INT32                   : origin = 0xFFC0, length = 0x0002
        INT33                   : origin = 0xFFC2, length = 0x0002
        INT34                   : origin = 0xFFC4, length = 0x0002
        INT35                   : origin = 0xFFC6, length = 0x0002
        INT36                   : origin = 0xFFC8, length = 0x0002
        INT37                   : origin = 0xFFCA, length = 0x0002
        INT38                   : origin = 0xFFCC, length = 0x0002
        INT39                   : origin = 0xFFCE, length = 0x0002
        INT40                   : origin = 0xFFD0, length = 0x0002
        INT41                   : origin = 0xFFD2, length = 0x0002
        INT42                   : origin = 0xFFD4, length = 0x0002
        INT43                   : origin = 0xFFD6, length = 0x0002
        INT44                   : origin = 0xFFD8, length = 0x0002
        INT45                   : origin = 0xFFDA, length = 0x0002
        INT46                   : origin = 0xFFDC, length = 0x0002
        INT47                   : origin = 0xFFDE, length = 0x0002
        INT48                   : origin = 0xFFE0, length = 0x0002
        INT49                   : origin = 0xFFE2, length = 0x0002
        INT50                   : origin = 0xFFE4, length = 0x0002
        INT51                   : origin = 0xFFE6, length = 0x0002
        INT52                   : origin = 0xFFE8, length = 0x0002
        INT53                   : origin = 0xFFEA, length = 0x0002
        INT54                   : origin = 0xFFEC, length = 0x0002
        INT55                   : origin = 0xFFEE, length = 0x0002
        INT56                   : origin = 0xFFF0, length = 0x0002
        INT57                   : origin = 0xFFF2, length = 0x0002
        INT58                   : origin = 0xFFF4, length = 0x0002
        INT59                   : origin = 0xFFF6, length = 0x0002
        INT60                   : origin = 0xFFF8, length = 0x0002
        INT61                   : origin = 0xFFFA, length = 0x0002
        INT62                   : origin = 0xFFFC, length = 0x0002
        RESET                   : origin = 0xFFFE, length = 0x0002
    }
    
    /****************************************************************************/
    /* SPECIFY THE SECTIONS ALLOCATION INTO MEMORY                              */
    /****************************************************************************/
    
    SECTIONS
    {
        .BSL430_VERSION        			: {} > BSL430_VERSION
        .ZAREA      					: {} > ZAREA
        .ZAREA_CODE 					: {} > ZAREA_CODE
        .BSLSIG     					: {} > BSLSIG
    
        .bss       : {} > RAM               /* GLOBAL & STATIC VARS              */
        .sysmem    : {} > RAM               /* DYNAMIC MEMORY ALLOCATION AREA    */
        .stack     : {} > RAM (HIGH)        /* SOFTWARE SYSTEM STACK             */
    
    
        .text      : {}>> FLASH      		/* CODE                              */
    
        .text:_isr : {} > FLASH             /* ISR CODE SPACE                    */
        .cinit     : {} > FLASH             /* INITIALIZATION TABLES             */
    
        .const     : {} > FLASH     		/* CONSTANT DATA                     */
    
        .cio       : {} > RAM               /* C I/O BUFFER                      */
    
        .pinit     : {} > FLASH             /* C++ CONSTRUCTOR TABLES            */
    
        .infoA     : {} > INFOA             /* MSP430 INFO FLASH MEMORY SEGMENTS */
        .infoB     : {} > INFOB
        .infoC     : {} > INFOC
        .infoD     : {} > INFOD
    
        .int00   : {} > INT00                 MSP430 INTERRUPT VECTORS          
        .int01   : {} > INT01
        .int02   : {} > INT02
        .int03   : {} > INT03
        .int04   : {} > INT04
        .int05   : {} > INT05
        .int06   : {} > INT06
        .int07   : {} > INT07
        .int08   : {} > INT08
        .int09   : {} > INT09
        .int10   : {} > INT10
        .int11   : {} > INT11
        .int12   : {} > INT12
        .int13   : {} > INT13
        .int14   : {} > INT14
        .int15   : {} > INT15
        .int16   : {} > INT16
        .int17   : {} > INT17
        .int18   : {} > INT18
        .int19   : {} > INT19
        .int20   : {} > INT20
        .int21   : {} > INT21
        .int22   : {} > INT22
        .int23   : {} > INT23
        .int24   : {} > INT24
        .int25   : {} > INT25
        .int26   : {} > INT26
        .int27   : {} > INT27
        .int28   : {} > INT28
        .int29   : {} > INT29
        .int30   : {} > INT30
        .int31   : {} > INT31
        .int32   : {} > INT32
        .int33   : {} > INT33
        .int34   : {} > INT34
        .int35   : {} > INT35
        .int36   : {} > INT36
        .int37   : {} > INT37
        .int38   : {} > INT38
        .int39   : {} > INT39
        .int40   : {} > INT40
        .int41   : {} > INT41
        .int42   : {} > INT42
        .int43   : {} > INT43
        .int44   : {} > INT44
        .int45   : {} > INT45
        .int46   : {} > INT46
        .int47   : {} > INT47
        .int48   : {} > INT48
        .int49   : {} > INT49
        .int50   : {} > INT50
        .int51   : {} > INT51
        .int52   : {} > INT52
        .int53   : {} > INT53
        .int54   : {} > INT54
        .int55   : {} > INT55
        .int56   : {} > INT56
        .int57   : {} > INT57
        .int58   : {} > INT58
        .int59   : {} > INT59
        .int60   : {} > INT60
        .int61   : {} > INT61
        .int62   : {} > INT62
        .reset   : {} > RESET              /* MSP430 RESET VECTOR               */ 
    }
    
    /****************************************************************************/
    /* INCLUDE PERIPHERALS MEMORY MAP                                           */
    /****************************************************************************/
    
    -l msp430f5529.cmd
    
    

    As you can see I remapped FLASH section into 2KB bootloader section (whole BSL code).

  • You can name the function that runs the BSL "main", if you really want to. But in any case you have to replace the C startup code with your own version that does not set the reset vector.

  • thanks but how? This is original source code an I only changed BSL entry start sequence ...
  • Do you know that you cannot jump, call, or vector into any address 0x1010-0x17FE from any address outside of 0x1000-0x17FE ?
    The Reset Vector 0x155A simply would not work.
    You could utilize the Z-Area to do so indirectly.
  • Hi, As you can see, every JUMP or BRANCH outside is done in ZAREA, so it can be done? Or? Guys, I totally disapointed about this. I am working around it about 4 days and without any success. Example from TI BSL main page just does not work, so I eddited BSL from TI wiki - I only edited BSL entry sequence. But as you can see, there is a problem which I cannot discover. Please give me some guidance.... please, I am totally lost

  • As you can see, I said "... jump, call, or vector into ..."

    I can see that the address of the Reset Vector is. at 0xFFFE which is obviously outside the area 0x1000-0x17FE.

    I can also see that the value of the Reset Vector is point to 0x155A which is clearly inside the area 0x1010-0x17FE.

    Thus it is obvious to me that this is not going to work.

  • sorry, my mistake. You are talking about BSL output code right? But this is compiled output from TI example. So now I really do not know where is a problem? Why 155A is at RESET vector is for me clear. Its start of the bootloader main code. IF on the reset vector MUST be FF FF how can I edit .cmd or .asm file not to do this? Or I just manually rewrite RESET vector to FF FF and download into MCU?
  • When you generate the BSL code, you should not generate any RESET vector. If you use assembler, just do not tell it to generate RESET vector. If you use c-compiler, you have to twist its arms to not generate RESET vector. Either way, the starting point of BSL code should be given in the BSL-Protecting-Function, and should not be given in the RESET vector.
  • So when the RESET vector will not be generated it means that it will be 0xFF 0xFF, but Clemens Ladisch said:

    The MSP430 indeed has boot code that is executed before the BSL or your application code, and that cannot be seen.

    The BSL is run if the reset vector is empty, so I'd guess your BSL code accidentally erased it.

     

    So when the RESET vector will not be set it still be invoked after RESET... or will not?

  • Actually, it is your assembler code that replaces the C startup code; your C_Branch jumps to _c_int00. It is the file that implements _c_int00 that also defines the reset vector to point to that address.

    The easiest way to handle this would be to remove the FFFE part from the .txt file. Alternatively, flash the BSL before the application, so the reset vector gets overwritten with the correct one.
  • Yes, I have a nice feeling that I understand. And do you know why R12 register is used to distinguish if the code jumps to BSL or to application code? It is something inside MSP430 that R12 is so important? Because only thing I do is that I set the R12 = 0x0002 if boot sequence was entered and then follows RETA... I think that R12 is wired inside the MSP430 and when is equal to 0x0002 the program jumps to 0x17FA location. Thank you
  • In the MSP430 ABI, R12 is the register used for the return value of a function.
  • OK, and where is R12 register compared in .asm file? I cannot see that operation...or the comparision is done "inside" MSP430? If you explain me full code flow it would be great! I mean the section where the device find out the path - if it jumps to application or into BSL memory. I understand that after R12 = 0x0002 program jump (somehow) to 0x17FA location where is ZAREA section and then simply branch to _init00 section which is the main function of BSL algorithm. If R12 is zero so program jump (somehow) to RESET vector and then to application code. But I want to know where the comparision is done. Thank you again! I am just curious..
  • All this is done in the bootcode, which is mostly undocumented, and even more protected than the BSL.
  • Yes I saw this picture many times... But it is not answer on my questions. But Clemens Ladisch's answer is enough for me. I changed reset vector to 0xFF 0xFF and it seems to be right. I will be testing it and let you know. Thank you you all.

  • Hi again,


    I did some changes, but BSL behavior is really strange. Here is my .asm part:

    BSL_Protect:
    			  ; Znulovanie registra R12
                  CLR      	RET_low
                  ; Nastavenie potrebnych bitov na ochranu BSL proti prepisu!!! Moze sa mi totizto stat, ze si ho omylom programovo prepisem.
                  BIS     	#SYSBSLPE+SYSBSLSIZE0+SYSBSLSIZE1 , &SYSBSLC
    			  ; Bola zadana spravna BSL sekvencia? Teraz mam placidla na !RST a TEST.
    			  BIT.W     #SYSBSLIND,&SYSCTL
    			  ; Ak nie, tak navrat z bootloadera
                  JZ      	BCC2BSL
    			  ; Ak ano, tak nastav R12 = 0x0002, aby program skocil na 0x17FA
                  BIS.B   	#BSL_REQ_APP_CALL, RET_low
    			  ; Bliknutie LED diody, ze som v BSL
                  BIS.B   	#BIT0, &P5DIR
                  BIS.B   	#BIT0, &P5OUT
                  ; Pre istotu si ulozim R11, Co ak ten blazon to ma vnutorne niekde zadratovane
    			  PUSH 	  R11
                  MOV.W   #300, R11
    DELAY_LOOP:   DEC.W   R11
                  JNZ     DELAY_LOOP
                  POP     R11
                  BIC.B   #BIT0, &P5OUT
    			  ; Navrat. Rovnako sem skoci, ak nebola zadana BSL sekvencia
    BCC2BSL:
    			  RETA

    When I make the BSL seguence the LED diode blinks once time and I am into bootloader. Everything works. But when I press RST button again to reset MCU the LED diode blinks again! The LED stops blinking only if I totally turn off my device and then turn on OR if I press TEST button and then RST button the LED also doesnt blink.


    I do not understand, why? The reset vector points do 0xFF 0xFF or to application code. Aplication code works... Thanks

  • Apparently, the reset does not clear the SYSBSLIND bit.

**Attention** This is a public forum