Author Topic: Microchip migration from config bits to pragma config bits  (Read 2187 times)

0 Members and 3 Guests are viewing this topic.

Offline matbTopic starter

  • Regular Contributor
  • *
  • Posts: 68
  • Country: fr
Microchip migration from config bits to pragma config bits
« on: October 12, 2022, 12:57:25 pm »
Hi everyone,
I'm trying to migrate from xc16 v1.25 to v1.26 to be able to use the license patch found on eev forum.

I managed to migrate most of it using the Window > Target memory view > Configuration bits but I'm having a hard time with FAS and FUID0.

My app uses a bootloader and for whatever reason previous devs (not here anymore obviously) used FAS and FUID0 to share software version and hardware version.
So they do :
Code: [Select]
_FAS(0x7000 | (112 & 0x0FFF))
This translate to
Code: [Select]
// FAS
#pragma config AWRP = OFF               // Auxiliary Segment Write-protect bit (Aux Flash may be written)
#pragma config APL = OFF                // Auxiliary Segment Code-protect bit (Aux Flash Code protect is disabled)
#pragma config APLK = OFF               // Auxiliary Segment Key bits (Aux Flash Write Protection and Code Protection is Disabled)
Where it is missing the software version. Can anyone advise me a solution / docs ...
Thanks a lot.
 

Online JPortici

  • Super Contributor
  • ***
  • Posts: 3509
  • Country: it
Re: Microchip migration from config bits to pragma config bits
« Reply #1 on: October 12, 2022, 02:54:31 pm »
Which Part?
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6166
  • Country: es
Re: Microchip migration from config bits to pragma config bits
« Reply #2 on: October 12, 2022, 04:40:45 pm »
If this is a commercial product bringing revenue, just buy the real stuff.

- For DIY and non-profit -

Isn't your patch working? Try xclm fixer: this, mirror (Password included in the ZIP comment), and just use v1.25, you'll save a heck of a work.
Works with most versions. FYI, tested working with xc8 v1.x-v2.40, xc16 v1.25-v2.00, so I expect it to work with most compilers up to date.
Edit: It seems MplabX v6.00 is causing some issues, complaining about wrong checksums when building, not happening with v5.50, so stay with that version or try yourself.

Please don't insult or blame me for it (hack tool exe blah blah), download it at your own responsability.
(Got it at Sonsrivri forum ages ago)
« Last Edit: October 31, 2022, 01:34:54 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Online JPortici

  • Super Contributor
  • ***
  • Posts: 3509
  • Country: it
Re: Microchip migration from config bits to pragma config bits
« Reply #3 on: October 12, 2022, 06:34:24 pm »
On XC8 too? got to try it just for kicks

Anyway, in case the OP ever comes back with the crucial information that's missing...
Compiler manual, search for "configuration" in the index and a chapter called "configuration bit access" (or a simillar name) will be found.
I don't have the compiler manual for 1.26 at hand but for 1.70 it says

Quote
The directive format options are:
Code: [Select]
#pragma config setting = state|value
#pragma config register = value

so (tested in the only device i could think of that has the AUX memory)
Code: [Select]
#pragma config UID0 = 8_bit_valuewill set UID0.
It is also accessible from the configuration window. On the bottom left click on the "Memory" list menu. Change from configuration bits to "User ID Memory".
Or you could find the definition on xc16_path/docs/config_index.html

but i can't find a way to set FAS as a whole. It surprises me that it worked anyway as the unimplemented bits should be set at a specific value
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6166
  • Country: es
Re: Microchip migration from config bits to pragma config bits
« Reply #4 on: October 12, 2022, 10:44:09 pm »
Yeah, this patcher works with all. Perhabs with XC32 too, haven't tried.
I've used that same patcher for the last...8 years or so lol.
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Online JPortici

  • Super Contributor
  • ***
  • Posts: 3509
  • Country: it
Re: Microchip migration from config bits to pragma config bits
« Reply #5 on: October 13, 2022, 05:20:06 am »
Oh, i never went beyond trying the specs.txt...
Before making commercial products i always thought i NEEDED all the optimization. In truth, good enough is good enough, i prefer being able to debug, and still i most parts run way lower than the maximum frequency allowed
 

Offline matbTopic starter

  • Regular Contributor
  • *
  • Posts: 68
  • Country: fr
Re: Microchip migration from config bits to pragma config bits
« Reply #6 on: October 13, 2022, 05:58:40 am »
Wow thanks everyone.
Maybe I wasn't clear enought I want to pass the 112 information using _FAS. This part works but now I'm moving to xc16 v1.26 to be able to use specs.txt file patch.
Just on xc16 not interested in xc8 and xc32 for the moment.
The µC is dsPIC33EP256MU810

« Last Edit: October 13, 2022, 06:19:45 am by matb »
 

Online JPortici

  • Super Contributor
  • ***
  • Posts: 3509
  • Country: it
Re: Microchip migration from config bits to pragma config bits
« Reply #7 on: October 13, 2022, 07:19:33 am »
But the values don't make sense.
What does 0x7000 means?
What does 112 means?
in any case it's writing to unimplemented bits of the configuration word FAS, they should always read back zero, and the higher byte of the configuration word should be unimplemented, always read back as zero

112 could mean something if it's the firmware version and it's written in UID0
by the way 112 is 0x70, if that means something (you would be writing 0x7070)
 

Offline matbTopic starter

  • Regular Contributor
  • *
  • Posts: 68
  • Country: fr
Re: Microchip migration from config bits to pragma config bits
« Reply #8 on: October 13, 2022, 07:36:43 am »
In p33EP256MU810.h we find
Code: [Select]
/* Register FAS (0xf80010)                               */

extern __attribute__((space(prog))) unsigned int _FAS;
#define _FAS(x) __attribute__((section("__FAS.sec"),space(prog))) unsigned int _FAS = (x);

/*
** Only one invocation of FAS should appear in a project,
** at the top of a C source file (outside of any function).
**
** The following constants can be used to set FAS.
** Multiple options may be combined, as shown:
**
** _FAS( OPT1_ON & OPT2_OFF & OPT3_PLL )
**
**   Auxiliary Segment Write-protect bit:
**     AWRP_ON              Aux Flash is write protected
**     AWRP_OFF             Aux Flash may be written
**
**   Auxiliary Segment Code-protect bit:
**     APL_ON               Aux Flash Code protect is enabled
**     APL_OFF              Aux Flash Code protect is disabled
**
**   Auxiliary Segment Key bits:
**     APLK_OFF             Aux Flash Write Protection and Code Protection is Disabled
**     APLK_ON              Aux Flash Write Protection or Code Protection is Enabled
**
*/

#define AWRP_ON              0xFFFE
#define AWRP_OFF             0xFFFF

#define APL_ON               0xFFFD
#define APL_OFF              0xFFFF

#define APLK_OFF             0xFFCF
#define APLK_ON              0xFFFF
and then there is a bootloader define condition
if the bootloader is not there (for devs) we set
Code: [Select]
//_FAS(APLK_OFF & APL_OFF & AWRP_OFF) /* Auxiliary program memory is not code-protected; Auxiliary program memory is not write-protected */ else we set
Code: [Select]
_FAS(0x7000|(112 & 0x0FFF)); and during bootup bootloader writes the normal values (ie _FAS(APLK_OFF & APL_OFF & AWRP_OFF) ) Software version is 1.12, 0x7000 is another software version.
I guess the bootloader reads these values and determines if there is an app and what soft it is.

To be 100% clear there are 2 values transfered from app to bootloader, software version and firmware version.

Software version is written in _FAS and firmware version is written in _FUID0.
Code: [Select]
_FUID0(((0&0x0F)<<8)|(104&0xFF)); Firmware version is 1.04

« Last Edit: October 13, 2022, 07:53:25 am by matb »
 

Offline matbTopic starter

  • Regular Contributor
  • *
  • Posts: 68
  • Country: fr
Re: Microchip migration from config bits to pragma config bits
« Reply #9 on: October 18, 2022, 07:27:32 am »
Nobody has got any idea ?
I guess this is so not standard that it wouldn't work with another compiler version.
The problem will be that I will have to change the bootloader and all associated softwares to reprogram the device.
Maybe I should contact Microchip about that, what do you think ? Useless ?
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6166
  • Country: es
Re: Microchip migration from config bits to pragma config bits
« Reply #10 on: October 18, 2022, 09:04:32 am »
Why are you still fighting it, when you could just compile with zero effort using patched v1.25 and carry on?  :-//
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline matbTopic starter

  • Regular Contributor
  • *
  • Posts: 68
  • Country: fr
Re: Microchip migration from config bits to pragma config bits
« Reply #11 on: October 18, 2022, 09:36:46 am »
What's the password of your files ?
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6166
  • Country: es
Re: Microchip migration from config bits to pragma config bits
« Reply #12 on: October 18, 2022, 09:46:54 am »
Edit: The pqssword is now in the zip comments (Download again from new l1nks)
« Last Edit: October 18, 2022, 09:54:15 am by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline matbTopic starter

  • Regular Contributor
  • *
  • Posts: 68
  • Country: fr
Re: Microchip migration from config bits to pragma config bits
« Reply #13 on: October 18, 2022, 11:27:18 am »
Thanks I'm an idiot haha. I will try this patch and let you know.
 

Offline matbTopic starter

  • Regular Contributor
  • *
  • Posts: 68
  • Country: fr
Re: Microchip migration from config bits to pragma config bits
« Reply #14 on: October 18, 2022, 11:39:43 am »
[Edit] Ok it works well thanks a lot for that
« Last Edit: October 18, 2022, 11:58:44 am by matb »
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6166
  • Country: es
Re: Microchip migration from config bits to pragma config bits
« Reply #15 on: October 18, 2022, 03:00:20 pm »
Enjoy the virus patch :-+
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf