/* * This file is part of the Black Magic Debug project. * * Copyright (C) 2011 Black Sphere Technologies Ltd. * Written by Gareth McMullin * * 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 . */ /* This file implements the platform specific functions for the STM32 * implementation. */ #ifndef __PLATFORM_H #define __PLATFORM_H #include #include #include "gdb_packet.h" /* Important pin mappings for STM32 implementation: * * LED0 = PB2 (Yellow LED : Running) * LED1 = PB10 (Yellow LED : Idle) * LED2 = PB11 (Red LED : Error) * * TPWR = RB0 (input) * nTRST = PB1 * SRST_OUT = PA2 * TDI = PA3 * TMS = PA4 (input for SWDP) * TCK = PA5 * TDO = PA6 (input) * nSRST = PA7 (input) * * USB cable pull-up: PA8 // was PA10 on prototype * Force DFU mode button: PB12 */ /* Hardware definitions... */ #ifndef LIGHT # define JTAG_PORT GPIOA # define TDI_PIN GPIO3 # define TMS_PIN GPIO4 # define TCK_PIN GPIO5 # define TDO_PIN GPIO6 # define SWDP_PORT JTAG_PORT # define SWDIO_PIN TMS_PIN # define SWCLK_PIN TCK_PIN # define USB_PU_PORT GPIOA # define USB_PU_PIN GPIO8 # define LED_PORT GPIOB # define LED_RUN GPIO2 # define LED_IDLE GPIO10 # define LED_ERROR GPIO11 #else # define JTAG_PORT GPIOA # define TDI_PIN GPIO3 # define TMS_PIN GPIO2 # define TCK_PIN GPIO7 # define TDO_PIN GPIO6 # define SWDP_PORT JTAG_PORT # define SWDIO_PIN TMS_PIN # define SWCLK_PIN TCK_PIN # define USB_PU_PORT GPIOA # define USB_PU_PIN GPIO15 #endif #define DEBUG(...) extern uint8_t running_status; extern volatile uint32_t timeout_counter; extern jmp_buf fatal_error_jmpbuf; extern const char *morse_msg; #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, state);} #define SET_ERROR_STATE(state) {gpio_set_val(LED_PORT, LED_ERROR, state);} #define PLATFORM_SET_FATAL_ERROR_RECOVERY() {setjmp(fatal_error_jmpbuf);} #define PLATFORM_FATAL_ERROR(error) { \ if(running_status) gdb_putpacketz("X1D"); \ else gdb_putpacketz("EFF"); \ running_status = 0; \ TARGET_LIST_FREE(); \ cur_target = last_target = NULL; \ morse("TARGET LOST.", 1); \ longjmp(fatal_error_jmpbuf, (error)); \ } int platform_init(void); void morse(const char *msg, char repeat); #endif