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.

IWR6843AOP: Flashing an image via usart doesn't work

Part Number: IWR6843AOP
Other Parts Discussed in Thread: UNIFLASH, IWR6843

Hey everyone. 

For a project that i am working on i would like to be able to flash the bootloader of the IWR6843 via usart with a efr32fg23a chip as a sort of middle man between a server and the IWR6843 so that it can be flashed remotely. I've written the basic code for this application and the frames that need to be send to the IWR6843 are build correctly according to the document swra627-bootloader modus. When i check the output of my program it matches the output of the uniflash messages completely (except for the GET STATUS command which should not be necessary according to the swra627 document).

The problem i am facing now is when i put the board into run mode, the flashed program on the IWR6843 does not function. There is no output data being send after running the gui needed. I'm trying to flash the overhead-3d-people-counting bin file from the industrial toolbox to be sure that the code on the IWR6843 is not the problem. When i flash this bin file with uniflash it works fine. But with my own code it does not function, eventhough the usart output is the same and my code waits for a ACK from the IWR6843 like it's supposed to. All the commands get send via usart and they all get an ACK back.

I've tried multiple solutions like waiting for the ACK message that's send when a command is received. I've even done this by hand to make sure all the message get an ACK back, which they do. I've also tried sending less that the 240 bytes, but this seems to give an error which i can't figure out what it means since the message is not documented, but i am guessing it's the NACK since it only shows up when i execute the close command. And like i said before all the messages are send over usart and they all get an ACK back so this got me really confused on what's going wrong.

Does anyone know what the problem might be or does anyone have a suggestion on what else i could try since i am running out of ideas. i've read on another forum post that the bootloader might have some bugs (IWR6843: Bootloader QSPI flash write) could i have stumbled on one of them? .

With kind regards,

Jan.

  • Hi Jan,

    Thanks for reaching out! 

    The attached c code was made to build these uart commands. There are no timing constraints but some commands (i.e. erase) respond with an ACK/NACK (NACK when checksum isn’t correct) while others send information packets of various sizes (i.e. getversioninfo). You need to anticipate the right type of information to be received back and read what is received before sending the next command. The code attached takes this into account and may help you understand better.

    What is the command you are sending that you believe you are getting a NACK back for? How are you sending the command byte by byte? What are you receiving that you think is a NACK?

    /*
     * Copyright (c) 2015-2021, Texas Instruments Incorporated
     * All rights reserved.
     *
     * 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.
     */
    
    /*
     *  ======== mmwavebldr.c ========
     */
    
    #include <mmwavebldr.h>
    #include <stdio.h>
    #include <stdint.h>
    #include <stddef.h>
    #include <unistd.h>
    
    #include <time.h>
    
    /* Driver Header files */
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/UART.h>
    
    //#define DEBUG_SPIN
    //#define DEBUG_VERBOSE
    
    #define CONSOLEPRINT(x) \
        if (bldrObj.loggerFxn) bldrObj.loggerFxn(x)
    #define CONSOLEPRINT1(x,a) \
        if (bldrObj.loggerFxn) bldrObj.loggerFxn(x,a)
    #define CONSOLEPRINT2(x,a,b) \
        if (bldrObj.loggerFxn) bldrObj.loggerFxn(x,a,b)
    #define CONSOLEPRINT3(x,a,b,c) \
        if (bldrObj.loggerFxn) bldrObj.loggerFxn(x,a,b,c)
    #define CONSOLEPRINT4(x,a,b,c,d) \
        if (bldrObj.loggerFxn) bldrObj.loggerFxn(x,a,b,c,d)
    #define CONSOLEPRINT5(x,a,b,c,d,e) \
        if (bldrObj.loggerFxn) bldrObj.loggerFxn(x,a,b,c,d,e)
    #define NOTIFY(x) \
        if (bldrObj.notifyFxn) bldrObj.notifyFxn(x)
    
    
    #ifdef DEBUG_SPIN
    volatile int spin = 1;
    #endif
    
    #ifdef DEBUG_VERBOSE
    static int debugVerbose = 1;
    #else
    static int debugVerbose = 0;
    #endif
    
    typedef struct MMWAVEBLDR_Obj {
        int initialised;
        int uartIndex;
        int gpioNhib;
        int gpioSop2;
        int gpioRst;
    
        UART_Handle uart;
    
        mylogger *loggerFxn;
    
        mygetver *getImgVerFxn;
        mygetlen *getImgLenFxn;
        mygetbuf *getImgBufFxn;
    } MMWAVEBLDR_Obj;
    
    static MMWAVEBLDR_Obj bldrObj = {
        0,
        0,
        0,
        0,
        0,
    
        0,
    
        0,
    
        0,
        0,
        0,
    };
    
    
    /*
     *  =============================== UART ===============================
     */
    #include <ti/drivers/UART.h>
    #include <ti/drivers/uart/UARTMSP432E4.h>
    #include <ti/devices/msp432e4/driverlib/uart.h>
    
    void setFlowControl(UART_Handle uart, int state)
    {
        UARTMSP432E4_HWAttrs const *hwAttrs = uart->hwAttrs;
    
        UARTFlowControlSet(hwAttrs->baseAddr, state);
    }
    
    void setBreak(UART_Handle uart, int state)
    {
        UARTMSP432E4_HWAttrs const *hwAttrs = uart->hwAttrs;
    
        UARTBreakCtl(hwAttrs->baseAddr, state);
    }
    /*
     *  ====================================================================
     */
    
    
    /*-------------------------------------------------------------------*/
    
    /*
    AWR_BOOTLDR_OPCODE_ACK               = struct.pack("B", 0xCC)
    AWR_BOOTLDR_OPCODE_NACK              = struct.pack("B", 0x33)
    AWR_BOOTLDR_OPCODE_PING              = struct.pack("B", 0x20)
    AWR_BOOTLDR_OPCODE_START_DOWNLOAD    = struct.pack("B", 0x21)
    AWR_BOOTLDR_OPCODE_FILE_CLOSE        = struct.pack("B", 0x22)
    AWR_BOOTLDR_OPCODE_GET_LAST_STATUS   = struct.pack("B", 0x23)
    AWR_BOOTLDR_OPCODE_SEND_DATA         = struct.pack("B", 0x24)
    AWR_BOOTLDR_OPCODE_SEND_DATA_RAM     = struct.pack("B", 0x26)
    AWR_BOOTLDR_OPCODE_DISCONNECT        = struct.pack("B", 0x27)
    AWR_BOOTLDR_OPCODE_ERASE             = struct.pack("B", 0x28)
    AWR_BOOTLDR_OPCODE_FILE_ERASE        = struct.pack("B", 0x2E)
    AWR_BOOTLDR_OPCODE_GET_VERSION_INFO  = struct.pack("B", 0x2F)
    */
    
    #define mmwaveBldr_CMD_PING                     0x20
    #define mmwaveBldr_CMD_PING_LEN                 1
    
    #define mmwaveBldr_CMD_OPENFILE                 0x21
    #define mmwaveBldr_CMD_OPENFILE_LEN             (1 + 4 + 4 + 4 + 4) // size + storage type + file type + reserved
    
    #define mmwaveBldr_CMD_CLOSEFILE                0x22
    #define mmwaveBldr_CMD_CLOSEFILE_LEN            (1 + 4) // storage type
    
    #define mmwaveBldr_CMD_FILE_RADARSS_BUILD       0
    #define mmwaveBldr_CMD_FILE_CALIB_DATA          1
    #define mmwaveBldr_CMD_FILE_CONFIG_INFO         2
    #define mmwaveBldr_CMD_FILE_MSS_BUILD           3
    #define mmwaveBldr_CMD_FILE_META_IMAGE1         4
    #define mmwaveBldr_CMD_FILE_META_IMAGE2         5
    #define mmwaveBldr_CMD_FILE_META_IMAGE3         6
    #define mmwaveBldr_CMD_FILE_META_IMAGE4         7
    
    #define mmwaveBldr_CMD_GETLASTSTATUS            0x23
    #define mmwaveBldr_CMD_GETLASTSTATUS_LEN        1
    #define mmwaveBldr_CMD_GETLASTSTATUS_RESPLEN    (1)
    
    #define mmwaveBldr_CMD_WRITEFILESFLASH          0x24
    #define mmwaveBldr_CMD_WRITEFILESFLASH_LEN      1
    
    #define mmwaveBldr_CMD_ERASE                    0x28
    #define mmwaveBldr_CMD_ERASE_LEN                (1 + 4 + 4 + 4)  // cmd + storage + offset + capacity
    
    #define mmwaveBldr_CMD_ERASE_STORAGE_SDRAM      0
    #define mmwaveBldr_CMD_ERASE_STORAGE_FLASH      1
    #define mmwaveBldr_CMD_ERASE_STORAGE_SFLASH     2
    #define mmwaveBldr_CMD_ERASE_STORAGE_EEPROM     3
    #define mmwaveBldr_CMD_ERASE_STORAGE_SRAM       4
    
    
    #define mmwaveBldr_CMD_GETVERSIONINFO           0x2F
    #define mmwaveBldr_CMD_GETVERSIONINFO_LEN       1
    #define mmwaveBldr_CMD_GETVERSIONINFO_RESPLEN   (4 + 8)
    
    #define mmwaveBldr_CMD_ACK_RESPLEN              (2)
    
    /*-------------------------------------------------------------------*/
    
    static uint8_t txPayload[250]; // max payload is 243-2
    static uint8_t rxPayload[250]; // max payload is 243-2
    
    typedef struct txHdr {
        uint8_t syncbyte;
        uint8_t len1;
        uint8_t len2;
        uint8_t chksum;
    } txHdr;
    
    typedef struct rxHdr {
        uint8_t len1;
        uint8_t len2;
        uint8_t chksum;
    } rxHdr;
    
    
    static void mmwaveBldr_sendPacket(uint8_t *payload, uint8_t length)
    {
        uint8_t i;
        txHdr hdr;
    
        hdr.syncbyte = 0xaa;
        hdr.len1 = 0;
        hdr.len2 = length + sizeof(hdr.chksum) + sizeof(hdr.syncbyte);  // length doesn't include the len of length field
        hdr.chksum = 0;
    
        //calc chksum
        for (i = 0; i < length; i++) {
            hdr.chksum += payload[i];
        }
    
        // send header
        UART_write(bldrObj.uart, (uint8_t *) &hdr, sizeof(hdr));
        // send payload
        UART_write(bldrObj.uart, payload, length);
    
    }
    
    static uint8_t mmwaveBldr_readPacket(uint8_t *payload, uint8_t length)
    {
        rxHdr hdr;
        uint8_t len;
    
        // read header
        UART_read(bldrObj.uart, (uint8_t *) &hdr, sizeof(hdr));
    
        len = hdr.len2 - sizeof(uint8_t) - sizeof(uint8_t); // same formula as above
    
        if (len > length) {
            for(;;);
        }
    
        // read payload
        UART_read(bldrObj.uart, payload, len);
    
        // check chksum??
    
        return len;
    }
    
    static void mmwaveBldr_checkAck(uint8_t *payload, uint8_t length)
    {
        if ((payload[0] == 0x00) && (payload[1] == 0xcc) && (length == 2)) {
            return;
        }
        else if ((payload[0] == 0x00) && (payload[1] == 0x33) && (length == 2)) {
            CONSOLEPRINT(">>NACK!!!!\n\r");
            for(;;);
        }
        else {
            for(;;);
        }
    
    }
    
    static void mmwaveBldr_getVersionInfo(void)
    {
        uint8_t len;
    
        txPayload[0] = mmwaveBldr_CMD_GETVERSIONINFO;
        mmwaveBldr_sendPacket(txPayload, mmwaveBldr_CMD_GETVERSIONINFO_LEN);
        len = mmwaveBldr_readPacket(rxPayload, sizeof(rxPayload));
        mmwaveBldr_checkAck(rxPayload, len);
    
        len = mmwaveBldr_readPacket(rxPayload, sizeof(rxPayload));
    
        if (len == mmwaveBldr_CMD_GETVERSIONINFO_RESPLEN) {
            CONSOLEPRINT4(">>ROM Version Info - %d.%d.%d.%d\n\r",
                          rxPayload[0],
                          rxPayload[1],
                          rxPayload[2],
                          rxPayload[3]);
        }
    }
    
    static void mmwaveBldr_getLastStatus(void)
    {
        uint8_t len;
    
        txPayload[0] = mmwaveBldr_CMD_GETLASTSTATUS;
        mmwaveBldr_sendPacket(txPayload, mmwaveBldr_CMD_GETLASTSTATUS_LEN);
    
        len = mmwaveBldr_readPacket(rxPayload, sizeof(rxPayload));
    
        if (len == mmwaveBldr_CMD_GETLASTSTATUS_RESPLEN) {
            if (debugVerbose) {
                CONSOLEPRINT1(">>Status - 0x%02x\n\r", rxPayload[0]);
                if(rxPayload[0] == 0x00) CONSOLEPRINT(">>Status - INITIAL_STATUS\n\r");
                if(rxPayload[0] == 0x40) CONSOLEPRINT(">>Status - SUCCESS\n\r");
                if(rxPayload[0] == 0x4B) CONSOLEPRINT(">>Status - ACCESS_IN_PROGRESS\n\r");
            }
        }
        else {
            CONSOLEPRINT1(">>GetLastStatus Error - 0x%02x\n\r", rxPayload[0]);
            for(;;);
        }
    }
    
    static void mmwaveBldr_ping(void)
    {
        uint8_t len;
    
        txPayload[0] = mmwaveBldr_CMD_PING;
        mmwaveBldr_sendPacket(txPayload, mmwaveBldr_CMD_PING_LEN);
    
        len = mmwaveBldr_readPacket(rxPayload, sizeof(rxPayload));
        mmwaveBldr_checkAck(rxPayload, len);
    
        if (len == mmwaveBldr_CMD_ACK_RESPLEN) {
            if( (rxPayload[0] == 0x00) && (rxPayload[1] == 0xcc) ) CONSOLEPRINT(">>PING ACK!\n\r");
        }
        else {
            CONSOLEPRINT1(">>Ping Response Ack Error - 0x%02x\n\r", rxPayload[1]);
            for(;;);
        }
    
    }
    
    static void mmwaveBldr_erase(void)
    {
        uint8_t len;
    
        txPayload[0] = mmwaveBldr_CMD_ERASE;
    
        txPayload[1] = 0; // storage type
        txPayload[2] = 0;
        txPayload[3] = 0;
        txPayload[4] = mmwaveBldr_CMD_ERASE_STORAGE_SFLASH;
    
        txPayload[5] = 0; // offset
        txPayload[6] = 0; // offset
        txPayload[7] = 0; // offset
        txPayload[8] = 0; // offset
    
        txPayload[9] = 0; // capacity
        txPayload[10] = 0; // capacity
        txPayload[11] = 0; // capacity
        txPayload[12] = 0; // capacity
    
        mmwaveBldr_sendPacket(txPayload, mmwaveBldr_CMD_ERASE_LEN);
        CONSOLEPRINT(">>Erase Requested...\n\r");
    
        len = mmwaveBldr_readPacket(rxPayload, sizeof(rxPayload));
        mmwaveBldr_checkAck(rxPayload, len);
    
        if (len == mmwaveBldr_CMD_ACK_RESPLEN) {
            if( (rxPayload[0] == 0x00) && (rxPayload[1] == 0xcc) ) CONSOLEPRINT(">>Erase Completed!\n\r");
        }
        else {
            CONSOLEPRINT1(">>Erase Response Ack Error - 0x%02x\n\r", rxPayload[1]);
            for(;;);
        }
    }
    
    static void mmwaveBldr_openFile(uint32_t fileSize)
    {
        uint8_t len;
    
        txPayload[0] = mmwaveBldr_CMD_OPENFILE;
    
        txPayload[1] = (fileSize & 0xff000000) >> 24; // file size
        txPayload[2] = (fileSize & 0x00ff0000) >> 16;
        txPayload[3] = (fileSize & 0x0000ff00) >> 8;
        txPayload[4] = (fileSize & 0x000000ff) >> 0;
    
        txPayload[5] = 0; // storage type
        txPayload[6] = 0;
        txPayload[7] = 0;
        txPayload[8] = mmwaveBldr_CMD_ERASE_STORAGE_SFLASH;
    
        txPayload[9] = 0; // file type
        txPayload[10] = 0; // file type
        txPayload[11] = 0; // file type
        txPayload[12] = mmwaveBldr_CMD_FILE_META_IMAGE1;
    
        txPayload[13] = 0; // reserved (mirror enabled)
        txPayload[14] = 0; // reserved
        txPayload[15] = 0; // reserved
        txPayload[16] = 0; // reserved
    
        mmwaveBldr_sendPacket(txPayload, mmwaveBldr_CMD_OPENFILE_LEN);
        CONSOLEPRINT(">>Open File requested...\n\r");
    
        len = mmwaveBldr_readPacket(rxPayload, sizeof(rxPayload));
        mmwaveBldr_checkAck(rxPayload, len);
    
        if (len == mmwaveBldr_CMD_ACK_RESPLEN) {
            if( (rxPayload[0] == 0x00) && (rxPayload[1] == 0xcc) ) CONSOLEPRINT(">>Done!\n\r");
        }
        else {
            CONSOLEPRINT1(">>Open File Ack Error - 0x%02x\n\r", rxPayload[1]);
            for(;;);
        }
    
    }
    
    static void mmwaveBldr_closeFile(void)
    {
        uint8_t len;
    
        txPayload[0] = mmwaveBldr_CMD_CLOSEFILE;
    
        txPayload[1] = 0; // storage type
        txPayload[2] = 0;
        txPayload[3] = 0;
        txPayload[4] = mmwaveBldr_CMD_ERASE_STORAGE_SFLASH;
    
        mmwaveBldr_sendPacket(txPayload, mmwaveBldr_CMD_CLOSEFILE_LEN);
        CONSOLEPRINT(">>Close File requested...\n\r");
    
        len = mmwaveBldr_readPacket(rxPayload, sizeof(rxPayload));
        mmwaveBldr_checkAck(rxPayload, len);
    
        if (len == mmwaveBldr_CMD_ACK_RESPLEN) {
            if( (rxPayload[0] == 0x00) && (rxPayload[1] == 0xcc) ) CONSOLEPRINT(">>Done!\n\r");
        }
        else {
            CONSOLEPRINT1(">>Close File Ack Error - 0x%02x\n\r", rxPayload[1]);
            for(;;);
        }
    }
    
    static void mmwaveBldr_sendChunk(uint8_t *buf, uint8_t chunklen)
    {
        uint8_t len;
    
        txPayload[0] = mmwaveBldr_CMD_WRITEFILESFLASH;
    
        if (chunklen > 240) {
            for(;;);
        }
    
        memcpy(&txPayload[1], buf, chunklen);  // file data...  up to 240 bytes
    
        mmwaveBldr_sendPacket(txPayload, mmwaveBldr_CMD_WRITEFILESFLASH_LEN + chunklen);
        if (debugVerbose) {
            CONSOLEPRINT(">>Write Chunk File requested...\n\r");
        }
        len = mmwaveBldr_readPacket(rxPayload, sizeof(rxPayload));
        mmwaveBldr_checkAck(rxPayload, len);
    
        if (len == mmwaveBldr_CMD_ACK_RESPLEN) {
            if( (rxPayload[0] == 0x00) && (rxPayload[1] == 0xcc) ) {
                if (debugVerbose) {
                    CONSOLEPRINT(">>Done!\n\r");
                }
            }
        }
        else {
            CONSOLEPRINT1(">>Send Chunk Ack Error - 0x%02x\n\r", rxPayload[1]);
            for(;;);
        }
    }
    
    
    /*
     *  ======== MMWAVEBLDR_open ========
     */
    void MMWAVEBLDR_open(MMWAVEBLDR_Params *params)
    {
        bldrObj.uartIndex = params->uartIndex;
        bldrObj.gpioSop2 = params->gpioSop2;
        bldrObj.gpioRst = params->gpioRst;
    
        bldrObj.loggerFxn = params->loggerFxn;
    
        bldrObj.getImgVerFxn = params->getImgVerFxn;
        bldrObj.getImgLenFxn = params->getImgLenFxn;
        bldrObj.getImgBufFxn = params->getImgBufFxn;
    
        bldrObj.initialised = 1;
    }
    
    /*
     *  ======== MMWAVEBLDR_getCurrentImageVersion ========
     */
    int MMWAVEBLDR_getCurrentImageVersion(void)
    {
        int appVersion = 0;
    
        return (appVersion);
    }
    
    /*
     *  ======== MMWAVEBLDR_doUpdate ========
     */
    void MMWAVEBLDR_doUpdate(void)
    {
        UART_Params uartParams;
    
        if (!bldrObj.initialised) return;
    
        UART_init();
        GPIO_init();
    
        UART_Params_init(&uartParams);
        uartParams.writeDataMode = UART_DATA_BINARY;
        uartParams.readDataMode = UART_DATA_BINARY;
        uartParams.readReturnMode = UART_RETURN_FULL;
        uartParams.readEcho = UART_ECHO_OFF;
        uartParams.baudRate = 115200;
    
        CONSOLEPRINT("Opening MMWAVE Bootloader UART\n\r");
    
        bldrObj.uart = UART_open(bldrObj.uartIndex, &uartParams);
    
        if (bldrObj.uart == NULL) {
            /* UART_open() failed */
            CONSOLEPRINT("Opening MMWAVE Bootloader UART - Failed to open UART - spin()\n\r");
            while(1);
        }
    
        CONSOLEPRINT("Disabling Flowcontrol\n\r");
        setFlowControl(bldrObj.uart, 0);
    
        CONSOLEPRINT("Entering Bootloader\n\r");
        CONSOLEPRINT("Setting Break\n\r");
        setBreak(bldrObj.uart, 1);
    
        CONSOLEPRINT("Set SOP2 High to enter bootloader\n\r");
        GPIO_write(bldrObj.gpioSop2, 1);
    
        CONSOLEPRINT("Set NRST Low\n\r");
        GPIO_write(bldrObj.gpioRst, 0);
        usleep(50000);
        CONSOLEPRINT("Set NRST High\n\r");
        GPIO_write(bldrObj.gpioRst, 1);
    
        //CONSOLEPRINT("Waiting for Target Break (Data = 0xff?) - device seems to send 80 bytes and then sets break = 0xff data\n\r");
        CONSOLEPRINT("Waiting for Target Break (Data = 0xff)\n\r");
        while(1) {
            static int count = 0;
            UART_read(bldrObj.uart, &rxPayload[0], 1);
            if (debugVerbose) {
                CONSOLEPRINT2("<- %d, 0x%02x\n\r", count++, rxPayload[0]);
            }
            if (rxPayload[0] == 0xff) break;
        }
    
        CONSOLEPRINT("Clear Break\n\r");
        setBreak(bldrObj.uart, 0);
        usleep(50000);
        CONSOLEPRINT("Set Break\n\r");
        setBreak(bldrObj.uart, 1);
    
        CONSOLEPRINT("Waiting for ACK\n\r");
    
        {
        uint8_t len;
        len = mmwaveBldr_readPacket(rxPayload, sizeof(rxPayload));
        mmwaveBldr_checkAck(rxPayload, len);
        }
    
        CONSOLEPRINT("Bootloader ACK Received \n\r");
    
        CONSOLEPRINT("Set Break False\n\r");
        setBreak(bldrObj.uart, 0);
    
        usleep(10000);
    
        mmwaveBldr_getVersionInfo();
    
        mmwaveBldr_getLastStatus();
    
        mmwaveBldr_ping();
    
        mmwaveBldr_erase();
    
        mmwaveBldr_getLastStatus();
    
        mmwaveBldr_openFile(bldrObj.getImgLenFxn());
    
        // Load Programming Image
        {
            uint32_t len = 0;
            uint32_t imglen = bldrObj.getImgLenFxn();
            uint32_t remain = imglen;
    
            while (remain > 0) {
                uint32_t offset = imglen - remain;
                uint8_t *imgPtr;
    
                if (remain < 240) {
                    len = remain;
                }
                else {
                    len = 240;
                }
    
                imgPtr = bldrObj.getImgBufFxn(offset);
    
                if (debugVerbose) {
                    CONSOLEPRINT2("Sending Write To Flash Programming Command - offset %d, len %d\n\r", offset, len);
                }
                else {
                    CONSOLEPRINT(".");
                }
    
                // Must be written as max size 240 byte chunks
                mmwaveBldr_sendChunk(imgPtr, len);
    
                mmwaveBldr_getLastStatus();
    
                remain -= len;
            }
        }
    
        CONSOLEPRINT("\n\r");
    
        mmwaveBldr_getLastStatus();
    
        mmwaveBldr_closeFile();
        CONSOLEPRINT("Programming Done\n\r");
    
    #if 0
        {
            uint8_t cmd[] = { 0xaa, 0x00, 0x03, 0x20, 0x20 };
    
            UART_write(bldrObj.uart, cmd, sizeof(cmd));
    
            while(1) {
                static int count = 0;
                UART_read(bldrObj.uart, &(rxPacket.data[0]), 1);
                CONSOLEPRINT2("<- %d, 0x%02x\n\r", count++, rxPacket.data[0]);
                if (rxPacket.data[0] == 0xff) break;
            }
        }
    #endif
    
        CONSOLEPRINT("Closing MMWAVE Bootloader UART\n\r");
        UART_close(bldrObj.uart);
    
        CONSOLEPRINT("Set SOP2 Low to return to functional mode\n\r");
        GPIO_write(bldrObj.gpioSop2, 0);
    
        CONSOLEPRINT("Set NRST Low\n\r");
        GPIO_write(bldrObj.gpioRst, 0);
    }
    
    
    /*
     *  ======== MMWAVEBLDR_fwUpdate ========
     */
    void MMWAVEBLDR_fwUpdate(void)
    {
        int curVersion;
        int newVersion;
    
        if (!bldrObj.initialised) return;
    
    #ifdef DEBUG_SPIN
        while (spin == 1){};
    #endif
    
        CONSOLEPRINT("\n\n\r");
        CONSOLEPRINT("MMWAVEBLDR Firmware Check - Version Check\n\r");
    
        curVersion = MMWAVEBLDR_getCurrentImageVersion();
        newVersion = bldrObj.getImgVerFxn();
    
        CONSOLEPRINT2("MMWAVEBLDR Firmware Check - Cur = %08x, New = %08x\n\r", curVersion, newVersion );
    
        if ( curVersion < newVersion ) {
    
            CONSOLEPRINT("MMWAVEBLDR Firmware Check - FW needs update ...\n\r");
    
            MMWAVEBLDR_doUpdate();
    
            curVersion = MMWAVEBLDR_getCurrentImageVersion();
    
            if ( curVersion < newVersion ) {
                CONSOLEPRINT("MMWAVEBLDR Firmware Check - FW update failed ALERT !!!\n\r");
            }
        }
        CONSOLEPRINT("MMWAVEBLDR Firmware Check - Done\n\r");
    }
    

    Thank you,

    Angie 

  • Hey Angie,

    Thanks for responding on such a short notice. The response that i am receiving is coming from the close command when i send chunks of 50 bytes instead of 240. The 50 bytes would be ideal since this would be the maximum i can receive over wireless. At this moment i can't seem to reproduce the response but as far as i remember the close command seems to be returning "00 04 33 00 33". Sadly this response is not documented so that's why i am guessing it's the NACK. I am indeed sending the command byte by byte using usart. My code looks similair to the you have send (thanks for sending this by the way). My code also returns the same command frames as uniflash (so i am guessing that's not the problem?)

    Are there any other necessary steps i need to take exept what is said in the bootloader flow for usart?

    On another maybe less related note. Uniflash sends a command which i am guessing is the erase command because of the command id 28 but it is formatted in a different way. I am also using this command just to be sure the output of uniflash and my code match to a T to eliminate any possible causes, but i would like to understand this command better. Could you confirm if this is the erase command? The command is "AA 00 0F 2A 28 00 00 00 02 00 00 00 00 00 00 00 00".

  • Hi Jan,

    The additional steps should be represented in the code attached in my answer above. Basically you need to have a full understanding of what will be received after sending a command (ACK/NACK or a received message) and the commands listed in the app note are not all correct. However they are correct in the code snippet attached. 

    For close you should send:

    txPayload[0] = mmwaveBldr_CMD_CLOSEFILE;

    txPayload[1] = 0; // storage type
    txPayload[2] = 0;
    txPayload[3] = 0;
    txPayload[4] = mmwaveBldr_CMD_ERASE_STORAGE_SFLASH;

    and you would receive an ACK or a NACK. An ACK would look like (rxPayload[0] == 0x00) && (rxPayload[1] == 0xcc).

    Erase should look like:

    txPayload[0] = 0x28;

    txPayload[1] = 0; // storage type
    txPayload[2] = 0;
    txPayload[3] = 0;
    txPayload[4] = 2;

    txPayload[5] = 0; // offset
    txPayload[6] = 0; // offset
    txPayload[7] = 0; // offset
    txPayload[8] = 0; // offset

    txPayload[9] = 0; // capacity
    txPayload[10] = 0; // capacity
    txPayload[11] = 0; // capacity
    txPayload[12] = 0; // capacity

    mmwaveBldr_sendPacket(txPayload, mmwaveBldr_CMD_ERASE_LEN);

    However, there are sometimes more than one way to send a command. Looking at the Uniflash source code is another way to get an idea for what commands work over UART.

    Thanks,

    Angie

  • Hi Angie,

    After taking a careful look at my code and the code you send i see nothing that could be the cause of my problem. The frames are build the same and every command gets an ACK back yet the flashed code will not function. Is it possible to look at the source code of uniflash? And if so where can i find this. As of now i've only looked at the usart output of uniflash which matches the output of my program.

  • Hi Jan,

    It is possible to look at the source code for uniflash. You will find what you are looking for at: C:\<uniflash_download_location>\uniflash_7.0.0\deskdb\content\TICloudAgent\win\ccs_base\mmWave\mmWaveProgFlash.py

    Thanks,

    Angie

  • Hey Angie,

    Thanks. I will have a look at it. Hopefully i can find something in there that will fix my problem.

  • Hi Jan,

    Sounds good, I am here if you have any questions.

    Thanks,

    Angie