|
|
View previous topic :: View next topic |
Author |
Message |
allenhuffman
Joined: 17 Jun 2019 Posts: 580 Location: Des Moines, Iowa, USA
|
SOLVED: PIC24 and getting the Configuration Bits address? |
Posted: Fri Dec 13, 2024 9:32 pm |
|
|
We use three different PIC24 chips on various boards. Our firmware has #defines for where the Configuration Bits/Fuses are located, like this:
Code: | #define START_ADDRESS_CONFIG 0xABFC // The start address of the configuration words |
Is there a way to obtain this in code, or is it just "look it up in the data sheet and hard code it"?
And here is why I ask... I am finally implementing a bootloader I wrote a few years ago. The bootloader contains the IVT, the bootloader code, and the #FUSES.
The application will have #FUSES none.
One of the options is to create a master .hex file that the factory can use to burn a fresh board -- this would have the bootloader and the application combined.
Using info from CCS support and others in this forum a few years ago, I use #import to pull in the bootloader to the application hex file:
Code: | #warning/information Including Bootloader in Application HEX file.
// Import the vector table and bootloader code.
#import(FILE=BOOTLOADER_HEX, HEX)
|
This produces the desired .hex, but it will give a warning about memory being used. Tonight I went searching and saw posts here where they said it was due to the bootloader.hex containing the FUSES, and import generates that warning. A suggestion was given to use two #imports, so I tested this tonight:
Code: | #warning/information Including Bootloader in Application HEX file.
// Import the vector table and bootloader code.
#import(FILE=BOOTLOADER_HEX, HEX, RANGE=0:BOOTLOADER_APP_ADDRESS-1)
// Import the configuration bits (fuses).
#import(FILE=BOOTLOADER_HEX, HEX, RANGE=START_ADDRESS_CONFIG:0xFFFFFF)
|
And no more warning.
However, while I had a #define for the start of the config bytes, I have not yet looked up our various PIC24s to see what the range should be.
Also, I was looking to see if there was a getenv("XXX") or something that would let me obtain the memory address instead of "just having to know" and hard code it in a #define.
Is there some way to get this value? _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002.
Last edited by allenhuffman on Mon Dec 16, 2024 10:23 am; edited 1 time in total |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1358
|
|
Posted: Fri Dec 13, 2024 11:51 pm |
|
|
I think one of the parameters does, maybe PROGRAM_MEMORY. Should be easy to test |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Sat Dec 14, 2024 3:53 am |
|
|
The address you are using is the flash config words address, which is
always at the top of the last page in the program memory. The
PROGRAM_MEMORY value should give this, since it is the address immediately
above the maximum value the program can use. However a quick check
shows this is giving the address of the top of this area, so will need to
have the size of the config area subtracted. If your chips are all similar this
will be the same on them all.
It would be quite nice to have this available, so I'd ask CCS for this. They
may say it is already available. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1358
|
|
Posted: Mon Dec 16, 2024 8:43 am |
|
|
Ttelmah wrote: | The address you are using is the flash config words address, which is
always at the top of the last page in the program memory. The
PROGRAM_MEMORY value should give this, since it is the address immediately
above the maximum value the program can use. However a quick check
shows this is giving the address of the top of this area, so will need to
have the size of the config area subtracted. If your chips are all similar this
will be the same on them all.
It would be quite nice to have this available, so I'd ask CCS for this. They
may say it is already available. |
That's certainly strange. I just tested it on my PIC241024GB610 with v5.113 and it returns 0xABF00, which when I look at my hex is the start of the configuration words?
So for me "PROGRAM_MEMORY" gives the start of the configuration words (no subtraction needed in my case). Perhaps it is chip family specific. Which chip did you test out |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Mon Dec 16, 2024 9:59 am |
|
|
That is what I'd have expected/hoped. I tried it on a chip I'm using, and
got the figure for the top of memory. Suggests I may get a problem on
this chip if it gets close to using all the memory!!!!!.
I'll report this to CCS as a fault on this device.
Good news. |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 580 Location: Des Moines, Iowa, USA
|
|
Posted: Mon Dec 16, 2024 10:23 am |
|
|
CCS replies:
Quote: | You can use getenv("CONFIGURATION_ADDRESS") |
_________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002. |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 580 Location: Des Moines, Iowa, USA
|
|
Posted: Mon Dec 16, 2024 10:31 am |
|
|
Some testing shows maybe this is not solved:
Code: |
#define START_ADDRESS_CONFIG 0x02AFF0 // The start address of the configuration words
#define START_ADDRESS_CONFIG2 getenv("CONFIGURATION_ADDRESS")
|
The hard-coded value matches what is shown in the .hex file:
Code: |
Configuration Words
02AFF0: 00FFFF4D 00FFFFEF 00FFFF7F 00FFFF39
02AFF8: 00FFFFF8 00FFFFFF 00FFFFFF 00FFFFFF
|
But running this program shows:
Code: |
START_ADDRESS_CONFIG : 0x2aff0 (176112)
START_ADDRESS_CONFIG_GETENV: 0x55fd8 (352216)
|
The internal PIC address (2 bytes per address) should be double, I thought, meaning 0x55FE0 (352224) so the getenv() is returning 8 bytes later. Is this the end of the config bytes or something? _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002. |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 580 Location: Des Moines, Iowa, USA
|
|
Posted: Mon Dec 16, 2024 10:40 am |
|
|
If I add 8 to the returned value, I can get a match:
Code: |
Configuration Words
02AFF0: 00FFFF4D 00FFFFEF 00FFFF7F 00FFFF39
02AFF8: 00FFFFF8 00FFFFFF 00FFFFFF 00FFFFFF
#define START_ADDRESS_CONFIG 0x02AFF0 // The start address of the configuration words
#define START_ADDRESS_CONFIG2 ((getenv("CONFIGURATION_ADDRESS")+8) / 2)
START_ADDRESS_CONFIG : 0xabfc (44028)
START_ADDRESS_CONFIG_GETENV: 0xabfc (44028)
|
But I need to check on our two other PIC24 types just in case there is an error in the CCS reporting for this chip. _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002.
Last edited by allenhuffman on Mon Dec 16, 2024 10:49 am; edited 3 times in total |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 580 Location: Des Moines, Iowa, USA
|
|
Posted: Mon Dec 16, 2024 10:43 am |
|
|
Ah, on one of our othjer boards using 24FJ64GA002, the getenv() matches what is in the hex:
Code: |
Configuration Words
00ABFC: 00FFFB15 00FF3F7F
#define START_ADDRESS_CONFIG 0xABFC // The start address of the configuration words
#define START_ADDRESS_CONFIG2 (getenv("CONFIGURATION_ADDRESS") / 2)
START_ADDRESS_CONFIG : 0xabfc (44028)
START_ADDRESS_CONFIG_GETENV: 0xabfc (44028) |
_________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Mon Dec 16, 2024 10:55 am |
|
|
That is really interesting.
Implies that the CCS values have rather more faults than I'd have expected
or hoped for. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Mon Dec 16, 2024 4:36 pm |
|
|
well.. it IS a 'Monday' after all....... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Wed Dec 18, 2024 2:40 am |
|
|
8.
Wonder. Remember the user_ID is actually part of the configuration data,
and is normally 8 bytes below the actual fuses. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1358
|
|
Posted: Wed Dec 18, 2024 8:34 am |
|
|
allenhuffman wrote: | Ah, on one of our othjer boards using 24FJ64GA002, the getenv() matches what is in the hex:
Code: |
Configuration Words
00ABFC: 00FFFB15 00FF3F7F
#define START_ADDRESS_CONFIG 0xABFC // The start address of the configuration words
#define START_ADDRESS_CONFIG2 (getenv("CONFIGURATION_ADDRESS") / 2)
START_ADDRESS_CONFIG : 0xabfc (44028)
START_ADDRESS_CONFIG_GETENV: 0xabfc (44028) |
|
Out of curiosity, did you try PROGRAM_MEMORY and see how it compared to the other options? |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1358
|
|
Posted: Wed Dec 18, 2024 8:34 am |
|
|
Ttelmah wrote: | That is what I'd have expected/hoped. I tried it on a chip I'm using, and
got the figure for the top of memory. Suggests I may get a problem on
this chip if it gets close to using all the memory!!!!!.
I'll report this to CCS as a fault on this device.
Good news. |
which chip was it? |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 580 Location: Des Moines, Iowa, USA
|
|
Posted: Wed Dec 18, 2024 11:30 am |
|
|
jeremiah wrote: | Out of curiosity, did you try PROGRAM_MEMORY and see how it compared to the other options? |
Not yet, but I will do that today.
I now can build a sample "blink S.O.S. on the LED" application in to my bootloader, and using the two imports I can bring in the bootloader and fuses only, skipping the S.O.S. app and allow me to have my real app there.
When I first wrote this a few years ago, I had to ifdef my stub test app function since it would conflict when trying to import the bootloader.
Learning is fun. _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002. |
|
|
|
|
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
|