Forum Discussion
Altera_Forum
Honored Contributor
11 years agoSo I finally got this working. I'm not sure why doing this triggered it but I think all I did after applying the above ideas was add the pin sharer (even though I'm not sharing any pins) and changed this
fd = alt_flash_open_dev(CFI_FLASH_CONTROLLER_NAME); to this (basically replacing the define with the text it was defining "/dev/CFI_Flash_Controller" And all of a sudden it worked. The code I ran was this:
//
// Setup Flash
//
IOWR_ALTERA_AVALON_PIO_DATA(PIO_3_BASE,0xC0);
fd = alt_flash_open_dev(CFI_FLASH_CONTROLLER_NAME);
if(fd != NULL){
printf("Flash recognized!\n");
printf("0x%x \n", fd);
}else{
printf("Flash device not recognized!\n");
printf("0x%x \n", fd);
}
Because initially I just wanted to see if I could open the devices. It looks like it's working I've run this:
//
// Setup Flash
//
IOWR_ALTERA_AVALON_PIO_DATA(PIO_3_BASE,0xC0);
fd = alt_flash_open_dev(CFI_FLASH_CONTROLLER_NAME);
if(fd != NULL){
printf("Flash recognized!\n");
printf("0x%x \n", fd);
}else{
printf("Flash device not recognized!\n");
printf("0x%x \n", fd);
}
// Test Flash memory
ret_code = alt_write_flash(fd, 0, source, BUFF_SIZE);
printf("Write return code: 0x%x \n", ret_code);
ret_code = alt_read_flash(fd, 0, dest, BUFF_SIZE);
printf("Read return code: 0x%x \n", ret_code);
alt_flash_close_dev(fd);
printf("Flash device closed! \n");
And everything checks out in that the functions return 0x00 and in debug mode my dest buffer has 0xAA's in it. I found this document that was somewhat helpful as well. http://www.altera.com/literature/hb/nios2/n2sw_nii5v2.pdf My Qsys config looks like this https://www.alteraforum.com/forum/attachment.php?attachmentid=9462 Maybe this will help someone else out.