Skip to content

LL used for GPIO pin configuration #369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cores/arduino/pins_arduino.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extern "C" {

WEAK uint32_t pinNametoDigitalPin(PinName p)
{
uint32_t i = NC;
uint32_t i = NUM_DIGITAL_PINS;
if(STM_VALID_PINNAME(p)) {
for(i = 0; i < NUM_DIGITAL_PINS; i++) {
if (digitalPin[i] == p)
Expand Down
2 changes: 1 addition & 1 deletion cores/arduino/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ uint32_t pinNametoDigitalPin(PinName p);
#define digitalPinToPort(p) (get_GPIO_Port(STM_PORT(digitalPinToPinName(p))))
#define digitalPinToBitMask(p) (STM_GPIO_PIN(digitalPinToPinName(p)))

#define analogInPinToBit(p) (STM_PIN(digitalPinToPinName(p)))
#define analogInPinToBit(p) (STM_GPIO_PIN(digitalPinToPinName(p)))
#define portOutputRegister(P) (&(P->ODR))
#define portInputRegister(P) (&(P->IDR))

Expand Down
10 changes: 6 additions & 4 deletions cores/arduino/stm32/PinConfigured.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ extern "C" {

#define PINCONF_VAL(X, Y) ((Y >> PINCONF_SHIFT(X)) & PINCONF_MASK)


bool is_pin_configured(PinName pin, uint32_t* map);
void set_pin_configured(PinName pin, uint32_t* map);
void reset_pin_configured(PinName pin, uint32_t* map);
#define is_pin_configured(pin, map) \
(PINCONF_VAL(pin, map[PINCONF_INDEX(pin)]))
#define set_pin_configured(pin, map) \
(map[PINCONF_INDEX(pin)] = map[PINCONF_INDEX(pin)] | PINCONF_BIT(pin))
#define reset_pin_configured(pin, map) \
(map[PINCONF_INDEX(pin)] = map[PINCONF_INDEX(pin)] & (~PINCONF_BIT(pin)))

#ifdef __cplusplus
}
Expand Down
21 changes: 1 addition & 20 deletions cores/arduino/stm32/PinNamesTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extern "C" {
/* STM PIN data as used in pin_function is coded on 32 bits as below
* [2:0] Function (like in MODER reg) : Input / Output / Alt / Analog
* [3] Output Push-Pull / Open Drain (as in OTYPER reg)
* [5:4] as in PUPDR reg: No Pull, Pull-up, Pull-Donc
* [5:4] as in PUPDR reg: No Pull, Pull-up, Pull-Down
* [7:6] Reserved for speed config (as in OSPEEDR), but not used yet
* [14:8] Alternate Num (as in AFRL/AFRG reg)
* [19:15] Channel (Analog/Timer specific)
Expand Down Expand Up @@ -135,25 +135,6 @@ typedef enum {
#define STM_VALID_PINNAME(X) (STM_PORT(X) <= LastPort)

#define STM_GPIO_PIN(X) ((uint16_t)(1<<STM_PIN(X)))
/* Defines to be used by application */
typedef enum {
PIN_INPUT = 0,
PIN_OUTPUT
} PinDirection;

typedef enum {
PullNone = 0,
PullUp = 1,
PullDown = 2,
OpenDrainPullUp = 3,
OpenDrainNoPull = 4,
OpenDrainPullDown = 5,
PushPullNoPull = PullNone,
PushPullPullUp = PullUp,
PushPullPullDown = PullDown,
OpenDrain = OpenDrainPullUp,
PullDefault = PullNone
} PinMode;

#ifdef __cplusplus
}
Expand Down
62 changes: 14 additions & 48 deletions cores/arduino/stm32/PortNames.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,73 +28,40 @@
*******************************************************************************
*/
#include "PortNames.h"
#include "stm32_def.h"

// Return GPIO base address
GPIO_TypeDef *get_GPIO_Port(uint32_t port_idx) {
GPIO_TypeDef* gpioPort = 0;
switch (port_idx) {
case PortA:
gpioPort = (GPIO_TypeDef *)GPIOA_BASE;
break;
case PortB:
gpioPort = (GPIO_TypeDef *)GPIOB_BASE;
break;
GPIO_TypeDef * GPIOPort[MAX_NB_PORT] = {
(GPIO_TypeDef *)GPIOA_BASE,
(GPIO_TypeDef *)GPIOB_BASE
#if defined GPIOC_BASE
case PortC:
gpioPort = (GPIO_TypeDef *)GPIOC_BASE;
break;
,(GPIO_TypeDef *)GPIOC_BASE
#endif
#if defined GPIOD_BASE
case PortD:
gpioPort = (GPIO_TypeDef *)GPIOD_BASE;
break;
,(GPIO_TypeDef *)GPIOD_BASE
#endif
#if defined GPIOE_BASE
case PortE:
gpioPort = (GPIO_TypeDef *)GPIOE_BASE;
break;
,(GPIO_TypeDef *)GPIOE_BASE
#endif
#if defined GPIOF_BASE
case PortF:
gpioPort = (GPIO_TypeDef *)GPIOF_BASE;
break;
,(GPIO_TypeDef *)GPIOF_BASE
#endif
#if defined GPIOG_BASE
case PortG:
gpioPort = (GPIO_TypeDef *)GPIOG_BASE;
break;
,(GPIO_TypeDef *)GPIOG_BASE
#endif
#if defined GPIOH_BASE
case PortH:
gpioPort = (GPIO_TypeDef *)GPIOH_BASE;
break;
,(GPIO_TypeDef *)GPIOH_BASE
#endif
#if defined GPIOI_BASE
case PortI:
gpioPort = (GPIO_TypeDef *)GPIOI_BASE;
break;
,(GPIO_TypeDef *)GPIOI_BASE
#endif
#if defined GPIOJ_BASE
case PortJ:
gpioPort = (GPIO_TypeDef *)GPIOJ_BASE;
break;
,(GPIO_TypeDef *)GPIOJ_BASE
#endif
#if defined GPIOK_BASE
case PortK:
gpioPort = (GPIO_TypeDef *)GPIOK_BASE;
break;
,(GPIO_TypeDef *)GPIOK_BASE
#endif
default:
// wrong port number
//TBD: error management
gpioPort = 0;
break;
}
return gpioPort;
}
};

// Enable GPIO clock and return GPIO base address
/* Enable GPIO clock and return GPIO base address */
GPIO_TypeDef *set_GPIO_Port_Clock(uint32_t port_idx) {
GPIO_TypeDef* gpioPort = 0;
switch (port_idx) {
Expand Down Expand Up @@ -173,4 +140,3 @@ GPIO_TypeDef *set_GPIO_Port_Clock(uint32_t port_idx) {
}
return gpioPort;
}

6 changes: 5 additions & 1 deletion cores/arduino/stm32/PortNames.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
extern "C" {
#endif

extern GPIO_TypeDef *GPIOPort[];

typedef enum {
FirstPort = 0x00,
PortA = FirstPort,
Expand Down Expand Up @@ -73,7 +75,9 @@ typedef enum {

#define MAX_NB_PORT (LastPort-FirstPort+1)

GPIO_TypeDef *get_GPIO_Port(uint32_t port_idx);
/* Return GPIO base address */
#define get_GPIO_Port(p) ((p < MAX_NB_PORT) ? GPIOPort[p] : (GPIO_TypeDef *)NULL)
/* Enable GPIO clock and return GPIO base address */
GPIO_TypeDef *set_GPIO_Port_Clock(uint32_t port_idx);

#ifdef __cplusplus
Expand Down
52 changes: 6 additions & 46 deletions cores/arduino/stm32/analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,27 +257,17 @@ static uint32_t get_dac_channel(PinName pin)
*/
void HAL_DAC_MspInit(DAC_HandleTypeDef *hdac)
{
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_TypeDef *port;
UNUSED(hdac);

/*##-1- Enable peripherals and GPIO Clocks #################################*/
/* Enable GPIO clock ****************************************/
port = set_GPIO_Port_Clock(STM_PORT(g_current_pin));

/* DAC Periph clock enable */
#ifdef __HAL_RCC_DAC1_CLK_ENABLE
__HAL_RCC_DAC1_CLK_ENABLE();
#endif
#ifdef __HAL_RCC_DAC_CLK_ENABLE
__HAL_RCC_DAC_CLK_ENABLE();
#endif
/*##-2- Configure peripheral GPIO ##########################################*/
/* DAC Channel1 GPIO pin configuration */
GPIO_InitStruct.Pin = STM_GPIO_PIN(g_current_pin);
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(port, &GPIO_InitStruct);
/* Configure DAC GPIO pins */
pinmap_pinout(g_current_pin, PinMap_DAC);
}


Expand Down Expand Up @@ -393,8 +383,6 @@ void dac_stop(PinName pin)
*/
void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc)
{
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_TypeDef *port;
/*##-1- Enable peripherals and GPIO Clocks #################################*/
/* ADC Periph clock enable */
if(hadc->Instance == ADC1) {
Expand Down Expand Up @@ -440,19 +428,8 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc)
__HAL_RCC_ADC_CONFIG(RCC_ADCCLKSOURCE_SYSCLK);
#endif

/* Enable GPIO clock ****************************************/
port = set_GPIO_Port_Clock(STM_PORT(g_current_pin));

/*##-2- Configure peripheral GPIO ##########################################*/
/* ADC Channel GPIO pin configuration */
GPIO_InitStruct.Pin = STM_GPIO_PIN(g_current_pin);
#ifdef GPIO_MODE_ANALOG_ADC_CONTROL
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL;
#else
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
#endif
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(port, &GPIO_InitStruct);
/* Configure ADC GPIO pin */
pinmap_pinout(g_current_pin, PinMap_ADC);
}

/**
Expand Down Expand Up @@ -682,29 +659,12 @@ uint16_t adc_read_value(PinName pin)
*/
void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim)
{
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_TypeDef *port;
uint32_t function = pinmap_function(g_current_pin, PinMap_PWM);
/*##-1- Enable peripherals and GPIO Clocks #################################*/
/* TIMx Peripheral clock enable */
timer_enable_clock(htim);

/* Enable GPIO Channels Clock */
/* Enable GPIO clock ****************************************/
port = set_GPIO_Port_Clock(STM_PORT(g_current_pin));

/* Common configuration for all channels */
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
#ifdef STM32F1xx
pin_SetF1AFPin(STM_PIN_AFNUM(function));
#else
GPIO_InitStruct.Alternate = STM_PIN_AFNUM(function);
#endif /* STM32F1xx */
GPIO_InitStruct.Pin = STM_GPIO_PIN(g_current_pin);

HAL_GPIO_Init(port, &GPIO_InitStruct);
/* Configure PWM GPIO pins */
pinmap_pinout(g_current_pin, PinMap_PWM);
}

/**
Expand Down
101 changes: 0 additions & 101 deletions cores/arduino/stm32/digital_io.c

This file was deleted.

Loading