gpio toggle works

This commit is contained in:
tkl
2016-08-15 22:25:35 +02:00
parent 067dd1d3e5
commit 073f5093dd
16 changed files with 99 additions and 593 deletions

View File

@@ -6,25 +6,48 @@
#ifndef BSP_STM32F4_DISCOVERY_H_
#define BSP_STM32F4_DISCOVERY_H_
#define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
#include <stddef.h>
#include <stdint.h>
#include "driver.h"
#include "gpio.h"
#if 0
#include "../../../../../kernel/include/sys_tick.h"
#include "../../../driver/include/stm32_sys_tick.h"
#include "../../../driver/include/stm32f4_pwm.h"
#include "../../../driver/include/stm32f4_uart.h"
#include "pwm.h"
#include "timer.h"
#include "uart.h"
#include "ringbuffer.h"
#include "sys_tick.h"
#endif
#include "stm32f4xx.h"
#include "gpio.h"
#include "stm32f4_gpio.h"
#include "stm32f4_pwm.h"
#include "stm32f4_uart.h"
#include "stm32_sys_tick.h"
#include "driver.h"
// GPIO_D12
static const GPIO_InitTypeDef port_cfg_d12 = {
.Pin = GPIO_PIN_12,
.Mode = GPIO_MODE_OUTPUT_PP,
.Speed = GPIO_SPEED_FREQ_HIGH,
.Pull = GPIO_PULLUP,
};
static const struct stm32f4_gpio stm32_f4_gpio_d12 = {
.port = GPIOD,
.pin = &port_cfg_d12,
};
static const struct gpio __gpio_d12 = {
(void*)&stm32_f4_gpio_d12,
&gpio_fp
};
const struct driver gpio_d12 = {
DRIVER_TYPE_GPIO,
&__gpio_d12,
};
#if 0
// SYSTEM TICK
static const enum stm32_sys_tick_time_base stm23_sys_tick_time_base =
STM32_SYS_TICK_TIME_BASE_MS;
@@ -38,7 +61,8 @@ static const struct loki_timer timer_1 = {
(void*)&stm32_sys_tick,
&timer_fp
};
#endif
#if 0
// PWM CHANNEL 4
/* apb1 clock = 84MHz */
/* period_reg = src_clk / presc / cnt_clk */
@@ -93,7 +117,8 @@ const struct driver pwm_4 = {
DRIVER_TYPE_PWM,
&pwm_ch4,
};
#endif
#if 0
// PWM Channel 3
static const GPIO_InitTypeDef port_cfg_D14 = {
.GPIO_Pin = GPIO_Pin_14,
@@ -126,7 +151,8 @@ const struct driver pwm_3 = {
DRIVER_TYPE_PWM,
&pwm_ch3,
};
#endif
#if 0
// PWM Channel 2
static const GPIO_InitTypeDef port_cfg_D13 = {
.GPIO_Pin = GPIO_Pin_13,
@@ -159,7 +185,8 @@ const struct driver pwm_2 = {
DRIVER_TYPE_PWM,
&pwm_ch2,
};
#endif
#if 0
// PWM Channel 1
static const GPIO_InitTypeDef port_cfg_D12 = {
.GPIO_Pin = GPIO_Pin_12,
@@ -192,7 +219,8 @@ const struct driver pwm_1 = {
DRIVER_TYPE_PWM,
&pwm_ch1,
};
#endif
#if 0
// UART 1
static char console_linear_buffer[80];
static struct ringbuffer console_buffer = {
@@ -252,7 +280,8 @@ const struct driver uart_1 = {
DRIVER_TYPE_UART,
&__uart_1,
};
#endif
#if 0
// GPIOC0
static const GPIO_InitTypeDef port_cfg_C0 = {
GPIO_Pin_0,
@@ -284,7 +313,8 @@ const struct driver gpio_c0 = {
DRIVER_TYPE_GPIO,
&__gpio_c0,
};
#endif
#if 0
// GPIO_C1
static const GPIO_InitTypeDef port_cfg_C1 = {
GPIO_Pin_1,
@@ -316,7 +346,8 @@ const struct driver gpio_c1 = {
DRIVER_TYPE_GPIO,
&__gpio_c1,
};
#endif
#if 0
// GPIO_C2
static const GPIO_InitTypeDef port_cfg_C2 = {
GPIO_Pin_2,
@@ -348,7 +379,8 @@ const struct driver gpio_c2 = {
DRIVER_TYPE_GPIO,
&__gpio_c2,
};
#endif
#if 0
// GPIO_C3
static const GPIO_InitTypeDef port_cfg_C3 = {
GPIO_Pin_3,
@@ -380,7 +412,7 @@ const struct driver gpio_c3 = {
DRIVER_TYPE_GPIO,
&__gpio_c3,
};
#endif
//! \brief Setup the hardware of the stm32f4-discovery board.
void board_init(void);

View File

@@ -1,49 +0,0 @@
//! \file stm32_sys_tick.h
//! \author tkl
//! \date Feb 15, 2012
//! \brief Header file of the stm32f10x architecture dependent sys tick timer implementation.
#ifndef STM32_SYS_TICK_H_
#define STM32_SYS_TICK_H_
#include "timer.h"
typedef void* (*stm32_sys_tick_cb_t)(void*); //!< callback for the external interrupt
//! \brief Type of sys tick base time.
enum stm32_sys_tick_time_base {
STM32_SYS_TICK_TIME_BASE_NONE = 0, //!< Not init
STM32_SYS_TICK_TIME_BASE_US, //!< Tick time = 1 us.
STM32_SYS_TICK_TIME_BASE_MS //!< Tick time = 1 ms.
};
//! \brief The sys tick device.
struct stm32_sys_tick {
const enum stm32_sys_tick_time_base *tick_time_base; //!< time base for the system tick
stm32_sys_tick_cb_t sys_tick_cb; //!< callback for the sys tick interrupt
void *sys_tick_cb_param; //!< parameter for the callback
};
//! \brief Open a sys tick timer.
//! \param sys_tick The sys tick to open. Must be of type const stm32_sys_tick_t*.
//! \return -1 in error case.
int stm32_sys_tick_open(const void *sys_tick);
//! \brief Close a sys tick timer.
//! \param sys_tick The sys tick to close. Must be of type const stm32_sys_tick_t*.
//! \return -1 in error case.
int stm32_sys_tick_close(const void *sys_tick);
//! \brief Set the call back for a sys tick timer.
//! \param sys_tick The sys tick to open. Mus be of type const stm32_sys_tick_t*.
//! \param callback The function pointer of the call back function.
//! \param param The parameter for the call back function.
//! \return -1 in error case.
int stm32_sys_tick_set_cb(const void *sys_tick, const void *callback, const void *param);
static const struct timer_fp timer_fp = {
stm32_sys_tick_open,
stm32_sys_tick_close,
stm32_sys_tick_set_cb
};
#endif /* STM32_SYS_TICK_H_ */

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
gpio_ext_it_cb_t ext_it_cb; //!< Gpio ext it callback (could be NULL)
void *param; //!< Parameter for the callback
};
//! \brief Open a gpio.

View File

@@ -1,40 +0,0 @@
/*
* stm32f4_pwm.h
*
* Created on: Aug 9, 2016
* Author: tkl
*/
#ifndef SOURCE_FIRMWARE_ARCH_STM32F4XX_DRIVER_INCLUDE_STM32F4_PWM_H_
#define SOURCE_FIRMWARE_ARCH_STM32F4XX_DRIVER_INCLUDE_STM32F4_PWM_H_
enum stm32f4_pwm_channel {
channel_1 = 1,
channel_2,
channel_3,
channel_4
};
struct stm32f4_pwm {
TIM_TypeDef *timer;
const TIM_TimeBaseInitTypeDef *timer_cfg;
const TIM_OCInitTypeDef *output_compare_cfg;
const TIM_BDTRInitTypeDef *bdtr_cfg;
GPIO_TypeDef *port;
uint8_t pin_src;
const GPIO_InitTypeDef *port_cfg;
enum stm32f4_pwm_channel channel;
};
int stm32f4_pwm_open(const void *pwm);
int stm32f4_pwm_close(const void *pwm);
int stm32f4_pwm_set_duty_cycle(const void *pwm, unsigned int duty_cycle_percent);
static const struct pwm_fp stm32f4_pwm_fp = {
.open = stm32f4_pwm_open,
.close = stm32f4_pwm_close,
.set_duty_cycle = stm32f4_pwm_set_duty_cycle,
};
#endif /* SOURCE_FIRMWARE_ARCH_STM32F4XX_DRIVER_INCLUDE_STM32F4_PWM_H_ */

View File

@@ -1,65 +0,0 @@
/*
* stm32_uart.h
*
* Created on: Jul 24, 2016
* Author: tkl
*/
#ifndef SOURCE_FIRMWARE_ARCH_STM32F4XX_DRIVER_UART_STM32_UART_H_
#define SOURCE_FIRMWARE_ARCH_STM32F4XX_DRIVER_UART_STM32_UART_H_
#include "driver.h"
#include "uart.h"
//! \brief Stm32f4 uart device.
struct stm32f4_uart {
const GPIO_InitTypeDef *gpio_init;
GPIO_TypeDef *gpio_port;
uint8_t pin_src_rx;
uint8_t pin_src_tx;
const USART_InitTypeDef *usart_init;
USART_TypeDef *usart_port;
uint16_t usart_it_select;
const NVIC_InitTypeDef *nvic_init;
};
//! \brief Open an uart device.
//! \param this The uart to open.
//! \retval -1 in error case.
int stm32f4_uart_open(const void *this);
//! \brief Close an uart device.
//! \param this The uart to close.
//! \retval -1 in error case.
int stm32f4_uart_close(const void *this);
//! \brief Read from an uart device.
//! \param this The uart to read from.
//! \param buffer The buffer to read to.
//! \param len The length of the buffer.
//! \retval -1 in error case, otherwise number of read characters.
int stm32f4_uart_read(const void *this, char *buffer, int len);
//! \brief Write to an uart device.
//! \param this The uart to write to.
//! \param buffer The buffer to write.
//! \param len The number of characters to write.
//! \retval -1 in error case, otherwise number of written characters.
int stm32f4_uart_write(const void *this, const char *buffer, int len);
//! \brief Set a callback for interrupt handling of the uart.
//! \param this The uart.
//! \param callback The callback to execute in interrupt case.
//! \param param The argument for the callback.
//! \retval -1 in error case.
int stm32f4_uart_set_cb(const void *this, const void *callback, const void *param);
static const struct uart_fp stm32f4_uart_fp = {
stm32f4_uart_open,
stm32f4_uart_close,
stm32f4_uart_read,
stm32f4_uart_write,
stm32f4_uart_set_cb
};
#endif /* SOURCE_FIRMWARE_ARCH_STM32F4XX_DRIVER_UART_STM32_UART_H_ */