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
Hi,
here an new interesting information, I checked the SCLK and SDI/SDO pins of the flash with the scope. While programming the flash and while booting from it I can see the clock and the data bits. But when I call my_epcs = alt_flash_open_dev(EPCS_FLASH_CONTROLLER_NAME) there is NO activity one each pin. No clock no data. Is there any new idea about this? - Altera_Forum
Honored Contributor
--- Quote Start --- Because I can boot from this flash, it should work principally with this device!? Right? I suggest you to firstly debug init of epcs verifying flash->silicon_id is returned as an EPCS64 (16h); then you should check if alt_flash_device_register is correctly performed with a good ret_code. After this 2 easy check start the difficult debugging of alt_flash_open_dev trying to understand if alt_find_dev is successful and then what is performed at dev->open call. I would do in this way... Good luck :) --- Quote End --- Is 16h the id? What's the id for an EPCS16? With the id there could maybe a problem. Because, to boot from Flash I had to check the "Disable EPCS id check" option while converting the programming file. - Altera_Forum
Honored Contributor
Ok, I did so.
Command "flash->silicon_id= epcs_read_electronic_signature(flash->register_base);" reads the id 0xd9800717. It is no option in the following if statement. So it runs to the else statement. The command "flash->silicon_id = epcs_read_device_id(flash->register_base);" returns 0xd9800717 again. So the end is "ret_code = -ENODEV; /* No known device found! */" That tells me what? The controller can not init because the device id is unknown. Right? What's to do? Had I to modify the alt_epcs_flash_query() function? But Altera dehorts about this. And the final question I ask my self, why could NIOS boot its software from the flash?? Greets - Altera_Forum
Honored Contributor
Hi,
about the clock activity it is correct because at call of dev->open within alter_flash_open_dev there is no access to device because there is not a open function defined for epcs. The ID I'm talking about is the answer to epcs_read_electronic_signature (command# define epcs_res ABh). The ID form my EPCS16 is 0x14, I suppose that yours should be 0x16. I don't that the option "Disable EPCS id check" could create problem. The electronic signature is answered by device and during initializationthe relative read command is the only one command sent by epcs controller and probably is why your device open fails. I would investigate about it! Ciao - Altera_Forum
Honored Contributor
If you peek into Nios bootloader, you'll see it doesn't check epcs silicon id. That's why Nios can boot.
If the missing entry in alt_epcs_flash_query() is the only issue, maybe you could create a variant of the epcs controller with the changes you need. Otherwise you must change the standard hal driver. Anyway, since ecps controller is nothing else than a spi controller, another smart solution would be adding a generic spi and writing your own functions for epcs reading and programming. Clearly you must also multiplex spi/epcs signals, switching from epcs controller to spi after boot has completed. Altera driver have some big limitations you can overcome with this solution. - Altera_Forum
Honored Contributor
--- Quote Start --- Hi, about the clock activity it is correct because at call of dev->open within alter_flash_open_dev there is no access to device because there is not a open function defined for epcs. The ID I'm talking about is the answer to epcs_read_electronic_signature (command# define epcs_res ABh). The ID form my EPCS16 is 0x14, I suppose that yours should be 0x16. I don't that the option "Disable EPCS id check" could create problem. The electronic signature is answered by device and during initializationthe relative read command is the only one command sent by epcs controller and probably is why your device open fails. I would investigate about it! Ciao --- Quote End --- But if the read command fails, why could NIOS boot? While booting the same read commands are used? Aren't? - Altera_Forum
Honored Contributor
--- Quote Start --- Hi, about the clock activity it is correct because at call of dev->open within alter_flash_open_dev there is no access to device because there is not a open function defined for epcs. The ID I'm talking about is the answer to epcs_read_electronic_signature (command# define epcs_res ABh). The ID form my EPCS16 is 0x14, I suppose that yours should be 0x16. I don't that the option "Disable EPCS id check" could create problem. The electronic signature is answered by device and during initializationthe relative read command is the only one command sent by epcs controller and probably is why your device open fails. I would investigate about it! Ciao --- Quote End --- Ok, I saw it in boot-loader. I had to think about... At the moment I tried simply to change the alt_epcs_flash_query() function. I added my device id in an additional if statement... Unfortunately I never reach this statement. Is there anywhere a copy of the file which is used? I changed the file in the bsp folder... but no effect. - Altera_Forum
Honored Contributor
I suppose there is something wrong in how you modify and compile your source...
Which is the device id that device answer you? You should get this info debugging alt_epcs_flash_query() function. I continue thinking that the ID it would answer your should be already supported. I want to remember you that everytime you Generate your BSP, all your driver source within BSP folder are removed and retrieved again from altera IP or NIOS2EDS folder. Ciao - Altera_Forum
Honored Contributor
I didn't know what my eclipse shows in debug mode, but nothing useful I think! :mad:
I now checked the silicon id with an simple alt_printf() and now I see, the id id 0xFF. Then I added a if statement for these id, and initialized the structure. And now the command alt_flash_open_dev(EPCS_FLASH_CONTROLLER_NAME) returns no error! :) I will check the next days if I now could really read/write the flash and give a report here. But one strange thing remains, I still had to call
in main(). This should be called automatically, or not? Can someone explain this behavior? Thanks SimALTERA_AVALON_EPCS_FLASH_CONTROLLER_INSTANCE ( EPCS_FLASH_CONTROLLER, epcs_flash_controller); ALTERA_AVALON_EPCS_FLASH_CONTROLLER_INIT ( EPCS_FLASH_CONTROLLER, epcs_flash_controller); - Altera_Forum
Honored Contributor
id=0xff is definitely an error, since this means the data rx line is stuck to high level, namely the undriven state or, equivalent, the epcs_controller rx register contains invalid data.
Then read and write operations will probably not work. Regarding the fact you need to perform those calls in main, please note this remark I found in altera_avalon_epcs_flash_controller.h header file just before ALTERA_AVALON_EPCS_FLASH_CONTROLLER_INSTANCE/_INIT definitions : /* * Macros used by alt_sys_init.c * * By default this driver is initialised in alt_sys_init. However if the * "small driver" feature has been selected, or if fast simulation has been requested * no initialisation is performed. * * This causes the driver to be excluded from the system (unless explicitly * initialised by the user from main()), and therefore reduces code footprint. * */