|
|
View previous topic :: View next topic |
Author |
Message |
lupoccs
Joined: 31 Jul 2018 Posts: 8
|
library problem with boot sector |
Posted: Tue Jun 11, 2019 6:11 am |
|
|
I'm trying to create a boot sector (uodate software with serial line).
I wrote several simple routines to see how they are put in the final code and to see if the boot sector contains only the software required.
The problem is that I use the math.h library (outside the boot block) and on the listing file I see a long sequence of DATA that is from the math.h library.
I see that in the math.h library there are 4 arrays of numbers that are not declared as constant, and are
double pas_64[5] line 1474 of math.h
double pas_64[5] line 1477 of math.h
double pat_64[6] line 1690 of math.h
double pat_64[6] line 1693 of math.h
If I add the const keyword to all of them (double const pas_64[5]) the DATAs are moved outside the boot sector.
I don't understand why the compiler, that understand that the arrays are constant numbers because put them in the FLASH section of memory, put the arrays in the boot sector if const is not present and outside the boot sector in const is present.
This behaviour is dangerous, because I have a part of a library inside a boot sector, that never changes during software update, and the boot sector is larger than I need.
How can I do to force the compiler to put in the ORG section only the code that I need? I don't want to change a standard library to work properly...
The problem is present also if I include the library without using it at all.
I use the 5.074 version of the compiler
Thank You
Fabrizio Borra - Lupo srl |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19487
|
|
Posted: Tue Jun 11, 2019 6:38 am |
|
|
The compiler does _not_ "understand that the arrays are constant numbers because put them in the FLASH section of memory".
Remember that a non constant variable that is initialised 'with' a value, has
to have that initialisation value stored somewhere. It is this value
that you are seeing stored in the flash. Not the actual variable.
Now it is actually slightly wasteful, that these values that can be constants
are not being actually used from flash. However Accessing RAM is quicker,
which is probably why this is done. If your #ORG that says to avoid the
boot area, is used before the math library is loaded, and includes the 'default'
keyword, the maths definitions are merrily moved up as required. |
|
|
lupoccs
Joined: 31 Jul 2018 Posts: 8
|
|
Posted: Tue Jun 11, 2019 8:30 am |
|
|
This is my code.
It makes no sense, because is only a code to "fill" the memory to check the addresses of the function inside and outside the boot sector
The code below is the original with the boot DATA inside
I moved the
Code: |
#include <mymath.h>
after
#org default
|
but nothing changes in the boot sector
What is my mistake?
Thank You
Code: |
#define DEBUG 0
// #define DEBUG 1
#define INIBOOT 0x15000 // boot sector address
#define ENDBOOT 0x157EB // boot sector end
#include <33EP128MC206.h>
#if (DEBUG == 1)
#device ICD=TRUE
//#device ICD=ICSP2
#device ICSP=2
#FUSES NOPROTECT // Code protected from reads
#else
#FUSES PROTECT // Code protected from reads
#FUSES CKSFSM // Clock Switching is enabled, fail Safe clock monitor is enabled
#endif
#FUSES NOWRT // Program Memory Not Write Protected
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOJTAG //JTAG disabled
#FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
#use delay(clock=140MHz,crystal=8MHz,restart_wdt)
#include <mymath.h>
#define N_BYTE_USB_BUFFER 100 //numero byte USB_buffer a 8 bit
#define EEPROM_SDA PIN_C4
#define EEPROM_SCL PIN_C5
#use i2c(MASTER, RESTART_WDT, I2C1, sda=EEPROM_SDA, scl=EEPROM_SCL,FAST=400000, stream=PER_1 )
void main1loop(void);
int16 divide(int16 uno, int16 due);
const int16 tablinquad[33] = {0,313,625,938,1250,1563,1875,2188,2501,2813,3126,3438,3751,4063,4376,4689,5001,5314,5626,5939,6252,6564,6877,7189,7502,7814,8127,8440,8752,9065,9377,9690,10000};
char USB_Buffer[N_BYTE_USB_BUFFER];
int inbuffer_USB;
int outbuffer_USB;
int nbytebuffer_USB;
#ORG INIBOOT - 10, INIBOOT -1
void main_start()
{
main1loop();
}
#ORG INIBOOT, ENDBOOT default
int16 moltiplica(int16 uno, int16 due);
void main(void)
{
int16 pippo = 0;
int16 pluto;
int16 vari1;
int16 vari2;
int16 dimerase;
int16 dimwrite;
int32 address;
int32 nextaddress;
int8 buffer[32];
int datimiei[48];
output_high(PIN_B2);
for (pluto = 0; pluto < N_BYTE_USB_BUFFER; pluto++)
{
USB_Buffer[pluto] = 0;
}
inbuffer_USB = 0;
outbuffer_USB = 0;
nbytebuffer_USB = 0;
address = 0;
nextaddress = 0;
dimerase = getenv("FLASH_ERASE_SIZE");
dimerase /= 2;
dimwrite = getenv("FLASH_WRITE_SIZE");
for(pluto = 0; pluto < 48; pluto++)
{
datimiei[pluto] = 0;
}
pippo = 0;
pluto = 0;
for(pluto = 0; pluto < 32; pluto++)
{
buffer[pluto] = 0xAA;
}
while(TRUE)
{
pippo++;
if(pippo >= 30)
{
pippo = 0;
main_start();
}
pluto = tablinquad[pippo];
vari1 = moltiplica(pippo,pluto);
vari2 = divide(pippo,pluto);
}
}
int16 moltiplica(int16 uno, int16 due)
{
int16 variab;
variab = uno * due;
return variab;
}
#ORG default
int16 divide(int16 uno, int16 due)
{
float TempFloat;
int16 variab;
TempFloat = ((float)110 * PI) / 180;
TempFloat = ((((((float)(100)) / 100) * 3999) / 3) * (1 + (cos(TempFloat) / cos(1.0471975512 - TempFloat))));
variab = uno * due;
return variab;
}
void main1loop(void)
{
char pippo;
pippo = ' ';
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19487
|
|
Posted: Tue Jun 11, 2019 10:36 am |
|
|
and the ORG statement, needs to be specifying the range to use as well
as 'default'. #ORG default on it's own just sets the ORG back to normal
with nothing at all reserved.
You need this statement:
#ORG INIBOOT, ENDBOOT default
before you load the math.h library. Then math.h, and your main will both
be placed in the memory you want. |
|
|
lupoccs
Joined: 31 Jul 2018 Posts: 8
|
|
Posted: Wed Jun 12, 2019 1:54 am |
|
|
You are right, if I put the math library after ORG with iniboot endboot default both main and math library are in the boot sector, but my question was different.
I don't want math library in the boot sector, and my original program leave this library outside the boot sector, but I want to know how to leave outside the boot sector also the constants to initialize the RAM array inside the math library. You said that the constants used to initialize the math array in RAM must be stored "somewhere", I want to know how to do in order to make this "somewhere" outside the boot sector.
Thank You. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19487
|
|
Posted: Wed Jun 12, 2019 5:00 am |
|
|
The point is that you can put the math code anywhere you want.
Just an #ORG START,END default
Then load 'math.h', and the ORG will specify where this is to be put. |
|
|
lupoccs
Joined: 31 Jul 2018 Posts: 8
|
|
Posted: Thu Jun 13, 2019 2:31 am |
|
|
I tried successfully to put the math.h in a specific flash range with an #ORG START,END default , but the constants to initialize the array still remains in the boot sector.....
Thank You |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9220 Location: Greensville,Ontario
|
|
Posted: Thu Jun 13, 2019 5:02 am |
|
|
Maybe I'm totally wrong but...
Do you TOTALLY erase the PIC before programming it? Do you CONFIRM the PIC is 100% erased ? I know the programming device/ap can be set to NOT erase 'blocks' of memory so I'm wondering if the data in the 'boot block' , is really 'left over' from a previous attempt ?
Just trying to help eliminate possible causes.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19487
|
|
Posted: Thu Jun 13, 2019 8:03 am |
|
|
If you want the compiler to not put anything in the bottom of memory, then
#build the code with the start address set above this. Otherwise, no matter
where you 'locate' the other code components, the compiler is always going
to consider all of the memory as being available. |
|
|
|
|
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
|