SDCC - error 129: pointer types incompatible  - Page 1
Forum section: electronics / general

author: PKTKS
author_rank: Super Contributor
timestamp: November 04, 2021, 04:42:06 pm
content: I am having a hard time trying to figure why SDCCis clashing on this structCode:const uc_p ccmrx={#ifdef NEED_TIMER_11_12TIM1->CCMR1,/* for TIMER11 */TIM1->CCMR2,/* for TIMER12 */#endifTIM1->CCMR3,/* for TIMER13 */ <-- at this line and all belowTIM1->CCMR4,/* for TIMER14 */TIM2->CCMR1,/* for TIMER21 */TIM2->CCMR2,/* for TIMER22 */#ifdef NEED_TIMER_23TIM2->CCMR3,/* for TIMER23 */#endif#ifdef NEED_TIMER_31_32TIM3->CCMR1,/* for TIMER31 */TIM3->CCMR2/* for TIMER32 */#endif};### Defined liketypedef unsigned char *uc_p;typedef struct TIM1_struct{__IO uint8_t CCMR1; /*!< CC mode register 1 */__IO uint8_t CCMR2; /*!< CC mode register 2 */__IO uint8_t CCMR3; /*!< CC mode register 3 */__IO uint8_t CCMR4; /*!< CC mode register 4 */Tried a lot of alternatives but nothing actually works.Any clue welcomeIf that is an SDCC BUG ... as wellPaul

author: Nominal Animal
author_rank: Super Contributor
timestamp: November 05, 2021, 12:20:14 pm
content: You're trying to initialize pointers to const from 8-bit values, and you don't notice because you're using a typedef to a pointer.You want an immutable (const) array of pointers to (non-const) 8-bit __IO, i.e.Code:__IO uint8_t *const ccmrx[] = {#ifdef NEED_TIMER_11_12&(TIM1->CCMR1),&(TIM1->CCMR2),#endif&(TIM1->CCMR3),&(TIM1->CCMR4),&(TIM2->CCMR1),&(TIM2->CCMR2),#ifdef NEED_TIMER_23&(TIM2->CCMR3),#endif#ifdef NEED_TIMER_31_32&(TIM3->CCMR1),&(TIM3->CCMR2),#endif};#define NUM_TIMERS (sizeof ccmrx / sizeof ccmrx)

author: PKTKS
author_rank: Super Contributor
timestamp: November 05, 2021, 12:39:38 pm
content: Thanks for your attention.This code comes from standardST Standard Peripheral Library SPLand that is the original form.I tried to do just that in the very first place.. failed - same errorthen tried to cast the array items with uint8_tthen tried another solution I found on the net in which same error is presentCode:struct _s { unsigned char STK; };static struct _s s;void *v = (struct _s *)&s + 1;The above hack came from folks which found such weird errorTried to redefine the struct and use (struct TIM1_struct *)but it gets even worst.. all the casts I tried to dereference the array item failed..Rather curious because thestruct TIM1_structshould be a valid clauseNevertheless the compiler is unable even to use&TIM_structSame error appearsThis code is not mine.This is a STM8 core port to SDCC - using STM8F103F3 compiler optionshere the flatten compiler commandCode:sdcc/build.11242/bin/sdcc../hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-1.c../build_249910/core/wiring_digital.c-1.c.o-MMD-c-Ddouble=float-DUSE_STDINT-D__PROG_TYPES_COMPAT__--less-pedantic-mstm8-DSTM8S103-DF_CPU=16000000L-DARDUINO=10816-DARDUINO_STM8S_BLUE-DARDUINO_ARCH_STM8-I.arduino15/packages/sduino/hardware/stm8/0.5.0/cores/sduino-I.arduino15/packages/sduino/hardware/stm8/0.5.0/variants/standard-I.arduino15/packages/sduino/hardware/stm8/0.5.0/STM8S_StdPeriph_Driver/inc-Isdcc/build.11242/share/sdcc/includestm8/0.5.0/cores/sduino/wiring_digital.c-1.c-obuild_249910/core/wiring_digital.c-1.c.oIn theory if not a bug itself or no workaround available to recognize the struct addrit can not compile that code...Some other post I found may lead to a workaround but I could not do that so far..e.g. I could find a way to write the hack properly..Paul

author: Nominal Animal
author_rank: Super Contributor
timestamp: November 05, 2021, 01:48:05 pm
content: So, this is theSTM8 core for Arduino?The structures are defined insystem/Drivers/STM8Sxx_StdPeriph_Driver/inc/stm8s.h. TIM1 type isstruct TIM1_structorTIM1_Typedef, butTIM1is actually a preprocessor macro,((TIM1_TypeDef *) TIM1_BaseAddress).So, knowing this, the following should work for you:Code:__IO uint8_t *const ccmrx[] = {#ifdef NEED_TIMER_11_12(__IO uint8_t *)&(TIM1->CCMR1),(__IO uint8_t *)&(TIM1->CCMR2),#endif(__IO uint8_t *)&(TIM1->CCMR3),(__IO uint8_t *)&(TIM1->CCMR4),(__IO uint8_t *)&(TIM2->CCMR1),(__IO uint8_t *)&(TIM2->CCMR2),#ifdef NEED_TIMER_23(__IO uint8_t *)&(TIM2->CCMR3),#endif#ifdef NEED_TIMER_31_32(__IO uint8_t *)&(TIM3->CCMR1),(__IO uint8_t *)&(TIM3->CCMR2),#endif};The test I used to verify the above should work isCode:typedef unsigned char uint8_t;#define __IO volatiletypedef struct TIM1_struct{__IO uint8_t CR1; /*!< control register 1 */__IO uint8_t CR2; /*!< control register 2 */__IO uint8_t SMCR; /*!< Synchro mode control register */__IO uint8_t ETR; /*!< external trigger register */__IO uint8_t IER; /*!< interrupt enable register*/__IO uint8_t SR1; /*!< status register 1 */__IO uint8_t SR2; /*!< status register 2 */__IO uint8_t EGR; /*!< event generation register */__IO uint8_t CCMR1; /*!< CC mode register 1 */__IO uint8_t CCMR2; /*!< CC mode register 2 */__IO uint8_t CCMR3; /*!< CC mode register 3 */__IO uint8_t CCMR4; /*!< CC mode register 4 */__IO uint8_t CCER1; /*!< CC enable register 1 */__IO uint8_t CCER2; /*!< CC enable register 2 */__IO uint8_t CNTRH; /*!< counter high */__IO uint8_t CNTRL; /*!< counter low */__IO uint8_t PSCRH; /*!< prescaler high */__IO uint8_t PSCRL; /*!< prescaler low */__IO uint8_t ARRH; /*!< auto-reload register high */__IO uint8_t ARRL; /*!< auto-reload register low */__IO uint8_t RCR; /*!< Repetition Counter register */__IO uint8_t CCR1H; /*!< capture/compare register 1 high */__IO uint8_t CCR1L; /*!< capture/compare register 1 low */__IO uint8_t CCR2H; /*!< capture/compare register 2 high */__IO uint8_t CCR2L; /*!< capture/compare register 2 low */__IO uint8_t CCR3H; /*!< capture/compare register 3 high */__IO uint8_t CCR3L; /*!< capture/compare register 3 low */__IO uint8_t CCR4H; /*!< capture/compare register 3 high */__IO uint8_t CCR4L; /*!< capture/compare register 3 low */__IO uint8_t BKR; /*!< Break Register */__IO uint8_t DTR; /*!< dead-time register */__IO uint8_t OISR; /*!< Output idle register */}TIM1_TypeDef;typedef struct TIM2_struct{__IO uint8_t CR1; /*!< control register 1 */uint8_t RESERVED1; /*!< Reserved register */uint8_t RESERVED2; /*!< Reserved register */__IO uint8_t IER; /*!< interrupt enable register */__IO uint8_t SR1; /*!< status register 1 */__IO uint8_t SR2; /*!< status register 2 */__IO uint8_t EGR; /*!< event generation register */__IO uint8_t CCMR1; /*!< CC mode register 1 */__IO uint8_t CCMR2; /*!< CC mode register 2 */__IO uint8_t CCMR3; /*!< CC mode register 3 */__IO uint8_t CCER1; /*!< CC enable register 1 */__IO uint8_t CCER2; /*!< CC enable register 2 */__IO uint8_t CNTRH; /*!< counter high */__IO uint8_t CNTRL; /*!< counter low */__IO uint8_t PSCR; /*!< prescaler register */__IO uint8_t ARRH; /*!< auto-reload register high */__IO uint8_t ARRL; /*!< auto-reload register low */__IO uint8_t CCR1H; /*!< capture/compare register 1 high */__IO uint8_t CCR1L; /*!< capture/compare register 1 low */__IO uint8_t CCR2H; /*!< capture/compare register 2 high */__IO uint8_t CCR2L; /*!< capture/compare register 2 low */__IO uint8_t CCR3H; /*!< capture/compare register 3 high */__IO uint8_t CCR3L; /*!< capture/compare register 3 low */}TIM2_TypeDef;#define TIM1_BaseAddress 0x5250#define TIM2_BaseAddress 0x5300#define TIM1 ((TIM1_TypeDef *) TIM1_BaseAddress)#define TIM2 ((TIM2_TypeDef *) TIM2_BaseAddress)__IO uint8_t *const ccmrx[] = {(__IO uint8_t *)&(TIM1->CCMR1),(__IO uint8_t *)&(TIM1->CCMR2),(__IO uint8_t *)&(TIM2->CCMR1),(__IO uint8_t *)&(TIM2->CCMR2),};#define NUM_TIMERS (sizeof ccmrx / sizeof ccmrx)which is a self-contained version usingsystem/Drivers/STM8Sxx_StdPeriph_Driver/inc/stm8s.hwith four timers initialized in the array, and yields essentially the following .asm:Code:.globl _ccmrx.area CODE_ccmrx:.dw 0x5258.dw 0x5259.dw 0x5307.dw 0x5308that matches my expectations for the contents of the _ccmrx array.

author: PKTKS
author_rank: Super Contributor
timestamp: November 05, 2021, 02:03:43 pm
content: Thanks again...Yes core ported to STM8 for the IDEAt some point I tried that casting wo the volatile...Tried again with volatile...Same errorCode:sduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-1.c:10: error 129: pointer types incompatiblesduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-1.c:11: error 129: pointer types incompatiblesduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-1.c:12: error 129: pointer types incompatiblesduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-1.c:13: error 129: pointer types incompatiblesduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-1.c:15: error 129: pointer types incompatiblesduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-2.c:14: error 129: pointer types incompatiblesduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-2.c:15: error 129: pointer types incompatiblesduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-2.c:16: error 129: pointer types incompatiblesduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-2.c:17: error 129: pointer types incompatiblesduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-2.c:19: error 129: pointer types incompatiblesduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-1.c:10: error 129: pointer types incompatiblesduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-1.c:11: error 129: pointer types incompatiblesduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-1.c:12: error 129: pointer types incompatiblesduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-1.c:13: error 129: pointer types incompatiblesduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-1.c:15: error 129: pointer types incompatiblesduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-2.c:14: error 129: pointer types incompatiblesduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-2.c:15: error 129: pointer types incompatiblesduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-2.c:16: error 129: pointer types incompatiblesduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-2.c:17: error 129: pointer types incompatiblesduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-2.c:19: error 129: pointer types incompatibleWhat version of SDCC and option set have you tried to produce the ASM ?I can easily change it.Paul

author: PKTKS
author_rank: Super Contributor
timestamp: November 05, 2021, 02:18:46 pm
content: Thanks again NOMINAL...Switched to other versions and it seems that is a COMPILER BUG.All versions previous to 3.6.0 are producing that error.IN fact the original code now compiles fine **WITH** and **WITHOUT** the castings.Code:# BUGGY version was being used..>./sdcc --versionSDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm83.4.0 #8981 (Apr 5 2014) (Linux)Switched to native 3.6.0 - matched against my own libsetCode:>sdcc --versionSDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm83.6.0 #9615 (Linux)Compiled both files one modified the other original just fineCode:;--------------------------------------------------------; File Created by SDCC : free open source ANSI-C Compiler; Version 3.6.0 #9615 (Linux);--------------------------------------------------------.module wiring_digital_c_1.optsdcc -mstm8;--------------------------------------------------------; Public variables in this module;--------------------------------------------------------.globl _ccmrx.globl _makeWord.globl _Serial_println_fd.globl _Serial_println_f.globl _Serial_println_ub.globl _Serial_println_ib.globl _Serial_println_u.globl _Serial_println_i.globl _Serial_println_sn.globl _Serial_println_s.globl _Serial_println.globl _Serial_print_fd.globl _Serial_print_f.globl _Serial_print_ub.globl _Serial_print_ib.globl _Serial_print_u.globl _Serial_print_i.globl _Serial_print_sn.globl _Serial_print_s.globl _Serial_print_c.globl _HardwareSerial_write.globl _Print_println_f.globl _Print_println_fd.globl _Print_println_ub.globl _Print_println_ib.globl _Print_println_u.globl _Print_println_i.globl _Print_println_sn.globl _Print_println_s.globl _Print_println.globl _Print_print_f.globl _Print_print_fd.globl _Print_print_ub.globl _Print_print_ib.globl _Print_print_u.globl _Print_print_i.globl _Print_print_sn.globl _Print_print_s;--------------------------------------------------------; ram data;--------------------------------------------------------.area DATA;--------------------------------------------------------; ram data;--------------------------------------------------------.area INITIALIZED;--------------------------------------------------------; absolute external ram data;--------------------------------------------------------.area DABS (ABS);--------------------------------------------------------; global & static initialisations;--------------------------------------------------------.area HOME.area GSINIT.area GSFINAL.area GSINIT;--------------------------------------------------------; Home;--------------------------------------------------------.area HOME.area HOME;--------------------------------------------------------; code;--------------------------------------------------------Thanks a lot... just wiped that old left over version ...That is a compiler bug..The code compiles fine in original format...Paul

author: Nominal Animal
author_rank: Super Contributor
timestamp: November 05, 2021, 02:39:55 pm
content: Quote from: PKTKS on November 05, 2021, 02:18:46 pmI've got 3.5.0 #9253 (Apr 3 2018) (Linux), and usedsdcc -mstm8to compile the self-contained test.Quote from: PKTKS on November 05, 2021, 02:18:46 pmA bug does make sense. Casting to a structure type, dereferencing a member of the structure, and obtaining the address of that, is a quirky thing for the AST to handle correctly, and not something typical test cases check. In fact, even in 3.5.0, even adding a completely safe additional cast in the middle,(__IO uint8_t *)(__IO void *)&(TIM1->CCMR1),generates the 129 error, and is an sdcc bug. But the exact form I suggested, does work.

author: PKTKS
author_rank: Super Contributor
timestamp: November 05, 2021, 03:56:28 pm
content: Quote from: Nominal Animal on November 05, 2021, 02:39:55 pmJust got the latest 4.1.0 - compiled absolute fine installed on system wide WITH PIC support.The STM8 core compiled perfectly even the applets are functional.Code:Sketch uses 7903 bytes (96%) of program storage space. Maximum is 8192 bytes.Global variables use 74 bytes (7%) of dynamic memory, leaving 950 bytes for local variables. Maximum is 1024 bytes.Get yourself something at least 3.6.0 ...that 3.4.0 is pure garbage..4.1.0 hopefully without new bugsPaul

author: PKTKS
author_rank: Super Contributor
timestamp: November 05, 2021, 04:50:16 pm
content: BTW thanks again..You led me in the proper directionPaul

author: spth
author_rank: Regular Contributor
timestamp: December 01, 2021, 03:22:15 pm
content: Quote from: PKTKS on November 05, 2021, 03:56:28 pmFrom the SDCC release notes, 3.4.0 was the very first release with stm8 support, So 3.4.0 surely has some bugs in the stm8 port that were found and fixed later.

author: PKTKS
author_rank: Super Contributor
timestamp: December 06, 2021, 10:38:44 am
content: Quote from: spth on December 01, 2021, 03:22:15 pmI have used it sparsely but with non IDE code...so far it worked..But when I decided to put the STM8 CORE to work I found that just impossible...Fortunately recent versions are up to the complete ported CORE..So far I have been able to use it on the IDE fine enough..Still just simple stuff however.. orders of magnitude simpler than using other IDEs.Paul