162 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			162 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
/****************************************************************************
 | 
						|
 | 
						|
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.
 | 
						|
****************************************************************************/
 | 
						|
 | 
						|
#include "chip_reg_base.h"
 | 
						|
#include "hw_reg_api.h"
 | 
						|
#include "iot_bitops.h"
 | 
						|
#include "os_lock.h"
 | 
						|
#include "iot_config.h"
 | 
						|
#include "ahb_rf.h"
 | 
						|
#include "os_mem.h"
 | 
						|
 | 
						|
#include "dbg_io.h"
 | 
						|
#include "iot_io.h"
 | 
						|
 | 
						|
#include "hw_reg_api.h"
 | 
						|
#include "ds35x1gaxxx.h"
 | 
						|
#include "iot_config.h"
 | 
						|
#include "gpio_mtx.h"
 | 
						|
#include "nand_flash.h"
 | 
						|
#include "iot_nand_flash_api.h"
 | 
						|
 | 
						|
#define RX_NUM  20
 | 
						|
#define TX_NUM  30
 | 
						|
 | 
						|
void nand_main() {
 | 
						|
    volatile uint32_t loop = 0x10000;
 | 
						|
    uint8_t dev_ID = 0;
 | 
						|
    uint8_t manuf_ID = 0;
 | 
						|
    uint8_t reg_stats = 0;
 | 
						|
    uint8_t i = 0;
 | 
						|
    uint8_t check_cnt = 0;
 | 
						|
    char TxBuf[TX_NUM] = {0x39,0x08,0x08,0x44,0x55,0x07,0x57,
 | 
						|
                          0x88,0x08,0x39,0x39,0x39,0xdd,0xee,0xff,
 | 
						|
                          0x15,0x20,0x88,0x11,0x39,0x60,0x70,
 | 
						|
                          0x88,0x90,0xa0,0xb0,0xc0,0xd0,0xe0,0xf0};
 | 
						|
    char RxBuf[RX_NUM];
 | 
						|
 | 
						|
    dbg_uart_init();
 | 
						|
    iot_printf("nand flash test start..........\r\n");
 | 
						|
 | 
						|
    iot_nandfc_cfg_t cfg = {0};
 | 
						|
    cfg.spi.gpio.clk = 37;
 | 
						|
    cfg.spi.gpio.cs = 28;
 | 
						|
    cfg.spi.gpio.miso = 40;
 | 
						|
    cfg.spi.gpio.mosi = 39;
 | 
						|
    cfg.spi.port = 0;
 | 
						|
    iot_nandfc_init(&cfg);
 | 
						|
 | 
						|
    os_mem_set(RxBuf, 0,RX_NUM);
 | 
						|
 | 
						|
    do {
 | 
						|
        iot_nandfc_reset_device();
 | 
						|
 | 
						|
        loop = 0x1000;
 | 
						|
        while(loop--);
 | 
						|
 | 
						|
        dev_ID = iot_nandfc_read_chip_ID();
 | 
						|
        manuf_ID = iot_nandfc_read_manufactury_ID();
 | 
						|
 | 
						|
        iot_printf("Device ID: %x\r\n", dev_ID);
 | 
						|
        iot_printf("Manuf ID: %x\r\n", manuf_ID);
 | 
						|
        iot_printf("******************************\r\n");
 | 
						|
        iot_printf("\r\n");
 | 
						|
 | 
						|
        reg_stats = nandfc_get_feature(STATUS_ADDR);
 | 
						|
        iot_printf("status reg: %x\r\n", reg_stats);
 | 
						|
        iot_printf("******************************\r\n");
 | 
						|
        iot_printf("\r\n");
 | 
						|
 | 
						|
        reg_stats = nandfc_set_feature(BLOCK_LOCK_ADDR,0x00);
 | 
						|
        iot_printf("BL reg set: %x\r\n", reg_stats);
 | 
						|
        iot_printf("******************************\r\n");
 | 
						|
        iot_printf("\r\n");
 | 
						|
 | 
						|
        reg_stats = nandfc_get_feature(BLOCK_LOCK_ADDR);
 | 
						|
        iot_printf("BL reg get: %x\r\n", reg_stats);
 | 
						|
        iot_printf("******************************\r\n");
 | 
						|
        iot_printf("\r\n");
 | 
						|
 | 
						|
        nandfc_write_en_switch(ENABLE);
 | 
						|
        loop = 0x1000;
 | 
						|
        while(loop--);
 | 
						|
 | 
						|
        reg_stats = nandfc_get_feature(STATUS_ADDR);
 | 
						|
        iot_printf("status reg: %x\r\n", reg_stats);
 | 
						|
        iot_printf("******************************\r\n");
 | 
						|
        iot_printf("\r\n");
 | 
						|
 | 
						|
        if(!iot_nandfc_program_data_with_erase(TxBuf, 2045+(11<<12), TX_NUM))
 | 
						|
        {
 | 
						|
            iot_printf("Program data done! \r\n");
 | 
						|
            iot_printf("******************************\r\n");
 | 
						|
            iot_printf("\r\n");
 | 
						|
        }
 | 
						|
        else
 | 
						|
        {
 | 
						|
            iot_printf("Program data Failed!!!! \r\n");
 | 
						|
            iot_printf("******************************\r\n");
 | 
						|
            iot_printf("\r\n");
 | 
						|
        }
 | 
						|
 | 
						|
        iot_nandfc_read_data(RxBuf, 2045+(11<<12), RX_NUM);
 | 
						|
 | 
						|
        for(i = 0; i<RX_NUM; i++)
 | 
						|
        {
 | 
						|
            iot_printf("Received data1[%d]: %x\r\n",i, RxBuf[i]);
 | 
						|
        }
 | 
						|
        iot_printf("******************************\r\n");
 | 
						|
        iot_printf("\r\n");
 | 
						|
 | 
						|
        for(i = 0; i<RX_NUM; i++)
 | 
						|
        {
 | 
						|
            if(RxBuf[i] != TxBuf[i])
 | 
						|
            {
 | 
						|
                iot_printf("Somthing wrong in programing or reading progress!!: RxBuf[%d] != TxBuf[%d]\r\n",i, i);
 | 
						|
            }
 | 
						|
            else
 | 
						|
            {
 | 
						|
                check_cnt++;
 | 
						|
            }
 | 
						|
        }
 | 
						|
        if(RX_NUM==check_cnt)
 | 
						|
        {
 | 
						|
            iot_printf("NAND flash test done!!!");
 | 
						|
        }
 | 
						|
        else
 | 
						|
        {
 | 
						|
            iot_printf("NAND flash test Failed!!!");
 | 
						|
        }
 | 
						|
        check_cnt = 0;
 | 
						|
        iot_printf("******************************\r\n");
 | 
						|
 | 
						|
        loop = 0x2000000;
 | 
						|
        while(loop--);
 | 
						|
    } while (true);
 | 
						|
 | 
						|
    return;
 | 
						|
}
 | 
						|
 | 
						|
#ifdef __GNUC__
 | 
						|
 | 
						|
int main(void) {
 | 
						|
    nand_main();
 | 
						|
    return 0;
 | 
						|
}
 | 
						|
#endif // __GCC__
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 |