- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am a newbie with Nios II. I'm doing a robotic project with a Cyclone and an EPCS4 flash memory. I've added an EPCS controller in my SOPC Builder system. I has to read/write some information in EPCS flash memory. I've tried to use the "epcs_command.h" header, but it doesn't work. My software program stay blocked for example on this line : device_id = epcs_read_device_id(epcs_flash_controller_0_base); This is the same thing for the other functions from this header. I read a lot of post on this forum, but I don't find any satisfying answer. Would you help me please ? If you don't use epcs_command.h, what functions and headers are you used to use ? Thanks a lot. migLink Copied
11 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi there,
If your project is using the reduced drivers option you will have to define the symbol ALT_USE_EPCS_FLASH in the system library properties. Then include the header file <altera_avalon_epcs_flash_controller.h> in your source code. Here's a snippet from my code as a starter for ten: # include <altera_avalon_epcs_flash_controller.h># include <sys\alt_flash.h> static alt_flash_fd *p_epcs_fd; static flash_region *p_epcs_reg_info; static int num_epcs_regs; void epcs_open(void) { <blockquote>p_epcs_fd=alt_flash_open_dev(EPCS_CONTROLLER_NAME); <blockquote>// Get pointer to flash info structure</blockquote> alt_epcs_flash_get_info(p_epcs_fd, &p_epcs_reg_info, &num_epcs_regs); <blockquote>// Verify flash details</blockquote></blockquote>} You could try compiliing and running this, then display the region info to see if it makes sense. I then go on to use the functions alt_epcs_flash_erase_block, alt_epcs_flash_write_block and alt_epcs_flash_read with p_epcs_fd as the first argument in each case. I hope this helps. Have fun.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi !
Thank you for your help ! I've just tried your code and it works ! The flash details are good I think : - Offset = 0 -> I don't know what that means - region_size = 524,288 -> It's good - numbre_of_blocks = 8 -> good too - block_size = 65536 -> good and : num_epcs_regs = 1 -> I don't know what that means I'm going to try to use the functions you've mentionned. I need to translate a small part of an old code given to me by a teacher. He has used a component called "ASMI". I have read on internet that it's quite close to EPCS. Do you know how to translate functions like this one : int nr_asmi_read_buffer (unsigned long address, int length, unsigned char *data); // This declaration is in escalibur.h Thanks again for your useful help !- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Excellent.
I'm not familiar with the old ASMI functions, but I'd guess the functions take similar arguments. You could try this: alt_epcs_flash_read(p_epcs_fd, epcs_address, buffer_address, bytes_to_read); where: p_epcs_fd was initialised by the epcs_open() function earlier epcs_address is the address offset into your EPCS device that you want to start reading from buffer_address is a pointer to a suitable RAM buffer bytes_to_read is the number of bytes to read! So you could do this: alt_u8 buffer[16]; alt_epcs_flash_read(p_epcs_fd, 0, (void*)buffer, 16); to read the first 16 bytes of data into an array. You can probably work out how the erase_block and write_block functions work by looking in altera_avalon_epcs_flash_controller.c Note that the erase function erases the entire block (64k) containing the offset you pass to it. P.S. num_epcs_regs is just telling you there is one region (512k made up of 8*64k blocks).- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thanks again for your help ! I have a problem and I think there is something I don't understand. I try to write something in several addresses like that : alt_u8 buffer_write[16]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F}; alt_epcs_flash_write(p_epcs_fd, 0, (void*)buffer_write, 16); alt_epcs_flash_write(p_epcs_fd, 16, (void*)buffer_write, 16); alt_epcs_flash_write(p_epcs_fd, 32, (void*)buffer_write, 16); alt_epcs_flash_write(p_epcs_fd, 48, (void*)buffer_write, 16); Then I unplug my card, plug it again and try to read what I have written : alt_epcs_flash_read(p_epcs_fd, 0, (void*)buffer_read, 16); alt_epcs_flash_read(p_epcs_fd, 16, (void*)buffer_read, 16); alt_epcs_flash_read(p_epcs_fd, 32, (void*)buffer_read, 16); alt_epcs_flash_read(p_epcs_fd, 48, (void*)buffer_read, 16); In Debug mode, the first three lines give me that : "buffer_read" buffer_read[0] = 255 buffer_read[1] = 255 buffer_read[2] = 255 buffer_read[3] = 255 buffer_read[4] = 255 buffer_read[5] = 255 buffer_read[6] = 255 buffer_read[7] = 255 buffer_read[8] = 255 buffer_read[9] = 255 buffer_read[10] = 255 buffer_read[11] = 255 buffer_read[12] = 255 buffer_read[13] = 255 buffer_read[14] = 255 buffer_read[15] = 255 And the last one give me the good thing. Does alt_epcs_flash_write erase the block ? Thank you- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello again,
Yes, alt_epcs_flash_write does erase the block. If it already contains data which you want to preserve, you have to read it out, add your new data, then write the whole lot back. I use the function alt_epcs_flash_write_block, which doesn't erase the block first, so if you know the area you are writing to has already been erased you can append data. The function prototype is very similar except there is an unused argument e.g. alt_epcs_flash_write_block(p_epcs_fd, 0, 0, (void*)buffer_write, 16); alt_epcs_flash_write_block(p_epcs_fd, 0, 16, (void*)buffer_write, 16); alt_epcs_flash_write_block(p_epcs_fd, 0, 32, (void*)buffer_write, 16); alt_epcs_flash_write_block(p_epcs_fd, 0, 48, (void*)buffer_write, 16); where the 0 in the second argument is ignored. This change should make your code do what you expected. I've written a very simple set of functions where I can store a data structure in the flash, then if I want to update it I read it out, modify it, write it back to a new location and invalidate the old version. This saves having to constantly erase the flash. Depending on your application you will have to decide the best approach to take.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok thank you !
It works very well ! Do you know how to read all the flah memory and save it into a file ? I have tried something but the result isn't very good : - I have a firmware of an another project. It's a .jic - with it I examine the EPCS - then I save it ino a .jic - I open the file with an Hex editor. - From the address 0x92, I can read something which looks like what I have written : a code, different of mine, is repeated 4 times. In other words, from address 0x92 I have this 16 bytes code 4 times : 00 80 40 c0 20 a0 60 e0 10 90 50 d0 30 b0 70 f0 insead of the number from 0 to F. A view of the hexa code : 00000090 : 01 00 00 80 40 c0 20 a0 60 e0 10 90 50 d0 30 b0 ...€@À `à.PÐ0° 000000a0 : 70 f0 00 80 40 c0 20 a0 60 e0 10 90 50 d0 30 b0 pð.€@À `à.PÐ0° 000000b0 : 70 f0 00 80 40 c0 20 a0 60 e0 10 90 50 d0 30 b0 pð.€@À `à.PÐ0° 000000c0 : 70 f0 00 80 40 c0 20 a0 60 e0 10 90 50 d0 30 b0 pð.€@À `à.PÐ0° 000000d0 : 70 f0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff pðÿÿÿÿÿÿÿÿÿÿÿÿÿÿ I think it's what I write, but with an another codage, doesn't it ? Do you know how to read the good thing or a best way to do that ? Thanks again !- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't know much about reading the EPCS to a file. The values you are seeing are your values but bit-reversed (01h becomes 80h etc.). The .jic file probably has a header block before the data too.
I'll do some investigation when I get a chance but in the meantime someone else might be able to answer your question. Cheers- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Actually, the bits are reversed.
I'm going to write a little program which reverses the byte and it will be good ! Thanks a lot for all your help !- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You're more than welcome.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, but in my program "alt_flash_open_dev" does not work, because it get always a NULL-pointer. :mad:
I defined "ALT_USE_EPCS_FLASH" in properties, too. Can anybody help me? :confused:- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- Hello, I am a newbie with Nios II. I'm doing a robotic project with a Cyclone and an EPCS4 flash memory. I've added an EPCS controller in my SOPC Builder system. I has to read/write some information in EPCS flash memory. I've tried to use the "epcs_command.h" header, but it doesn't work. My software program stay blocked for example on this line : device_id = epcs_read_device_id(epcs_flash_controller_0_base); This is the same thing for the other functions from this header. I read a lot of post on this forum, but I don't find any satisfying answer. Would you help me please ? If you don't use epcs_command.h, what functions and headers are you used to use ? Thanks a lot. mig --- Quote End --- It's been a while, so you probably don't care anymore; however, I recently ran into this problem as well, so I thought I would post a solution... The short answer is that instead of this: device_id = epcs_read_device_id(epcs_flash_controller_0_base); you need to do this: device_id = epcs_read_device_id(epcs_flash_controller_0_base+
epcs_flash_controller_0_register_offset);
This was definitely not clear from the Altera documentation I found; however, when using the functions in <epcs_commands.h>, the parameter 'alt_u32 base', is not what it seems (at least not to me)... With other peripherals, you simply take the peripherals base address as defined in <system.h>. For the EPCS commands, you need to offset this base address by the register offset, also found in <system.h> (in the definition of the EPCS Flash controller, probably below the BASE value). Hope this helps someone!

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page