Ver código fonte

f7: Flash status LED if external oscillator doesn't start.

Keir Fraser 4 anos atrás
pai
commit
3276cf7c38
3 arquivos alterados com 15 adições e 9 exclusões
  1. 4 0
      inc/stm32/f7.h
  2. 1 5
      src/f7/board.c
  3. 10 4
      src/f7/stm32.c

+ 4 - 0
inc/stm32/f7.h

@@ -116,6 +116,10 @@ void identify_board_config(void);
 
 GPIO gpio_from_id(uint8_t id);
 
+void early_fatal(int blinks) __attribute__((noreturn));
+#define early_delay_ms(ms) (delay_ticks((ms)*2000))
+#define early_delay_us(us) (delay_ticks((us)*2))
+
 /*
  * Local variables:
  * mode: C

+ 1 - 5
src/f7/board.c

@@ -84,12 +84,8 @@ const static struct board_config _board_config[] = {
 };
 const struct board_config *board_config;
 
-#define early_delay_ms(ms) (delay_ticks((ms)*2000))
-#define early_delay_us(ms) (delay_ticks((ms)*2))
-
 /* Blink the activity LED to indicate fatal error. */
-static void early_fatal(int blinks) __attribute__((noreturn));
-static void early_fatal(int blinks)
+void early_fatal(int blinks)
 {
     int i;
     rcc->ahb1enr |= RCC_AHB1ENR_GPIOBEN;

+ 10 - 4
src/f7/stm32.c

@@ -9,11 +9,10 @@
  * See the file COPYING for more details, or visit <http://unlicense.org>.
  */
 
-#define early_delay_us(ms) (delay_ticks((ms)*2))
-
 static void clock_init(void)
 {
     unsigned int hse = board_config->hse_mhz;
+    int i;
 
     /* Disable all peripheral clocks except the essentials before enabling 
      * Over-drive mode (see note in RM0431, p102). We still need access to RAM
@@ -26,8 +25,15 @@ static void clock_init(void)
     if (board_config->hse_byp)
         rcc->cr |= RCC_CR_HSEBYP;
     rcc->cr |= RCC_CR_HSEON;
-    while (!(rcc->cr & RCC_CR_HSERDY))
-        cpu_relax();
+
+    /* Wait up to approximately one second for the oscillator to start. 
+     * If it doesn't start, we indicate this via the status LED. */
+    i = 0;
+    while (!(rcc->cr & RCC_CR_HSERDY)) {
+        early_delay_ms(1);
+        if (i++ >= 1000)
+            early_fatal(3);
+    }
 
     /* Main PLL. */
     rcc->pllcfgr = (RCC_PLLCFGR_PLLSRC_HSE | /* PLLSrc = HSE */