obqFlush calculated size

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
lungj
Posts: 8
Joined: Wed Feb 03, 2016 7:57 am
Been thanked: 1 time

obqFlush calculated size

Post by lungj »

Hi,

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!
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: obqFlush calculated size

Post by Giovanni »

Hi,

Thanks for finding, it will be fixed in next release.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: obqFlush calculated size

Post by Giovanni »

Hi,

Fixed in repository: https://sourceforge.net/p/chibios/bugs/701/

Giovanni
Post Reply