Merge pull request from rikvdh/feature/readable-reset-stlink

Change the ST-Link SRST reset function
This commit is contained in:
Gareth McMullin 2018-09-07 08:13:48 +12:00 committed by GitHub
commit 3a598a0cf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 15 deletions
src/platforms/stlink

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()