Forum Discussion
Altera_Forum
Honored Contributor
14 years agoHow to use an EPCS Flash
Hallo together,
I'm actually trying to save data from NIOS II into an EPCS64 device. My system contains an EPCS controller. But now the confusion is complete, there are so many files for using an flash... and I'm not sure which to use. There are: - altera_avalon_epcs_flash_controller.h - sys\alt_flash.h - epcs_commands.h And all these headers include different read/write functions. Then I tried an example from the Internet to start.
static alt_flash_fd* epcs16_dev_ptr;
static flash_region *p_epcs_reg_info;
static int num_epcs_regs;
void epcs_open(void)
{
epcs16_dev_ptr = alt_flash_open_dev(EPCS_FLASH_CONTROLLER_NAME);
if (epcs16_dev_ptr == NULL)
{
alt_printf("** Can't open flash device **\n\n");
return;
}
alt_epcs_flash_get_info(epcs16_dev_ptr, &p_epcs_reg_info, &num_epcs_regs);
return;
} But to open the EPCS flash always fails. Is there something else to configure in the EPCS controller before start? Which header and functions are the right? Greets Sim47 Replies
- Altera_Forum
Honored Contributor
As I answered you before, I access M25P16 with EPCS controller and I haven't any problem. Your device is similar to mine but support page erase and has different "Device Identification" (80h 15h instead of 20h 15h of mine). You can take a look to datasheet to understand if there are other differences.
I've introduced epcs controller in my design (firmware is located in cfi flash memory) only to support the update of FPGA by means of physical connection different by JTAG (e.g. serial port or ethernet). Epcs controller gives you the possibility to handle (r/w) EPCS memory device from Nios. I suppose that you have to use epcs controller. In order to update your firmware (if you placed it within epcs flash) you need epcs controller. The fastest way to get success in your trouble could be using M25P16. I did'n need to make any modification to HAL driver substituting Altera device with Numonyx one. BR, Paolo - Altera_Forum
Honored Contributor
--- Quote Start --- It is a Micron M25PE16. --- Quote End --- From a rapid look to the datasheet, M25PE16 and EPCS commands are compatible. As I said above, you only need to modify the identification procedure, since the devices have different IDs; the read indentification command is slightly different, too. Search the altera_avalon_epcs_flash_controller.c file in Altera directory and refer to alt_epcs_flash_query function. If you are lucky you only need to add a M25PE16 entry here. - Altera_Forum
Honored Contributor
--- Quote Start --- As I answered you before, I access M25P16 with EPCS controller and I haven't any problem. Your device is similar to mine but support page erase and has different "Device Identification" (80h 15h instead of 20h 15h of mine). You can take a look to datasheet to understand if there are other differences. I've introduced epcs controller in my design (firmware is located in cfi flash memory) only to support the update of FPGA by means of physical connection different by JTAG (e.g. serial port or ethernet). Epcs controller gives you the possibility to handle (r/w) EPCS memory device from Nios. I suppose that you have to use epcs controller. In order to update your firmware (if you placed it within epcs flash) you need epcs controller. The fastest way to get success in your trouble could be using M25P16. I did'n need to make any modification to HAL driver substituting Altera device with Numonyx one. BR, Paolo --- Quote End --- ok, could you show me your code as an example? - Altera_Forum
Honored Contributor
Here there is my initialization, but is not different than your...
I suggest you to debug your device at startup placing some breakpoints within alt_epcs_flash_init function called within altera_sys_init by means of ALTERA_AVALON_EPCS_FLASH_CONTROLLER_INIT macro. I took a brief look to alt_epcs_flash_query function and I suppose that there shouldn't be any different behaviour between my EPCS flash device and yours. Within that function is only retrieved the size of memory device and corresponding region_size, number_of_blocks, and block_size. My doubt is only that the kind of you memory (page erasable PE) is not fully supported by that drivers (is only a supposition because I didn't verified it). Ciaofd_epcs = alt_flash_open_dev(EPCS_FLASH_CONTROLLER_NAME); if (fd_epcs > 0) { alt_epcs_flash_get_info(fd_epcs, &flashInfo_epcs, &number_of_regions); if (number_of_regions && (flashInfo_epcs->offset == 0)) { printf("EPCS_FLASH block_size=%d region_size=%d\n", flashInfo_epcs->block_size, flashInfo_epcs->region_size); } alt_flash_close_dev(fd_epcs); } - Altera_Forum
Honored Contributor
Hallo,
that's an interesting point. I set some breakpoints in alt_epcs_flash_init, but I never get there. Is there any EPCS initialization I had to do, before I could open the device? Greets - Altera_Forum
Honored Contributor
Ok,
take a look within altera_sys_init() function placed within a file with same name and verify that is present ALTERA_AVALON_EPCS_FLASH_CONTROLLER_INIT call (that file is under BSP folder). If it is present take a look to where that macro is defined (altera_avalon_epcs_flash_controller.h) and verify that it is not empty; in that case (defined empty) it means that it is not satisfied following definition check:
. The use of small driver is selected within BSP editor. Ciao#if (!defined(ALT_USE_SMALL_DRIVERS) && !defined(ALT_SIM_OPTIMIZE)) || defined ALT_USE_EPCS_FLASH - Altera_Forum
Honored Contributor
Ok, I take a look at these function an see:
So it is present. Now I look in altera_avalon_epcs_flash_controller.h and see:void alt_sys_init( void ) { ALTERA_AVALON_TIMER_INIT ( TIMER_STAMP, timer_stamp); ALTERA_AVALON_TIMER_INIT ( TIMER_US, timer_us); ALTERA_AVALON_TIMER_INIT ( WATCHDOG, watchdog); ALTERA_AVALON_EPCS_FLASH_CONTROLLER_INIT ( EPCS_FLASH_CONTROLLER, epcs_flash_controller); ALTERA_AVALON_JTAG_UART_INIT ( JTAG_UART_0, jtag_uart_0); ALTERA_AVALON_SPI_INIT ( SPI_ADC, spi_adc); ALTERA_AVALON_SPI_INIT ( SPI_DAC, spi_dac); ALTERA_AVALON_SYSID_QSYS_INIT ( SYSID, sysid); ALTERA_AVALON_UART_INIT ( DEBUG_UART, debug_uart); }
So it is not empty. As already said, I use the small driver option, but I define ALT_USE_EPCS_FLASH. Any ideas? Or did I miss something? ciao#define ALTERA_AVALON_EPCS_FLASH_CONTROLLER_INIT(name, dev) alt_epcs_flash_init(&dev) - Altera_Forum
Honored Contributor
It's quite strange that if you put a breakpoint within alt_epcs_flash_init() it doesn't break... I tried that and I got break there.
I'm sure you verified it, but just to be absolutely sure, use the IDE as editor and check that is defined part of ALTERA_AVALON_EPCS_FLASH_CONTROLLER_INIT macro with alt_epcs_flash_init and not the other; if it is, there is no possibility that you can't break there. Just as an attempt you could try disabling small driver. As you would agree with me, without initialization device is not registered (alt_flash_device_register) and cannot be opened. I think that once you get a correct initialization of device it will start working. :) Ciao - Altera_Forum
Honored Contributor
--- Quote Start --- It's quite strange that if you put a breakpoint within alt_epcs_flash_init() it doesn't break... I tried that and I got break there. I'm sure you verified it, but just to be absolutely sure, use the IDE as editor and check that is defined part of ALTERA_AVALON_EPCS_FLASH_CONTROLLER_INIT macro with alt_epcs_flash_init and not the other; if it is, there is no possibility that you can't break there. Just as an attempt you could try disabling small driver. As you would agree with me, without initialization device is not registered (alt_flash_device_register) and cannot be opened. I think that once you get a correct initialization of device it will start working. :) Ciao --- Quote End --- Yes to all your points :) I set 3 break points in this function, then I started in Debug mode and Eclispe starts at the main(). Then I click run and it runs... never comes to bp. When should this macro be called?? Had I to call this macro? - Altera_Forum
Honored Contributor
You have not to call it, it is called once alt_sys_init() function is called. Try putting a breakpoint at the beginning of alt_sys_init(), it is called before your main().
Ciao