palWriteLine() Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
steved
Posts: 823
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 135 times

palWriteLine()  Topic is solved

Postby steved » Tue Oct 16, 2018 10:02 pm

On GPIO2 driver (STM32F091) I get a load of errors of the type:

Code: Select all

ioManager.c:52:13: note: in expansion of macro 'palWriteLine'
   case 13 : palWriteLine(LINE_OP14, newValue); break;
             ^~~~~~~~~~~~
../../chibios_18.2.1_DD/os/hal/ports/STM32/LLD/GPIOv2/hal_pal_lld.h:397:23: note: did you mean to use logical not?
   ((port)->BSRR.W = ((~(bits) & (mask)) << (16U + (offset))) |              \
                       ^
../../chibios_18.2.1_DD/os/hal/ports/STM32/LLD/GPIOv2/hal_pal_lld.h:425:42: note: in expansion of macro 'pal_lld_writegroup'
 #define pal_lld_writepad(port, pad, bit) pal_lld_writegroup(port, 1, pad, bit)
                                          ^~~~~~~~~~~~~~~~~~
../../chibios_18.2.1_DD/os/hal/include/hal_pal.h:590:37: note: in expansion of macro 'pal_lld_writepad'
 #define palWritePad(port, pad, bit) pal_lld_writepad(port, pad, bit)
                                     ^~~~~~~~~~~~~~~~
../../chibios_18.2.1_DD/os/hal/include/hal_pal.h:705:33: note: in expansion of macro 'palWritePad'
 #define palWriteLine(line, bit) palWritePad(PAL_PORT(line), PAL_PAD(line), bit)
                                 ^~~~~~~~~~~
ioManager.c:52:13: note: in expansion of macro 'palWriteLine'
   case 13 : palWriteLine(LINE_OP14, newValue); break;
             ^~~~~~~~~~~~
../../chibios_18.2.1_DD/os/hal/ports/STM32/LLD/GPIOv2/hal_pal_lld.h:397:23: warning: '~' on a boolean expression [-Wbool-operation]
   ((port)->BSRR.W = ((~(bits) & (mask)) << (16U + (offset))) |              \
                       ^
../../chibios_18.2.1_DD/os/hal/ports/STM32/LLD/GPIOv2/hal_pal_lld.h:425:42: note: in expansion of macro 'pal_lld_writegroup'
 #define pal_lld_writepad(port, pad, bit) pal_lld_writegroup(port, 1, pad, bit)
                                          ^~~~~~~~~~~~~~~~~~
../../chibios_18.2.1_DD/os/hal/include/hal_pal.h:590:37: note: in expansion of macro 'pal_lld_writepad'
 #define palWritePad(port, pad, bit) pal_lld_writepad(port, pad, bit)
                                     ^~~~~~~~~~~~~~~~
../../chibios_18.2.1_DD/os/hal/include/hal_pal.h:705:33: note: in expansion of macro 'palWritePad'
 #define palWriteLine(line, bit) palWritePad(PAL_PORT(line), PAL_PAD(line), bit)
 

The following typecasting in the macro gets rid of the errors:

Code: Select all

#define pal_lld_writegroup(port, mask, offset, bits)                        \
  ((port)->BSRR.W = ((~(uint16_t)(bits) & (mask)) << (16U + (offset))) |              \
                     (((uint16_t)(bits) & (mask)) << (offset)))

(Line 396 in GPIOv2/hal_pal_lld.h)

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

Re: palWriteLine()

Postby Giovanni » Wed Oct 17, 2018 10:01 am

Maybe the typecast should be done on the expression result, not just one operand.

What is the type of "bits" you are passing to the macro?

Giovanni

steved
Posts: 823
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 135 times

Re: palWriteLine()

Postby steved » Wed Oct 17, 2018 1:27 pm

It's a boolean (type bool).

I'm updating this code to work with GCC7/Chibi 18.2, and changed all that code to use the 'palSetLine()' syntax; previously they were of the form palWritePad(GPIOB, 12, newValue);

N.B. I've not tested yet; so far I've just been eliminating compiler errors and warnings.

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

Re: palWriteLine()

Postby Giovanni » Sat Oct 27, 2018 12:25 pm

Probably it should be something like this:

Code: Select all

#define pal_lld_writegroup(port, mask, offset, bits) {                      \
  uint32_t w = ((~(uint32_t)(bits) & (uint32_t)(mask)) << (16U + (offset))) | \
               ((uint32_t)(bits) & (uint32_t)(mask)) << (offset);           \
  (port)->BSRR.W = w;                                                       \
}


The destination is uint32_t not uint16_t.

There are also other macros that could be made more robust with extra casts, working on it.

Giovanni

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

Re: palWriteLine()

Postby Giovanni » Sat Oct 27, 2018 12:37 pm

I committed a tentative change for GPIOv1, GPIOv2 and GPIOv3 PAL drivers.

Giovanni


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 23 guests