Hi,
I’m trying to get LwIP going on an STH7. The initialisation of the network functions calls the stdlib function rand() in a number of places. The function fails and you end up in the syscalls module:
void _exit (int status)
{
_kill(status, -1);
while (1) {} /* Make sure we hang here */
}
LwIP Initialisation gets called from the default task which I named monitorTask as a static task as it runs all the time.
I am using the cmsis calling protocol as it is built in to the ST code generator.
Below are the relevant extracts from main.c.
/* Definitions for monitorTaskHnd */
osThreadId_t monitorTaskHndHandle;
uint32_t monitorTaskHndBuffer[ 4096 ];
osStaticThreadDef_t monitorTaskHndControlBlock;
const osThreadAttr_t monitorTaskHnd_attributes = {
.name = "monitorTaskHnd",
.cb_mem = &monitorTaskHndControlBlock,
.cb_size = sizeof(monitorTaskHndControlBlock),
.stack_mem = &monitorTaskHndBuffer[0],
.stack_size = sizeof(monitorTaskHndBuffer),
.priority = (osPriority_t) osPriorityNormal,
};...
int main(void)
{ ...
uint32_t randNo = rand();
...
}
void monitorTask(void *argument)
{
uint32_t randNo = rand();
/* init code for LWIP */
MX_LWIP_Init();
/* USER CODE BEGIN 5 */
/* Infinite loop */
for(;;)
{
osDelay(100);
}
/* USER CODE END 5 */
}
To take LwIP out of the equation I called rand() from within the main function and then at the start of the monitor task.
rand() works when called from main, but errors out when called from the task.
I tried turning off interrupts as rand is not guaranteed re-entrent but it sill failed to the
_exit (int status) function.
The disassembly of and stepping shows it fails at the assert line
rand:
900347fc: ldr r3, [pc, #88] @ (0x90034858 <rand+92>)
900347fe: push {r4, lr}
90034800: ldr r4, [r3, #0]
90034802: ldr r3, [r4, #48] @ 0x30
90034804: cbnz r3, 0x90034834 <rand+56>
90034806: movs r0, #24
90034808: bl 0x90034680 <malloc>
9003480c: mov r2, r0
9003480e: str r0, [r4, #48] @ 0x30
90034810: cbnz r0, 0x9003481c <rand+32>
90034812: ldr r3, [pc, #72] @ (0x9003485c <rand+96>)
90034814: ldr r0, [pc, #72] @ (0x90034860 <rand+100>)
90034816: movs r1, #82 @ 0x52
90034818: bl 0x90034638 <__assert_func> /* <== ****** Fails here ********/
I reckon the problem has something to do with the heap, but I don’t understand what it might be.
Has anyone any ideas.
Rob