Author Topic: SDCC - error 129: pointer types incompatible  (Read 4602 times)

0 Members and 1 Guest are viewing this topic.

Offline PKTKSTopic starter

  • Super Contributor
  • ***
  • Posts: 1766
  • Country: br
SDCC - error 129: pointer types incompatible
« on: November 04, 2021, 04:42:06 pm »
I am having a hard time trying to figure why SDCC
is clashing on this struct

Code: [Select]
const uc_p ccmrx[NUM_TIMERS]={
#ifdef NEED_TIMER_11_12
TIM1->CCMR1, /* for TIMER11 */
TIM1->CCMR2, /* for TIMER12 */
#endif
TIM1->CCMR3, /* for TIMER13 */               <-- at this line and all below
TIM1->CCMR4, /* for TIMER14 */
TIM2->CCMR1, /* for TIMER21 */
TIM2->CCMR2, /* for TIMER22 */
#ifdef NEED_TIMER_23
TIM2->CCMR3, /* for TIMER23 */
#endif
#ifdef NEED_TIMER_31_32
TIM3->CCMR1, /* for TIMER31 */
TIM3->CCMR2 /* for TIMER32 */
#endif
};

### Defined like
typedef 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 welcome

If that is an SDCC  BUG ... as well
Paul
 

Online Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6232
  • Country: fi
    • My home page and email address
Re: SDCC - error 129: pointer types incompatible
« Reply #1 on: November 05, 2021, 12:20:14 pm »
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: [Select]
__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[0])
 
The following users thanked this post: PKTKS

Offline PKTKSTopic starter

  • Super Contributor
  • ***
  • Posts: 1766
  • Country: br
Re: SDCC - error 129: pointer types incompatible
« Reply #2 on: November 05, 2021, 12:39:38 pm »
Thanks for your attention.

This code comes from standard ST Standard Peripheral Library SPL
and that is the original form.

I tried to do just that in the very first place.. failed - same error
then tried to cast the array items with uint8_t

then tried another solution I found on the net in which same error is present
Code: [Select]
struct _s { unsigned char STK[128]; };
static struct _s s;
void *v = (struct _s *)&s + 1;

The above hack came from folks which found such weird error

Tried 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 the struct TIM1_struct should be a valid clause
Nevertheless the compiler is unable even to use &TIM_struct

Same error appears
This code is not mine.

This is a STM8 core port to SDCC - using STM8F103F3 compiler options

here the flatten compiler command
Code: [Select]
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/include
stm8/0.5.0/cores/sduino/wiring_digital.c-1.c
-o
build_249910/core/wiring_digital.c-1.c.o



In theory if not a bug itself or no workaround available to recognize the struct addr
it 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
« Last Edit: November 05, 2021, 12:45:09 pm by PKTKS »
 

Online Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6232
  • Country: fi
    • My home page and email address
Re: SDCC - error 129: pointer types incompatible
« Reply #3 on: November 05, 2021, 01:48:05 pm »
So, this is the STM8 core for Arduino?

The structures are defined in system/Drivers/STM8Sxx_StdPeriph_Driver/inc/stm8s.h.  TIM1 type is struct TIM1_struct or TIM1_Typedef, but TIM1 is actually a preprocessor macro, ((TIM1_TypeDef *) TIM1_BaseAddress).

So, knowing this, the following should work for you:
Code: [Select]
__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 is
Code: [Select]
typedef unsigned char uint8_t;
#define  __IO  volatile

typedef 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[0])
which is a self-contained version using system/Drivers/STM8Sxx_StdPeriph_Driver/inc/stm8s.h with four timers initialized in the array, and yields essentially the following .asm:
Code: [Select]
      .globl _ccmrx
      .area CODE
_ccmrx:
      .dw 0x5258
      .dw 0x5259
      .dw 0x5307
      .dw 0x5308
that matches my expectations for the contents of the _ccmrx array.
 
The following users thanked this post: PKTKS

Offline PKTKSTopic starter

  • Super Contributor
  • ***
  • Posts: 1766
  • Country: br
Re: SDCC - error 129: pointer types incompatible
« Reply #4 on: November 05, 2021, 02:03:43 pm »
Thanks again...

Yes core ported to STM8 for the IDE
At some point I tried that casting wo the volatile...
Tried again with volatile...

Same error
Code: [Select]

sduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-1.c:10: error 129: pointer types incompatible
sduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-1.c:11: error 129: pointer types incompatible
sduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-1.c:12: error 129: pointer types incompatible
sduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-1.c:13: error 129: pointer types incompatible
sduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-1.c:15: error 129: pointer types incompatible
sduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-2.c:14: error 129: pointer types incompatible
sduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-2.c:15: error 129: pointer types incompatible
sduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-2.c:16: error 129: pointer types incompatible
sduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-2.c:17: error 129: pointer types incompatible
sduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-2.c:19: error 129: pointer types incompatible
sduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-1.c:10: error 129: pointer types incompatible
sduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-1.c:11: error 129: pointer types incompatible
sduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-1.c:12: error 129: pointer types incompatible
sduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-1.c:13: error 129: pointer types incompatible
sduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-1.c:15: error 129: pointer types incompatible
sduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-2.c:14: error 129: pointer types incompatible
sduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-2.c:15: error 129: pointer types incompatible
sduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-2.c:16: error 129: pointer types incompatible
sduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-2.c:17: error 129: pointer types incompatible
sduino/hardware/stm8/0.5.0/cores/sduino/wiring_digital.c-2.c:19: error 129: pointer types incompatible


What version of SDCC and option set  have you tried to produce the ASM ?
I can easily change it.

Paul
 

Offline PKTKSTopic starter

  • Super Contributor
  • ***
  • Posts: 1766
  • Country: br
Re: SDCC - error 129: pointer types incompatible
« Reply #5 on: November 05, 2021, 02:18:46 pm »
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: [Select]
# BUGGY version was being used..

>./sdcc --version
SDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8
3.4.0 #8981 (Apr  5 2014) (Linux)

Switched to native 3.6.0 - matched against my own libset
Code: [Select]
>sdcc --version
SDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8
3.6.0 #9615 (Linux)

Compiled both files one modified the other original just fine

Code: [Select]
;--------------------------------------------------------
; 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
 

Online Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6232
  • Country: fi
    • My home page and email address
Re: SDCC - error 129: pointer types incompatible
« Reply #6 on: November 05, 2021, 02:39:55 pm »
All versions previous to 3.6.0 are producing that error.
I've got 3.5.0 #9253 (Apr  3 2018) (Linux), and used sdcc -mstm8 to compile the self-contained test.

IN fact the original code now compiles fine **WITH** and **WITHOUT** the castings.
A 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.
 
The following users thanked this post: PKTKS

Offline PKTKSTopic starter

  • Super Contributor
  • ***
  • Posts: 1766
  • Country: br
Re: SDCC - error 129: pointer types incompatible
« Reply #7 on: November 05, 2021, 03:56:28 pm »
All versions previous to 3.6.0 are producing that error.
I've got 3.5.0 #9253 (Apr  3 2018) (Linux), and used sdcc -mstm8 to compile the self-contained test.
(.)

Just 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: [Select]
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 bugs  :-+

Paul
« Last Edit: November 07, 2021, 11:04:05 am by PKTKS »
 

Offline PKTKSTopic starter

  • Super Contributor
  • ***
  • Posts: 1766
  • Country: br
Re: SDCC - error 129: pointer types incompatible
« Reply #8 on: November 05, 2021, 04:50:16 pm »

BTW thanks again..

You led me in the proper direction  :popcorn:

Paul
 

Offline spth

  • Regular Contributor
  • *
  • Posts: 163
  • Country: de
Re: SDCC - error 129: pointer types incompatible
« Reply #9 on: December 01, 2021, 03:22:15 pm »
Get yourself something at least 3.6.0 ...
that 3.4.0 is pure garbage..


4.1.0 hopefully without new bugs  :-+

Paul

From 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.
 

Offline PKTKSTopic starter

  • Super Contributor
  • ***
  • Posts: 1766
  • Country: br
Re: SDCC - error 129: pointer types incompatible
« Reply #10 on: December 06, 2021, 10:38:44 am »
Get yourself something at least 3.6.0 ...
that 3.4.0 is pure garbage..


4.1.0 hopefully without new bugs  :-+

Paul

From 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.

I 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
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf