stlink: add support for SRST handling

This enables SRST signals in open drain mode for both stlinkv1 and
stlinkv2 hardware platforms.

Signed-off-by: Paul Fertser <fercerpav@gmail.com>
This commit is contained in:
Paul Fertser 2013-05-05 00:46:48 +04:00 committed by Gareth McMullin
parent e0fc21a2a7
commit cdaed128c1
2 changed files with 23 additions and 0 deletions

View File

@ -98,6 +98,11 @@ int platform_init(void)
GPIO_CNF_OUTPUT_PUSHPULL, TCK_PIN);
gpio_set_mode(TDI_PORT, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, TDI_PIN);
uint16_t srst_pin = platform_hwversion() == 0 ?
SRST_PIN_V1 : SRST_PIN_V2;
gpio_set(SRST_PORT, srst_pin);
gpio_set_mode(SRST_PORT, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_OPENDRAIN, srst_pin);
gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, led_idle_run);
@ -127,6 +132,16 @@ void platform_delay(uint32_t delay)
while(timeout_counter);
}
void platform_srst_set_val(bool assert)
{
uint16_t pin;
pin = platform_hwversion() == 0 ? SRST_PIN_V1 : SRST_PIN_V2;
if (assert)
gpio_clear(SRST_PORT, pin);
else
gpio_set(SRST_PORT, pin);
}
void sys_tick_handler(void)
{
if(running_status)

View File

@ -79,6 +79,10 @@ extern usbd_device *usbdev;
#define SWDIO_PIN TMS_PIN
#define SWCLK_PIN TCK_PIN
#define SRST_PORT GPIOB
#define SRST_PIN_V1 GPIO1
#define SRST_PIN_V2 GPIO0
#define LED_PORT GPIOA
/* Use PC14 for a "dummy" uart led. So we can observere at least with scope*/
#define LED_PORT_UART GPIOC
@ -98,6 +102,9 @@ extern usbd_device *usbdev;
gpio_set_mode(USBUSART_PORT, GPIO_MODE_OUTPUT_2_MHZ, \
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, USBUSART_TX_PIN);
#define SRST_SET_VAL(x) \
platform_srst_set_val(x)
#define USB_DRIVER stm32f103_usb_driver
#define USB_IRQ NVIC_USB_LP_CAN_RX0_IRQ
#define USB_ISR usb_lp_can_rx0_isr
@ -152,6 +159,7 @@ int platform_init(void);
void morse(const char *msg, char repeat);
const char *platform_target_voltage(void);
void platform_delay(uint32_t delay);
void platform_srst_set_val(bool assert);
/* <cdcacm.c> */
void cdcacm_init(void);