FrenchRiviera
Newbie level 4
![Newbie level 4](/styles/images/ranks/blevel1.gif)
Hi all,
I am building a custom system, using an FPGA board with a Nios II processor. I'm using Quartus 15.0 and DE0 NanoBoard( Cyclone IV as FPGA)
My application contains:
1. Clock Source
2. Nios II Processor
3. System ID
4. JTAG UART
5. EPCS Serial Flash Controller
6. PIO
7. SDRAM Controller
The SDRAM aims is to store instructions and data for NIOS application. The EPCS64 flash aims is to store the FPGA configuration data and the nios firmware.
So, the system can boot from flash for both hardware and software.
Now, I trying to write/read into/from the flash device. Unfortunately, what I write and read is not similar.
Below is the code for both writing and reading operations:
Can you help please if you have any idea ?
Thank in advance.
Best regards
I am building a custom system, using an FPGA board with a Nios II processor. I'm using Quartus 15.0 and DE0 NanoBoard( Cyclone IV as FPGA)
My application contains:
1. Clock Source
2. Nios II Processor
3. System ID
4. JTAG UART
5. EPCS Serial Flash Controller
6. PIO
7. SDRAM Controller
The SDRAM aims is to store instructions and data for NIOS application. The EPCS64 flash aims is to store the FPGA configuration data and the nios firmware.
So, the system can boot from flash for both hardware and software.
Now, I trying to write/read into/from the flash device. Unfortunately, what I write and read is not similar.
Below is the code for both writing and reading operations:
Code:
int Write_flash( alt_flash_fd* fd, float *Ks_para,int test_offset)
{
int i;
int ret_code = 0;
alt_u8 *ptr_ks=(alt_u8*) Ks_para;
int test_length = sizeof(Ks_para);
// before writing in a sector, we should erase it before
ret_code=alt_erase_flash_block(fd, test_offset,regions->block_size);
if(!ret_code){
for(i=0;i<test_length;i++){
printf( "data_written[%d]= 0x%08x\n\r",i,ptr_ks[i]);
}
//ret_code = alt_epcq_controller_write_block(fd, test_offset, test_offset,ptr_ks, test_length);
ret_code=alt_write_flash_block(fd,test_offset,test_offset,ptr_ks,test_length);
}
if (ret_code)
{
printf( "\nERROR: function alt_write_flash failed. ret_code %d\n",ret_code);
return ret_code;
}
return ret_code;
}
Code:
float Read_flash( alt_flash_fd* fd,int test_offset)
{
int test_length = 4;
alt_u8 data_read[test_length];
int i=0;
union conv2float read_flash;
float Ks_para=0.0;
int ret_code = 0;
if (!ret_code)
{
//ret_code = alt_epcq_controller_read(fd, test_offset, data_read, test_length);
ret_code=alt_read_flash(fd, test_offset, data_read, test_length);
if(!ret_code)
{
for(i=0;i<4;i++){
read_flash.V_In[i]=data_read[i];
printf( "Flash+%d= 0x%08x\n\r",i,read_flash.V_In[i]);
}
Ks_para=(float)read_flash.V_Fl;
}
}
alt_flash_close_dev(fd);
if (ret_code)
{
printf( "\nERROR: function READ failed. ret_code %d\n",ret_code);
//return ret_code;
}
return Ks_para;
}
Can you help please if you have any idea ?
Thank in advance.
Best regards