#include "os_types.h" #include "os_task.h" #include "os_mem.h" #include "dbg_io.h" #include "iot_diag.h" #include "iot_io.h" //#include #include "iot_system_api.h" #include "iot_config.h" //#include "iot_gptmr.h" #include "iot_system.h" //#include "os_mem.h" //#include "cpu.h" //#include "os_task.h" #include "platform.h" #include "encoding.h" //#include "sec_glb.h" //#include "ahb.h" //#include "intc.h" #include "bits.h" #include "os_utils.h" #include "iot_rtc.h" #include "chip_reg_base.h" #include "hw_reg_api.h" #include "iot_bitops.h" #include "flash.h" #include "os_lock.h" #include "iot_config.h" #include "ahb.h" #include "sec_glb.h" #if HW_PLATFORM > HW_PLATFORM_SIMU #include "dbg_io.h" #endif #include "iot_io.h" #define SFC_API_TEST 1 #if SFC_API_TEST == 1 #include "sfc.h" #endif #define FLASH_TEST_OFFSET (0x100000) uint8_t rdata[0x1000] = {0}; uint8_t wdata[0x1000] = {1,2,3,4,5,6,7,8,9,0,255,254,253,252,251,250}; #include "chip_reg_base.h" #include "hw_reg_api.h" #include "iot_bitops.h" #include "os_lock.h" #include "iot_config.h" #include "sram.h" #include "os_mem.h" #include "smc.h" #if HW_PLATFORM > HW_PLATFORM_SIMU #include "dbg_io.h" #endif #include "iot_io.h" #include "ahb.h" #include "sec_glb.h" #define CLK 48 //16 //48 #define PSRAM_ACCSEE_WAY 0 //0:cache 1:software extern void sfc_bus_share_en(); static int32_t iot__platform_init() { /*platform intialization*/ platform_init(); dbg_uart_init(); return 0; } void get_id_test() { uint8_t param[0x100] = {0}; iot_printf("[SFDP data]\n"); sfc_read_sfdp(param, 0x0, 0x4); iot_printf("0x0: %x %x %x %x\n", param[0], param[1], param[2], param[3]); sfc_read_sfdp(param, 0x10, 0x4); iot_printf("0x0: %x %x %x %x\n", param[0], param[1], param[2], param[3]); iot_printf("\n[SFC API TEST] start get id test\n"); //g_sfc_ctrl->get_dev_id(rdata); iot_printf("Manufacturer ID:%x%x\r\n",rdata[1], rdata[0]); sfc_qspi_get_id_mult(rdata, MOD_SFC_SERIAL); iot_printf("Manufacturer ID:%x%x\r\n",rdata[1], rdata[0]); sfc_qspi_get_id_mult(rdata, MOD_SFC_DUAL); iot_printf("Manufacturer ID dual: %x%x\r\n",rdata[1], rdata[0]); sfc_qspi_get_id_mult(rdata, MOD_SFC_QUAD); iot_printf("Manufacturer ID quad: %x%x\r\n",rdata[1], rdata[0]); iot_printf("[SFC API TEST] end get id test\n"); } void get_sts_reg_test() { uint8_t data; uint8_t reg = 0; iot_printf("\n[SFC API TEST] start get status reg test\n"); g_sfc_ctrl->get_sts_reg(&data, reg); iot_printf("get reg[%d]: %08x\n ", reg, data); reg = 1; g_sfc_ctrl->get_sts_reg(&data, reg); iot_printf("get reg[%d]: %08x\n ", reg, data); iot_printf("[SFC API TEST] end get status reg test\n"); } void erase_test(void) { uint32_t i = 0, error = 0; iot_printf("erase sector test\n"); os_mem_set(rdata,0,sizeof(rdata)); g_sfc_ctrl->erase_sector(FLASH_TEST_OFFSET, MOD_SW_MODE_DIS); //4k for (i=0; i<0x10; i++) { g_sfc_ctrl->read(rdata+0x100*i,(FLASH_TEST_OFFSET+0x100*i),0x100, MOD_SFC_READ_SIG); //read page 256 } for (i=0;ierase_sector(FLASH_TEST_OFFSET, MOD_SW_MODE_DIS); //4k erase_test(); for (i=0; i<0x10; i++) { g_sfc_ctrl->write((wdata+0x100*i),(FLASH_TEST_OFFSET+0x100*i), 0x100, MOD_SFC_PROG_STAND, MOD_SW_MODE_DIS); //write page 256 } for (i=0; i<0x10; i++) { g_sfc_ctrl->read(rdata+0x100*i,(FLASH_TEST_OFFSET+0x100*i),0x100, MOD_SFC_READ_SIG); //read page 256 } for (i=0; ierase_sector(FLASH_TEST_OFFSET, MOD_SW_MODE_DIS); //4k erase_test(); for (i=0; i<0x10; i++) { g_sfc_ctrl->write((wdata+0x100*i),(FLASH_TEST_OFFSET+0x100*i),0x100, MOD_SFC_PROG_QUAD, MOD_SW_MODE_DIS); } for (i=0; i<0x10; i++) { g_sfc_ctrl->read(rdata+0x100*i,(FLASH_TEST_OFFSET+0x100*i),0x100, MOD_SFC_READ_SIG); //read page 256 } for (i=0; iread(rdata+0x100*i,(FLASH_TEST_OFFSET+0x100*i),0x100, MOD_SFC_READ_SIG); //read page 256 } for (i=0; iread(rdata+0x100*i,(FLASH_TEST_OFFSET+0x100*i),0x100, MOD_SFC_READ_HIGH_SPD); //read page 256 } for (i=0; iread(rdata+0x100*i,(FLASH_TEST_OFFSET+0x100*i),0x100, MOD_SFC_READ_DUAL_FAST); //read page 256 } for (i=0; iread(rdata+0x100*i,(FLASH_TEST_OFFSET+0x100*i),0x100, MOD_SFC_READ_QUAD_FAST); //read page 256 } for (i=0; iread(rdata+0x100*i,(FLASH_TEST_OFFSET+0x100*i),0x100, MOD_SFC_READ_DUAL_IO_FAST); //read page 256 } for (i=0; iread(rdata+0x100*i,(FLASH_TEST_OFFSET+0x100*i),0x100, MOD_SFC_READ_QUAD_IO_FAST); //read page 256 } for (i=0; iread(rdata+0x100*i,(FLASH_TEST_OFFSET+0x100*i),0x100, MOD_SFC_READ_QUAD_IO_WORD_FAST); //read page 256 } for (i=0; i>>>>>>>>>>>>>>>>>>>>>>>flash read && write test begin<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\r\n"); /* init sfc and flash */ flash_init(1); do { iot_printf("quad: %d\n", g_sfc_ctrl->is_quad); get_id_test(); get_sts_reg_test(); g_sfc_ctrl->query_wip_sts(&wip_sts); if(wip_sts == 1) { iot_printf("FLASH is WORK IN STATUS\r\n"); } else{ erase_test(); write_test(); read_test(); sfc_cache_read_test(); erase_test(); os_delay(5); } loop++; iot_printf("\r\n>>>>>>>>>>>>>>>>>>>>>>>>>>>flash read && write test cnt : %d<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\r\n",loop); } while (1); while(1) { iot_printf("user_task_test_1 \n"); os_delay(1000); } return; } void smc_main() { uint32_t loop = 0; uint8_t rdata[0x40] = {0}; uint8_t wdata[0x40] = {1,2,3,4,5,6,7,8,9,0x11,0x22,0x33,0x44}; int i = 0, j = 0, k = 0; int offset = 0; int len = sizeof(wdata); for(i = 0; i < len; i++) { wdata[i] = 0x5a; } iot_printf("\r\n-------------------------------psram read && write test begin-------------------------------\r\n"); if(PSRAM_ACCSEE_WAY == 0) { while(1) { int i,j,error = 0; uint32_t rdat; for (j=0;j<100;j++) { for (i=0;i<1000;i++) { *((volatile uint32_t*)(0x18300000+i*4+1000*4*j)) = 0x12345678+i+j; } ahb_cachex_flush(1,0x18300000+1000*4*j, 0x400*4); ahb_cachex_flush(0,0x10100000,1024*1024); for (i=0;i<1000;i++) { rdat=((volatile uint32_t)*((volatile uint32_t*)(0x10300000+i*4+1000*4*j))); if(((0x12345678+i+j) != rdat)) { iot_printf("ERROR addr 0x%x, WR:0x%x, RD 0x%X\r\n",(0x10300000+i*4+1000*4*j), (0x12345678+i+j),rdat); error++; } } os_delay(1); } for (j=0;j<100;j++) { for (i=0;i<1000;i++) { *((volatile uint32_t*)(0x28300000+i*4+1000*4*j)) = 0x12345678+i+j; } ahb_cachex_flush(3,0x28300000+1000*4*j, 0x400*4); ahb_cachex_clear(2); for (i=0;i<1000;i++) { rdat=((volatile uint32_t)*((volatile uint32_t*)(0x20300000+i*4+1000*4*j))); if(((0x12345678+i+j) != rdat)) { iot_printf("ERROR addr 0x%x, WR:0x%x, RD 0x%X\r\n",(0x20300000+i*4+1000*4*j), (0x12345678+i+j),rdat); error++; } } os_delay(1); } if (0 == error) { iot_printf("*********************psram cache0~4 flush and read test success***********************\r\n"); }else { iot_printf("*********************psram cache0~4 flush and read test failed************************\r\n"); } loop++; iot_printf("\r\n------------------------------- psram read && write test cnt : %d -------------------------------\n\r",loop); } }else{ /* init sfc and sram */ sfc_bus_share_en(); sram_qspi_init(); hal_smc_spi_cfg(CLK); do { if(sram_qspi_is_busy() != HAL_SRAM_OK){ iot_printf("SRAM IS Busy Now!\r\n"); }else{ /* spi mode */ // sram_qspi_exit(); iot_printf("spi write & read \n"); wdata[10] = 0xaa; sram_qspi_write(wdata,0x1000,sizeof(wdata)); while(sram_qspi_is_busy()); os_mem_set(rdata,0,sizeof(rdata)); sram_qspi_read(rdata,0x1000,sizeof(rdata)); iot_printf("wdata[10]:%x, rdata[10]:%x\n", wdata[10], rdata[10]); if (wdata[10] != rdata[10]) { iot_printf("ERROR!! qspi write, qspi read not match\n"); //return; } /* qpi mode */ iot_printf("qpi write & read \n"); sram_qspi_enter(); hal_smc_qspi_quad_cfg(CLK); wdata[10] = 0xbb; sram_qspi_quad_write(wdata,0x2000,sizeof(wdata)); while(sram_qspi_is_busy()); os_mem_set(rdata,0,sizeof(rdata)); sram_qspi_quad_read(rdata,0x2000,sizeof(rdata)); iot_printf("wdata[10]:%x, rdata[10]:%x\n", wdata[10], rdata[10]); if (wdata[10] != rdata[10]) { iot_printf(" quad write, quad read not match\n"); return; } /* write read test */ iot_printf(" write read loop test \n"); offset = 0; j = 0; for (j = 0; j < 10; j++) { iot_printf("\r\n------loop %d offset %x------\r\n", j, offset); sram_qspi_quad_write(wdata, 0x1000+offset,sizeof(wdata)); while(sram_qspi_is_busy()); os_mem_set(rdata,0,sizeof(rdata)); sram_qspi_quad_read(rdata, 0x1000 +offset, sizeof(rdata)); for(i=0; i