Skip to main content
afortunato
Visitor II
July 13, 2015
Question

Cube Firmware Error in osPoolAlloc function in cmsis_os.c

  • July 13, 2015
  • 1 reply
  • 665 views
Posted on July 14, 2015 at 00:42

In the latest version of the STM32CubeF4 package (and the last few I've used), there seems to be an error in the CMSIS OS wrapper for FreeRTOS. I imagine this is in the other Cube packages as well, though I haven't looked. In the memory pool allocation function (osPoolAlloc() in cmsis_os.c), we traverse the list of free memory blocks with the following code:

for (i = 0; i < pool_id->pool_sz; i++) {

    index = pool_id->currentIndex + i;

    if (index >= pool_id->pool_sz) {

      index = 0;

    }

This should read something like:

 

for (i = 0; i < pool_id->pool_sz; i++) {

    index = pool_id->currentIndex + i;

    if (index >= pool_id->pool_sz) {

    index = index - pool_id->pool_sz;

    }

To properly traverse the list of blocks in a circular manner. Otherwise, depending on how fast you allocate and release items from the pool, you can run into cases where allocations fail even though the pool has plenty of free space.
    This topic has been closed for replies.

    1 reply

    rmawatson
    Associate II
    November 11, 2015
    Posted on November 11, 2015 at 19:28

    *bump*

    just came across this as well and found this post.