浏览代码

Support new board V4 Slim

Keir Fraser 3 年之前
父节点
当前提交
ec553a0d4e

+ 19 - 0
inc/board.h

@@ -0,0 +1,19 @@
+/*
+ * board.h
+ * 
+ * Board definitions
+ * 
+ * Written & released by Keir Fraser <keir.xen@gmail.com>
+ * 
+ * This is free and unencumbered software released into the public domain.
+ * See the file COPYING for more details, or visit <http://unlicense.org>.
+ */
+
+struct board_config {
+    uint8_t hse_mhz;
+    bool_t hse_byp;
+    bool_t hs_usb;
+    bool_t flippy;
+    const struct pin_mapping *user_pins;
+    const struct pin_mapping *msel_pins;
+};

+ 1 - 0
inc/decls.h

@@ -30,6 +30,7 @@
 #endif
 #include "intrinsics.h"
 
+#include "board.h"
 #include "time.h"
 #include "timer.h"
 #include "usb.h"

+ 17 - 0
inc/mcu/at32/f4.h

@@ -23,3 +23,20 @@ void early_fatal(int blinks) __attribute__((noreturn));
 #define AHB_MHZ (SYSCLK_MHZ / 1)  /* 144MHz */
 #define APB1_MHZ (SYSCLK_MHZ / 2) /* 72MHz */
 #define APB2_MHZ (SYSCLK_MHZ / 2) /* 72MHz */
+
+enum {
+    F4SM_v4 = 0,
+    F4SM_v4_slim,
+};
+
+/* Core floppy pin assignments vary between F4 submodels (except INDEX, RDATA, 
+ * and WDATA). All the following assignments are within GPIOB. */
+struct core_floppy_pins {
+    uint8_t trk0;
+    uint8_t wrprot;
+    uint8_t dir;
+    uint8_t step;
+    uint8_t wgate;
+    uint8_t head;
+};
+extern const struct core_floppy_pins *core_floppy_pins;

+ 1 - 0
inc/mcu/at32/f4_regs.h

@@ -4,6 +4,7 @@
 #define RCC_CFGR_PLLRANGE_GT72MHZ (1u<<31)
 #define RCC_CFGR_PLLMUL_18 ((uint32_t)0x20040000)
 #define RCC_CFGR_USBPSC_3  ((uint32_t)0x08400000)
+#define RCC_CFGR_HSE_PREDIV2 (1u<<17)
 #define RCC_CFGR_APB2PSC_2 (4u<<11)
 #define RCC_CFGR_APB1PSC_2 (4u<< 8)
 

+ 0 - 6
inc/mcu/stm32/f1.h

@@ -69,12 +69,6 @@ enum {
     F1SM_plus_unbuffered,
 };
 
-struct board_config {
-    bool_t flippy;
-    const struct pin_mapping *user_pins;
-    const struct pin_mapping *msel_pins;
-};
-
 /*
  * Local variables:
  * mode: C

+ 0 - 9
inc/mcu/stm32/f7.h

@@ -99,15 +99,6 @@ enum {
     F7SM_v3,
 };
 
-struct board_config {
-    uint8_t hse_mhz;
-    bool_t hse_byp;
-    bool_t hs_usb;
-    bool_t flippy;
-    const struct pin_mapping *user_pins;
-    const struct pin_mapping *msel_pins;
-};
-
 void identify_board_config(void);
 
 /* On reset, SYSCLK=HSI at 16MHz. SYSCLK runs at 2MHz. */

+ 2 - 1
scripts/greaseweazle/tools/info.py

@@ -18,7 +18,8 @@ from greaseweazle import version
 model_id = { 1: { 0: 'F1',
                   1: 'F1 Plus',
                   2: 'F1 Plus (Unbuffered)' },
-             4: { 0: 'V4' },
+             4: { 0: 'V4',
+                  1: 'V4 Slim' },
              7: { 0: 'F7 v1',
                   1: 'F7 Plus (Ant Goffart, v1)',
                   2: 'F7 Lightning',

+ 66 - 15
src/mcu/at32f4/board.c

@@ -12,7 +12,18 @@
 #define gpio_led gpiob
 #define pin_led 13
 
-const static struct pin_mapping _msel_pins[] = {
+/* V4 pin assignments */
+
+const static struct core_floppy_pins _core_floppy_pins_v4 = {
+    .trk0   = 4, /* PB4 */
+    .wrprot = 3, /* PB3 */
+    .dir    = 8, /* PB8 */
+    .step   = 6, /* PB6 */
+    .wgate  = 7, /* PB7 */
+    .head   = 5  /* PB5 */
+};
+
+const static struct pin_mapping _msel_pins_v4[] = {
     { 10, _A,  3 },
     { 12, _B,  9 },
     { 14, _A,  4 },
@@ -20,19 +31,49 @@ const static struct pin_mapping _msel_pins[] = {
     {  0,  0,  0 }
 };
 
-const static struct pin_mapping _user_pins[] = {
+const static struct pin_mapping _user_pins_v4[] = {
     {  2, _A,  6 },
     {  4, _A,  5 },
     {  6, _A,  7 },
     {  0,  0,  0 }
 };
 
-const static struct board_config _board_config = {
-    .flippy    = TRUE,
-    .user_pins = _user_pins,
-    .msel_pins = _msel_pins
+/* V4 Slim pin assignments */
+
+const static struct core_floppy_pins _core_floppy_pins_v4_slim = {
+    .trk0   = 7, /* PB7 */
+    .wrprot = 8, /* PB8 */
+    .dir    = 5, /* PB5 */
+    .step   = 6, /* PB6 */
+    .wgate  = 3, /* PB3 */
+    .head   = 9  /* PB9 */
+};
+
+const static struct pin_mapping _msel_pins_v4_slim[] = {
+    { 10, _B,  4 },
+    { 14, _B,  1 },
+    {  0,  0,  0 }
+};
+
+const static struct pin_mapping _user_pins_v4_slim[] = {
+    {  0,  0,  0 }
+};
+
+const static struct board_config _board_config[] = {
+    [F4SM_v4] = {
+        .hse_mhz   = 8,
+        .flippy    = TRUE,
+        .user_pins = _user_pins_v4,
+        .msel_pins = _msel_pins_v4 },
+    [F4SM_v4_slim] = {
+        .hse_mhz   = 16,
+        .hse_byp   = TRUE,
+        .user_pins = _user_pins_v4_slim,
+        .msel_pins = _msel_pins_v4_slim },
 };
 
+const struct core_floppy_pins *core_floppy_pins;
+
 /* Blink the activity LED to indicate fatal error. */
 void early_fatal(int blinks)
 {
@@ -87,25 +128,35 @@ void identify_board_config(void)
     }
 
     /* Panic if the ID is unrecognised. */
-    if (id != 0)
+    if (id >= ARRAY_SIZE(_board_config))
         early_fatal(2);
 
     /* Single static config. */
     gw_info.hw_submodel = id;
-    board_config = &_board_config;
+    board_config = &_board_config[id];
 }
 
 static void mcu_board_init(void)
 {
-    gpio_pull_up_pins(gpioa, 0x0101); /* PA0,8 */
-    gpio_pull_up_pins(gpiob, 0x1803); /* PB0-1,11-12 */
-    gpio_pull_up_pins(gpioc, 0xffff); /* PC0-15 */
+    switch (gw_info.hw_submodel) {
+    case F4SM_v4:
+        gpio_pull_up_pins(gpioa, 0x0101); /* PA0,8 */
+        gpio_pull_up_pins(gpiob, 0x1803); /* PB0-1,11-12 */
+        gpio_pull_up_pins(gpioc, 0xffff); /* PC0-15 */
+        core_floppy_pins = &_core_floppy_pins_v4;
+        break;
+
+    case F4SM_v4_slim:
+        gpio_pull_up_pins(gpioa, 0x01fb); /* PA0-1,3-8 */
+        gpio_pull_up_pins(gpiob, 0x0800); /* PB11 */
+        gpio_pull_up_pins(gpioc, 0xffff); /* PC0-15 */
+        core_floppy_pins = &_core_floppy_pins_v4_slim;
+        break;
+    }
 
     /* Flippy TRK0_DISABLE output: Set inactive (LOW). */
-    gpio_configure_pin(gpiob, 14, GPO_pushpull(IOSPD_LOW, LOW));
-
-    /* /RDY input line is externally pulled up. */
-    gpio_configure_pin(gpiob, 15, GPI_floating);
+    if (board_config->flippy)
+        gpio_configure_pin(gpiob, 14, GPO_pushpull(IOSPD_LOW, LOW));
 }
 
 /*

+ 23 - 11
src/mcu/at32f4/floppy.c

@@ -20,19 +20,19 @@
 #define gpio_index  gpiob
 #define pin_index   10 /* PB10 */
 #define gpio_trk0   gpiob
-#define pin_trk0    4 /* PB4 */
+#define pin_trk0    (core_floppy_pins->trk0)
 #define gpio_wrprot gpiob
-#define pin_wrprot  3 /* PB3 */
+#define pin_wrprot  (core_floppy_pins->wrprot)
 
 /* Output pins. */
 #define gpio_dir   gpiob
-#define pin_dir    8  /* PB8 */
+#define pin_dir    (core_floppy_pins->dir)
 #define gpio_step  gpiob
-#define pin_step   6  /* PB6 */
+#define pin_step   (core_floppy_pins->step)
 #define gpio_wgate gpiob
-#define pin_wgate  7  /* PB7 */
+#define pin_wgate  (core_floppy_pins->wgate)
 #define gpio_head  gpiob
-#define pin_head   5  /* PB5 */
+#define pin_head   (core_floppy_pins->head)
 
 /* RDATA: Pin A15, Timer 2 Channel 1, DMA1 Channel 5. */
 #define gpio_rdata  gpioa
@@ -146,17 +146,29 @@ static void dma_wdata_start(void)
 
 static uint8_t mcu_get_floppy_pin(unsigned int pin, uint8_t *p_level)
 {
-    if (pin == 34) {
-        *p_level = gpio_read_pin(gpiob, 15);
-        return ACK_OKAY;
+    switch (gw_info.hw_submodel) {
+    case F4SM_v4:
+        if (pin == 34) {
+            *p_level = gpio_read_pin(gpiob, 15);
+            return ACK_OKAY;
+        }
+        break;
+    case F4SM_v4_slim:
+        if (pin == 34) {
+            *p_level = gpio_read_pin(gpiob, 12);
+            return ACK_OKAY;
+        }
+        break;
     }
     return ACK_BAD_PIN;
 }
 
 static void flippy_trk0_sensor(bool_t level)
 {
-    gpio_write_pin(gpiob, 14, level);
-    delay_us(10);
+    if (board_config->flippy) {
+        gpio_write_pin(gpiob, 14, level);
+        delay_us(10);
+    }
 }
 
 /*

+ 15 - 2
src/mcu/at32f4/stm32.c

@@ -15,6 +15,7 @@ unsigned int at32f4_series;
 static void clock_init(void)
 {
     uint32_t cfgr;
+    int i;
 
     if (at32f4_series == AT32F415) {
         /* Flash controller: reads require 4 wait states at 144MHz. */
@@ -22,9 +23,18 @@ static void clock_init(void)
     }
 
     /* Start up the external oscillator. */
+    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);
+    }
 
     /* PLLs, scalers, muxes. */
     cfgr = (RCC_CFGR_PLLMUL_18 |        /* PLL = 18*8MHz = 144MHz */
@@ -34,6 +44,9 @@ static void clock_init(void)
             RCC_CFGR_APB2PSC_2 |        /* APB2 = 144/2MHz = 72MHz */
             RCC_CFGR_APB1PSC_2);        /* APB1 = 144/2MHz = 72MHz */
 
+    if (board_config->hse_mhz == 16)
+        cfgr |= RCC_CFGR_HSE_PREDIV2;
+
     switch (at32f4_series) {
     case AT32F403:
         cfgr |= RCC_CFGR_PLLRANGE_GT72MHZ;

+ 5 - 1
src/mcu/at32f4/testmode.c

@@ -61,7 +61,11 @@ void testmode_wdat_osc_off(void)
 
 uint8_t testmode_init(void)
 {
-    return ACK_OKAY;
+    switch (gw_info.hw_submodel) {
+    case F4SM_v4:
+        return ACK_OKAY;
+    }
+    return ACK_BAD_COMMAND;
 }
 
 /*

+ 1 - 1
src/mcu/stm32f1/board.c

@@ -140,7 +140,7 @@ static void mcu_board_init(void)
     switch (gw_info.hw_submodel) {
     case F1SM_plus:
     case F1SM_plus_unbuffered:
-        /* /RDY input line is externally pulled up. */
+        /* Floppy pin 34 input line is externally pulled up. */
         pu[_A] &= ~(1u << 8); /* PA8 */
         break;
     }

+ 1 - 1
src/mcu/stm32f7/board.c

@@ -218,7 +218,7 @@ static void mcu_board_init(void)
 
     case F7SM_v3:
     case F7SM_lightning_plus:
-        /* /RDY input line is externally pulled up. */
+        /* Floppy pin 34 input line is externally pulled up. */
         pu[_C] &= ~(1u << 2); /* PC2 */
         break;