]> git.gag.com Git - fw/altos/commitdiff
altos: Add telegps v4.0 test firmware
authorKeith Packard <keithp@keithp.com>
Wed, 2 Oct 2024 04:52:56 +0000 (21:52 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 2 Oct 2024 04:57:46 +0000 (21:57 -0700)
This is custom firmware for testing TeleGPS v4.0 boards at Seeed. It
checks to make sure flash, ADC and GPS are working correctly. On
success, it will hold the green LED steady. On failure, it will blink
out a pattern identifying the failing component.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/telegps-v4.0-seeed/ao_pins.h [new file with mode: 0644]
src/telegps-v4.0-seeed/ao_telegps_seeed.c [new file with mode: 0644]
src/telegps-v4.0-seeed/flash-loader/.gitignore [new file with mode: 0644]
src/telegps-v4.0-seeed/flash-loader/ao_pins.h [new file with mode: 0644]

diff --git a/src/telegps-v4.0-seeed/ao_pins.h b/src/telegps-v4.0-seeed/ao_pins.h
new file mode 100644 (file)
index 0000000..a5ea6ea
--- /dev/null
@@ -0,0 +1,170 @@
+/*
+ * Copyright © 2024 Bdale Garbee <bdale@gag.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#ifndef _AO_PINS_H_
+#define _AO_PINS_H_
+
+#define LED_PORT_ENABLE STM_RCC_AHBENR_IOPBEN
+#define LED_PORT        (&stm_gpiob)
+#define LED_PIN_GREEN   5
+#define AO_LED_GREEN    (1 << LED_PIN_GREEN)
+#define AO_LED_PANIC   AO_LED_GREEN
+#define AO_LED_GPS_LOCK        AO_LED_GREEN
+
+#define LEDS_AVAILABLE  (AO_LED_GREEN)
+
+#define AO_STACK_SIZE          512
+
+#define IS_FLASH_LOADER                0
+#define HAS_BEEP              0
+
+#define AO_HSE                  16000000
+#define AO_RCC_CFGR_PLLMUL      STM_RCC_CFGR_PLLMUL_3
+#define AO_RCC_CFGR2_PLLDIV    STM_RCC_CFGR2_PREDIV_1
+#define AO_PLLMUL               3
+#define AO_PLLDIV               1
+
+/* HCLK = 48MHz */
+#define AO_AHB_PRESCALER        1
+#define AO_RCC_CFGR_HPRE_DIV    STM_RCC_CFGR_HPRE_DIV_1
+
+/* APB = 48MHz */
+#define AO_APB_PRESCALER        1
+#define AO_RCC_CFGR_PPRE_DIV    STM_RCC_CFGR_PPRE_DIV_1
+
+#define HAS_USB                         1
+#define AO_USB_DIRECTIO                 0
+#define AO_PA11_PA12_RMP                1
+#define HAS_USB_CONNECT                        1
+#define AO_USB_CONNECT_PORT            (&stm_gpiob)
+#define AO_USB_CONNECT_PIN             3
+
+#define IS_FLASH_LOADER 0
+
+/* ADC */
+
+#define HAS_ADC                        1
+#define AO_ADC_PIN0_PORT        (&stm_gpiob)
+#define AO_ADC_PIN0_PIN         1
+#define AO_ADC_PIN0_CH          9
+
+#define AO_ADC_RCC_AHBENR       ((1 << STM_RCC_AHBENR_IOPBEN))
+
+#define ao_telemetry_battery_convert(a)        ((a) << 3)
+
+#define AO_NUM_ADC              1
+
+#define AO_DATA_RING           4
+
+/*
+ * Voltage divider on ADC battery sampler
+ */
+#define AO_BATTERY_DIV_PLUS    56      /* 5.6k */
+#define AO_BATTERY_DIV_MINUS   100     /* 10k */
+
+/*
+ * ADC reference in decivolts
+ */
+#define AO_ADC_REFERENCE_DV    33
+
+struct ao_adc {
+        int16_t                 v_batt;
+};
+
+#define AO_ADC_DUMP(p) \
+        printf("tick: %5lu batt: %5d\n", \
+               (p)->tick, \
+               (p)->adc.v_batt)
+
+/* SPI */
+#define HAS_SPI_1               1
+#define HAS_SPI_2               0
+#define SPI_1_PA5_PA6_PA7       1
+#define SPI_1_PB3_PB4_PB5       0
+#define SPI_1_OSPEEDR           STM_OSPEEDR_HIGH
+
+/* Flash */
+
+#define M25_MAX_CHIPS           1
+#define AO_M25_SPI_CS_PORT      (&stm_gpiob)
+#define AO_M25_SPI_CS_MASK      (1 << 0)
+#define AO_M25_SPI_BUS          AO_SPI_1_PA5_PA6_PA7
+
+/* Serial */
+#define HAS_SERIAL_1           0
+#define SERIAL_1_PB6_PB7       1
+#define USE_SERIAL_1_STDIN     0
+
+#define HAS_SERIAL_2           1
+#define SERIAL_2_PA2_PA3       1
+#define USE_SERIAL_2_STDIN     0
+#define USE_SERIAL_2_FLOW       0
+#define USE_SERIAL_2_SW_FLOW    0
+
+#define ao_gps_getchar         ao_serial2_getchar
+#define ao_gps_putchar         ao_serial2_putchar
+#define ao_gps_set_speed       ao_serial2_set_speed
+
+#define HAS_EEPROM             1
+#define USE_INTERNAL_FLASH     0
+#define HAS_RADIO              1
+#define HAS_TELEMETRY          1
+#define HAS_RDF                        1
+#define HAS_APRS               1
+
+#define HAS_GPS                        1
+#define HAS_FLIGHT             0
+#define HAS_LOG                        1
+#define FLIGHT_LOG_APPEND      1
+#define HAS_TRACKER            1
+#define LOG_ADC                        0
+
+#define AO_CONFIG_DEFAULT_APRS_INTERVAL                0
+#define AO_CONFIG_DEFAULT_RADIO_POWER          0xc0
+#define AO_LOG_FORMAT                          AO_LOG_FORMAT_TELEGPS
+
+/*
+ * GPS
+ */
+
+#define AO_SERIAL_SPEED_UBLOX  AO_SERIAL_SPEED_9600
+#define AO_UBLOX_VERSION       10
+
+/*
+ * Radio (cc1200)
+ */
+
+/* gets pretty close to 434.550 */
+
+#define AO_RADIO_CAL_DEFAULT    5695733
+
+#define AO_FEC_DEBUG            0
+#define AO_CC1200_SPI_CS_PORT   (&stm_gpioa)
+#define AO_CC1200_SPI_CS_PIN    1
+#define AO_CC1200_SPI_BUS       AO_SPI_1_PA5_PA6_PA7
+#define AO_CC1200_SPI           stm_spi1
+
+#define AO_CC1200_INT_PORT              (&stm_gpioa)
+#define AO_CC1200_INT_PIN               4
+
+#define AO_CC1200_INT_GPIO      2
+#define AO_CC1200_INT_GPIO_IOCFG        CC1200_IOCFG2
+
+#define HAS_BOOT_RADIO          0
+
+#endif /* _AO_PINS_H_ */
diff --git a/src/telegps-v4.0-seeed/ao_telegps_seeed.c b/src/telegps-v4.0-seeed/ao_telegps_seeed.c
new file mode 100644 (file)
index 0000000..ae7c9b1
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * Copyright © 2013 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#include <ao.h>
+#include <ao_log.h>
+#include <ao_exti.h>
+#include <ao_tracker.h>
+
+static void
+ao_validate(void)
+{
+       static struct ao_telemetry_location     gps_data;
+       static struct ao_telemetry_satellite    gps_tracking_data;
+       uint8_t new;
+       uint8_t data;
+       int16_t decivolt;
+       AO_TICK_TYPE    gps_start;
+
+       /* Check the flash part */
+       ao_storage_setup();
+       if (ao_storage_total != 2 * 1024 * 1024)
+               ao_panic(AO_PANIC_FLASH);
+
+       /* Check the battery voltage */
+       data = ao_data_head;
+       do {
+               ao_sleep((void *) &ao_data_head);
+       } while (ao_data_head == data);
+       decivolt = ao_battery_decivolt(ao_data_ring[data].adc.v_batt);
+       if (decivolt < 35 && 55 < decivolt)
+               ao_panic(AO_PANIC_ADC);
+
+       /* Check to make sure GPS data is being received */
+       gps_start = ao_time();
+       for (;;) {
+               while ((new = ao_gps_new) == 0)
+                       ao_sleep_for(&ao_gps_new, AO_SEC_TO_TICKS(1));
+               ao_mutex_get(&ao_gps_mutex);
+               if (new & AO_GPS_NEW_DATA)
+                       memcpy(&gps_data, &ao_gps_data, sizeof (ao_gps_data));
+               if (new & AO_GPS_NEW_TRACKING)
+                       memcpy(&gps_tracking_data, &ao_gps_tracking_data, sizeof (ao_gps_tracking_data));
+               ao_gps_new = 0;
+               ao_mutex_put(&ao_gps_mutex);
+
+               if (new & AO_GPS_NEW_DATA) {
+                       if (gps_data.flags & AO_GPS_RUNNING)
+                               break;
+               }
+               if ((AO_TICK_SIGNED) (ao_time() - gps_start) > (AO_TICK_SIGNED) AO_SEC_TO_TICKS(10))
+                       ao_panic(AO_PANIC_CRASH);
+       }
+       ao_led_on(LEDS_AVAILABLE);
+}
+
+struct ao_task ao_validate_task;
+
+int
+main(void)
+{
+       ao_clock_init();
+       ao_task_init();
+       ao_cmd_init();
+       ao_config_init();
+
+       ao_led_init();
+       ao_led_off(LEDS_AVAILABLE);
+
+       /* internal systems */
+       ao_timer_init();
+       ao_dma_init();
+       ao_exti_init();
+
+       /* SoC hardware */
+       ao_adc_init();
+       ao_serial_init();
+       ao_spi_init();
+       ao_usb_init();
+
+       /* External hardware */
+       ao_storage_init();
+       ao_radio_init();
+       ao_gps_init();
+
+
+       ao_add_task(&ao_validate_task, ao_validate, "validate");
+
+       ao_start_scheduler();
+}
diff --git a/src/telegps-v4.0-seeed/flash-loader/.gitignore b/src/telegps-v4.0-seeed/flash-loader/.gitignore
new file mode 100644 (file)
index 0000000..7bbed04
--- /dev/null
@@ -0,0 +1,2 @@
+*.elf
+*.bin
diff --git a/src/telegps-v4.0-seeed/flash-loader/ao_pins.h b/src/telegps-v4.0-seeed/flash-loader/ao_pins.h
new file mode 100644 (file)
index 0000000..c7bf4e7
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright © 2024 Bdale Garbee <bdale@gag.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#ifndef _AO_PINS_H_
+#define _AO_PINS_H_
+
+#include <ao_flash_stm_pins.h>
+
+/* Pin 5 on debug connector */
+
+#define AO_BOOT_PIN            1
+#define AO_BOOT_APPLICATION_GPIO       stm_gpiob
+#define AO_BOOT_APPLICATION_PIN                6
+#define AO_BOOT_APPLICATION_VALUE      1
+#define AO_BOOT_APPLICATION_MODE       AO_EXTI_MODE_PULL_UP
+
+#define HAS_USB                        1
+#define AO_USB_DIRECTIO                0
+#define AO_PA11_PA12_RMP       1
+
+#endif /* _AO_PINS_H_ */