• AVR Freaks

Helpful ReplyHot!Break the 256 words limit of strings?

Page: 12 > Showing page 1 of 2
Author
EverGreen_28
New Member
  • Total Posts : 28
  • Reward points : 0
  • Joined: 2018/08/14 11:09:01
  • Location: Argentina
  • Status: offline
2019/11/27 20:42:46 (permalink)
0

Break the 256 words limit of strings?

Hi guys!
 
I need a little help.
I creating a double termometer on a pic 16F88 with 20x4 LCD 44780 compatible.
The problem is the size of strings.
MPLABX log is:
 
Psect Usage Map:
 
 Psect      | Contents                       | Memory Range  | Size
------------|--------------------------------|---------------|--------------
 reset_vec  | Reset vector                   | 0000h - 0002h |    3 words  
 intentry   | Interrupt context entry code   | 0004h - 000Ah |    7 words  
 end_init   | Initialization code            | 000Bh - 000Ch |    2 words  
 _main_text |                                | 001Ah - 0199h |  384 words  
 cinit      | Initialization code            | 019Ah - 01AAh |   17 words  
 text30     | Program and library code       | 01ABh - 07B2h | 1544 words  
 text1      | Program and library code       | 07B3h - 07F3h |   65 words  
 text45     | Program and library code       | 091Eh - 0921h |    4 words  
 text43     | Program and library code       | 0922h - 0926h |    5 words  
 clrtext    | Memory clearing code           | 0927h - 092Eh |    8 words  
 text44     | Program and library code       | 092Fh - 0943h |   21 words  
 text3      | Program and library code       | 0944h - 095Ah |   23 words  
 text20     | Program and library code       | 095Bh - 0986h |   44 words  
 text53     | Program and library code       | 0987h - 09B3h |   45 words  
 text5      | Program and library code       | 09B4h - 0A28h |  117 words  
 text18     | Program and library code       | 0A29h - 0AA3h |  123 words  
 text7      | Program and library code       | 0AA4h - 0C42h |  415 words  
 text21     | Program and library code       | 0C43h - 0EFFh |  701 words  
            |                                |               |              
 strings    | Strings and constant data      | 0800h - 08FFh |  256 words    Full capacity
            |                                |               |              
 swtext1    |                                | 000Dh - 0018h |   12 words  
 swtext2    |                                | 07F4h - 07FFh |   12 words  
------------|--------------------------------|---------------|--------------
 cstackCOMM | Stack in common memory         | 0072h - 0075h |    4 bytes  
 bssCOMMON  | RAM variables in common memory | 0076h - 0078h |    3 bytes  
 bitbssCOMM | Bit variables in common memory | 0079h - 0079h |    1 byte   
            |                                |               |              
 cstackBANK |                                | 0026h - 0027h |    2 bytes  
 cstackBANK |                                | 002Eh - 005Eh |   49 bytes  
 bssBANK0hl |                                | 005Fh - 0060h |    2 bytes  
 cstackBANK |                                | 0064h - 0067h |    4 bytes  
 nvBANK0hll |                                | 0068h - 0068h |    1 byte   
 cstackBANK |                                | 006Ah - 006Fh |    6 bytes  
            |                                |               |              
 bssBANK1   | BSS variables in bank 1        | 00A0h - 00E2h |   67 bytes  
            |                                |               |              
 abs_s1     | Absolute RAM variables         | 0022h - 0025h |    4 bytes  
 abs_s1     | Absolute RAM variables         | 002Ah - 002Dh |    4 bytes  
 abs_s1     | Absolute RAM variables         | 0062h - 0063h |    2 bytes  
 abs_s1     | Absolute RAM variables         | 0069h - 0069h |    1 byte   
 abs_s1     | Absolute RAM variables         | 0071h - 0071h |    1 byte   
 abs_s1     | Absolute RAM variables         | 007Eh - 007Fh |    2 bytes  
------------|--------------------------------|---------------|--------------
 eeprom_dat | User-programmed EEPROM data    | 0000h - 0007h |    8 bytes  
------------|--------------------------------|---------------|--------------
 config     |                                | 2007h - 2008h |    2 words  
------------|--------------------------------|---------------|--------------
 idloc      | User-programmed ID locations   | 2000h - 2003h |    4 bytes  
------------|--------------------------------|---------------|--------------
 
.
At this point, all OK because strings is <=256words
 
I need to write more strings but not be able because the error:
 
:0: error: (1347) can't find 0x101 words (0x101 withtotal) for psect "strings" in class "STRING" (largest unused contiguous range 0x100)
(908) exit status = 1
 
The question is.
 
Exist any form to shift code to another memory position or better, any form to break the 256 limit?
 
I already set "PRO" mode, "space favour" and "24 bit for float and long" but problem persist.
I not use a var like "strings[256]={...}"
The strings is a "dispersed style" on the main code.
Like "ERROR " in the next fragment of my code:
 

        if (MAX6675_Status_bit[SENS1].TC_Open) {
            
            buffer_ptr[0] = buffer[0];
            strcpy(buffer_ptr[0], "ERROR ");
        }
        
        if (MAX6675_Status_bit[SENS2].TC_Open) {
            
            buffer_ptr[1] = buffer[1];
            strcpy(buffer_ptr[1], "ERROR ");
        }

 
I have 16F88 with 288 (0x120) positions of free program memory but if a write only 1 string character on main rutine, the compiler fails.
 
 
Thx in advance!
 
 
#1
ric
Super Member
  • Total Posts : 24608
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Break the 256 words limit of strings? 2019/11/27 20:58:05 (permalink)
+1 (1)
Which version of the compiler are you using?
Have you actually purchased a PRO license?
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#2
EverGreen_28
New Member
  • Total Posts : 28
  • Reward points : 0
  • Joined: 2018/08/14 11:09:01
  • Location: Argentina
  • Status: offline
Re: Break the 256 words limit of strings? 2019/11/27 22:27:20 (permalink)
0
Hi ric! Thanks for response.
 
Like I mentioned, i set PRO mode in xc8 compiler. I have PRO License.
Compiler is version 1.45
I try'ed compiler version 2.10 and same problem.
#3
EverGreen_28
New Member
  • Total Posts : 28
  • Reward points : 0
  • Joined: 2018/08/14 11:09:01
  • Location: Argentina
  • Status: offline
Re: Break the 256 words limit of strings? 2019/11/27 22:35:51 (permalink)
0
Apparently is a isolate problem because if i write
 
 
 

strcpy(buffer_ptr[0], "ERROR ");



Original string of 8 characters!!!


like this


 
 

strcpy(buffer_ptr[0], "ERROR ");



Note the number of space difference.
In this case have 9 characters

With this last code, strings psect is greater than 256 words but works fine, compiler finishes without error.

stringtext | Strings and constant data    | 0500h - 0603h |  260 words

Is very strange.
 
post edited by EverGreen_28 - 2019/11/27 22:38:23
#4
du00000001
Just Some Member
  • Total Posts : 3238
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: Break the 256 words limit of strings? 2019/11/28 00:53:55 (permalink)
0
You don't have strings[256] ?
 
I'm keen to see the definitions of buffer[][] and buffer_ptr[]  !
 
BTW: your last post looks like some C/P error: I cannot see any difference between the 2 lines.

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#5
ric
Super Member
  • Total Posts : 24608
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Break the 256 words limit of strings? 2019/11/28 01:31:04 (permalink)
+1 (1)
Before the post was edited, version#1 was:
strcpy(buffer_ptr, "ERROR   ");
and version#2 was
strcpy(buffer_ptr, "ERROR    ");
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#6
EverGreen_28
New Member
  • Total Posts : 28
  • Reward points : 0
  • Joined: 2018/08/14 11:09:01
  • Location: Argentina
  • Status: offline
Re: Break the 256 words limit of strings? 2019/11/28 03:42:57 (permalink)
0
Sorry, and yes, no differences, i try'ed to correct.
 
version without any error on compiling:

if (MAX6675_Status_bit[SENS1].TC_Open) {
            
            buffer_ptr[0] = buffer[0];
            strcpy(buffer_ptr[0], "ERROR  "); 7 characters
        }
        
        if (MAX6675_Status_bit[SENS2].TC_Open) {
            
            buffer_ptr[1] = buffer[1];
            strcpy(buffer_ptr[1], "ERROR  "); 7 characters
        }


version with compiling errors:
 

if (MAX6675_Status_bit[SENS1].TC_Open) {
            
            buffer_ptr[0] = buffer[0];
            strcpy(buffer_ptr[0], "ERROR   "); 8 characters
        }
        
        if (MAX6675_Status_bit[SENS2].TC_Open) {
            
            buffer_ptr[1] = buffer[1];
            strcpy(buffer_ptr[1], "ERROR   "); 8 characters
        }

 
 
and finally i encounter a strange "bug?":
This code again, compile with no errors:
 

if (MAX6675_Status_bit[SENS1].TC_Open) {
            
            buffer_ptr[0] = buffer[0];
            strcpy(buffer_ptr[0], "ERROR    "); 9 characters
        }
        
        if (MAX6675_Status_bit[SENS2].TC_Open) {
            
            buffer_ptr[1] = buffer[1];
            strcpy(buffer_ptr[1], "ERROR    "); 9 characters
        }

 
 
Anyone know whats happens?
#7
EverGreen_28
New Member
  • Total Posts : 28
  • Reward points : 0
  • Joined: 2018/08/14 11:09:01
  • Location: Argentina
  • Status: offline
Re: Break the 256 words limit of strings? 2019/11/28 03:53:33 (permalink)
0
Hi du00000001!


The definitions of buffer is irrelevant because buffer is the output of strcpy but here the definitions:




char buffer[2][20];
char *buffer_ptr[2];




Any ideas guys?
post edited by EverGreen_28 - 2019/11/28 04:17:23
#8
du00000001
Just Some Member
  • Total Posts : 3238
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: Break the 256 words limit of strings? 2019/11/28 07:51:11 (permalink)
+1 (1)

Any ideas ... ?

 
I don't expect this to be a compiler bug but a linkage issue:
following "some" strategy (often in descending link order), the linker allocates space for all elements to be allocated in some section. When the section is nearly full, could be that the next element violates the boarder. For the XC linker there might be some difference between some "pre-calculation" of the buffer size required and the real size - due to additional alignment requirements that may not have been considered during the "pre-calculation".
But this is just a parly wild, partly eduacated guess ...

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#9
EverGreen_28
New Member
  • Total Posts : 28
  • Reward points : 0
  • Joined: 2018/08/14 11:09:01
  • Location: Argentina
  • Status: offline
Re: Break the 256 words limit of strings? 2019/11/28 09:11:21 (permalink)
0
No solution for this more than rewrite main rutine?
 
Is very strange!
The problem, i think, isn't the buffer definition because buffer is allocated on Data memory (RAM).
The problem is on ROM because the string "ERROR    " is allocated on it.
If the linker looks a good ROM address for "ERROR    " (9 characters), for why not use same address when i change to "ERROR   " (8 characters) ?    o.O
#10
du00000001
Just Some Member
  • Total Posts : 3238
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: Break the 256 words limit of strings? 2019/11/28 10:10:24 (permalink) ☄ Helpfulby EverGreen_28 2019/11/28 20:17:11
+2 (2)
Tip:
  • Avoid multiple copies of the ever-same constant:
Instead of 
.....
buffer_ptr[0] = buffer[0];
strcpy(buffer_ptr[0], "ERROR ");
.....
buffer_ptr[1] = buffer[1];
strcpy(buffer_ptr[1], "ERROR ");
.....
 
create a global or module-local constant
const char ERROR_TEXT[] = "ERROR ";
. . . 
buffer_ptr[0] = buffer[0];
strcpy(buffer_ptr[0], ERROR_TEXT);
.....

 
There is hardly some "patent recipe" to avoid copies, it requires some thinking - and don't rant about the eventual necessity to adjust spaces:
....
const char _10BLANKS[] = "          ";
. . .
strncpy(&buffer_ptr[0][strlen(buffer_ptr[0])], _10BLANKS, 5);
....

(Variants of the previous apply...) 

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#11
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3348
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: online
Re: Break the 256 words limit of strings? 2019/11/28 10:50:15 (permalink)
0
I have a string array of nearly 6000 characters in total on a pic18f.
 
const char *tunes[]={
"TV Theme - Star Trek:t=-1,d=32,o=5,b=120:8f#,8e.6,16d#6,c#.6,b.,a#.,
4a,16g.,8f#,8f#.6,16e6,d#.6,c#.6,b.,4a#,16a,8g#.,
16a#,16b,c#.6,d#.6,e6,d#.6,4f#6,8a.6,16g#6,8f#6,4g#,8c#6,2b.",
...
};
 
Why struggle with an ancient 15 Year old chip ?
MPLAB_XC8_C_Compiler_Users_Guide

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#12
mad_c
Super Member
  • Total Posts : 1206
  • Reward points : 0
  • Joined: 2010/12/12 17:48:27
  • Location: Brisbane, Australia
  • Status: offline
Re: Break the 256 words limit of strings? 2019/11/28 13:23:07 (permalink) ☄ Helpfulby EverGreen_28 2019/11/28 21:07:01
+2 (2)
Hi,
 
The compiler monitors the amount of string data you use. For your device, if that is less than around 256 bytes, then the data is placed in the strings psect and linked into the STRING linker class, which covers the entire program memory but only in 100h chunks. If the amount of string data you use exceeds the threshold, it is placed into the stringtext psect, which is linked into the STRCODE linker class, which is one big area covering the entire program memory. (Check your map file.)
 
Note that for your device, there is also code that has to exist with your string data and which increases the size of the psects. The compiler, however, should be aware of this and handle the transition fine. Assuming you have not manually placed objects into psects or in any other way circumvented the compiler's normal way of operating, then there could be some compiler miscalculation. Adding extra strings might be enough to make the compiler change its behaviour.
 
If the problem persists, you would need to send your project to Support so they can take a look to see where the cause lies.
 
Jeff.
#13
ric
Super Member
  • Total Posts : 24608
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Break the 256 words limit of strings? 2019/11/28 14:48:41 (permalink)
+1 (1)
And also be aware, all these funny limitations disappear if you move to an "enhanced" PIC16F device
(PIC16F1xxx and PIC16F1xxxx).
These devices make it MUCH easier to read constants from code memory.
If you want to stay with the 18 pin footprint, a PIC16F1827 can do everything a PIC16F88 can do, and more, yet is half the price.
(And a PIC16F1847 has twice the memory, and is only a few cents more than a PIC16F1827)

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#14
EverGreen_28
New Member
  • Total Posts : 28
  • Reward points : 0
  • Joined: 2018/08/14 11:09:01
  • Location: Argentina
  • Status: offline
Re: Break the 256 words limit of strings? 2019/11/28 20:20:28 (permalink)
0
Thx du00000001!
 
I think your solution of create constant.
 
I understand you're say, but XC8 in PRO mode is omniscient. You think XC8 not check the "ERROR   " string duplicated and simplified this to one ROM string?
#15
EverGreen_28
New Member
  • Total Posts : 28
  • Reward points : 0
  • Joined: 2018/08/14 11:09:01
  • Location: Argentina
  • Status: offline
Re: Break the 256 words limit of strings? 2019/11/28 20:29:47 (permalink)
+1 (1)
Hi Gort2015! and thx for your interest
 
I explain you question "Why struggle with an ancient 15 Year old chip ?"
 
The reply is simple, i live on Argentina and the situation of USD is very HARD. Here 1 PIC isn't easy to purchase nor easy to get specific model.
 
I look for replace the 16F88 with 16F1847 because this is more powerful (is built in I2C master mode via hardware and a lot of memory saved for my soft, and raises ROM from 4K to 8K) but here no market has it.
 
#16
EverGreen_28
New Member
  • Total Posts : 28
  • Reward points : 0
  • Joined: 2018/08/14 11:09:01
  • Location: Argentina
  • Status: offline
Re: Break the 256 words limit of strings? 2019/11/28 20:44:08 (permalink)
0
Thx mad_c for your interest!
 
I not manipulate absolute address'es of any rutine if you refer to this.
 
I only manipulate absolute address of some RAM registers.
 
---------------------------
 
Thx ric! for your interest.
 
Here in Argentina is difficult to get specific models of PIC because price of a USD. Here 1 USD = ARS60.
1 PIC 16F88 is around ARS512 = USD8.53 aprox. The price is a scam where i look the price on aliexpress/ebay/etc...
Excesive and uncontrolled price's.
For example 18F2550 is less than USD8.53 and i get much more benefits. But i need a 18 PIN compatible device like 16F1847.
 
#17
ric
Super Member
  • Total Posts : 24608
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Break the 256 words limit of strings? 2019/11/28 20:52:20 (permalink)
0
Yep, you could order through Microchip direct.
The PIC16F1847 chip is only US$1.65, but shipping would be US$25.76
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#18
ric
Super Member
  • Total Posts : 24608
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Break the 256 words limit of strings? 2019/11/28 20:55:15 (permalink)
+1 (1)
EverGreen_28
Thx mad_c for your interest!
 
I not manipulate absolute address'es of any rutine if you refer to this.
 
I only manipulate absolute address of some RAM registers.

mad_c did not make any mention of "absolute addresses".
He simply indicated that the compiler handles strings differently if the entire size of them exceeds roughly 256 characters.

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#19
EverGreen_28
New Member
  • Total Posts : 28
  • Reward points : 0
  • Joined: 2018/08/14 11:09:01
  • Location: Argentina
  • Status: offline
Re: Break the 256 words limit of strings? 2019/11/28 21:14:42 (permalink)
0
thx ric for clearing, yes i misunderstood. I not familiarized with the build process and executables involucred.
 
I newbie in this matter. I know little of programation because i have not studies nor professor. I completelly autodidact.
My knowledgment is based on books and datasheet haha!
I know best assembler than C/C+/C++ but i decided to left assembler because my fingers is on fire.
#20
Page: 12 > Showing page 1 of 2
Jump to:
© 2019 APG vNext Commercial Version 4.5