clang: cast to 'GPIO_TypeDef *' from smaller integer type 'unsigned int' Topic is solved

Use this forum for requesting small changes in ChibiOS. Large changes should be discussed in the development forum. This forum is NOT for support.
Post Reply
User avatar
wurstnase
Posts: 121
Joined: Tue Oct 17, 2017 2:24 pm
Has thanked: 43 times
Been thanked: 30 times

clang: cast to 'GPIO_TypeDef *' from smaller integer type 'unsigned int'

Post by wurstnase »

Hi,

I've got ctags with my vim working. But now I get an error:

Code: Select all

cast to 'GPIO_TypeDef *' from smaller integer type 'unsigned int'


In hall_pal_lld.h (in my case for STM32F103) I found

Code: Select all

 /**
  * @brief   Decodes a port identifier from a line identifier.
  */
 #define PAL_PORT(line)                                                      \
   ((GPIO_TypeDef *)(((uint32_t)(line)) & 0xFFFFFFF0U))


a simple

Code: Select all

 #define PAL_PORT(line)                                                      \
   ((GPIO_TypeDef *)((size_t)((uint32_t)(line)) & 0xFFFFFFF0U))

will hide this.

Would this be the right way?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: clang: cast to 'GPIO_TypeDef *' from smaller integer type 'unsigned int'

Post by Giovanni »

I don't see problems with the original code, probably you are just hiding some other problem there.

Giovanni
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: clang: cast to 'GPIO_TypeDef *' from smaller integer type 'unsigned int'

Post by steved »

Should it be (GPIO_TypeDef) rather than (GPIO_TypeDef *)?
User avatar
wurstnase
Posts: 121
Joined: Tue Oct 17, 2017 2:24 pm
Has thanked: 43 times
Been thanked: 30 times

Re: clang: cast to 'GPIO_TypeDef *' from smaller integer type 'unsigned int'

Post by wurstnase »

It's simple a palSetLine where this happened.

Just have an idea. Probably clang uses the stdint from my OS instead of the arm cross compiler.

I will check it later.

Btw.: It's not a problem while compiling. Just ctags/clang showing me an error.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: clang: cast to 'GPIO_TypeDef *' from smaller integer type 'unsigned int'

Post by Giovanni »

It is like it is assuming 64 bits pointers, size_t would be 64 bits too.

Giovanni
User avatar
wurstnase
Posts: 121
Joined: Tue Oct 17, 2017 2:24 pm
Has thanked: 43 times
Been thanked: 30 times

Re: clang: cast to 'GPIO_TypeDef *' from smaller integer type 'unsigned int'

Post by wurstnase »

Yes, Right. That's my guess also (stdint from 64bit OS). I will check it tomorrow.


Ah no. Thanks. Pointer related. Not stdint...
User avatar
wurstnase
Posts: 121
Joined: Tue Oct 17, 2017 2:24 pm
Has thanked: 43 times
Been thanked: 30 times

Re: clang: cast to 'GPIO_TypeDef *' from smaller integer type 'unsigned int'

Post by wurstnase »

Well...
After some hours of searching.

Code: Select all

UINTPTR_MAX == UINT64_MAX

I don't have currently an idea how to tell clang that I have 32bit pointer.

As a sidenote: For now I replaced uint32_t with uintptr_t.
User avatar
wurstnase
Posts: 121
Joined: Tue Oct 17, 2017 2:24 pm
Has thanked: 43 times
Been thanked: 30 times

Re: clang: cast to 'GPIO_TypeDef *' from smaller integer type 'unsigned int'

Post by wurstnase »

Finally. The clang needs an extra flag.

Code: Select all

-target arm-none-eabi
User avatar
tfAteba
Posts: 551
Joined: Fri Oct 16, 2015 11:03 pm
Has thanked: 91 times
Been thanked: 50 times

Re: clang: cast to 'GPIO_TypeDef *' from smaller integer type 'unsigned int'

Post by tfAteba »

Hello All,

Nice topic, well investigated, thanks for sharing that with us :) .
User avatar
wurstnase
Posts: 121
Joined: Tue Oct 17, 2017 2:24 pm
Has thanked: 43 times
Been thanked: 30 times

Re: clang: cast to 'GPIO_TypeDef *' from smaller integer type 'unsigned int'

Post by wurstnase »

I'm using you-complete-me with the YCM-Generator plugin for vim.
I modified the YCM-Generator to be able to use the target flag. https://github.com/Wurstnase/YCM-Generator/tree/develop
In the makefile I add a YCMG-flag for generating the ycm xml file.

Makefile:

Code: Select all

    ifeq($(YCMG), 1)
        CFLAGS += -target arm-none-eabi
    endif

and then start the generator in vim with:
YCMGeneratConfig -M=YCMG=1 -f
Post Reply