gpio driver compiles

This commit is contained in:
tkl 2016-08-15 21:41:22 +02:00
parent 70fce5a306
commit 067dd1d3e5
9 changed files with 49 additions and 143 deletions

View File

@ -6,8 +6,8 @@
#ifndef BOARD_H_
#define BOARD_H_
#ifdef BOARD_STM32F4_DISCOVERY
//#ifdef BOARD_STM32F4_DISCOVERY
#include "stm32f4-discovery.h"
#endif
//#endif
#endif /* BOARD_H_ */

View File

@ -1,6 +1,6 @@
INCLUDES += source/firmware/arch/stm32f4xx/board
DOC_SRC += source/firmware/arch/stm32f4xx/board
ifeq ($(BOARD), stm32f4-discovery)
#ifeq ($(BOARD), stm32f4-discovery)
include source/firmware/arch/stm32f4xx/board/stm32f4-discovery/stm32f4-discovery.mk
endif
#endif

View File

@ -1,5 +1,2 @@
CHECK_FOLDER += source/firmware/arch/stm32f4xx/driver
SUB_FOLDER += source/firmware/arch/stm32f4xx/driver
SRC_DIR += source/firmware/arch/stm32f4xx/driver
INCLUDES += source/firmware/arch/stm32f4xx/driver/include
DOC_SRC += source/firmware/arch/stm32f4xx/driver
DOC_SRC += source/firmware/arch/stm32f4xx/driver/include

View File

@ -12,8 +12,6 @@ typedef void* (*gpio_ext_it_cb_t)(void*);
struct stm32f4_gpio {
GPIO_TypeDef *port; //!< Gpio port
const GPIO_InitTypeDef *pin; //!< Gpio pin
const EXTI_InitTypeDef *exti; //!< Gpio exit it (could be NULL)
const NVIC_InitTypeDef *nvic; //!< Gpio nvic (could be NULL)
gpio_ext_it_cb_t ext_it_cb; //!< Gpio ext it callback (could be NULL)
void *param; //!< Parameter for the callback
};

View File

@ -17,6 +17,7 @@ typedef struct {
void *param; //!< Parameter for the callback
}exti_cb_list_t;
#if 0
//! \brief Contains call back data for all 16 exti lines.
static struct {
exti_cb_list_t callback_list[16]; //!< Call back data list for the exti lines.
@ -45,83 +46,34 @@ static uint8_t gpio_bin2dec(uint16_t bin)
}
return ret;
}
static void gpio_init(const struct stm32f4_gpio *gpio)
{
uint8_t m_port = 0;
uint8_t m_pin = 0;
uint32_t clock = 0;
if(gpio == NULL)
return;
if(gpio->port == GPIOA) {
clock = RCC_AHB1Periph_GPIOA;
m_port = EXTI_PortSourceGPIOA;
}
else if(gpio->port == GPIOB) {
clock = RCC_AHB1Periph_GPIOB;
m_port = EXTI_PortSourceGPIOB;
}
else if(gpio->port == GPIOC) {
clock = RCC_AHB1Periph_GPIOC;
m_port = EXTI_PortSourceGPIOC;
}
else if(gpio->port == GPIOD) {
clock = RCC_AHB1Periph_GPIOD;
m_port = EXTI_PortSourceGPIOD;
}
else if(gpio->port == GPIOE) {
clock = RCC_AHB1Periph_GPIOE;
m_port = EXTI_PortSourceGPIOE;
}
else if(gpio->port == GPIOF) {
clock = RCC_AHB1Periph_GPIOF;
m_port = EXTI_PortSourceGPIOF;
}
else if(gpio->port == GPIOG) {
clock = RCC_AHB1Periph_GPIOG;
m_port = EXTI_PortSourceGPIOG;
}
else if(gpio->port == GPIOH) {
clock = RCC_AHB1Periph_GPIOH;
m_port = EXTI_PortSourceGPIOH;
}
else if(gpio->port == GPIOI) {
clock = RCC_AHB1Periph_GPIOI;
m_port = EXTI_PortSourceGPIOI;
}
RCC_AHB1PeriphClockCmd(clock, ENABLE);
m_pin = gpio_bin2dec(gpio->pin->GPIO_Pin);
SYSCFG_EXTILineConfig(m_port, m_pin);
}
#endif
int stm32f4_gpio_open(const void *gpio)
{
struct stm32f4_gpio *this;
uint8_t m_pin = 0;
if(gpio == NULL)
return -1;
this = (struct stm32f4_gpio *)gpio;
gpio_init(this);
m_pin = gpio_bin2dec(this->pin->GPIO_Pin);
GPIO_Init(this->port, (GPIO_InitTypeDef*)this->pin);
if(this->ext_it_cb != NULL) {
gpio_obj.callback_list[m_pin].callback = this->ext_it_cb;
gpio_obj.callback_list[m_pin].param = this->param;
}
if((this->exti != NULL) && (this->nvic != NULL)) {
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
EXTI_Init((EXTI_InitTypeDef*)this->exti);
NVIC_Init((NVIC_InitTypeDef*)this->nvic);
}
if(this->port == GPIOA)
__HAL_RCC_GPIOA_CLK_ENABLE();
else if(this->port == GPIOB)
__HAL_RCC_GPIOB_CLK_ENABLE();
else if(this->port == GPIOC)
__HAL_RCC_GPIOC_CLK_ENABLE();
else if(this->port == GPIOD)
__HAL_RCC_GPIOD_CLK_ENABLE();
else if(this->port == GPIOE)
__HAL_RCC_GPIOE_CLK_ENABLE();
else if(this->port == GPIOF)
__HAL_RCC_GPIOF_CLK_ENABLE();
else if(this->port == GPIOG)
__HAL_RCC_GPIOG_CLK_ENABLE();
else if(this->port == GPIOH)
__HAL_RCC_GPIOH_CLK_ENABLE();
else if(this->port == GPIOI)
__HAL_RCC_GPIOI_CLK_ENABLE();
HAL_GPIO_Init(this->port, (GPIO_InitTypeDef*)this->pin);
return 0;
}
@ -129,7 +81,8 @@ int stm32f4_gpio_close(const void *gpio)
{
if(gpio == NULL)
return -1;
// TODO: deinit exti, nvic & gpio
struct stm32f4_gpio *this = (struct stm32f4_gpio *)gpio;
HAL_GPIO_DeInit(this->port, this->pin->Pin);
return 0;
}
@ -140,7 +93,7 @@ char stm32f4_gpio_read(const void *gpio)
return 0;
this = (struct stm32f4_gpio *)gpio;
return GPIO_ReadOutputDataBit(this->port, this->pin->GPIO_Pin);
return HAL_GPIO_ReadPin(this->port, this->pin->Pin);
}
void stm32f4_gpio_write(const void *gpio, char byte) {
@ -149,7 +102,7 @@ void stm32f4_gpio_write(const void *gpio, char byte) {
return;
this = (struct stm32f4_gpio *)gpio;
GPIO_WriteBit(this->port, this->pin->GPIO_Pin, (BitAction)byte);
HAL_GPIO_WritePin(this->port, this->pin->Pin, (GPIO_PinState)(byte & 0x01));
}
void stm32f4_gpio_toggle(const void *gpio)
@ -159,16 +112,13 @@ void stm32f4_gpio_toggle(const void *gpio)
return;
this = (struct stm32f4_gpio *)gpio;
BitAction act = Bit_SET;
if(GPIO_ReadOutputDataBit(this->port, this->pin->GPIO_Pin))
act = Bit_RESET;
GPIO_WriteBit(this->port, this->pin->GPIO_Pin, act);
HAL_GPIO_TogglePin(this->port, this->pin->Pin);
}
int stm32f4_gpio_set_exti_callback(const void *gpio,
const void *callback, const void *param)
{
#if 0
struct stm32f4_gpio *this;
uint8_t pin;
if((gpio == NULL) || (callback == NULL))
@ -179,10 +129,11 @@ int stm32f4_gpio_set_exti_callback(const void *gpio,
gpio_obj.callback_list[pin].callback = (gpio_ext_it_cb_t)callback;
gpio_obj.callback_list[pin].param = (void*)param;
#endif
return 0;
}
#if 0
//! \brief The ISR for the EXTI0_IRQn interrupt.
void EXTI0_IRQHandler(void)
{
@ -258,3 +209,4 @@ void EXTI9_5_IRQHandler(void) {
void EXTI15_10_IRQHandler(void) {
// TODO: detect & clear pending bit
}
#endif

View File

@ -3,8 +3,6 @@
// Copyright (c) 2014 Liviu Ionescu.
//
// ----------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include "diag/Trace.h"
@ -12,32 +10,10 @@
#include "Timer.h"
#include "BlinkLed.h"
// ----------------------------------------------------------------------------
//
// Standalone STM32F4 led blink sample (trace via DEBUG).
//
// In debug configurations, demonstrate how to print a greeting message
// on the trace device. In release configurations the message is
// simply discarded.
//
// Then demonstrates how to blink a led with 1 Hz, using a
// continuous loop and SysTick delays.
//
// Trace support is enabled by adding the TRACE macro definition.
// By default the trace messages are forwarded to the DEBUG output,
// but can be rerouted to any device or completely suppressed, by
// changing the definitions required in system/src/diag/trace_impl.c
// (currently OS_USE_TRACE_ITM, OS_USE_TRACE_SEMIHOSTING_DEBUG/_STDOUT).
//
// ----- Timing definitions -------------------------------------------------
// Keep the LED on for 2/3 of a second.
#define BLINK_ON_TICKS (TIMER_FREQUENCY_HZ * 3 / 4)
#define BLINK_OFF_TICKS (TIMER_FREQUENCY_HZ - BLINK_ON_TICKS)
// ----- main() ---------------------------------------------------------------
// Sample pragmas to cope with warnings. Please note the related line at
// the end of this function, used to pop the compiler diagnostics status.
#pragma GCC diagnostic push
@ -45,38 +21,21 @@
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#pragma GCC diagnostic ignored "-Wreturn-type"
int
main(int argc, char* argv[])
int main(int argc, char* argv[])
{
// Send a greeting to the trace device (skipped on Release).
trace_puts("Hello ARM World!");
// At this stage the system clock should have already been configured
// at high speed.
trace_printf("System clock: %u Hz\n", SystemCoreClock);
timer_start();
blink_led_init();
uint32_t seconds = 0;
// Infinite loop
while (1)
{
blink_led_on();
timer_sleep(seconds == 0 ? TIMER_FREQUENCY_HZ : BLINK_ON_TICKS);
blink_led_off();
timer_sleep(BLINK_OFF_TICKS);
++seconds;
// Count seconds on the trace device.
trace_printf("Second %u\n", seconds);
}
// Infinite loop, never return.
trace_puts("Hello ARM World!");
trace_printf("System clock: %u Hz\n", SystemCoreClock);
timer_start();
blink_led_init();
uint32_t seconds = 0;
while(1) {
blink_led_on();
timer_sleep(seconds == 0 ? TIMER_FREQUENCY_HZ : BLINK_ON_TICKS);
blink_led_off();
timer_sleep(BLINK_OFF_TICKS);
++seconds;
trace_printf("Second %u\n", seconds);
}
}
#pragma GCC diagnostic pop
// ----------------------------------------------------------------------------