OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 10406|回复: 3

官方例程的内部keil仿真出现flash出现写入全为0

[复制链接]

1

主题

1

帖子

0

精华

新手入门

积分
25
金钱
25
注册时间
2015-5-4
在线时间
0 小时
发表于 2015-5-4 16:48:02 | 显示全部楼层 |阅读模式
5金钱
[mw_shl_code=c,true]#include "stm32f10x_lib.h" #include "platform_config.h" /* Private typedef -----------------------------------------------------------*/ typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus; /* Private define ------------------------------------------------------------*/ #define StartAddr ((u32)0x08008000) #define EndAddr ((u32)0x0800C000) /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ u32 EraseCounter = 0x00, Address = 0x00; u32 Data; u32 dt; vu32 NbrOfPage = 0x00; volatile FLASH_Status FLASHStatus; volatile TestStatus MemoryProgramStatus; ErrorStatus HSEStartUpStatus; /* Private function prototypes -----------------------------------------------*/ void NVIC_Configuration(void); void RCC_Configuration(void); /* Private functions ---------------------------------------------------------*/ /******************************************************************************* * Function Name : main * Description : Main program * Input : None * Output : None * Return : None *******************************************************************************/ int main(void) { #ifdef DEBUG debug(); #endif FLASHStatus = FLASH_COMPLETE; MemoryProgramStatus = PASSED; Data = 0x15041979; /* RCC Configuration */ RCC_Configuration(); /* NVIC Configuration */ NVIC_Configuration(); /* Unlock the Flash Program Erase controller */ FLASH_Unlock(); /* Define the number of page to be erased */ NbrOfPage = (EndAddr - StartAddr) / FLASH_PAGE_SIZE; /* Clear All pending flags */ FLASH_ClearFlag(0x00000000); /* Erase the FLASH pages */ for(EraseCounter = 0; (EraseCounter < NbrOfPage) && (FLASHStatus == FLASH_COMPLETE); EraseCounter++) { FLASHStatus = FLASH_ErasePage(StartAddr + (FLASH_PAGE_SIZE * EraseCounter)); } /* FLASH Word program of data 0x15041979 at addresses defined by StartAddr and EndAddr*/ Address = StartAddr; while((Address < EndAddr) && (FLASHStatus == FLASH_COMPLETE)) { FLASHStatus = FLASH_ProgramWord(Address, Data); Address = Address + 4; dt=(*(vu32*) Address); } /* Check the corectness of written data */ Address = StartAddr; while((Address < EndAddr) && (MemoryProgramStatus != FAILED)) { if((*(vu32*) Address) != Data) { MemoryProgramStatus = FAILED; } Address += 4; } while (1) { } } /******************************************************************************* * Function Name : NVIC_Configuration * Description : Configures Vector Table base location. * Input : None * Output : None * Return : None *******************************************************************************/ void NVIC_Configuration(void) { #ifdef VECT_TAB_RAM /* Set the Vector Table base location at 0x20000000 */ NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); #else /* VECT_TAB_FLASH */ /* Set the Vector Table base location at 0x08000000 */ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); #endif } /******************************************************************************* * Function Name : RCC_Configuration * Description : Configures the different system clocks. * Input : None * Output : None * Return : None *******************************************************************************/ void RCC_Configuration(void) { /* RCC system reset(for debug purpose) */ RCC_DeInit(); /* Enable HSE */ RCC_HSEConfig(RCC_HSE_ON); /* Wait till HSE is ready */ HSEStartUpStatus = RCC_WaitForHSEStartUp(); if(HSEStartUpStatus == SUCCESS) { /* Enable Prefetch Buffer */ FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); /* Flash 2 wait state */ FLASH_SetLatency(FLASH_Latency_2); /* HCLK = SYSCLK */ RCC_HCLKConfig(RCC_SYSCLK_Div1); /* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1); /* PCLK1 = HCLK/2 */ RCC_PCLK1Config(RCC_HCLK_Div2); /* PLLCLK = 8MHz * 9 = 72 MHz */ RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); /* Enable PLL */ RCC_PLLCmd(ENABLE); /* Wait till PLL is ready */ while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) { } /* Select PLL as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); /* Wait till PLL is used as system clock source */ while(RCC_GetSYSCLKSource() != 0x08) { } } } #ifdef DEBUG /******************************************************************************* * Function Name : assert_failed * Description : Reports the name of the source file and the source line number * where the assert_param error has occurred. * Input : - file: pointer to the source file name * - line: assert_param error line source number * Output : None * Return : None *******************************************************************************/ void assert_failed(u8* file, u32 line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ while (1) { } } #endif[/mw_shl_code]

刚学stm32,我用的是例程里面的flash代码,上面的代码 FLASH_ClearFlag(0x00000000);是我从原来的代码FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP|FLASH_FLAG_PGERR |FLASH_FLAG_WRPRTERR)得到的,按原来的代码运行,会导致flash-sr寄存器busy位一直置高,无法写入,现在遇到的问题就是,写入的不是预想的0x15041979,而全是0,下面附keil软件仿真图,从地址0x08008000到0x0800C000全为0,求大家指教!



正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165371
金钱
165371
注册时间
2010-12-1
在线时间
2110 小时
发表于 2015-5-4 23:39:31 | 显示全部楼层
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复

使用道具 举报

17

主题

587

帖子

0

精华

论坛元老

Rank: 8Rank: 8

积分
4467
金钱
4467
注册时间
2013-6-27
在线时间
565 小时
发表于 2016-10-26 12:01:16 | 显示全部楼层
在单片机运行时使用部分内部FLASH当EEPROM使用,下载到单片机没问题,现在直接在keil软件仿真,发现FLASH写失败,所以想keil仿真下是否可以对flash进行读写?
让我们的思维驾驭在电的速度之上!
回复

使用道具 举报

0

主题

2

帖子

0

精华

新手入门

积分
9
金钱
9
注册时间
2020-10-3
在线时间
1 小时
发表于 2022-4-29 10:42:04 | 显示全部楼层
我也遇到这问题了,请问解决了吗,我是在软件仿真时Flash的状态总是处于BUSY导致写入失败
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-2-25 18:25

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表