Skip to main content
Visitor II
April 29, 2023
Question

semihosting in stm32f746disco

  • April 29, 2023
  • 6 replies
  • 2708 views

Hi everyone,

 i want to ask a question about semihosting printing messages in console. I've been using it for some time and it works well. I use it on boards designed by me with various micros and with the ST-LINK/V2 emulator, no problem. I happened to have to use the STM32F746G-DISCO evaluation card, this card already has the emulator integrated on the card... in this case I couldn't get the semihosting to work with console messages. What's different ? Can anyone tell me if he managed to make it work and how?

Thanks

    This topic has been closed for replies.

    6 replies

    Technical Moderator
    April 29, 2023

    You may find the answer in Application Note AN4989, section 7.4.

    Hope that helps?

    Good luck and regards

    /Peter

    Graduate II
    April 29, 2023

    VCP UART and Pins? SWD PB3 SWO pin? Correct core frequency and HSE_VALUE? 25 MHz not 8 MHz​

    mBosc.11Author
    Visitor II
    April 30, 2023

    mBosc.11Author
    Visitor II
    April 30, 2023

    thanks for the answer, and the documentation, I checked and did exactly as described, since in other tabs it works.

    I found out where the problem is... this micro is an M7 and it has the i cache and the dcache, if I disable these the semihosting works...

    But unfortunately I need them because I use ethenet and LWIP, I configured the regions for ethernet (which works). But I don't know what I have to do for semihosting.

    can you help me ?

    Graduate II
    April 30, 2023

    Can only help if you explain method and show related code. Not clear why cache would be a specific issue.

    DTCM shouldn't be an issue, not sure how USART would be either.​

    Perhaps need to use memory fencing instructions or cache ByAddr maintenance. ​

    Super User
    April 30, 2023

    Confirmed here, with STM32F767 on custom board similar to Discovery-STM32746G.

    When D-Cache is NOT enabled, semihosting prints and file opens work well.

    After D-Cache enabled, printf prints garbage, opening a file fails.

    #include <unistd.h>
    #include <fcntl.h>
    #include <sys/stat.h>
    #include <stdio.h>
    extern void initialise_monitor_handles(void);
     
    void test_semihosting(void)
    {
     initialise_monitor_handles();
     //SCB_EnableDCache(); //<<< if this is commented, semihosting works
     SCB_EnableICache();
     __DSB();
     
     printf("Test semihosting! read big file from host\n");
     char const* fname = "F:/test/test.bin";
     
     int fd = open(fname, O_RDONLY|O_BINARY);
     if (fd <= 0) {
    	 printf("Error open file!\n");
    	 return;
     }
    ......................

     My program runs in RAM, if this matters (and there's another OpenOCD related bug...)