Page 1 of 1

PAL : GPIO output default state is high?

Posted: Mon Jun 20, 2016 1:51 pm
by Ilfirin
Hello,

I have strange behaviour on STM32F072 MCU, when setting pin to push/pull output.
I was expecting logical Low as default state (and according reference manual and StdPeriph sample it should be), but pins have high state.

It is intended, it's a bug, or bad code?

Sample code:

Code: Select all

palSetPadMode(LED_GREEN_PORT, LED_GREEN_PIN,
              PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_LOWEST);
palSetPadMode(LED_RED_PORT, LED_RED_PIN,
              PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_LOWEST);
palSetPadMode(INT_TEST_PORT, INT_TEST_PIN,
              PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_LOWEST);
palSetPadMode(INT_1_PORT, INT_1_PIN,
              PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_LOWEST);


Thank you

Re: PAL : GPIO output default state is high?

Posted: Mon Jun 20, 2016 2:52 pm
by RoccoMarco
Hi,
default state is set in board.h (you can change this state through palSetXXX, palClearXXX or palWriteXXX).
BY the way, if you have to change pad mode in certain point of you application palSetPadMode() is the right API. If you have to set up the whole board just once (like a kind of initialization) it is highly recommended to create your own board file.
Ciao,
RM

Edit: Note that there are some tools to create your own board file.
https://www.youtube.com/watch?v=HwJqZfITvV0

Re: PAL : GPIO output default state is high?

Posted: Mon Jun 20, 2016 3:59 pm
by Ilfirin
RoccoMarco wrote:Hi,
default state is set in board.h (you can change this state through palSetXXX, palClearXXX or palWriteXXX).
BY the way, if you have to change pad mode in certain point of you application palSetPadMode() is the right API. If you have to set up the whole board just once (like a kind of initialization) it is highly recommended to create your own board file.
Ciao,
RM

Edit: Note that there are some tools to create your own board file.


And you are right.
It was there (PIN_ODR_HIGH). I know there was this default state definiton, but (wrongly) assumed, that is only about setting input/output state, not complete register, including latches.
Well, it is really better to create own board configuration, which I wanted to skip. I will learn that.

Thank you very much for your help

Edit: No I can't find out, how to mark this thread as solved. It should be at some "checklist" button, but I cannot find it.

Re: PAL : GPIO output default state is high?

Posted: Mon Jun 20, 2016 4:07 pm
by RoccoMarco
It is the "✓" button. By the way, marked as solved.
Ciao,
RM