Parcourir la source

blinky: Log serial, flash size, and ID codes.
Warn on non-zero ID code as STM10xx8/B is supposed to have an erratum.

Keir Fraser il y a 5 ans
Parent
commit
a537b56420
3 fichiers modifiés avec 31 ajouts et 0 suppressions
  1. 2 0
      inc/stm32f10x.h
  2. 7 0
      inc/stm32f10x_regs.h
  3. 22 0
      src/blinky.c

+ 2 - 0
inc/stm32f10x.h

@@ -13,6 +13,7 @@
 #define STK volatile struct stk * const
 #define SCB volatile struct scb * const
 #define NVIC volatile struct nvic * const
+#define DBG volatile struct dbg * const
 #define FLASH volatile struct flash * const
 #define PWR volatile struct pwr * const
 #define BKP volatile struct bkp * const
@@ -35,6 +36,7 @@
 static STK stk = (struct stk *)STK_BASE;
 static SCB scb = (struct scb *)SCB_BASE;
 static NVIC nvic = (struct nvic *)NVIC_BASE;
+static DBG dbg = (struct dbg *)DBG_BASE;
 static FLASH flash = (struct flash *)FLASH_BASE;
 static PWR pwr = (struct pwr *)PWR_BASE;
 static BKP bkp = (struct bkp *)BKP_BASE;

+ 7 - 0
inc/stm32f10x_regs.h

@@ -102,6 +102,13 @@ struct nvic {
 
 #define NVIC_BASE 0xe000e100
 
+struct dbg {
+    uint32_t mcu_idcode; /* 00: MCU ID code */
+    uint32_t mcu_cr;     /* 04: Debug MCU configuration */
+};
+
+#define DBG_BASE 0xe0042000
+
 /* Flash memory interface */
 struct flash {
     uint32_t acr;      /* 00: Flash access control */

+ 22 - 0
src/blinky.c

@@ -209,6 +209,8 @@ fail:
 
 int main(void)
 {
+    uint32_t id, dev_id, rev_id;
+
     /* Relocate DATA. Initialise BSS. */
     if (_sdat != _ldat)
         memcpy(_sdat, _ldat, _edat-_sdat);
@@ -226,6 +228,26 @@ int main(void)
     gpio_configure_pin(gpiob, 12, GPO_opendrain(_2MHz, HIGH));
     gpio_configure_pin(gpioc, 13, GPO_opendrain(_2MHz, HIGH));
 
+    printk("Serial = %04x:%04x:%04x:%04x:%04x:%04x\n",
+           *(volatile uint16_t *)0x1ffff7e8,
+           *(volatile uint16_t *)0x1ffff7ea,
+           *(volatile uint16_t *)0x1ffff7ec,
+           *(volatile uint16_t *)0x1ffff7ee,
+           *(volatile uint16_t *)0x1ffff7f0,
+           *(volatile uint16_t *)0x1ffff7f2);
+    printk("Flash Size  = %ukB\n", *(volatile uint16_t *)0x1ffff7e0);
+
+    id = dbg->mcu_idcode;
+    dev_id = id & 0xfff;
+    rev_id = id >> 16;
+    printk("Device ID = 0x%04x\n", dev_id);
+    printk("Revision  = 0x%04x\n", rev_id);
+    if (id != 0) {
+        /* Erratum 2.3 in STM32F10xx8/B Errata Sheet. */
+        /* I feel bad outright failing on this, so just warn. */
+        printk("**WARNING**: 10xx8/B device returned valid IDCODE! Fake?\n");
+    }
+
     /* Test I2C peripherals. */
 #if NR_I2C >= 1
     rcc->apb1enr |= RCC_APB1ENR_I2C1EN;