各位大侠,您们好! 我现在在使用stm32l011f4芯片,要用到eeprom写入保存的数据 为什么老是进入HardFault_Handler? 程序如下: uint8_t FLASHEx_DATAEEPROM_Unlock(void) //解锁 { while ((FLASH->SR & FLASH_SR_BSY) != 0) { } if((FLASH->PECR & FLASH_PECR_PELOCK) != RESET) { /* Disable interrupts to avoid any interruption during unlock sequence */ __disable_irq(); /* Unlocking the Data memory and FLASH_PECR register access*/ FLASH->PEKEYR = FLASH_PEKEY1; FLASH->PEKEYR = FLASH_PEKEY2; /* Re-enable the interrupts */ __enable_irq(); if((FLASH->PECR & FLASH_PECR_PELOCK) != RESET) { return 0; } } return 1; } uint8_t FLASHEx_DATAEEPROM_Lock(void) //加锁 { while ((FLASH->SR & FLASH_SR_BSY) != 0) /* (1) */ { /* For robust implementation, add here time-out management */ } /* Set the PELOCK Bit to lock the data memory and FLASH_PECR register access */ FLASH->PECR |= FLASH_PECR_PELOCK; /* Re-enable the interrupts */ __enable_irq(); return 1; } uint8_t FLASHEx_DATAEEPROM_Erase(uint32_t Address) //擦除 { /* Wait for last operation to be completed */ while ((FLASH->SR & FLASH_SR_BSY) != 0) /* (1) */ { /* For robust implementation, add here time-out management */ } FLASH->PECR |= FLASH_PECR_ERASE | FLASH_PECR_DATA; /* (1) */ *(__IO uint32_t *)(DATA_EEPROM_BASE+Address) = (uint32_t)0; /* (2) */ __WFI(); /* (3) */ FLASH->PECR &= ~(FLASH_PECR_ERASE | FLASH_PECR_DATA); /* (4) */ return 1; } void FLASHEx_DATAEEPROM_Program(uint32_t Address, uint32_t Data) //写入 { /* Wait for last operation to be completed */ while ((FLASH->SR & FLASH_SR_BSY) != 0) /* (1) */ { /* For robust implementation, add here time-out management */ } /* Program word (32-bit) at a specified address.*/ *(__IO uint32_t *)(DATA_EEPROM_BASE+Address) = Data; /* Wait for last operation to be completed */ while ((FLASH->SR & FLASH_SR_BSY) != 0) /* (1) */ { /* For robust implementation, add here time-out management */ } } uint8_t FLASHEx_EEPROM_WRITE(uint32_t Address, uint32_t *Data, uint8_t len) { uint8_t i; // uint8_t status; FLASHEx_DATAEEPROM_Unlock(); for(i=0;i<len;i++) { FLASHEx_DATAEEPROM_Erase(Address+i*4); FLASHEx_DATAEEPROM_Program(Address+i*4,*Data); Data++; } FLASHEx_DATAEEPROM_Lock(); return 1; } 这个程序是在调用HAL_FLASH库写的程序也是出问题后,自己修改的,还是不行,一往EEPROM里写,还是会进入HardFault_Handler 到底怎么回事情?有大侠能指教一下么?还望大家不吝赐教。 |
FLASHEx_DATAEEPROM_Lock,和FLASHEx_DATAEEPROM_UnLock 都是调用
__enable_irq()
不对啊,__enable_irq()应是您解锁的吧。
评分
查看全部评分
另外对于EEPROM是不需要先擦除,再去写的。直接写就好了,而FLASH才需要。
评分
查看全部评分