Files
kunlun/dtest/nor_flash_test/nor_flash_test.c
2024-09-28 14:24:04 +08:00

157 lines
4.7 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 "iot_bitops.h"
#include "os_lock.h"
#include "iot_config.h"
#include "dbg_io.h"
#include "iot_io.h"
#include "ahb.h"
#include "hw_reg_api.h"
#include "gd25lq16x.h"
#include "iot_config.h"
#include "gpio_mtx.h"
#include "nor_flash.h"
#include "iot_nor_flash_api.h"
#define ENABLE 1
#define DISABLE 0
#define RX_NUM 30
#define TX_NUM 30
void nor_main() {
volatile uint32_t loop = 0x10000;
uint32_t dev_info = 0;
uint8_t memType_ID = 0;
uint8_t manuf_ID = 0;
uint8_t capacity_ID = 0;
uint8_t reg_stats_l = 0;
uint8_t reg_stats_h = 0;
uint8_t check_cnt = 0;
uint8_t i = 0;
char TxBuf[TX_NUM] = { 0x13,0x48,0x48,0x48,0x28,0x68,0x70,
0x88,0x90,0xA8,0xB3,0xC1,0xDD,0xE8,0xF0,
0x11,0x47,0x47,0x47,0x47,0x66,0x77,
0x88,0x99,0x8A,0xBB,0x81,0xDD,0xEE,0xF9};
char RxBuf[RX_NUM];
dbg_uart_init();
iot_printf("nand flash test start..........\r\n");
iot_norfc_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_norfc_init(&cfg);
do {
dev_info = iot_norfc_read_chip_info();
memType_ID = (uint8_t)( (dev_info>>8) & 0xFF);
capacity_ID = (uint8_t)((dev_info>>16) & 0xFF);
manuf_ID = (uint8_t)dev_info;
iot_printf("Memery type ID: %x\r\n", memType_ID);
iot_printf("Manufact ID: %x\r\n", manuf_ID);
iot_printf("Capacity ID: %x\r\n", capacity_ID);
iot_printf("******************************\r\n");
iot_printf("\r\n");
reg_stats_l = norfc_get_status_reg(READ_STS_REG_L_CMD);
iot_printf("Low Status Reg: %x\r\n", reg_stats_l);
iot_printf("******************************\r\n");
iot_printf("\r\n");
loop = 0x10000;
while(loop--);
reg_stats_h = norfc_get_status_reg(READ_STS_REG_H_CMD);
iot_printf("High Status Reg: %x\r\n", reg_stats_l);
iot_printf("******************************\r\n");
iot_printf("\r\n");
if( reg_stats_h & 0x40 )
{
/*set BP2,BP1,BP0*/
reg_stats_l |= 0x1C;
}
else
{
/*clear BP2,BP1,BP0*/
reg_stats_l &= 0xE3;
}
norfc_set_status_reg(&reg_stats_l, 1);
loop = 0x10000;
while(loop--);
reg_stats_l = norfc_get_status_reg(READ_STS_REG_L_CMD);
iot_printf("Lower status reg set: %x\r\n", reg_stats_l);
iot_printf("******************************\r\n");
iot_printf("\r\n");
if(!iot_norfc_erase_data(BLOCK_ERASE_32K_CMD,50))
{
iot_printf("Erase block done! \r\n");
iot_printf("******************************\r\n");
iot_printf("\r\n");
}
if(!iot_norfc_program_page(TxBuf, 50, TX_NUM))
{
iot_printf("Program random data done! \r\n");
iot_printf("******************************\r\n");
iot_printf("\r\n");
}
iot_norfc_read_data(RxBuf, 50, RX_NUM);
for(i = 0; i<RX_NUM; i++)
{
iot_printf("Received data1: %x\r\n", RxBuf[i]);
if(RxBuf[i] != TxBuf[i])
{
iot_printf("Something wrong when programming or reading!!!!\r\n");
iot_printf("\r\n");
check_cnt++;
}
}
if (check_cnt == 0)
{
iot_printf("\r\n");
iot_printf("nand flash test done..........\r\n");
}
check_cnt = 0;
iot_printf("\r\n");
iot_printf("******************************\r\n");
iot_printf("\r\n");
loop = 0x2000000;
while(loop--);
} while (true);
return;
}
#ifdef __GNUC__
int main(void) {
nor_main();
return 0;
}
#endif // __GCC__