swlink: Handle LED.

This commit is contained in:
Uwe Bonnes 2018-09-22 19:26:07 +02:00 committed by Gareth McMullin
parent 06272e0a59
commit 184ef991bf
4 changed files with 36 additions and 10 deletions

View File

@ -35,6 +35,8 @@
#include <libopencm3/usb/usbd.h>
#include <libopencm3/stm32/f1/adc.h>
uint32_t led_error_port;
uint16_t led_error_pin;
static uint8_t rev;
int platform_hwversion(void)
@ -75,8 +77,13 @@ void platform_init(void)
switch (rev) {
case 0:
/* LED GPIO already set in detect_rev()*/
led_error_port = GPIOA;
led_error_pin = GPIO8;
break;
case 1:
led_error_port = GPIOC;
led_error_pin = GPIO13;
/* Enable MCO Out on PA8*/
RCC_CFGR &= ~(0xf << 24);
RCC_CFGR |= (RCC_CFGR_MCO_HSE << 24);
@ -86,9 +93,6 @@ void platform_init(void)
}
platform_srst_set_val(false);
gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, LED_IDLE_RUN);
/* Remap TIM2 TIM2_REMAP[1]
* TIM2_CH1_ETR -> PA15 (TDI, set as output above)
* TIM2_CH2 -> PB3 (TDO)
@ -137,3 +141,15 @@ const char *platform_target_voltage(void)
{
return "unknown";
}
void set_idle_state(int state)
{
switch (rev) {
case 0:
gpio_set_val(GPIOA, GPIO8, state);
break;
case 1:
gpio_set_val(GPIOC, GPIO13, (!state));
break;
}
}

View File

@ -53,8 +53,6 @@
#define SWDIO_PIN TMS_PIN
#define SWCLK_PIN TCK_PIN
#define LED_PORT GPIOA
#define LED_IDLE_RUN GPIO8
/* Use PC14 for a "dummy" uart led. So we can observere at least with scope*/
#define LED_PORT_UART GPIOC
#define LED_UART GPIO14
@ -125,9 +123,12 @@ int usbuart_debug_write(const char *buf, size_t len);
# define DEBUG(...)
#endif
#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(x)
#define LED_PORT GPIOC
#define LED_IDLE_RUN GPIO15
#define SET_RUN_STATE(state)
#define SET_ERROR_STATE(state)
extern void set_idle_state(int state);
#define SET_IDLE_STATE(state) set_idle_state(state)
extern uint8_t detect_rev(void);

View File

@ -51,6 +51,7 @@ uint8_t detect_rev()
gpio_set(GPIOB, GPIO9);
switch (rev) {
case 0:
gpio_clear(GPIOA, GPIO8);
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO8);
break;

View File

@ -27,6 +27,7 @@
#include "platform.h"
uint32_t app_address = 0x08002000;
uint32_t rev;
void dfu_detach(void)
{
@ -45,7 +46,7 @@ int main(void)
{
/* Check the force bootloader pin*/
bool normal_boot = 0;
int rev = detect_rev();
rev = detect_rev();
switch (rev) {
case 0:
/* For Stlink on STM8S check that CN7 PIN 4 RESET# is
@ -94,5 +95,12 @@ void dfu_event(void)
void sys_tick_handler(void)
{
gpio_toggle(GPIOA, GPIO8);
switch (rev) {
case 0:
gpio_toggle(GPIOA, GPIO8);
break;
case 1:
gpio_toggle(GPIOC, GPIO13);
break;
}
}