我的目的是要将数组大小为64的0-63的数,写入到bank1中,但是我通过写操作后,读出来只写进入0-15,后面16-63都没有写入,因为我用读的api和直接访问物理地址的数是一样的都只有0-15,下面是我的代码:
oReturnCheck = Fapi_BlockProgram( ucBank, g_test_Address, (uint32_t)&data_test_buf[0], g_test_Size); if(oReturnCheck) { // Indicate that the flash programming failed. printf("\r Program Flash failed: \r\n"); return; } oReturnCheck = Fapi_UpdateStatusProgram( ucBank, g_test_Address, (uint32_t)&data_test_buf[0], g_test_Size); if(oReturnCheck) { // Indicate that the flash programming failed. printf("\r check Program Flash failed: \r\n"); return; } printf("\r check Program Flash success: \r\n"); printf("data_test_buf:"); for(i = 0;i<BUFFER_SIZE;i++) { printf("%d,",data_test_buf[i]); } printf("\r\n"); printf("Program Flash success\r\n"); oReturnCheck = Fapi_BlockRead(ucBank, g_test_Address, (uint32_t)data_read_buf, g_test_Size); if(oReturnCheck) { printf("read is error\r\n"); } else { printf("data_read_buf:"); for(i = 0;i<BUFFER_SIZE;i++) { printf("%d,",data_read_buf[i]); } printf("\r\n"); cur_buf = (uint32_t*)g_test_Address; printf("cur_buf:"); for(i = 0;i<BUFFER_SIZE;i++) { printf("%d,",cur_buf[i]); } printf("\r\n"); }
从结果看应该是写入的时候发生的错误,但是不知道是哪里错了。写函数如下所示:
//Bank here is not used. We calculate the bank in the function based on the Flash-Start-addr uint32_t Fapi_BlockProgram( uint32_t Bank, uint32_t Flash_Address, uint32_t Data_Address, uint32_t SizeInBytes) { register uint32_t src = Data_Address; register uint32_t dst = Flash_Address; uint32_t bytes; if (SizeInBytes < 16) bytes = SizeInBytes; else bytes = 16; if ((Fapi_initializeFlashBanks((uint32_t)SYS_CLK_FREQ)) == Fapi_Status_Success){(void)Fapi_setActiveFlashBank((Fapi_FlashBankType)Bank);(void)Fapi_enableMainBankSectors(0xFFFF);/* used for API 2.01*/ }else {return (1); } while( FAPI_CHECK_FSM_READY_BUSY != Fapi_Status_FsmReady ); while( FAPI_GET_FSM_STATUS != Fapi_Status_Success );while( SizeInBytes > 0) { Fapi_issueProgrammingCommand((uint32_t *)dst,(uint8_t *)src,(uint32_t) bytes,0,0,Fapi_AutoEccGeneration); while( FAPI_CHECK_FSM_READY_BUSY == Fapi_Status_FsmBusy ); //while(FAPI_GET_FSM_STATUS != Fapi_Status_Success); src += bytes; dst += bytes; SizeInBytes -= bytes;if ( SizeInBytes < 16){bytes = SizeInBytes;}} return (0); }
这个函数是bootloader中的我是直接移过来使用。
大神帮忙看看这个问题。
user4091827:
回复 gaoyang9992006:
是的,开始没有找到,我写入的字节大小就是16个,后来改成64就对了,谢谢。