Browse Source

Activity LED (C13 on Blue Pill, B13 on F7 board):
1. Lit when a USB command is in progress.
2. Blinks when enumerated but idle in bootloader mode (200ms toggle)

Keir Fraser 5 years ago
parent
commit
fec5d4c2df
6 changed files with 55 additions and 0 deletions
  1. 2 0
      bootloader/Makefile
  2. 3 0
      inc/stm32/f1_regs.h
  3. 1 0
      inc/util.h
  4. 17 0
      src/board.c
  5. 6 0
      src/floppy.c
  6. 26 0
      src/fw_update.c

+ 2 - 0
bootloader/Makefile

@@ -8,6 +8,8 @@ OBJS += fw_update.o
 OBJS += string.o
 OBJS += cortex.o
 OBJS += stm32$(stm32).o
+OBJS += time.o
+OBJS += timer.o
 OBJS += util.o
 OBJS += fpec_$(stm32).o
 

+ 3 - 0
inc/stm32/f1_regs.h

@@ -202,6 +202,9 @@ struct gpio {
 #define _2MHz  2
 #define _10MHz 1
 #define _50MHz 3
+#define IOSPD_LOW  _2MHz
+#define IOSPD_MED  _10MHz
+#define IOSPD_HIGH _50MHz
 #define LOW  0
 #define HIGH 1
 

+ 1 - 0
inc/util.h

@@ -76,6 +76,7 @@ int snprintf(char *str, size_t size, const char *format, ...)
 
 /* Board-specific callouts */
 void board_init(void);
+void act_led(bool_t on);
 
 #ifndef NDEBUG
 

+ 17 - 0
src/board.c

@@ -9,6 +9,14 @@
  * See the file COPYING for more details, or visit <http://unlicense.org>.
  */
 
+#if STM32F == 1
+#define gpio_led gpioc
+#define pin_led 13
+#elif STM32F == 7
+#define gpio_led gpiob
+#define pin_led 13
+#endif
+
 /* Pull up currently unused and possibly-floating pins. */
 static void gpio_pull_up_pins(GPIO gpio, uint16_t mask)
 {
@@ -37,6 +45,15 @@ void board_init(void)
     /* Pull up unused debug pins (A9,A10 = serial console). */
     gpio_pull_up_pins(gpioa, (1u<<9) | (1u<<10));
 #endif
+
+    /* Activity LED is active low. */
+    gpio_configure_pin(gpio_led, pin_led, GPO_pushpull(IOSPD_LOW, HIGH));
+}
+
+/* Set the activity LED status. */
+void act_led(bool_t on)
+{
+    gpio_write_pin(gpio_led, pin_led, on ? LOW : HIGH);
 }
 
 /*

+ 6 - 0
src/floppy.c

@@ -215,6 +215,8 @@ static void floppy_reset(void)
     write_pin(step,   FALSE);
     write_pin(wgate,  FALSE);
     write_pin(side,   FALSE);
+
+    act_led(FALSE);
 }
 
 void floppy_init(void)
@@ -263,6 +265,8 @@ static void floppy_end_command(void *ack, unsigned int ack_len)
     auto_off_arm();
     usb_write(EP_TX, ack, ack_len);
     u_cons = u_prod = 0;
+    if (floppy_state == ST_command_wait)
+        act_led(FALSE);
     if (ack_len == USB_FS_MPS) {
         ASSERT(floppy_state == ST_command_wait);
         floppy_state = ST_zlp;
@@ -752,6 +756,7 @@ static void process_command(void)
     uint8_t resp_sz = 2;
 
     auto_off_arm();
+    act_led(TRUE);
 
     switch (cmd) {
     case CMD_GET_INFO: {
@@ -875,6 +880,7 @@ static void floppy_configure(void)
     floppy_flux_end();
     floppy_state = ST_command_wait;
     u_cons = u_prod = 0;
+    act_led(FALSE);
 }
 
 void floppy_process(void)

+ 26 - 0
src/fw_update.c

@@ -21,6 +21,11 @@
 
 int EXC_reset(void) __attribute__((alias("main")));
 
+static struct {
+    time_t time;
+    bool_t state;
+} blink;
+
 static enum {
     ST_inactive,
     ST_command_wait,
@@ -38,13 +43,22 @@ static struct gw_info gw_info = {
     .hw_type = STM32F
 };
 
+static void blink_init(void)
+{
+    blink.time = time_now();
+    blink.state = FALSE;
+    act_led(FALSE);
+}
+
 static void update_reset(void)
 {
+    blink_init();
     state = ST_inactive;
 }
 
 static void update_configure(void)
 {
+    blink_init();
     state = ST_command_wait;
     u_prod = 0;
 }
@@ -56,6 +70,8 @@ const struct usb_class_ops usb_cdc_acm_ops = {
 
 static void end_command(void *ack, unsigned int ack_len)
 {
+    if (state == ST_command_wait)
+        blink_init();
     usb_write(EP_TX, ack, ack_len);
     u_prod = 0;
 }
@@ -118,6 +134,8 @@ static void process_command(void)
     uint8_t len = u_buf[1];
     uint8_t resp_sz = 2;
 
+    act_led(TRUE);
+
     switch (cmd) {
     case CMD_GET_INFO: {
         uint8_t idx = u_buf[2];
@@ -168,11 +186,18 @@ bad_command:
 static void update_process(void)
 {
     int len;
+    time_t now = time_now();
 
     switch (state) {
 
     case ST_command_wait:
 
+        if (time_diff(blink.time, now) > time_ms(200)) {
+            blink.time = now;
+            blink.state ^= 1;
+            act_led(blink.state);
+        }
+
         len = ep_rx_ready(EP_RX);
         if ((len >= 0) && (len < (sizeof(u_buf)-u_prod))) {
             usb_read(EP_RX, &u_buf[u_prod], len);
@@ -277,6 +302,7 @@ int main(void)
     }
 
     stm32_init();
+    time_init();
     console_init();
     console_crash_on_input();
     board_init();