Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


vPortFree() Hangs due to Assertion Failure

I have difficulty with the below code which I have paired down to it’s essentials:


  1. define malloc(size) pvPortMalloc(size)
  2. define free(ptr) vPortFree(ptr)


typedef uint8_t Msg_Itr_t;
typedef struct
{ Msg_Itr_t itr;
int32_t strln;
char *pstr;
} Msg_t;

typedef Msg_t* pMsg_t;

pMsg_t pEchoMsg;
pEchoMsg = malloc( sizeof( pMsg_t ) );

if( pEchoMsg )
{ pEchoMsg->pstr = malloc( sizeof( uint8_t ) );
if( pEchoMsg->pstr )
{ free( pEchoMsg->pstr ); // Hangs here
}
free( pEchoMsg );
}



Please note that I have redefined malloc() and free() with the macros included in the above code.

On the call to the first free() it hangs because in vPortFree() the below assertion fails, causing it to go into an infinite loop:

configASSERT( pxLink->pxNextFreeBlock == NULL );

If I free pEchoMsg right after it is allocated it works. But if I free the allocation pointed within pEchoMsg as shown in the code above it fails. What is going wrong here?

I found it. This line should have been:

pEchoMsg = malloc( sizeof( Msg_t ) );

Not enough memory was allocated.