2

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?

4

1 回答 1

0

好吧,我没有理解所描述行为的真正深层原因是什么。但:

1) 首先找到了一个解决方法:在不成功的调用之后立即再次调用osMailFree()就足够了。然后它预期会返回osOK并且(正如我的长期测试所显示的那样)时间资源正在被真正释放。

2) 在我更改了fatfs_sd_sdio.c文件中的IRQ 优先级设置过程后,效果完全消失了,该文件是FatFS我正在使用的库的一部分。特别是以下代码行:

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);

替换为以下内容:

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

其中0x0ERTXSysTick 的优先级减 1。值得注意的是,直到我摆脱了NVIC_PriorityGroupConfig()最初对我来说似乎并不重要的呼叫,治疗才完成。

于 2015-11-02T13:28:57.533 回答