我觉得应该是nios中的设置问题。因为能够下载下去程序,说明硬件的连接应该是对的。 你使用的是hal sdk的软件,建议你再看看nios中的software中的说明,比如头文件或其他设置,看看怎么通过hal中的api来读写flash。 这里有一个flash的测试程序,也是基于hal sdk的,希望对你有用。 #include <stdio.h> #include <sys/alt_flash.h> #include "system.h" #include <unistd.h> #define DATA_OFFSET 0x300000 int main(void) { alt_flash_fd* flash_handle; FILE *uart; char write_data = 0; char read_data = 0; write_data = 100; uart = fopen(UART_NAME,"w"); flash_handle = alt_flash_open_dev(CFI_FLASH_NAME); fprintf(uart, "open flash device...\n"); usleep(10000); if (flash_handle) { fprintf(uart, "open flash device successed!!!\n"); usleep(10000); alt_write_flash(flash_handle, DATA_OFFSET, &write_data, 1); fprintf(uart, "wirte_data = %d\n", write_data); usleep(10000); alt_read_flash(flash_handle, DATA_OFFSET, &read_data, 1); fprintf(uart, "read_data = %d\n", read_data); usleep(10000); if(read_data == write_data) { fprintf(uart, "flash write and read successed!!!\n"); usleep(10000); } else { fprintf(uart, "flash write or read failed!!!\n"); usleep(10000); } alt_flash_close_dev(flash_handle); fprintf(uart, "close flash device...\n"); usleep(10000); } else { fprintf(uart, "open flash device failed!!!\n"); usleep(10000); } }
[此贴子已经被作者于2008-1-24 13:11:57编辑过] |