Code Space storage

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I have 6 large tables, each with 512 32-bit words, that need to be transferred over SPI. The tables are fixed, and I'd like to use code space flash for them, preferably in the mega32.

It's easy for me to express the tables as 32, 16 or 8 bit words in .h files.

Could you please point me to which litterature I should read to do this in AVR-GCC?

Thanks,
Borge

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your data is 6 x 512 x 4 bytes = 12kB ---- a significant proportion of a mega32's flash memory.

You need to have your SPM routines in bootloader space. They can load in as part of your regular application.

The application reads blocks of data to SRAM over the SPI bus. Your SPM function then erases a page of flash memory, and programs the new data.

You will probably find it easiest to use fixed page addresses for your data. The application will access the data by casting an appropriate pointer to these fixed memory pages.

Once you have initialised your appropriate pointers, you just use regular C constructs. The compiler will police your types.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

that need to be transferred over SPI.

In which direction? Do you just want to build the tables into the code image and then send out over SPI? If so then just read Dean's "PROGMEM" article in the Tutorial Forum.

Otherwise if data is to be received into the AVR and stored in code flash then you will want to follow David's advice - in this case the article in Tutorial about "Bootloader FAQ" may be of use.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks guys! I'll read the PROGMEM article.

It will work to hardcode the tables into the code image and then read from there to the FPGA over SPI.

I'm using SPI extensively in this project, so the simplest thing is probably to just slap on an SPI flash memory chip. If I eventually need R/W flexibility, that is. And even now my code fits into a mega16, though the tables will not. So mega16+external might be easier than going for a mega32.

It's good to know that it can be done in internal flash. That opens up some cost, area and security trade-offs.

Borge

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

security trade-offs

That would be true if AVRs were secure - they are not - $500 gets you in past any lock bits.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Related question, if I may. Working on an ATmega164, I need to put tables in FLASH that may be updated (rarely). When I erase the old tables the FLASH system will, of course, erase in 64 word blocks. I need to tell the compiler to start the table at the beginning of a block and ensure that no vital code is located in the last block and gets inadvertently erased. The PROGMEM attribute allows me to put a table in FLASH, but nowhere can I find any attribute or command that lets me tell the compiler exactly where to put the data. The alignment attribute lets me align data on a byte or word boundary, but won't take a block boundary. Any suggestions would be greatly appreciated.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Warning, pblase does the multiposting thing. (original answer removed).

Stealing Proteus doesn't make you an engineer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

pblase,

As long as you promise to keep the discussion in this thread and allow me to delete your cross post I will tell you that you need to look at using a named section (like PROGMEM does but this one has a name you choose) then you give it an absolute position with a --section-start=.yourname=0xNNNN where NNNN is the base address (and a page boundary) given in bytes.

Now can I delete you cross post?

Moderator.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, I found the documentation in the avr-libc FAQ
http://www.nongnu.org/avr-libc/u...
for placing code at fixed addresses. The problem is that this is the ONLY place that this is documented anywhere! It was not evident in the gcc manual at all.
Go ahead and delete posts as necessary.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry about the cross post, I forgot where I put the original one.