cancel
Showing results for 
Search instead for 
Did you mean: 

GPIO_WriteBit() in HAL ??? (32f407)

pcm-lab
Associate II
Posted on February 14, 2015 at 21:31

Hi there!

Who knows how to implement the function of GPIO SPL -

GPIO_WriteBit (GPIO_TypeDef * GPIOx, uint16_t GPIO_Pin, BitAction BitVal)

on the library HAL?

In the HAL library

I can see only

HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)

:(

-----------------------------------------

If you can

- Give a short example PLEASE !

I need this, for

programming character LCD 16x2 (KS 0066 or Equivalent HD4478)

On the SPL I did like this :

(in lcd.h)

#define DB0(a)        GPIO_WriteBit(DB0_PORT, DB0_PIN, (BitAction)a)

#define DB1(a)        GPIO_WriteBit(DB1_PORT, DB1_PIN, (BitAction)a)

#define DB2(a)        GPIO_WriteBit(DB2_PORT, DB2_PIN, (BitAction)a)

etc

(in lcd.c)

void LCD_Set_Data(uint8_t data)

{

    if ( ((data >> 7)&0x01) == 1 ) {DB7(1);} else {DB7(0);}

    if ( ((data >> 6)&0x01) == 1 ) {DB6(1);} else {DB6(0);}            

    if ( ((data >> 5)&0x01) == 1 ) {DB5(1);} else {DB5(0);}

    if ( ((data >> 4)&0x01) == 1 ) {DB4(1);} else {DB4(0);}

    if ( ((data >> 3)&0x01) == 1 ) {DB3(1);} else {DB3(0);}

    if ( ((data >> 2)&0x01) == 1 ) {DB2(1);} else {DB2(0);}

    if ( ((data >> 1)&0x01) == 1 ) {DB1(1);} else {DB1(0);}

    if ( ((data >> 0)&0x01) == 1 ) {DB0(1);} else {DB0(0);}   

}

================================================

maybe me need

insert ready function

GPIO_WriteBit from stm32f4xx_gpio.c (SPL)

to stm32f4xx_hal_gpio.c ??? (HAL)     :))

But I want to do like that on the new (fully only on HAL!)

Help me please !

3 REPLIES 3
Posted on February 17, 2015 at 09:05

And what's wrong with the documentation?

This is what I read in STM32F417xx_User_Manual.chm under Modules->GPIO->GPIO Exported Functions->IO operation functions->Functions->HAL_GPIO_WritePin. IMO, it's crystal clear:

void ( GPIO_TypeDef *  GPIOx,

uint16_t  GPIO_Pin,

  PinState 

)

Sets or clears the selected data port bit.

Note:

This function uses GPIOx_BSRR register to allow atomic read/modify accesses. In this way, there is no risk of an IRQ occurring between the read and the modify access.

Parameters:

GPIOx,: where x can be (A..K) to select the GPIO peripheral for STM32F429X device or x can be (A..I) to select the GPIO peripheral for STM32F40XX and STM32F427X devices.

GPIO_Pin,: specifies the port bit to be written. This parameter can be one of GPIO_PIN_x where x can be (0..15).

PinState,: specifies the value to be written to the selected bit. This parameter can be one of the GPIO_PinState enum values:

  • GPIO_PIN_RESET: to clear the port pin
  • GPIO_PIN_SET: to set the port pin

Return values:

None

Definition at line of file .

pcm-lab
Associate II
Posted on February 19, 2015 at 00:09

Thanks for the reply

0690X0000060Mn7QAE.gif

With documentation i not have problems

but

Code that worked 100% on the SPL, With GPIO_WriteBit ()

still can not run on HAL, in using HAL_GPIO_WritePin ()

=======================================================

If you are using SPL - GPIO_WriteBit

- All Ok

If you are using HAL - HAL_GPIO_WritePin HAL 1.3

- All Ok

When i using HAL = HAL_GPIO_WritePin HAL 1.4

>

RS(0); DB7(0); DB6(0); DB5(1); DB4(1); DB3(1); DB2(1); DB1(0); DB0(0);

or without #define DB0(a).... >

HAL_GPIO_WritePin(LCD_DB0_PORT, LCD_DB0_PIN, 1)

HAL_GPIO_WritePin(LCD_DB1_PORT, LCD_DB0_PIN, 0)

- Warning

..\Src\main.c(98): warning: #188-D: enumerated type mixed with another type

and LCD does not react :(

Logic analyzer will check and try different options on,

and report the results here.

I now about parameters for HAL_GPIO_WritePin :

GPIO_PIN_RESET = 0,

GPIO_PIN_SET

but me need send bit data (may by byte data) to pin/port

as i sent in GPIO_WriteBit () //SPL :(

================================================================================

################################################################################

Here are different versions of device drivers

SPL, HAL 1.3 & 1.4

--------------

SPL

void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal)

{

/* Check the parameters */

assert_param(IS_GPIO_ALL_PERIPH(GPIOx));

assert_param(IS_GET_GPIO_PIN(GPIO_Pin));

assert_param(IS_GPIO_BIT_ACTION(BitVal));

if (BitVal != Bit_RESET)

{

GPIOx->BSRRL = GPIO_Pin;

}

else

{

GPIOx->BSRRH = GPIO_Pin ;

}

}

=========================================================================================

HAL ver 1.3

void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)

{

/* Check the parameters */

assert_param(IS_GPIO_PIN(GPIO_Pin));

assert_param(IS_GPIO_PIN_ACTION(PinState));

if(PinState != GPIO_PIN_RESET)

{

GPIOx->BSRRL = GPIO_Pin;

}

else

{

GPIOx->BSRRH = GPIO_Pin ;

}

}

=====================================================

HAL ver 1.4

void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)

{

/* Check the parameters */

assert_param(IS_GPIO_PIN(GPIO_Pin));

assert_param(IS_GPIO_PIN_ACTION(PinState));

if(PinState != GPIO_PIN_RESET)

{

GPIOx->BSRR = GPIO_Pin;

}

else

{

GPIOx->BSRR = (uint32_t)GPIO_Pin << 16;

}

}

=======================================================

Ok

I will continue to look for a solution

Posted on February 19, 2015 at 06:54

Isn't this an eye-opener experience for you? Why do you stick to using a ''library'' with all its implications and overhead for something that really ought to be a simple macro?

JW