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.
User avatar
wurstnase
Posts: 69
Joined: Tue Oct 17, 2017 2:24 pm
Has thanked: 27 times
Been thanked: 9 times
Contact:

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

Postby wurstnase » Mon Sep 03, 2018 2:03 pm

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?
\o/ Nico

User avatar
Giovanni
Site Admin
Posts: 11375
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 429 times
Been thanked: 361 times
Contact:

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

Postby Giovanni » Mon Sep 03, 2018 3:53 pm

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

Giovanni

steved
Posts: 558
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 4 times
Been thanked: 61 times

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

Postby steved » Mon Sep 03, 2018 4:42 pm

Should it be (GPIO_TypeDef) rather than (GPIO_TypeDef *)?

User avatar
wurstnase
Posts: 69
Joined: Tue Oct 17, 2017 2:24 pm
Has thanked: 27 times
Been thanked: 9 times
Contact:

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

Postby wurstnase » Mon Sep 03, 2018 5:23 pm

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.
\o/ Nico

User avatar
Giovanni
Site Admin
Posts: 11375
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 429 times
Been thanked: 361 times
Contact:

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

Postby Giovanni » Mon Sep 03, 2018 7:45 pm

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

Giovanni

User avatar
wurstnase
Posts: 69
Joined: Tue Oct 17, 2017 2:24 pm
Has thanked: 27 times
Been thanked: 9 times
Contact:

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

Postby wurstnase » Mon Sep 03, 2018 8:07 pm

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


Ah no. Thanks. Pointer related. Not stdint...
\o/ Nico

User avatar
wurstnase
Posts: 69
Joined: Tue Oct 17, 2017 2:24 pm
Has thanked: 27 times
Been thanked: 9 times
Contact:

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

Postby wurstnase » Tue Sep 04, 2018 3:16 pm

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.
\o/ Nico

User avatar
wurstnase
Posts: 69
Joined: Tue Oct 17, 2017 2:24 pm
Has thanked: 27 times
Been thanked: 9 times
Contact:

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

Postby wurstnase » Tue Sep 04, 2018 5:42 pm

Finally. The clang needs an extra flag.

Code: Select all

-target arm-none-eabi
\o/ Nico

User avatar
tfAteba
Posts: 514
Joined: Fri Oct 16, 2015 11:03 pm
Location: Chartres, France
Has thanked: 76 times
Been thanked: 44 times

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

Postby tfAteba » Thu Oct 11, 2018 10:45 am

Hello All,

Nice topic, well investigated, thanks for sharing that with us :) .
regards,

Theo.

User avatar
wurstnase
Posts: 69
Joined: Tue Oct 17, 2017 2:24 pm
Has thanked: 27 times
Been thanked: 9 times
Contact:

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

Postby wurstnase » Thu Oct 18, 2018 9:45 am

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
\o/ Nico


Return to “Small Change Requests”

Who is online

Users browsing this forum: No registered users and 5 guests