Sign up ×
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

I would like my compiles to exclude some code depending upon the flash/program space available. To be used in the demo code of a library I support. Whereas my current solution is to use a #ifdef of processor type. But I would like to be more general and not have to specify all the various chips. Rather it would be nice if there was a pre-processor constant that stated the available size.

Where I am not fluent enough in gcc and or avr-gcc I might expect to find some constants similar those that define the beginning and end of the heap.

On case example. Is that both the UNO and Leo have 32K of Flash. But the Leo's core library uses 4K for USB support, resulting in only 28K available. My Library's demo is near max'ed out on the UNO and I would like to automatically trim out based on available program space.

share|improve this question
    
I've seen programs that do this, but I can't find any –  TheDoctor Feb 12 '14 at 4:39

1 Answer 1

up vote 7 down vote accepted

Find the io__.h file for your microcontroller, on Linux it is located in /usr/lib/avr/include/avr, on Windows it will be in a somewhat similar location.

Scroll down to the part that says /* Constants */. There are couple interesting macros defined there, FLASHEND being the one you should be interested in. You can use it for example as follows:

#if FLASHEND > 0x8000
/* Include some extra code when sufficient flash is available. */

#endif
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.