Page 1 of 2
PULL-UP Input
Posted: Mon Sep 19, 2016 2:47 pm
by duracell
Hi to all,
I configured the GPIOB0 pin as input, the code is the following:
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT(0)|PIN_PUPDR_PULLUP(0));
And in an another board I configured GPIOA7 as output.
palSetPadMode(GPIOA, 7, PAL_STM32_MODE_OUTPUT);
The pin A7 have to generate a square wave, and everythings works fine, but when I connect A7 to B0 the sqare wave is not able to go to 0V again.
The wave no longer oscillates between 3 and 0 but it oscillates between 1 and 3. Why? Where I am wrong?
Thanks to all!
Re: PULL-UP Input
Posted: Mon Sep 19, 2016 6:53 pm
by Giovanni
hi,
I don't understand those (0), remove them.
Giovanni
Re: PULL-UP Input
Posted: Mon Sep 19, 2016 6:56 pm
by RoccoMarco
HI,
as Giovanni says bit masks are wrong. If I understand well you have two different boards. In this case remember to refer them to the same ground.
Re: PULL-UP Input
Posted: Tue Sep 20, 2016 9:37 am
by duracell
Hi Giovanni, hi RoccoMarco,
thanks for your reply. I have already connected the grounds.
I agree with you Giovanni that those (0) makes no sense, but if I remove those (0) :
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT | PIN_PUPDR_PULLUP);
The compiler gives me an error.
[spoil]08:52:58 **** Incremental Build of configuration Default for project CAN_Back_Bone ****
make -j4 all
Compiling extlib.c
In file included from ../../chibios161/os/hal/include/pal.h:113:0,
from ../../chibios161/os/hal/include/hal.h:47,
from ./userlib/include/extlib.h:3,
from ./userlib/src/extlib.c:1:
./userlib/src/extlib.c: In function 'gpioconfig':
./userlib/src/extlib.c:101:27: error: 'PIN_MODE_INPUT' undeclared (first use in this function)
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT | PIN_PUPDR_PULLUP);
^
../../chibios161/os/hal/ports/STM32/LLD/GPIOv2/pal_lld.h:528:47: note: in definition of macro 'pal_lld_setgroupmode'
_pal_lld_setgroupmode(port, mask << offset, mode)
^
../../chibios161/os/hal/include/pal.h:527:3: note: in expansion of macro 'palSetGroupMode'
palSetGroupMode(port, PAL_PORT_BIT(pad), 0U, mode)
^
./userlib/src/extlib.c:101:3: note: in expansion of macro 'palSetPadMode'
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT | PIN_PUPDR_PULLUP);
^
./userlib/src/extlib.c:101:27: note: each undeclared identifier is reported only once for each function it appears in
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT | PIN_PUPDR_PULLUP);
^
../../chibios161/os/hal/ports/STM32/LLD/GPIOv2/pal_lld.h:528:47: note: in definition of macro 'pal_lld_setgroupmode'
_pal_lld_setgroupmode(port, mask << offset, mode)
^
../../chibios161/os/hal/include/pal.h:527:3: note: in expansion of macro 'palSetGroupMode'
palSetGroupMode(port, PAL_PORT_BIT(pad), 0U, mode)
^
./userlib/src/extlib.c:101:3: note: in expansion of macro 'palSetPadMode'
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT | PIN_PUPDR_PULLUP);
^
./userlib/src/extlib.c:101:44: error: 'PIN_PUPDR_PULLUP' undeclared (first use in this function)
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT | PIN_PUPDR_PULLUP);
^
../../chibios161/os/hal/ports/STM32/LLD/GPIOv2/pal_lld.h:528:47: note: in definition of macro 'pal_lld_setgroupmode'
_pal_lld_setgroupmode(port, mask << offset, mode)
^
../../chibios161/os/hal/include/pal.h:527:3: note: in expansion of macro 'palSetGroupMode'
palSetGroupMode(port, PAL_PORT_BIT(pad), 0U, mode)
^
./userlib/src/extlib.c:101:3: note: in expansion of macro 'palSetPadMode'
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT | PIN_PUPDR_PULLUP);
^
make: *** [build/obj/extlib.o] Error 1
08:52:59 Build Finished (took 1s.973ms)[/spoil]
I do not understand how to make the PIN 0 as input pin and connect it with the weak pull-up resistor built-in in the MCU.
P.S. the B0 pin is also used by the EXTI peripheral, but i don't think that is a limitation.
Re: PULL-UP Input
Posted: Tue Sep 20, 2016 9:57 am
by RoccoMarco
Indeed you should write,
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT_PULLUP);
Take a look to hal reference manual.
Re: PULL-UP Input
Posted: Tue Sep 20, 2016 10:15 am
by duracell
Hi Marco,
The line code you wrote is not accepted by the compiler. it says it is not defined.
I searched the string "PIN_MODE_INPUT_PULLUP" in my chibistudio project and I have been not able to find its declaration.
I am reading the RM, and I see that the pull-up resistor on B0 is activated simply by setting the register GPIOB_PUPDR=0x00000001, but I would like to use the hal and the macros.
Thank you for your help!
Re: PULL-UP Input
Posted: Tue Sep 20, 2016 11:30 am
by duracell
P.S you said hal reference manual, I understood the RM of the micro.
wow there is a 964 pages HAL manual! I will take a look right now!
Re: PULL-UP Input
Posted: Tue Sep 20, 2016 11:39 am
by RoccoMarco
What version of chibios are you using?
Re: PULL-UP Input
Posted: Tue Sep 20, 2016 12:55 pm
by duracell
If I remember well I am using version 3.0.5, where I can read to be sure?
Re: PULL-UP Input
Posted: Tue Sep 20, 2016 12:59 pm
by RoccoMarco
C:\ChibiStudio\chibios161\os\hal\include\hal.h
Code: Select all
/*===========================================================================*/
/* Driver constants. */
/*===========================================================================*/
/**
* @brief ChibiOS/HAL identification macro.
*/
#define _CHIBIOS_HAL_
/**
* @brief Stable release flag.
*/
#define CH_HAL_STABLE 1
/**
* @name ChibiOS/HAL version identification
* @{
*/
/**
* @brief HAL version string.
*/
#define HAL_VERSION "4.0.6"
/**
* @brief HAL version major number.
*/
#define CH_HAL_MAJOR 4
/**
* @brief HAL version minor number.
*/
#define CH_HAL_MINOR 0
/**
* @brief HAL version patch number.
*/
#define CH_HAL_PATCH 6
/** @} */
/**
* @name Return codes
* @{
*/
#define HAL_SUCCESS false
#define HAL_FAILED true
/** @} */
BTW in the same directory take a look to pal.h
Code: Select all
/*===========================================================================*/
/* Driver constants. */
/*===========================================================================*/
/**
* @name Pads mode constants
* @{
*/
/**
* @brief After reset state.
* @details The state itself is not specified and is architecture dependent,
* it is guaranteed to be equal to the after-reset state. It is
* usually an input state.
*/
#define PAL_MODE_RESET 0U
/**
* @brief Safe state for <b>unconnected</b> pads.
* @details The state itself is not specified and is architecture dependent,
* it may be mapped on @p PAL_MODE_INPUT_PULLUP,
* @p PAL_MODE_INPUT_PULLDOWN or @p PAL_MODE_OUTPUT_PUSHPULL for
* example.
*/
#define PAL_MODE_UNCONNECTED 1U
/**
* @brief Regular input high-Z pad.
*/
#define PAL_MODE_INPUT 2U
/**
* @brief Input pad with weak pull up resistor.
*/
#define PAL_MODE_INPUT_PULLUP 3U
/**
* @brief Input pad with weak pull down resistor.
*/
#define PAL_MODE_INPUT_PULLDOWN 4U
/**
* @brief Analog input mode.
*/
#define PAL_MODE_INPUT_ANALOG 5U
/**
* @brief Push-pull output pad.
*/
#define PAL_MODE_OUTPUT_PUSHPULL 6U
/**
* @brief Open-drain output pad.
*/
#define PAL_MODE_OUTPUT_OPENDRAIN 7U
/** @} */
If you cannot find PAL_MODE_INPUT_PULLUP I am afraid you have screwed up something.