Factor out common GPIO code in STM32 platforms.

This commit is contained in:
Gareth McMullin 2015-02-28 22:09:50 -08:00
parent 48fb7ec662
commit 5eff0ab5d6
5 changed files with 74 additions and 116 deletions

View File

@ -34,9 +34,9 @@
#include <alloca.h>
#include "gdb_packet.h"
#include "gpio.h"
#include "morse.h"
#define INLINE_GPIO
#define CDCACM_PACKET_SIZE 64
#define PLATFORM_HAS_TRACESWO
#define BOARD_IDENT "Black Magic Probe (F4Discovery), (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")"
@ -200,31 +200,9 @@ void uart_usb_buf_drain(uint8_t ep);
#define sprintf siprintf
#define vasprintf vasiprintf
#ifdef INLINE_GPIO
static inline void _gpio_set(uint32_t gpioport, uint16_t gpios)
{
GPIO_BSRR(gpioport) = gpios;
GPIO_BSRR(gpioport) = gpios;
}
#define gpio_set _gpio_set
static inline void _gpio_clear(uint32_t gpioport, uint16_t gpios)
{
GPIO_BSRR(gpioport) = gpios<<16;
GPIO_BSRR(gpioport) = gpios<<16;
}
#define gpio_clear _gpio_clear
static inline uint16_t _gpio_get(uint32_t gpioport, uint16_t gpios)
{
return (uint16_t)GPIO_IDR(gpioport) & gpios;
}
#define gpio_get _gpio_get
#endif
#endif
#define disconnect_usb() do {usbd_disconnect(usbdev,1); nvic_disable_irq(USB_IRQ);} while(0)
void assert_boot_pin(void);
#define setup_vbus_irq()
#endif

View File

@ -35,9 +35,9 @@
#include <alloca.h>
#include "gdb_packet.h"
#include "gpio.h"
#include "morse.h"
#define INLINE_GPIO
#define CDCACM_PACKET_SIZE 64
#define PLATFORM_HAS_TRACESWO
#define PLATFORM_HAS_POWER_SWITCH
@ -164,14 +164,6 @@ extern volatile uint32_t timeout_counter;
extern jmp_buf fatal_error_jmpbuf;
#define gpio_set_val(port, pin, val) do { \
if(val) \
gpio_set((port), (pin)); \
else \
gpio_clear((port), (pin)); \
} while(0)
#define SET_RUN_STATE(state) {running_status = (state);}
#define SET_IDLE_STATE(state) {gpio_set_val(LED_PORT, LED_IDLE_RUN, state);}
#define SET_ERROR_STATE(state) {gpio_set_val(LED_PORT, LED_ERROR, state);}
@ -189,6 +181,8 @@ extern jmp_buf fatal_error_jmpbuf;
int platform_init(void);
const char *platform_target_voltage(void);
int platform_hwversion(void);
void platform_set_timeout(uint32_t ms);
bool platform_timeout_expired(void);
void platform_delay(uint32_t delay);
/* <cdcacm.c> */
@ -205,27 +199,6 @@ void uart_usb_buf_drain(uint8_t ep);
#define sprintf siprintf
#define vasprintf vasiprintf
#ifdef INLINE_GPIO
static inline void _gpio_set(uint32_t gpioport, uint16_t gpios)
{
GPIO_BSRR(gpioport) = gpios;
}
#define gpio_set _gpio_set
static inline void _gpio_clear(uint32_t gpioport, uint16_t gpios)
{
GPIO_BRR(gpioport) = gpios;
}
#define gpio_clear _gpio_clear
static inline uint16_t _gpio_get(uint32_t gpioport, uint16_t gpios)
{
return (uint16_t)GPIO_IDR(gpioport) & gpios;
}
#define gpio_get _gpio_get
#endif
#define disconnect_usb() gpio_set_mode(USB_PU_PORT, GPIO_MODE_INPUT, 0, USB_PU_PIN);
void assert_boot_pin(void);
void setup_vbus_irq(void);

View File

@ -35,8 +35,8 @@
#include <alloca.h>
#include "gdb_packet.h"
#include "gpio.h"
#define INLINE_GPIO
#define CDCACM_PACKET_SIZE 64
#define BOARD_IDENT "Black Magic Probe (STLINK), (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")"
#define BOARD_IDENT_DFU "Black Magic (Upgrade) for STLink/Discovery, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")"
@ -143,13 +143,6 @@ extern volatile uint32_t timeout_counter;
extern jmp_buf fatal_error_jmpbuf;
#define gpio_set_val(port, pin, val) do { \
if(val) \
gpio_set((port), (pin)); \
else \
gpio_clear((port), (pin)); \
} while(0)
extern uint16_t led_idle_run;
#define SET_RUN_STATE(state) {running_status = (state);}
#define SET_IDLE_STATE(state) {gpio_set_val(LED_PORT, led_idle_run, state);}
@ -182,28 +175,8 @@ void uart_usb_buf_drain(uint8_t ep);
#define sprintf siprintf
#define vasprintf vasiprintf
#ifdef INLINE_GPIO
static inline void _gpio_set(uint32_t gpioport, uint16_t gpios)
{
GPIO_BSRR(gpioport) = gpios;
}
#define gpio_set _gpio_set
static inline void _gpio_clear(uint32_t gpioport, uint16_t gpios)
{
GPIO_BRR(gpioport) = gpios;
}
#define gpio_clear _gpio_clear
static inline uint16_t _gpio_get(uint32_t gpioport, uint16_t gpios)
{
return (uint16_t)GPIO_IDR(gpioport) & gpios;
}
#define gpio_get _gpio_get
#endif
#endif
void disconnect_usb(void);
void assert_boot_pin(void);
#endif

View File

@ -0,0 +1,61 @@
/*
* This file is part of the Black Magic Debug project.
*
* Copyright (C) 2015 Black Sphere Technologies Ltd.
* Written by Gareth McMullin <gareth@blacksphere.co.nz>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GPIO_H
#define __GPIO_H
#define INLINE_GPIO
#define gpio_set_val(port, pin, val) do { \
if(val) \
gpio_set((port), (pin)); \
else \
gpio_clear((port), (pin)); \
} while(0)
#ifdef INLINE_GPIO
static inline void _gpio_set(uint32_t gpioport, uint16_t gpios)
{
GPIO_BSRR(gpioport) = gpios;
#ifdef F4DISCOVERY
GPIO_BSRR(gpioport) = gpios;
#endif
}
#define gpio_set _gpio_set
static inline void _gpio_clear(uint32_t gpioport, uint16_t gpios)
{
#ifndef F4DISCOVERY
GPIO_BRR(gpioport) = gpios;
#else
GPIO_BSRR(gpioport) = gpios<<16;
GPIO_BSRR(gpioport) = gpios<<16;
#endif
}
#define gpio_clear _gpio_clear
static inline uint16_t _gpio_get(uint32_t gpioport, uint16_t gpios)
{
return (uint16_t)GPIO_IDR(gpioport) & gpios;
}
#define gpio_get _gpio_get
#endif
#endif

View File

@ -35,8 +35,8 @@
#include <alloca.h>
#include "gdb_packet.h"
#include "gpio.h"
#define INLINE_GPIO
#define CDCACM_PACKET_SIZE 64
#define BOARD_IDENT "Black Magic Probe (SWLINK), (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")"
#define BOARD_IDENT_DFU "Black Magic (Upgrade), STM8S Discovery, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")"
@ -141,14 +141,6 @@ extern volatile uint32_t timeout_counter;
extern jmp_buf fatal_error_jmpbuf;
#define gpio_set_val(port, pin, val) do { \
if(val) \
gpio_set((port), (pin)); \
else \
gpio_clear((port), (pin)); \
} while(0)
#define led_idle_run GPIO8
#define SET_RUN_STATE(state) {running_status = (state);}
#define SET_IDLE_STATE(state) {gpio_set_val(LED_PORT, led_idle_run, state);}
@ -180,27 +172,8 @@ void uart_usb_buf_drain(uint8_t ep);
#define sprintf siprintf
#define vasprintf vasiprintf
#ifdef INLINE_GPIO
static inline void _gpio_set(uint32_t gpioport, uint16_t gpios)
{
GPIO_BSRR(gpioport) = gpios;
}
#define gpio_set _gpio_set
static inline void _gpio_clear(uint32_t gpioport, uint16_t gpios)
{
GPIO_BRR(gpioport) = gpios;
}
#define gpio_clear _gpio_clear
static inline uint16_t _gpio_get(uint32_t gpioport, uint16_t gpios)
{
return (uint16_t)GPIO_IDR(gpioport) & gpios;
}
#define gpio_get _gpio_get
#endif
#endif
void disconnect_usb(void);
void assert_boot_pin(void);
#endif