/**************************************************************************** Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED. This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT be copied by any method or incorporated into another program without the express written consent of Aerospace C.Power. This Information or any portion thereof remains the property of Aerospace C.Power. The Information contained herein is believed to be accurate and Aerospace C.Power assumes no responsibility or liability for its use in any way and conveys no license or title under any patent or copyright and makes no representation or warranty that this Information is free from patent or copyright infringement. ****************************************************************************/ /* os shim includes */ #include "os_types.h" #include "os_task.h" #include "os_utils.h" /* common includes */ #include "iot_io.h" #include "iot_bitops.h" #include "iot_pkt.h" #include "iot_ipc.h" #include "iot_dbglog_api.h" #include "iot_config.h" /* driver includes */ #include "iot_clock.h" #include "iot_uart.h" #include "uart.h" #include "apb_dma.h" #include "dma_hw.h" /* cli includes */ #include "iot_cli.h" #include "iot_uart_h.h" /* debug includes*/ #include "dbg_io.h" #include "spi.h" #include "iot_gptmr.h" #include "gp_timer.h" #include "iot_gpio.h" #include "dtest_printf.h" #include "iot_share_task.h" #include "uart.h" #include "apb.h" #include "irq.h" #include "rtc.h" #include "ahb.h" #include "iot_mem.h" #include "sd_card.h" #include "flash.h" char file_buf[409]; void flash_gpio_config(void) { gpio_sig_info_t info = {0}; for(int i = 0; i < DEV_PIN_MAX; i++) { info.CFG[i].func = 0; info.CFG[i].gpio = 0xff; } #if 0 // monitor info.CFG[0].gpio = 28; info.CFG[0].outid = GPIO_MTX_SFC_SPI_CLK_OUT_MON; info.CFG[0].inid = 0xff; info.CFG[0].type = IO_TYPE_OUT; info.CFG[1].gpio = 29; info.CFG[1].outid = GPIO_MTX_SFC_SPI_CS0_OUT_MON; info.CFG[1].inid = 0xff; info.CFG[1].type = IO_TYPE_OUT; info.CFG[2].gpio = 30; info.CFG[2].outid = GPIO_MTX_SFC_SPI_SI_OUT_MON; info.CFG[2].inid = 0xff; info.CFG[2].type = IO_TYPE_OUT; info.CFG[3].gpio = 31; info.CFG[3].outid = GPIO_MTX_SFC_SPI_SO_OUT_MON; info.CFG[3].inid = 0xff; info.CFG[3].type = IO_TYPE_OUT; info.CFG[4].gpio = 32; info.CFG[4].outid = GPIO_MTX_SFC_SPI_WP_OUT_MON; info.CFG[4].inid = 0xff; info.CFG[4].type = IO_TYPE_OUT; info.CFG[5].gpio = 33; info.CFG[5].outid = GPIO_MTX_SFC_SPI_HOLD_OUT_MON; info.CFG[5].inid = 0xff; info.CFG[5].type = IO_TYPE_OUT; info.CFG[6].gpio = 64; info.CFG[6].outid = GPIO_MTX_SFC_SPI_CS1_OUT_MON; info.CFG[6].inid = 0xff; info.CFG[6].type = IO_TYPE_OUT; #else // info.CFG[0].gpio = 28; // info.CFG[0].outid = GPIO_MTX_SFC_SPI_CLK_OUT; // info.CFG[0].inid = GPIO_MTX_SFC_SPI_CLK_I; // info.CFG[0].type = IO_TYPE_OUT; // // info.CFG[1].gpio = 29; // info.CFG[1].outid = GPIO_MTX_SFC_SPI_CS0_OUT; // info.CFG[1].inid = GPIO_MTX_SFC_SPI_CS0_I; // info.CFG[1].type = IO_TYPE_OUT; // // info.CFG[2].gpio = 30; // info.CFG[2].outid = GPIO_MTX_SFC_SPI_SI_OUT; // info.CFG[2].inid = GPIO_MTX_SFC_SPI_SI_I; // info.CFG[2].type = IO_TYPE_OUT; // // info.CFG[3].gpio = 31; // info.CFG[3].outid = GPIO_MTX_SFC_SPI_SO_OUT; // info.CFG[3].inid = GPIO_MTX_SFC_SPI_SO_I; // info.CFG[3].type = IO_TYPE_OUT; // // info.CFG[4].gpio = 32; // info.CFG[4].outid = GPIO_MTX_SFC_SPI_WP_OUT; // info.CFG[4].inid = GPIO_MTX_SFC_SPI_WP_I; // info.CFG[4].type = IO_TYPE_OUT; // // info.CFG[5].gpio = 33; // info.CFG[5].outid = GPIO_MTX_SFC_SPI_HOLD_OUT; // info.CFG[5].inid = GPIO_MTX_SFC_SPI_HOLD_I; // info.CFG[5].type = IO_TYPE_OUT; // // info.CFG[6].gpio = 64; // info.CFG[6].outid = GPIO_MTX_SFC_SPI_CS1_OUT; // info.CFG[6].inid = GPIO_MTX_SFC_SPI_CS1_I; // info.CFG[6].type = IO_TYPE_OUT; info.CFG[0].gpio = 38; info.CFG[0].outid = GPIO_MTX_SFC_SPI_CLK_OUT; info.CFG[0].inid = GPIO_MTX_SFC_SPI_CLK_I; info.CFG[0].type = IO_TYPE_OUT; info.CFG[1].gpio = 39; info.CFG[1].outid = GPIO_MTX_SFC_SPI_CS0_OUT; info.CFG[1].inid = GPIO_MTX_SFC_SPI_CS0_I; info.CFG[1].type = IO_TYPE_OUT; info.CFG[2].gpio = 35; info.CFG[2].outid = GPIO_MTX_SFC_SPI_SI_OUT; info.CFG[2].inid = GPIO_MTX_SFC_SPI_SI_I; info.CFG[2].type = IO_TYPE_OUT; info.CFG[3].gpio = 3; info.CFG[3].outid = GPIO_MTX_SFC_SPI_SO_OUT; info.CFG[3].inid = GPIO_MTX_SFC_SPI_SO_I; info.CFG[3].type = IO_TYPE_OUT; info.CFG[4].gpio = 36; info.CFG[4].outid = GPIO_MTX_SFC_SPI_WP_OUT; info.CFG[4].inid = GPIO_MTX_SFC_SPI_WP_I; info.CFG[4].type = IO_TYPE_OUT; info.CFG[5].gpio = 34; info.CFG[5].outid = GPIO_MTX_SFC_SPI_HOLD_OUT; info.CFG[5].inid = GPIO_MTX_SFC_SPI_HOLD_I; info.CFG[5].type = IO_TYPE_OUT; info.CFG[6].gpio = 64; info.CFG[6].outid = GPIO_MTX_SFC_SPI_CS1_OUT; info.CFG[6].inid = GPIO_MTX_SFC_SPI_CS1_I; info.CFG[6].type = IO_TYPE_OUT; #endif /* GPIO_MTX_SFC_SPI_CLK_OUT_MON = 110, GPIO_MTX_SFC_SPI_CS1_OUT_MON = 111, GPIO_MTX_SFC_SPI_CS0_OUT_MON = 112, GPIO_MTX_SFC_SPI_SI_OUT_MON = 113, GPIO_MTX_SFC_SPI_SO_OUT_MON = 114, GPIO_MTX_SFC_SPI_WP_OUT_MON = 115, GPIO_MTX_SFC_SPI_HOLD_OUT_MON = 116, */ info.sig_type = 7; //gpio_mtx_enable(); gpio_module_pin_select(&info); gpio_module_sig_select(&info, GPIO_MTX_MODE_MATRIX); } void print_buf(char *name, uint8_t buf[], int len) { iot_printf("%s", name); for (int i = 0; i < len; i++) { if (i % 16 == 0) { iot_printf("\n"); } iot_printf("%02x ", buf[i] & 0xff); } iot_printf("\n"); } void flash_test(void) { flash_write_param_t param = {0}; param.read_mode = MOD_SFC_READ_QUAD_IO_FAST; param.write_mode = MOD_SFC_PROG_QUAD; param.is_erase = 1; param.sw_mode = MOD_SW_MODE_DIS; // for (int i = 0; i < sizeof(file_buf); i++) { // file_buf[i] = i % 0xff; // } file_buf[0] = 0x11; file_buf[1] = 0x22; file_buf[2] = 0x33; file_buf[3] = 0x44; //flash_gpio_config(); flash_init(1); int size = flash_get_dev_size(); char buf[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; flash_get_dev_id(buf); print_buf("dev id:",(uint8_t *) buf, 2); flash_get_chip_id(buf); print_buf("chip id:",(uint8_t *) buf,16); iot_printf("size=%d\n", size); iot_printf("start ..\r\n"); flash_otp_read(FLASH_OTP_REGION0, 0, file_buf, 256); print_buf("1 read:",(uint8_t *) file_buf, 256); for(int i = 0; i < 256; i++) { file_buf[i] = i % 0xff; } flash_otp_write(FLASH_OTP_REGION0, 0, file_buf, 256); for(int i = 0; i < 256; i++) { file_buf[i] = 0; } flash_otp_read(FLASH_OTP_REGION0, 0, file_buf, 256); print_buf("2 read:",(uint8_t *) file_buf, 256); return ; flash_write(file_buf, 0, sizeof(file_buf), ¶m); flash_read(file_buf, 0, sizeof(file_buf), MOD_SFC_READ_QUAD_IO_FAST); int i; for (i = 0; i < sizeof(file_buf); i++) { if (file_buf[i] != i % 0xff) { iot_printf("err at %d,read:%02x,write:%02x\r\n", i, file_buf[i] & 0xff, i % 0xff); break; } } if (i == sizeof(file_buf)) { iot_printf("flash_write_read ok\r\n"); } } int main() { uint32_t otp_bytes; dbg_uart_init(); iot_printf("start\n"); flash_init(1); otp_bytes = flash_otp_get_size(); iot_printf("otp_bytes=%d\r\n", otp_bytes); flash_otp_read(FLASH_OTP_REGION1, 0, file_buf, otp_bytes); print_buf("1 read:",(uint8_t *) file_buf, otp_bytes); for(int i = 0; i < otp_bytes; i++) { file_buf[i] = (0x00 + i) % 0x100; } flash_otp_write(FLASH_OTP_REGION1, 0, file_buf, otp_bytes); for(int i = 0; i < otp_bytes; i++) { file_buf[i] = 0; } flash_otp_read(FLASH_OTP_REGION1, 0, file_buf, otp_bytes); print_buf("2 read:",(uint8_t *) file_buf, otp_bytes); flash_otp_lock(FLASH_OTP_REGION1); while(1) { } return 0; }