altos: Place STM config values at fixed addresses for re-use
authorKeith Packard <keithp@keithp.com>
Tue, 17 Jul 2012 08:24:52 +0000 (01:24 -0700)
committerKeith Packard <keithp@keithp.com>
Tue, 17 Jul 2012 08:24:52 +0000 (01:24 -0700)
Just like cc1111, stick the serial number and radio calibration values
at known fixed addresses so that when re-flashing the board, we can go
find the existing values.

Signed-off-by: Keith Packard <keithp@keithp.com>
13 files changed:
ao-tools/ao-load/ao-load.c
src/avr/ao_arch.h
src/avr/ao_romconfig.c
src/cc1111/ao_arch.h
src/core/ao_product.c
src/drivers/ao_cc1120.c
src/drivers/ao_companion.c
src/megametrum-v0.1/Makefile
src/megametrum-v0.1/ao_pins.h
src/stm-bringup/Makefile
src/stm/altos.ld
src/stm/ao_arch.h
src/stm/ao_romconfig.c

index 1b729d393a7bba5f7f3942f4768b3bee480e946c..e3cef4a5664f61c8d06959482dc48db8a342a08d 100644 (file)
@@ -197,7 +197,7 @@ main (int argc, char **argv)
 
        serial = strtoul(serial_string, NULL, 0);
        if (!serial)
-(argv[0]);
+               usage(argv[0]);
 
        serial_int[0] = serial & 0xff;
        serial_int[1] = (serial >> 8) & 0xff;
index c775dab649a7d38068fa88a46f9815f46024a603..a14d0adecc6d7fc3d0cb3d5e0965768c15eb4818 100644 (file)
@@ -67,7 +67,11 @@ extern void putchar(char c);
 extern char getchar(void);
 extern void ao_avr_stdio_init(void);
 
-extern const uint16_t ao_serial_number;
+#define AO_ROMCONFIG_VERSION   2
+
+#define AO_ROMCONFIG_SYMBOL(a) const
+
+extern AO_ROMCONFIG_SYMBOL(0) uint16_t ao_serial_number;
 
 #define AVR_PUSH8(stack, val)  (*((stack)--) = (val))
 
index bbb677e2e045dcd9dbb0fb795cf9e079128c5b41..ecc19c76d44c42b16952cc26930c27561d7bc190 100644 (file)
@@ -17,4 +17,4 @@
 
 #include "ao.h"
 
-const uint16_t ao_serial_number = 0;
+AO_ROMCONFIG_SYMBOL (0) uint16_t ao_serial_number = 0;
index 8d9e49529769fc9bdf6836a731380c6ca7d96a96..06b04b93651d75fcad23fd40433ad3a0d9fd5622 100644 (file)
 
 #define AO_ROMCONFIG_VERSION   2
 
-extern __code __at (0x00a0) uint16_t ao_romconfig_version;
-extern __code __at (0x00a2) uint16_t ao_romconfig_check;
-extern __code __at (0x00a4) uint16_t ao_serial_number;
-extern __code __at (0x00a6) uint32_t ao_radio_cal;
+#define AO_ROMCONFIG_SYMBOL(a) __code __at(a)
+
+extern AO_ROMCONFIG_SYMBOL(0x00a0) uint16_t ao_romconfig_version;
+extern AO_ROMCONFIG_SYMBOL(0x00a2) uint16_t ao_romconfig_check;
+extern AO_ROMCONFIG_SYMBOL(0x00a4) uint16_t ao_serial_number;
+extern AO_ROMCONFIG_SYMBOL(0x00a6) uint32_t ao_radio_cal;
 
 #ifndef HAS_USB
 #error Please define HAS_USB
index 67ec67935fc7b20fb212a80ff194a9ea7f85a308..ec91b9783f091151358d588ddab214e819cb21aa 100644 (file)
@@ -29,7 +29,7 @@ const char ao_product[] = AO_iProduct_STRING;
 #if HAS_USB
 #include "ao_usb.h"
 /* USB descriptors in one giant block of bytes */
-__code __at(0x00aa) uint8_t ao_usb_descriptors [] =
+AO_ROMCONFIG_SYMBOL(0x00aa) uint8_t ao_usb_descriptors [] =
 {
        /* Device descriptor */
        0x12,
index 569df3b7c80ad92416130ac6391dda1130f42f18..97a434d8975131338034ad1783c1e0e61bae5c7a 100644 (file)
@@ -29,7 +29,7 @@ uint8_t ao_radio_in_recv;
 #define CC1120_DEBUG   AO_FEC_DEBUG
 #define CC1120_TRACE   0
 
-const uint32_t ao_radio_cal = 0x6ca333;
+extern const uint32_t  ao_radio_cal;
 
 #define FOSC   32000000
 
index 6e0bd2ec15691a95f89bfbfeb59b08c517657def..c749adea9de2f2da295bf2aa64f28c9642ed1103 100644 (file)
@@ -68,7 +68,7 @@ ao_companion_get_setup(void)
        ao_spi_recv(&ao_companion_setup, sizeof (ao_companion_setup), AO_COMPANION_SPI_BUS);
        COMPANION_DESELECT();
        return (ao_companion_setup.board_id ==
-               ~ao_companion_setup.board_id_inverse);
+               (uint16_t) ~ao_companion_setup.board_id_inverse);
 }
 
 static void
@@ -116,6 +116,8 @@ ao_companion_status(void) __reentrant
 {
        uint8_t i;
        printf("Companion running: %d\n", ao_companion_running);
+       if (!ao_companion_running)
+               return;
        printf("device: %d\n", ao_companion_setup.board_id);
        printf("update period: %d\n", ao_companion_setup.update_period);
        printf("channels: %d\n", ao_companion_setup.channels);
index a519609e8038c8b35dbeacbc4520f024d57bfcff..4a4c983ac544d701f4299851e7f5d11c885fddb6 100644 (file)
@@ -92,7 +92,7 @@ OBJ=$(SRC:.c=.o)
 
 all: $(PROG)
 
-$(PROG): Makefile $(OBJ)
+$(PROG): Makefile $(OBJ) altos.ld
        $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(OBJ) $(SAT_CLIB) -lgcc
 
 ../altitude.h: make-altitude
index 2c438f6c9f53dba8f82a6ce4244fbdb49c370b42..6b0f9832f669696ce411c09a4a66a83f6cd56527 100644 (file)
@@ -268,6 +268,10 @@ struct ao_adc {
  * Radio (cc1120)
  */
 
+/* gets pretty close to 434.550 */
+
+#define AO_RADIO_CAL_DEFAULT   0x6ca333
+
 #define AO_FEC_DEBUG           0
 #define AO_CC1120_SPI_CS_PORT  (&stm_gpioc)
 #define AO_CC1120_SPI_CS_PIN   5
index 01c8061432b6f4d7caf4c8b0d5ec7295922f12f4..d45e836d6a822967c03771f249e622d525943631 100644 (file)
@@ -16,7 +16,7 @@ DEF_CFLAGS=-g -std=gnu99 -Os -mlittle-endian -mthumb -ffreestanding -nostdlib -I
 
 # to run from SRAM
 LD_FLAGS_RAM=-L../stm -Wl,-Taltos-ram.ld
-LD_FLAGS=-L../stm -Wl,-Taltos.ld
+LD_FLAGS=-L../stm -Wl,-Tbringup.ld
 
 CFLAGS=$(DEF_CFLAGS) -mcpu=cortex-m3 -DCONFIG_STM32L_DISCOVERY
 
@@ -28,7 +28,7 @@ all: bringup-ram.elf bringup.elf
 %.bin: %.elf
        $(OBJCOPY) -O binary $^ $@
 
-bringup.elf: $(OBJ) $(C_LIB) altos.ld
+bringup.elf: $(OBJ) $(C_LIB) bringup.ld
        $(CC) $(CFLAGS) $(LD_FLAGS) -o $@ $(OBJ) $(C_LIB) -lgcc
 
 bringup-ram.elf: $(OBJ) $(C_LIB) altos-ram.ld
index f5a84f4c2c658931dd409351b4c1b8e1c1a90ec6..f78a45d677e335570a735097c621903939b792b6 100644 (file)
@@ -25,18 +25,22 @@ INCLUDE registers.ld
 EXTERN (stm_interrupt_vector)
 
 SECTIONS {
-       . = ORIGIN(rom);
-
        /*
         * Rom contents
         */
 
-       __text_start__ = .;
-
-       .text : {
+       .text ORIGIN(rom) : {
+               __text_start__ = .;
                *(.interrupt)   /* Interrupt vectors */
+
+               . = ORIGIN(rom) + 0x100;
+
+               ao_romconfig.o(.romconfig*)
+               ao_product.o(.romconfig*)
+
                *(.text*)       /* Executable code */
                *(.rodata*)     /* Constants */
+
        } > rom
 
        .ARM.exidx : {
@@ -44,12 +48,10 @@ SECTIONS {
                __text_end__ = .;
        } > rom
 
-       . = ORIGIN(ram);
-       __data_start__ = .;
-
        /* Data -- relocated to RAM, but written to ROM
         */
-       .data : AT (ADDR(.ARM.exidx) + SIZEOF (.ARM.exidx)) {
+       .data ORIGIN(ram) : AT (ADDR(.ARM.exidx) + SIZEOF (.ARM.exidx)) {
+               __data_start__ = .;
                *(.data)        /* initialized data */
                __data_end__ = .;
                __bss_start__ = .;
@@ -63,7 +65,6 @@ SECTIONS {
 
        PROVIDE(__stack__ = ORIGIN(ram) + LENGTH(ram));
        PROVIDE(end = .);
-
 }
 
 ENTRY(start);
index d8fa3e899d0792409dbc05964913d241acfc289b..484ce89eb5892232e4109ea232a66cffeba3614f 100644 (file)
@@ -59,7 +59,19 @@ extern void putchar(char c);
 extern char getchar(void);
 extern void ao_avr_stdio_init(void);
 
+
+/*
+ * ao_romconfig.c
+ */
+
+#define AO_ROMCONFIG_VERSION   2
+
+#define AO_ROMCONFIG_SYMBOL(a) __attribute__((section(".romconfig"))) const
+
+extern const uint16_t ao_romconfig_version;
+extern const uint16_t ao_romconfig_check;
 extern const uint16_t ao_serial_number;
+extern const uint32_t ao_radio_cal;
 
 #define ARM_PUSH32(stack, val) (*(--(stack)) = (val))
 
index 8431745815308b1b55ce34d5b458ace5c517279c..cbb922ece661f731b4cc2a3ecf2d89cb3dcd955c 100644 (file)
@@ -17,4 +17,9 @@
 
 #include "ao.h"
 
-const uint16_t ao_serial_number = 58;
+AO_ROMCONFIG_SYMBOL (0) uint16_t ao_romconfig_version = AO_ROMCONFIG_VERSION;
+AO_ROMCONFIG_SYMBOL (0) uint16_t ao_romconfig_check = ~AO_ROMCONFIG_VERSION;
+AO_ROMCONFIG_SYMBOL (0) uint16_t ao_serial_number = 0;
+#ifdef AO_RADIO_CAL_DEFAULT
+AO_ROMCONFIG_SYMBOL (0) uint32_t ao_radio_cal = AO_RADIO_CAL_DEFAULT;
+#endif