9 years, 5 months ago.

Having problem when reading data from txt/bin file......

Hi.I want to send a monochrome image data from mbed to Multimedia screen.But,at max i can use a buffer of 20kb.Above this size mbed does not read file. What should I do now??? Can I use mbed rom as ram to increase the buffer size?Or should I pick the data in chunks?? If i pick the data in chunks then how I will use the fgets command?? Thanks

Question relating to:

Mr. Andy A thnks...... we tried these two buffers but there is problem. When we read data in these buffers and display it then also some additional lines re shown on screen??Can u please mention why is it??

posted by Muhammad Yousaf 08 Dec 2014

1 Answer

9 years, 5 months ago.

On the NXP1768 if you aren't using Ethernet or CAN then there is some extra memory you can use.

static char buffer1[0x4000] __attribute__((section("AHBSRAM0")));
static char buffer2[0x4000] __attribute__((section("AHBSRAM1")));

Will give you two 16k buffers outside of the normal memory area. These are right next to each other in memory so with the above code you could treat buffer1 as a single 32k buffer.

If you need to hold more data than that allows then your best bet would be to use either LocalFileSystem or an SD card and SDFileSystem and save the image as a file on that. You can then read the from the file as needed. Ideally split your memory into two buffers, use one for the data you are currently sending to the display while the other one is reading the next block of data from the file and then switch them over at the end of each block. That way you avoid any pauses in the data output caused by reading the next part of the file from storage.

Thanks.......... 1.so now i can use fgets(buffer1, 32k, fp) ?? 2.what is 0x4000 in index location of above buffer1 and buffer2 ?? 3.YOu said we can use buffer1 as single 32k buffer so i want to know that is in this case we just have to use first line of above two line code?

posted by Muhammad Yousaf 13 Nov 2014

1) Yes.

2) It's the size of the array to allocate. 0x indicates a hexadecimal number, 0x4000 is 16k. When you want a something that is an exact power of 2 it's normally easier to use hex, it's clearer and makes it obvious that you mean a round number. e.g. 0x4002 is far easier to spot as being wrong than than 16386

3) You only need the first line but include both anyway. Since C doesn't check the limits on arrays you could technically define buffer1 as being 1 byte and then still use it as a 32k buffer. Unless you use ethernet or CAN nothing else is going to use that memory so it would work fine. However if you do define both buffers you are flagging all 32k of memory as being used, that way you'll get compile errors if something else does try to reserve it.

posted by Andy A 14 Nov 2014