flash写入数据暂停异常
硬件:STM32F072C8T6软件:HAL + FreeRTOS + keil
keil仿真时,程序跑着跑着,突然暂停了(未打断点),
每次都是停在HAL写FLASH数据时的这段代码status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
暂停时,我看了下status值是OK的,不知道怎么老是暂停,点继续执行,数据可以正常写入,不知道正常不??https://www.stmcu.org.cn/module/forum/forum.php?mod=image&aid=436174&size=300x300&key=0cce74dbbc7c7025&nocache=yes&type=fixnonehttps://www.stmcu.org.cn/module/forum/forum.php?mod=image&aid=436173&size=300x300&key=283a26d25ee458cc&nocache=yes&type=fixnone
以下是HAL库写FLASH的原始代码:
HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
{
HAL_StatusTypeDef status = HAL_ERROR;
uint8_t index = 0U;
uint8_t nbiterations = 0U;
/* Process Locked */
__HAL_LOCK(&pFlash);
/* Check the parameters */
assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
/* Wait for last operation to be completed */
status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
if(status == HAL_OK)
{
if(TypeProgram == FLASH_TYPEPROGRAM_HALFWORD)
{
/* Program halfword (16-bit) at a specified address. */
nbiterations = 1U;
}
else if(TypeProgram == FLASH_TYPEPROGRAM_WORD)
{
/* Program word (32-bit = 2*16-bit) at a specified address. */
nbiterations = 2U;
}
else
{
/* Program double word (64-bit = 4*16-bit) at a specified address. */
nbiterations = 4U;
}
for (index = 0U; index < nbiterations; index++)
{
FLASH_Program_HalfWord((Address + (2U*index)), (uint16_t)(Data >> (16U*index)));
/* Wait for last operation to be completed */
status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
/* If the program operation is completed, disable the PG Bit */
CLEAR_BIT(FLASH->CR, FLASH_CR_PG);
/* In case of error, stop programation procedure */
if (status != HAL_OK)
{
break;
}
}
}
/* Process Unlocked */
__HAL_UNLOCK(&pFlash);
return status;
}
是不是曾经这里打过断点,你可以试下去掉全部断点 C++优化等级降低点试看看 要是没调试能运行正常,那可能断点没清掉,去掉所有断点,重新拔插仿真器再试一下 所有断点都去掉的,优化等级是Leve 0(-O 0),问题是几十次出现一次自动暂停
页:
[1]