I'm running a shell over USB on an STM32F072RB Nucleo board using ChibiOS 3 (svn revision 8795) and I'm having some problems with buffering. I'm using chprintf and then calling the obqFlush(output_buffers_queue_t *) function in hal_buffers.c but my output is not as expected: it contains extra characters at the end of the output string. I think I've tracked this down to a bug in hal_buffers.c:
When obqGetEmptyBufferTimeoutS(output_buffers_queue_ *, systime_t) is called, the pointer to the end of the buffer, ptr, is initialized to bwrptr + sizeof(size_t); the buffer's memory is between bwrptr + sizeof(size_t) + length of buffer (e.g., for a 4-byte size_t and a 256 byte buffer, 260 bytes of RAM is reserved).
In obqFlush, size is calculated on line 858 as
Code: Select all
size_t size = (size_t)obqp->ptr - (size_t)obqp->bwrptr;and is passed directly into obqPostFullBufferS. This leads to the size of the buffer being, on the STM32F0, 4 bytes too long.
I believe this line should instead be
Code: Select all
size_t size = (size_t)obqp->ptr - (size_t)obqp->bwrptr - sizeof (size_t);There is a similar adjustment in, for example, obqPutTimeout (line 696).
Please let me know if you need more info or if I'm misusing obqFlush or otherwise doing something wrong (and it's not too much trouble since I realize you're not here to help me debug my own code). Thanks!