AnsweredAssumed Answered

Cube Firmware Error in osPoolAlloc function in cmsis_os.c

Question asked by fortunato.anthony on Jul 14, 2015
Latest reply on Nov 11, 2015 by w.rob.001
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.

Outcomes