AnsweredAssumed Answered

Semihosting problem with IMXRT1050-EVKB on MCUXpresso IDE

Question asked by Tobias Chalupka on Oct 12, 2018
Latest reply on Oct 16, 2018 by Takashi Kashiwagi

Hello there,

 

I cannot seem to read from a file when using semihosting in the MCUXpresso IDE v10.2.1 with the IMXRT1050-EVKB.

I followed the step-by-step guide and successfully ran the "Hello world" example on the board. The board is connected via USB to my Windows 7 PC.

I've set the library/header type to "Newlib (semihost)" via the the quick settings. And added some fopen(), fprintf() and fscanf() routines to the example (the whole project including the changed hello_world.c is attached).


The thing the main program now should do is to open a file, write "Hello World!" to it, read the contents of the file again to strings and print it out on stdout. But, I get only garbage when reading from the file. When I examined the file, I found that the writing had worked correctly.

 

The program's output is:

[[MCUXpresso Semihosting Telnet console for 'evkbimxrt1050_hello_world_file LinkServer Debug' started on port 56900 @ 127.0.0.1]

+b  ðÿÿÿÿÿÿÿÿ  .


[Closed Telnet Session]

 

The string is supposed to be the string "Hello World!", as read from the file. Is this a known problem with the semihosting? Is there an update or at least a workaround? Reading from files is essential for our demo applications.

 

Note: With the redlib (semihost) library, even file opening does not work at all.

 

Unfortunately, I cannot attach the project fie because the site won't let me ("An unexpected error has occurred. Please make sure that your session did not expire while viewing this page."). So I added only the relevant content of hello_world.c at the end of this post.

 

Thanks for any help!

 

/*!
 * @brief Main function
 */
int main(void)
{
    char ch;
    FILE *myfile;
    char mystrings[2][10];

    /* Init board hardware. */
    BOARD_ConfigMPU();
    BOARD_InitPins();
    BOARD_BootClockRUN();
    BOARD_InitDebugConsole();

    /* Write to file */
    myfile = fopen("tmp.txt", "w");
    if (myfile == NULL) {
        fprintf(stderr, "Could not open file for writing\n");
        return 1;
    }
    fprintf(myfile, "hello world.\n");
    fclose (myfile);

    /* Read from file */
    myfile = fopen("tmp.txt", "r");
    if (myfile == NULL) {
        fprintf(stderr, "Could not open file for reading\n");
        return 1;
    }
    fscanf(myfile, "%s %s", mystrings[0], mystrings[1]);
    fclose (myfile);

    /* Print file's contents */
    printf("%s %s.\n\n", mystrings[0], mystrings[1]);

    while (1)
    {
        ch = GETCHAR();
        PUTCHAR(ch);
    }
}

Outcomes