Change the ST-Link SRST function to use libopencm3 helper functions and fix waiting for the pin-state, change init to use the SRST function for reset de-assertion

This commit is contained in:
Rik van der Heijden 2018-08-26 21:48:03 +02:00
parent c5c0783337
commit 95053b3b4e
1 changed files with 10 additions and 15 deletions

View File

@ -68,9 +68,8 @@ void 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);
gpio_set(SRST_PORT, srst_pin);
gpio_set_mode(SRST_PORT, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_OPENDRAIN, srst_pin);
platform_srst_set_val(false);
gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, led_idle_run);
@ -90,21 +89,17 @@ void platform_init(void)
void platform_srst_set_val(bool assert)
{
uint32_t crl = GPIOB_CRL;
uint32_t shift = (srst_pin == GPIO0) ? 0 : 4;
uint32_t mask = 0xf << shift;
crl &= ~mask;
if (assert) {
/* Set SRST as Open-Drain, 50 Mhz, low.*/
GPIOB_BRR = srst_pin;
GPIOB_CRL = crl | (7 << shift);
gpio_set_mode(SRST_PORT, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_OPENDRAIN, srst_pin);
gpio_clear(SRST_PORT, srst_pin);
while (gpio_get(SRST_PORT, srst_pin)) {};
} else {
/* Set SRST as input, pull-up.
* SRST might be unconnected, e.g on Nucleo-P!*/
GPIOB_CRL = crl | (8 << shift);
GPIOB_BSRR = srst_pin;
gpio_set_mode(SRST_PORT, GPIO_MODE_INPUT,
GPIO_CNF_INPUT_PULL_UPDOWN, srst_pin);
gpio_set(SRST_PORT, srst_pin);
while (!gpio_get(SRST_PORT, srst_pin)) {};
}
while (gpio_get(SRST_PORT, srst_pin) == assert) {};
}
bool platform_srst_get_val()