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.
In our design we use the msp430F2274 device, which we want to program every time the main CPU (AM5746) boots up. Thus, we run the msp430_bsl application on the main CPU (under Linux 5.4 OS), which we compile from the 'Sitara Linux Host for MSP430 UART BSL' folder provided by TI in the slaa760.zip file.
From the 'Sitara Linux Host for MSP430 UART BSL' folder we use the BSL application file-set provided in the UART_BSL_MSP430 sub-folder to compile the msp430_bsl application. For our initial test purpose of developing our custom msp430_bsl application we use a simple blinking LED msp430 program.
Originally, we have successfully tested our blinking LED msp430 program by downloading it to the msp430F2274 micro-controller via a JTAG programmer.
So, after we compile the msp430_bsl programming application we run manually it after the OS has booted and we observe the following: (refer to the main.c file)
An obvious question is: Why does this happen?
File 0_BSL_timing_overall.png contains the overall timing of the signals involved in the BSL programming, with references to the following files, providing a more detailed view of the overall timing diagram, which was collected by a logic analyzer:
The Fist Attempt
------------------------
The signal sequence starts with a device reset (line 176), which is followed by the BSL entry sequence (line 185), which is followed by the HEADER (80) and ACK (90) characters exchange between the msp430_bsl application (MCU_BSL_RX) and the msp device (MCU_BSL_TX) signals. In the further text this characters' exchange is marked as a SYNC event.
See 1_detail_bsl-entry_wrt-pwd_def.png for details.
Then the msp430_bsl application sends the 'RX password' command (line 187), to which the msp device responds with an ACK but only after a rather long time of ~450 ms!? (see 2_bsl-entry_wrt-pwd_def_with_delayed_ack.png). This is followed by a SYNC exchange.
Then the msp430_bsl application sends the 'TX data block command', trying to get the device ID. However, at this point, the msp device responds with a DATA_NACK (A0), indicating an unsuccessful command execution. For details, see 3_detail_delayed_ack_and_tx_data_block_nack.png.
As the consequence of this failure, the msp430_bsl application then starts the second attempt of the msp device programming process.
The Second Attempt
-----------------------------
For details see 4_tx_data_block_nack_rst_new_bsl_entry_with_success_seq.png
Like in the first attempt, a new device reset is generated followed by the bsl entry sequence, which is followed by a SYNC event.
The msp430_bsl application sends the 'RX password' command again but this time the msp device responds with ACK with no delay, which is followed by a SYNC event as before.
Then the msp430_bsl application sends the 'TX data block command' again but this time the msp device responds correctly, by sending the device ID data!
From that point on, the remaining BSL programming sequence finishes correctly and the msp device starts properly executing its newly downloaded program.
Questions:
/* * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ //****************************************************************************** // Version history: // 1.0 07/17 Initial version. (Nima Eskandari) // 1.1 07/17 Added Comments. (Nima Eskandari) //---------------------------------------------------------------------------- // Designed 2017 by Texas Instruments // // Nima Eskandari // Texas Instruments Inc. // August 2017 // Built with CCS Version: Code Composer Studio v7 //****************************************************************************** #include <stdio.h> #include <stdbool.h> #include <stddef.h> #include <termios.h> #include <time.h> #include <fcntl.h> #include <unistd.h> #include <sys/types.h> #include <string.h> #include <gpiod.h> #include <time.h> #include "uart_if.h" #include "bsl.h" #include "config.h" #include "gpiod_if.h" #include "utils.h" //***************************************************************************** // MSP430 Image to use ******************************************************** //***************************************************************************** #include "msp430f2274_image.h" //***************************************************************************** // Program the MSP430 with the specified image ******************************** //***************************************************************************** bool ProgramMSP430() { bool numberOfErrors = 0; bool result = true; uint16_t section = 0; uint8_t * flashStartOfData = 0; for (section = 0; section < flash_sections; section++) { printf("\n\n****Section: %d****\n\n", section); printf("Address: 0x%X\n", flash_address[section]); result = EraseSegment(flash_address[section]); if (!result) { printf("Erase failed\n"); return false; } else { printf("Erase successful\n"); } } for (section = 0; section < flash_sections; section++) { printf("\n\n****Section: %d****\n\n", section); printf("Address: 0x%X\n", flash_address[section]); if (section == 0) { flashStartOfData = flash; } else { flashStartOfData = flashStartOfData + flash_length_of_sections[section - 1]; } result = EraseCheck(flash_address[section], flash_length_of_sections[section]); if (!result) { printf("Erase check failed\n"); return false; } else { printf("Erase check successful\n"); } result = WriteLargeDataToMemory(flash_address[section], flash_length_of_sections[section], flashStartOfData); if (!result) { printf("Write Large Data To Memory failed\n"); return false; } else { printf("Write Large Data To Memory successful\n"); } } if (numberOfErrors != 0) { return false; } return true; } #define MAX_RETRY 5 int main() { bool result = true; uint8_t status; printf("\n\n******** MSP430 BSL Program *****\n"); // debug // PinMuxConfig(); // Do not modify pin muxing as the CPU bootloader has // already done that. printf("Configuring & initialising the signals\n"); GPIO_IF_line_config("CPU_LED"); GPIO_IF_line_config("MCU_BSL_EN"); GPIO_IF_line_config("MCU_RESET"); uint8_t retry = MAX_RETRY; uint8_t first_pass = 0; int time_Delay; struct timespec t_Ref; while (retry) { printf("\n\n***** Attempt %d *****\n\n", MAX_RETRY - retry + 1); // Configure and initialise the signals if (first_pass == 1) { UART_Close(); } Reset(); printf("Device Reset\n"); printf("Initialsing UART4\n"); UART_Initialize(); first_pass = 1; // UART_ReadByteWithTimeout(0, &status); TOBE removed BSLEntrySequence(); printf("Writing password\n"); result = WritePasswordDefault(); if (!result) { printf("Writing password failed\n"); retry --; continue; } printf("Writing Password Succeeded\n"); uint8_t deviceIDBytes[2] = {0}; printf("Reading Device ID\n"); result = ReadMemory(0x0FF0, 2, deviceIDBytes); if (!result) { printf("Device ID reading failed\n"); retry --; continue; } else { uint16_t deviceID = deviceIDBytes[0] << 8 | deviceIDBytes[1]; printf("Device ID: 0x%X\n", deviceID); } printf("Programing MSP 430 Device\n"); result = ProgramMSP430(); if (!result) { printf("\nMSP430 programming failed\n"); retry --; continue; } printf("\nMSP430 programming succeeded\n"); Reset(); printf("Device is reset\n"); UART_Close(); GPIO_IF_release_lines(); return 0; } printf("Max retries exceeded\n"); Reset(); printf("Device is reset\n"); UART_Close(); GPIO_IF_release_lines(); return 1; }
Hi,
Thank you for the detail explanation. Please see this from SLAU319X:
It is a normal operation. The reason why it operate like this is that:
1. You already have code in it.
2. In attempt one: Device check the password(you may send 32 byte 0xFFFF). It is not same as with the data saved in FFE0h to FFFFh
3. Device do mass erase and the data saved in FFE0h to FFFFh to be all 0xFFFF.
4. In attempt two: Device check the password(you may send 32 byte 0xFFFF). It is same as with the data saved in FFE0h to FFFFh
5. Device response to other BSL command.
Eason
Actually, I do have one question.
When you say "Device do mass erase and the data saved in FFE0h to FFFFh to be all 0xFFFF.", do you mean that the msp430 device does mass erase on its own only because the password sent was incorrect?
This would seem to be the case as the msp430_bsl application does not send the mass-erase command.
Is the big delay in sending the ACK to the RX password due to the time required to mass-erase the device flash memory?
Bud
Hi Bud,
Sorry, I don't know the details of bootloader code. I'm not sure whether it will erase the code first then to send the ACK.
If it takes about 1s, I think yes.
Eason
**Attention** This is a public forum