mc6pac / toolchainSDCC

SDCC plug-in for MPLABX
https://sites.google.com/site/rmaalmeida/mplabx-sdcc-toolchain
GNU General Public License v3.0
13 stars 3 forks source link

Config bits for pic16f1826 issues in MPLABX 4.01 using SDCC toolchain 2.0.5 #2

Closed HausofLars closed 7 years ago

HausofLars commented 7 years ago

Greetings, I am using the SDCC-toolchain 2.0.5 in MPLABx 4.01 for PIC16F1826. When I set the memory views in MPLAB X. The following is generated:


// PIC16F1826 Configuration Bit Settings

// 'C' source line config statements

code char at CONFIG1 CONFIG1 = FOSC_INTOSC & WDTE_OFF & PWRTE_OFF & MCLRE_ON & CP_OFF & CPD_OFF & BOREN_ON & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF code char at CONFIG2 CONFIG2 = WRT_OFF & PLLEN_OFF & STVREN_ON & BORV_LO & LVP_OFF


I placed the lines into the beginning of my project and attempted to build to test it out, I get:

sdcc_test1.c:16: syntax error: token -> 'char' ; column 9

I searched for information of the correct way to set the config bits but haven't found the way it is supposed to work correctly.

I have replaced the &'s with ',' and tried variations of __CONFIG. The examples in the help file didn't seem to work. #PRAGMA directives weren't unrecognized as well. Please advise.

test code:


/*

include </usr/local/share/sdcc/include/pic14/pic16regs.h>

// use full path in include as mplabx cannot find .h file. Compiler seems to ignore error.

// PIC16F1826 Configuration Bit Settings // 'C' source line config statements

code char at CONFIG1 CONFIG1 = FOSC_INTOSC & WDTE_OFF & PWRTE_OFF & MCLRE_ON & CP_OFF & CPD_OFF & BOREN_ON & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF code char at CONFIG2 CONFIG2 = WRT_OFF & PLLEN_OFF & STVREN_ON & BORV_LO & LVP_OFF

void main(void) { return; }


On build, I get the following output: make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf make[1]: Entering directory '/home/{user}/MPLABXProjects/sdcc_test1.X' sdcc_test1.c:16: syntax error: token -> 'char' ; column 9 make[2]: [build/default/production/sdcc_test1.o] Error 1 make[1]: [.build-conf] Error 2 make: *** [.build-impl] Error 2 make -f nbproject/Makefile-default.mk dist/default/production/sdcc_test1.X.production.hex make[2]: Entering directory '/home/{user}/MPLABXProjects/sdcc_test1.X' mkdir -p "build/default/production" rm -f build/default/production/sdcc_test1.o "/usr/local/bin/sdcc" --use-non-free -c -mpic14 -p16f1826 sdcc_test1.c -obuild/default/production/sdcc_test1.o nbproject/Makefile-default.mk:102: recipe for target 'build/default/production/sdcc_test1.o' failed make[2]: Leaving directory '/home/{user}/MPLABXProjects/sdcc_test1.X' nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed make[1]: Leaving directory '/home/lars/MPLABXProjects/sdcc_test1.X' nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed

BUILD FAILED (exit value 2, total time: 83ms)


system information: Linux Mint17 x64 $ uname -a Linux {hostname} 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

$ sdcc -v SDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8 3.6.9 #10000 (Linux)

MPLABX information: Product version: MPLAB X IDE v4.01 Java: 1.8.0_141:Java HotShot(TM) 64-Bit Server VM 25.141.b15 Runtime: Java(TM) SE Runtime Environment 1.8.0_141-b15 System: Linux version 3.13.0-24-generic running on AMD64; UTF-8; en_US (mplab)

mc6pac commented 7 years ago

Hi HausofLars.

From The SDCC manual:


4.5.4 Configuration Bits

Configuration bits (also known as fuses) can be configured using ‘code’ and ‘at’ modifiers. Possible options should be ANDed and can be found in your processor header file. Example for PIC16F88:

include //Contains config addresses and options

include //Needed for uint16_t

static __code uint16_t __at (_CONFIG1) configword1 = _INTRC_IO & _CP_ALL & _WDT_OFF & [...];

static __code uint16_t __at (_CONFIG2) configword2 = [...];

Although data type is ignored if the address (__at()) refers to a config word location, using a type large enough for the configuration word (uint16_t in this case) is recommended to prevent changes in the compiler (implicit, early range check and enforcement) from breaking the definition. If your processor header file doesn’t contain config addresses you can declare it manually or use a literal address:

static __code uint16_t __at (0x2007) configword1 = _INTRC_IO & _CP_ALL & _WDT_OFF & [...];


So when you use ”code char at __CONFIG1 CONFIG1 = …” it will not work.

And by the way, the config word is 16bits, it will not fit in a ”char”.

But you can also try the following:

include

__CONFIG(_CONFIG1, _EXTRC_OSC_CLKOUT);

This uses a macro to set config bits. Does the same as you are trying to do.

Take a look at the new_file templates in MPLABX:

Regards,

Patrick (mc6pac)

Fra: HausofLars [mailto:notifications@github.com] Sendt: 4. oktober 2017 07:48 Til: mc6pac/toolchainSDCC toolchainSDCC@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Emne: [mc6pac/toolchainSDCC] Config bits for pic16f1826 issues in MPLABX 4.01 using SDCC toolchain 2.0.5 (#2)

Greetings, I am using the SDCC-toolchain 2.0.5 in MPLABx 4.01 for PIC16F1826. When I set the memory views in MPLAB X. The following is generated:


// PIC16F1826 Configuration Bit Settings

// 'C' source line config statements

code char at CONFIG1 CONFIG1 = FOSC_INTOSC & WDTE_OFF & PWRTE_OFF & MCLRE_ON & CP_OFF & CPD_OFF & BOREN_ON & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF code char at CONFIG2 CONFIG2 = WRT_OFF & PLLEN_OFF & STVREN_ON & BORV_LO & LVP_OFF


I placed the lines into the beginning of my project and attempted to build to test it out, I get:

sdcc_test1.c:16: syntax error: token -> 'char' ; column 9

I searched for information of the correct way to set the config bits but haven't found the way it is supposed to work correctly.

I have replaced the &'s with ',' and tried variations of __CONFIG. The examples in the help file didn't seem to work. #PRAGMA directives weren't unrecognized as well. Please advise.

test code:


/*

include </usr/local/share/sdcc/include/pic14/pic16regs.h>

// use full path in include as mplabx cannot find .h file. Compiler seems to ignore error.

// PIC16F1826 Configuration Bit Settings // 'C' source line config statements

code char at CONFIG1 CONFIG1 = FOSC_INTOSC & WDTE_OFF & PWRTE_OFF & MCLRE_ON & CP_OFF & CPD_OFF & BOREN_ON & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF code char at CONFIG2 CONFIG2 = WRT_OFF & PLLEN_OFF & STVREN_ON & BORV_LO & LVP_OFF

void main(void) { return; }


On build, I get the following output: make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf make[1]: Entering directory '/home/{user}/MPLABXProjects/sdcc_test1.X' sdcc_test1.c:16: syntax error: token -> 'char' ; column 9 make[2]: [build/default/production/sdcc_test1.o] Error 1 make[1]: [.build-conf] Error 2 make: *** [.build-impl] Error 2 make -f nbproject/Makefile-default.mk dist/default/production/sdcc_test1.X.production.hex make[2]: Entering directory '/home/{user}/MPLABXProjects/sdcc_test1.X' mkdir -p "build/default/production" rm -f build/default/production/sdcc_test1.o "/usr/local/bin/sdcc" --use-non-free -c -mpic14 -p16f1826 sdcc_test1.c -obuild/default/production/sdcc_test1.o nbproject/Makefile-default.mk:102: recipe for target 'build/default/production/sdcc_test1.o' failed make[2]: Leaving directory '/home/{user}/MPLABXProjects/sdcc_test1.X' nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed make[1]: Leaving directory '/home/lars/MPLABXProjects/sdcc_test1.X' nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed

BUILD FAILED (exit value 2, total time: 83ms)


system information: Linux Mint17 x64 $ uname -a Linux {hostname} 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

$ sdcc -v SDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8 3.6.9 #10000 (Linux)

MPLABX information: Product version: MPLAB X IDE v4.01 Java: 1.8.0_141:Java HotShot(TM) 64-Bit Server VM 25.141.b15 Runtime: Java(TM) SE Runtime Environment 1.8.0_141-b15Hous

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mc6pac/toolchainSDCC/issues/2 , or mute the thread https://github.com/notifications/unsubscribe-auth/AQLcFB_viP_u5XvZXOTAAzKT-hqWqcSeks5soxwDgaJpZM4PtH6V . https://github.com/notifications/beacon/AQLcFG3vClWKIuCIClfgUuEyaun7R2o9ks5soxwDgaJpZM4PtH6V.gif

HausofLars commented 7 years ago

I have changed the code according to the manual but I still get the syntax error.

I used the (_CONFIG1) and (_CONFIG2) at first but the processor didn't see the address so (0x8007) and (0x8008) were used instead despite the (_CONFIGx)'s were declared in pic16f1826.h :/

The config bits for pic16f1826 use 8007h and 8008h according to the datasheet.


/*

include </usr/local/share/sdcc/non-free/include/pic14/pic16f1826.h>

// use full path in include as mplabx cannot find .h file. Compiler seems to ignore error.

include </usr/local/share/sdcc/include/pic16/stdint.h>

// PIC16F1826 Configuration Bit Settings

// 'C' source line config statements

static code uint16_t at (0x8007) configword1 = _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF static code uint16_t at (0x8007) configword2 = _WRT_OFF & _PLLEN_OFF & _STVREN_ON & _BORV_LO & _LVP_OFF

void main(void) { return; }


Build output:


CLEAN SUCCESSFUL (total time: 60ms) make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf make[1]: Entering directory '/home/lars/MPLABXProjects/sdcc_test1.X' make -f nbproject/Makefile-default.mk dist/default/production/sdcc_test1.X.production.hex make[2]: Entering directory '/home/lars/MPLABXProjects/sdcc_test1.X' mkdir -p "build/default/production" rm -f build/default/production/sdcc_test1.o sdcc_test1.c:19: syntax error: token -> 'static' ; column 6 make[2]: [build/default/production/sdcc_test1.o] Error 1 make[1]: [.build-conf] Error 2 make: *** [.build-impl] Error 2 "/usr/local/bin/sdcc" --use-non-free -c -mpic14 -p16f1826 sdcc_test1.c -obuild/default/production/sdcc_test1.o nbproject/Makefile-default.mk:102: recipe for target 'build/default/production/sdcc_test1.o' failed make[2]: Leaving directory '/home/lars/MPLABXProjects/sdcc_test1.X' nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed make[1]: Leaving directory '/home/lars/MPLABXProjects/sdcc_test1.X' nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed

BUILD FAILED (exit value 2, total time: 71ms)


The IDE on the other hand, issues warnings for the static lines:


Unable to resolve identifier configword1 unexpected token: configword1 Unable to resolve built-in identifier __code


So I change back to #include </usr/local/share/sdcc/include/pic14/pic16regs.h>

The IDE issues another warning: There are unresolved includes inside </usr/local/share/sdcc/include/pic14/pic16regs.h>

When I entered the configs:

__CONFIG(_CONFIG1,_FOSC_INTOSC,_WDTE_OFF,_PWRTE_OFF,_MCLRE_ON,_CP_OFF,_CPD_OFF,_BOREN_ON,_CLKOUTEN_OFF,_IESO_OFF,_FCMEN_OFF); __CONFIG(_CONFIG2,_WRT_OFF,_PLLEN_OFF,_STVREN_ON,_BORV_LO,_LVP_OFF);

The IDE issues warning of - unexpected token: unsigned and the compile fails.

I'm not sure if the unresolved includes are causing this and I've been searching for a while on this but don't seem to turn up any real solution on the matter. Even if I put in it's full path. Not sure if it is a bug or if it is a misconfiguration. If these config bits codes are the correct way, then shouldn't the config bits generator output that instead?

mc6pac commented 7 years ago

Hi, First, these issues have nothing to do with the plugin, they belong to the SDCC compiler forum for support.

Second, when using the __CONFIG() macro, remember to and (&) the options together: __CONFIG(_CONFIG2,_WRT_OFF,_PLLEN_OFF,_STVREN_ON,_BORV_LO,_LVP_OFF); - this is wrong. __CONFIG(_CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_ON & _BORV_LO & _LVP_OFF); - this works.

Third, when doing it directly, you still need to terminate your lines with ; as in: static __code uint16_t __at (0x8007) configword1 = _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF <- semicolon missing at end of line. The compiler even complains about it: sdcc_test1.c:19: syntax error: token -> 'static' ; column 6 - the previous line is not terminated.

Fourth, my error. I missed a const after static in static __code uint16_t __at (0x8007) configword1 = ... I just copy pasted from the manual, without checking. Also inserted a space after __at by mistake. Should be: static const __code uint16_t __at(0x8007) configword1 = ...

But again, all this has noting to do with the plugin, this is general compiler stuff. Please continue to SDCC forum for support. I am btw. not involved in the compiler work,

HausofLars commented 7 years ago

Greetings,

First, these issues have nothing to do with the plugin, they belong to the SDCC compiler forum for >support.

Second, when using the CONFIG() macro, remember to and (&) the options together: CONFIG(_CONFIG2,_WRT_OFF,_PLLEN_OFF,_STVREN_ON,_BORV_LO,_LVP_OFF); - this is >wrong. __CONFIG(_CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_ON & _BORV_LO & _LVP_OFF); >- this works.

You are correct. I had posted the ','s in place of '&' when it didn't work and posted it without the full information. when the '&' conjunctions didn't work. My goof.

A minor oversight. __CONFIG(_CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF); __CONFIG(_CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_ON & _BORV_LO & _LVP_OFF);

These passed without error during compile despite the inline errors that are yielded.

Third, when doing it directly, you still need to terminate your lines with ; as in: static __code uint16_t __at (0x8007) configword1 = _FOSC_INTOSC & _WDTE_OFF & >_PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & >_IESO_OFF & _FCMEN_OFF <- semicolon missing at end of line.

I did after I posted and forgot to update as with the ';' , I omitted the space between __at and ( . I still got a syntax error.

But again, all this has noting to do with the plugin, this is general compiler stuff. Please continue to >SDCC forum for support.

Understood. I wasn't sure were to post these questions. The posts in the Microchip forum led me here. I will go there next. Sorry for the trouble.

mc6pac commented 7 years ago

You are welcome.

And the inline error in the IDE when using the __CONFIG macro, is an error in the macro. It defines the config word as char which is wrong. But the compiler does not care, it does some special handeling and disregards the type. This is an error in the SDCC headerfile.

Hope you got it working.