Hello forum.
This is my first post to this forum, hope this questions will be useful to someone else...
My STM32F0 board has a magnetometer/accelerometer sensor connected. I'm using a Chibios static thread to read sensor information every 20ms and write it to a Linux host, using the USB-CDC serial driver (/dev/ttyACM0).
To debug I am using a blinking led inside the thread, and "chprintf" syscall to write the information from Chibios to Linux side:
chprintf((BaseSequentialStream *)&SDU1,
"%d %d %d %d %d %d\r\n", xa, ya, za, xm, ym, zm);
While minicom console app (Linux side) is connected and printing chars sent by Chibios to USB port, this solution works great, the led toggles on/off every loop. However, after closing minicom console app, board running chibios seems to block at "chprintf" after a second or so, led stops blinking, and everything continues stalled until minicom app is executed again (chprintf seems to unblock and led starts blinking again).
What is wrong with this solution and how this problem should be fixed?
Thank you in advance!
thread blocked by chprintf Topic is solved
Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess
- RoccoMarco
- Posts: 655
- Joined: Wed Apr 24, 2013 4:11 pm
- Location: Munich (Germany)
- Has thanked: 83 times
- Been thanked: 67 times
- Contact:
Re: thread blocked by chprintf
I don't know how internally works SDU1 but (as far I can remember) if the connection is closed the thread goes in suspend mode. Thread becomes ready as soon as you open the COM port on Linux/Windows side.
I suppose that the SDU write function (used internally by chprintf) is blocking (I will take a look to the code). Why this is a problem for you?
Ciao,
RM
I suppose that the SDU write function (used internally by chprintf) is blocking (I will take a look to the code). Why this is a problem for you?
Ciao,
RM
- RoccoMarco
- Posts: 655
- Joined: Wed Apr 24, 2013 4:11 pm
- Location: Munich (Germany)
- Has thanked: 83 times
- Been thanked: 67 times
- Contact:
Re: thread blocked by chprintf
Maybe I get it. Are you using the same thread to read data and print data? In this case use two separate threads. The printing thread will run only when connection is open.
Ciao,
RM
Ciao,
RM
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: thread blocked by chprintf
I'm using the "stable_16.1.x" branch.
Yes, the same thread is reading from sensor and writing to the console. I will try suggested solution.
Thanks a lot for your fast answer.
Yes, the same thread is reading from sensor and writing to the console. I will try suggested solution.
Thanks a lot for your fast answer.
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: thread blocked by chprintf
Hi,
Version 16.1 should not be affected by this problem, could you post your usbcfg.c file?
Giovanni
Version 16.1 should not be affected by this problem, could you post your usbcfg.c file?
Giovanni
Re: thread blocked by chprintf
My usbcfg.c file has the same md5sum as the file I took as example to start writing my project:
2b2187c33fc8f8cef726be72f0b5fcdf usbcfg.c
2b2187c33fc8f8cef726be72f0b5fcdf ../ChibiOS/testhal/STM32/STM32F0xx/USB_CDC/usbcfg.c
2b2187c33fc8f8cef726be72f0b5fcdf usbcfg.c
2b2187c33fc8f8cef726be72f0b5fcdf ../ChibiOS/testhal/STM32/STM32F0xx/USB_CDC/usbcfg.c
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: thread blocked by chprintf Topic is solved
At line 292 there is the workaround, on USB disconnect the SDU driver is reset and threads are freed from write operations. The problem is that you don't disconnect the USB peripheral, you simply stop consuming the sent data, when buffers are filled the application hangs, the device has no way to know that you closed the application on the host side.
What you could do is to add a small timeout to write operations, however chprintf() does not support this directly. You could print using chprintf to a memory stream then write the buffer with timeout using chnWriteTimeout().
Giovanni
What you could do is to add a small timeout to write operations, however chprintf() does not support this directly. You could print using chprintf to a memory stream then write the buffer with timeout using chnWriteTimeout().
Giovanni
Who is online
Users browsing this forum: No registered users and 52 guests