CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

write_virtual_eeprom() and ROM/RA usage: How to minimize?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
apakSeO



Joined: 07 Dec 2016
Posts: 60
Location: Northeast USA

View user's profile Send private message

write_virtual_eeprom() and ROM/RA usage: How to minimize?
PostPosted: Mon Sep 24, 2018 10:03 am     Reply with quote

CCS v5.073
PIC16F1503

Is there a way to lessen the amount of program space and/or RAM the write_virtual_eeprom() function is using? The PIC in my application is very limited with 2K program space and only 128 bytes of RAM. I've been pulling hairs trying to limit the code and variable usage and I think I am at the practical limit of what I can acheive.

In my application code, prior to inserting the line
Code:
 write_virtual_eeprom(addr,data);

I have the following program/ram memory:



In this thread: https://www.ccsinfo.com/forum/viewtopic.php?t=57436 user Ttelmah helped me to setup this driver for read/write of the program flash memory. I defined the number of pages to use as only 1 in my code ( I only need 3 bytes total of non-volatile memory for storing calibration data ) by using the define

Code:
 #define VIRTUAL_EEPROM_NUM_PAGES 1



When I add in the write_virtual_eeprom(addr,data) function call into my code, the compiler returns the message:

Quote:
C:\...\Microchip Projects\...\main.c:706:1: Error#71 Out of ROM, A segment or the program is too large MAIN
Seg 00020-007BF, 0240 left, need 00244
Seg 007C0-007C5, 0000 left, need 00244 Reserved
Seg 007C6-007FF, 003A left, need 00244
Seg 00000-00002, 0000 left, need 00244 Reserved
Seg 00003-00003, 0001 left, need 00244
Seg 00004-0001F, 0000 left, need 00244 Reserved



Yet prior to this insertion, when I browse the program memory, it appears I have more than enough space free for doing the "copy entire page at a time, change value, write entire page at a time" operation that the virtual_eeprom.c driver needs:



The main program memory ends at about 0x6AB
My 3 bytes of calibration constants start at 0x7C0

Short of posting the entirety of my code here, is there anything I can do to lower the amount of ROM & RAM the virtual_eeprom.c driver uses?
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Mon Sep 24, 2018 10:10 am     Reply with quote

In these chips, a 'routine', must be small enough to fit inside the page. Your chip is not out of ROM, but you have a routine (your main), which is a too large 'lump'. You need to split it up. A search here for:
"Out of ROM, A segment or the program is too large"
Will find dozens of threads about this descibing how to split the code up.

Writing to the program memory is quite complex. Unfortunately you are meeting a limitation of your chip. This is why people will say if you want eeprom, get a chip with eeprom...

If you only want (perhaps) a maximum of 16 bytes, then use an alternative approach.

Have a RAM array of 32bytes.
Read a single 32byte page of the flash using read_program_memory.
Use this for your config data, only using the low byte of each 16bits.
Make any changes you want, and write the entire 32bytes back.

You have to write a whole page, since this is the block that will erase. when a write is done.
apakSeO



Joined: 07 Dec 2016
Posts: 60
Location: Northeast USA

View user's profile Send private message

PostPosted: Mon Sep 24, 2018 2:28 pm     Reply with quote

I read as many threads here in 3 hours I could find regarding this "Out of ROM" message & the #separate directive. Unfortunately, this doesn't seem to do anything at all for me when I implement it in source code. I do not see a change in the ROM usage at all.

I was able to refactor and gain a little bit of ROM space by consolidating functions into a single function, and that allowed me to call write_virtual_eeprom() a single time, without compile errors. Calling it a second time leads to the Out of ROM error.

I've even tried to delve into the virtual_eeprom.c driver and put #separate before each function definition. I can't tell if this helped matters at all, for I do not see a change in the ROM usage. Without the any call to write_virtual_eeprom(), my Memory usage: ROM=83% RAM=31%-85%

Including a single call to write_virtual_eeprom() within an if {} block jumps the Memory usage: ROM=97% RAM=31%-95% A second call to write_virtual_eeprom() takes me over the edge and the program will not compile, resulting in:

Quote:

C:\Users\...\Microchip Projects\...\main.c:742:1: Error#71 Out of ROM, A segment or the program is too large MAIN
Seg 00020-007BF, 01AC left, need 001B1
Seg 007C0-007C5, 0000 left, need 001B1 Reserved
Seg 007C6-007FF, 003A left, need 001B1
Seg 00000-00002, 0000 left, need 001B1 Reserved
Seg 00003-00003, 0001 left, need 001B1
Seg 00004-0001F, 0000 left, need 001B1 Reserved


With a single call to write_virtual_eeprom(), my stack usage is 8; this PIC has a stack of 16 so I'm not running out of headroom there.

I'm also not using any #inline functions.

How can I delve deeper into what is going on here?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 24, 2018 4:30 pm     Reply with quote

Order the 16F1825, put your code in that with read_eeprom() and
write_eeprom() and you're done.

You could do a test compile of that now. It would brighten you up since you
would see a solution.
apakSeO



Joined: 07 Dec 2016
Posts: 60
Location: Northeast USA

View user's profile Send private message

PostPosted: Tue Sep 25, 2018 10:31 am     Reply with quote

Thanks for the kind sentiments, PCM

In order to fit the 16F1503 on this tiny PCB, I had to go with the 3mm x 3mm UQFN The 16F1825 does not offer this package option, regrettably, and is only offered in the 4mm x 4mm UQFN as far as I can tell.

I was hoping I could replace the 16F1503 on these PCBs, for I am more or less a PCB rework expert, but alas, seems not to be the case. In rev 2, I'll have to move onto the 1825.

If I figure this out, I'll reply back here for posterity.
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Tue Sep 25, 2018 11:15 am     Reply with quote

As a comment though, you don't want to consolidate, you want to _separate_. Change the declaration to write_virtual_eeprom. Declare it as #separate. By default the compiler tends to 'inline' code. Do the same to any other of your own functions you call. You may well then find things fit.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group