Skip to main content
mBosc.11
Associate II
Apr 29, 2023 12:53 PM UTC
Question

semihosting in stm32f746disco

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.

7 replies

Peter BENSCH
ST Technical Moderator
Apr 29, 2023 6:40 PM UTC

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

Hope that helps?

Good luck and regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Tesla DeLorean
Guru
Apr 29, 2023 7:29 PM UTC

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

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
mBosc.11
mBosc.11Author
Associate II
Apr 30, 2023 10:01 AM UTC

mBosc.11
mBosc.11Author
Associate II
Apr 30, 2023 10:03 AM UTC

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 ?

Tesla DeLorean
Guru
Apr 30, 2023 12:44 PM UTC

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. ​

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
mBosc.11
mBosc.11Author
Associate II
Apr 30, 2023 1:07 PM UTC
Pavel A.
Apr 30, 2023 4:14 PM UTC

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...)