tingox / serial_flash_programmer_C2000

Serial Flash programmer for C2000 microcontrollers
The Unlicense
0 stars 0 forks source link

F2837xD device, program hangs after application load #3

Open tingox opened 2 months ago

tingox commented 2 months ago

after selecting DFU for CPU1, the application is downloaded and loaded

20
0
0
0
0
0
0
0
Bit rate /s of transfer was: 40451.464844
Application load successful!
Done waiting for application to download and boot...

then it hangs. After pressing the reset button on the board

0
0
0
0
0
0
Bit rate /s of transfer was: 40451.464844
Application load successful!
Done waiting for application to download and boot... Input and Output successfully flushedERROR with Packet Command!
ERROR Status: Not Recognized Error

What operation do you want to perform?
         1-DFU CPU1
         2-DFU CPU2
         3-Erase CPU1
         4-Erase CPU2
         5-Verify CPU1
         6-Verify CPU2
         7-Unlock CPU1 Zone 1
         8-Unlock CPU1 Zone 2
         9-Unlock CPU2 Zone 1
        10-Unlock CPU2 Zone 2
        11-Run CPU1
        12-Reset CPU1
        13-Run CPU1 and Boot CPU2
        14-Reset CPU1 and Boot CPU2
        15-Run CPU2
        16-Reset CPU2
         0-DONE
tingox commented 2 months ago

If I comment out the call to clearBuffer(); in f021_DownloadImage (in file f021_DownloadImage.cpp) like so

#if checksum_enable
    loadProgram_checksum(Afh);
#else
    loadProgram(Afh);
#endif

    VERBOSEPRINT(_T("\nApplication load successful!"));

    VERBOSEPRINT(_T("\nDone waiting for application to download and boot... "));
    // clearBuffer();
    return (1);
}

it doesn't hang, it goes straight back to the menu

0
0
0
0
0
0
0
Bit rate /s of transfer was: 41006.867188
Application load successful!
Done waiting for application to download and boot...
What operation do you want to perform?
         1-DFU CPU1
         2-DFU CPU2
         3-Erase CPU1
         4-Erase CPU2
         5-Verify CPU1
         6-Verify CPU2
         7-Unlock CPU1 Zone 1
         8-Unlock CPU1 Zone 2
         9-Unlock CPU2 Zone 1
        10-Unlock CPU2 Zone 2
        11-Run CPU1
        12-Reset CPU1
        13-Run CPU1 and Boot CPU2
        14-Reset CPU1 and Boot CPU2
        15-Run CPU2
        16-Reset CPU2
         0-DONE

interesting.

tingox commented 2 months ago

and clearBuffer() is just

void clearBuffer(void)
{

#ifdef __linux__
    if (tcflush(fd, TCIOFLUSH) == 0)
    {
        QUIETPRINT(_T("Input and Output successfully flushed"));
    }
    else
    {
        perror("tcflush error");
    }
#else
    PurgeComm(file, PURGE_RXCLEAR);
    unsigned char readBufferData[800];
    DWORD dwRead;
    COMSTAT ComStat;
    DWORD dwErrorFlags;
    ClearCommError(file, &dwErrorFlags, &ComStat);
    ReadFile(file, &readBufferData, ComStat.cbInQue, &dwRead, NULL);
#endif
}
tingox commented 2 months ago

Hmm, perhaps this will work

#if checksum_enable
        loadProgram_checksum(Afh);
#else
        loadProgram(Afh);
#endif

        VERBOSEPRINT(_T("\nApplication load successful!"));

        VERBOSEPRINT(_T("\nDone waiting for application to download and boot... "));
        Sleep(1);
        clearBuffer();
        return (1);
}
tingox commented 2 months ago

no, it didn't work. I changed it to Sleep(6) - that didn't help either.

tingox commented 2 months ago

I also tested changing the clearBuffer function to have separate input and output flushes, like this

void clearBuffer(void)
{

#ifdef __linux__
    int tci, tco;

    tco = tcflush(fd, TCOFLUSH);
    QUIETPRINT(_T("Output successfully flushed: %d"), tco);
    tci = tcflush(fd, TCIFLUSH);
    QUIETPRINT(_T("Input sucessfully flushed: %d"), tci);

    if (tcflush(fd, TCIOFLUSH) == 0)
    {
        QUIETPRINT(_T("Input and Output successfully flushed"));
    }
    else
    {
        perror("tcflush error");
    }
#else
    PurgeComm(file, PURGE_RXCLEAR);
    unsigned char readBufferData[800];
    DWORD dwRead;
    COMSTAT ComStat;
    DWORD dwErrorFlags;
    ClearCommError(file, &dwErrorFlags, &ComStat);
    ReadFile(file, &readBufferData, ComStat.cbInQue, &dwRead, NULL);
#endif
}

that didn't help either, it hangs on the first tcflush call, before the QUITPRINT(..). And it doesn't help if I change the order; flushing input before output.