FreeRTOS任务切换导致SPI(FLASH)读写错误问题解决记录

博客讲述在FreeRTOS系统中,任务里循环调用SPI操作FLASH时,系统出现看门狗重启问题,调试发现任务在切换函数和SPI读写函数间循环。推测是任务切换导致SPI读写错误,通过开关任务级临界段阻止任务调度解决卡死问题,后将临界段放整体读写函数解决读取错误,还可使用调度锁。

情景:

在一个任务里面,使用 for 或者 while 循环调用 SPI 操作[读写] FLASH(W25Q128),但是该循环操作未超过看门狗复位时间。

问题:

FreeRTOS系统重启(看门狗),调试发现在任务切换函数和SPI读写函数循环。

	{
		if( ( xTicksToWait == portMAX_DELAY ) && ( xCanBlockIndefinitely != pdFALSE ) )
		{
			/* Add the task to the suspended task list instead of a delayed task
			list to ensure it is not woken by a timing event.  It will block
			indefinitely. */
			vListInsertEnd( &xSuspendedTaskList, &( pxCurrentTCB->xStateListItem ) );
		}
		else
		{
			/* Calculate the time at which the task should be woken if the event
			does not occur.  This may overflow but this doesn't matter, the
			kernel will manage it correctly. */
			xTimeToWake = xConstTickCount + xTicksToWait;

			/* The list item will be inserted in wake time order. */
			listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xStateListItem ), xTimeToWak
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值