CMSIS-RTOS's osMailFree() returns some address instead of osStatus-type value

怎甘沉沦 提交于 2019-12-10 22:48:35

问题


So I'm using CMSIS-RTOS mail-queue mechanics with Keil uVision 5.0.5 at STM32F427 microcontroller running at 180MHz. And every now and then releasing previously allocated mailbox element with osMailFree() resulted in some address being returned instead of osStatus-type value like osOK or osErrorValue or whatever is said in the docs.

This address points to os_mailQ_p_##blahlbah element of a service structure allocated with osMailQDef. This also means it points right beyond the end of an actual data buffer allocated with the same osMailQDef macro.

All of my structures are allocated statically; stack sizes for threads (OS_STKSIZE 600) are also looking pretty enough - anyway, doubling and tripling them gave no effect.

It wouldn't bother me if it's not the fact that early or later my program comes into situation when one thread is unable to allocate a mail element (osMailAlloc() returns 0) while other, waiting thread, is constantly taking osEventTimeout. Seems like all memory blocks are in use - yet I'm honestly releasing it after every use (in wrapping object's destructor, to be sure it is truly released).

What could that mean and where to dig?


回答1:


Well, I didn't unsedstand what was the real in-depth reason for the behaviour described. But:

1) At first there was found a workaround for this: it is enough to call osMailFree() once again immediately after the unsuccessull call. It then expectedly returns osOK and (as my long-term tests have shown) that time resource is being freed for real.

2) The effect has vanished completely after I have altered IRQ priority setting procedure inside fatfs_sd_sdio.c file that is a part of FatFS library I'm using. Particularly it was the following code lines:

NVIC_PriorityGroupConfig (NVIC_PriorityGroup_1);

NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init (&NVIC_InitStructure);

NVIC_InitStructure.NVIC_IRQChannel = SD_SDIO_DMA_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_Init (&NVIC_InitStructure);

replaced with the following ones:

NVIC_EnableIRQ(SDIO_IRQn);
NVIC_SetPriority (SDIO_IRQn, 0x0e);
NVIC_EnableIRQ(SD_SDIO_DMA_IRQn);
NVIC_SetPriority (SD_SDIO_DMA_IRQn, 0x0e);

where 0x0E is a RTX SysTick's priority level minus 1. It is notable that the cure wasn't complete until I got rid of NVIC_PriorityGroupConfig() call that initially seemed of no significant importance for me.



来源:https://stackoverflow.com/questions/32995099/cmsis-rtoss-osmailfree-returns-some-address-instead-of-osstatus-type-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!