cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 6 MCU

Contributor II

Hi,

I'm trying to load a .cyacd2 file into my code by using cybtldr_parse.c.

Everything works fine until I reach the end of the file. At that point, CyBtldr_ReadLine() returns CYRET_ERR_EOF.

By looking at the condition for failing, I find it a bit hard to follow the logic.

if (NULL != dataFile && !feof(dataFile))

{

    if (NULL != fgets(buffer, CY_MAX_BUFFER_SIZE * 2, dataFile))

    {

        len = strlen(buffer);

        while (len > 0 && ('\n' == buffer[len - 1] || '\r' == buffer[len - 1]))

            --len;

    }

    else

        err = CYRET_ERR_EOF;

}

else

    err = CYRET_ERR_FILE;

It looks like the first if() is there because the code expects the last line to be incomplete. However, if the last line was complete, followed immediately by the EOF, then the first if() fails and returns CYRET_ERR_FILE.

Wouldn't the following be better?

if (NULL != dataFile)

{

    if (!feof(dataFile) && (NULL != fgets(buffer, CY_MAX_BUFFER_SIZE * 2, dataFile)))

    {

        len = strlen(buffer);

        while (len > 0 && ('\n' == buffer[len - 1] || '\r' == buffer[len - 1]))

            --len;

    }

    else

        err = CYRET_ERR_EOF;

}

else

    err = CYRET_ERR_FILE;

Thank you,

Fred

0 Likes
Reply
2 Replies
Moderator
Moderator

Which is the PSoC Creator version?

Please use the cybootloaderutils API files available as part of PSoC Creator 4.2 installation directory to bootload using .cyacd2 files (ie., C:\Program Files (x86)\Cypress\PSoC Creator\4.2\PSoC Creator\cybootloaderutils)

0 Likes
Reply
Contributor II

Hi GeonaM,

The file I'm using and the one in cybootloaderutils are the same (compared with KDiff3).

0 Likes
Reply
Top labels