Skip to content

Commit 859634a

Browse files
committed
Use LL for GPIO access
Signed-off-by: Frederic.Pillon <[email protected]>
1 parent fa40ba6 commit 859634a

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

cores/arduino/stm32/digital_io.c

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ void digital_io_init(PinName pin, uint32_t mode, uint32_t pull)
5757
GPIO_InitTypeDef GPIO_InitStructure;
5858
GPIO_TypeDef *port = set_GPIO_Port_Clock(STM_PORT(pin));
5959
GPIO_InitStructure.Pin = STM_GPIO_PIN(pin);
60+
#ifdef GPIO_SPEED_FREQ_VERY_HIGH
61+
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
62+
#else
6063
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;
64+
#endif
6165
GPIO_InitStructure.Mode = mode;
6266
GPIO_InitStructure.Pull = pull;
6367
#ifdef STM32F1xx
@@ -66,34 +70,6 @@ void digital_io_init(PinName pin, uint32_t mode, uint32_t pull)
6670
HAL_GPIO_Init(port, &GPIO_InitStructure);
6771
}
6872

69-
/**
70-
* @brief This function set a value to an IO
71-
* @param port : one of the gpio port
72-
* @param pin : one of the gpio pin
73-
* @param val : 0 to set to low, any other value to set to high
74-
* @retval None
75-
*/
76-
void digital_io_write(GPIO_TypeDef *port, uint32_t pin, uint32_t val)
77-
{
78-
if(val) {
79-
HAL_GPIO_WritePin(port, pin, GPIO_PIN_SET);
80-
} else {
81-
HAL_GPIO_WritePin(port, pin, GPIO_PIN_RESET);
82-
}
83-
}
84-
85-
86-
/**
87-
* @brief This function set a value to an IO
88-
* @param port : one of the gpio port
89-
* @param pin : one of the gpio pin
90-
* @retval The pin state (LOW or HIGH)
91-
*/
92-
uint32_t digital_io_read(GPIO_TypeDef *port, uint32_t pin)
93-
{
94-
return (uint32_t)HAL_GPIO_ReadPin(port, pin);
95-
}
96-
9773
#ifdef __cplusplus
9874
}
9975
#endif

cores/arduino/stm32/digital_io.h

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
/* Includes ------------------------------------------------------------------*/
4343
#include "stm32_def.h"
4444
#include "PeripheralPins.h"
45+
#include "stm32yyxx_ll_gpio.h"
4546

4647
#ifdef __cplusplus
4748
extern "C" {
@@ -52,8 +53,34 @@
5253
/* Exported macro ------------------------------------------------------------*/
5354
/* Exported functions ------------------------------------------------------- */
5455
void digital_io_init(PinName pin, uint32_t mode, uint32_t pull);
55-
void digital_io_write(GPIO_TypeDef *port, uint32_t pin, uint32_t val);
56-
uint32_t digital_io_read(GPIO_TypeDef *port, uint32_t pin);
56+
57+
/**
58+
* @brief This function set a value to an IO
59+
* @param port : one of the gpio port
60+
* @param pin : one of the gpio pin
61+
* @param val : 0 to set to low, any other value to set to high
62+
* @retval None
63+
*/
64+
static inline void digital_io_write(GPIO_TypeDef *port, uint32_t pin, uint32_t val)
65+
{
66+
if(val) {
67+
LL_GPIO_SetOutputPin(port, pin);
68+
} else {
69+
LL_GPIO_ResetOutputPin(port, pin);
70+
}
71+
}
72+
73+
74+
/**
75+
* @brief This function set a value to an IO
76+
* @param port : one of the gpio port
77+
* @param pin : one of the gpio pin
78+
* @retval The pin state (LOW or HIGH)
79+
*/
80+
static inline uint32_t digital_io_read(GPIO_TypeDef *port, uint32_t pin)
81+
{
82+
return LL_GPIO_IsInputPinSet(port, pin);
83+
}
5784

5885
#ifdef __cplusplus
5986
}

0 commit comments

Comments
 (0)