From 9d515a031d388bec41583f0335e97ecd78c75864 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 27 Aug 2022 17:06:58 -0700 Subject: [PATCH] altos: Add BMI088 test framework using Nucleo32 board for stm32f042 This allows a BMI088 chip to be connected to a nucleo-32 board with an stm32f042 chip to be tested. Signed-off-by: Keith Packard --- libaltos/libaltos.h | 1 + libaltos/libaltos.i0 | 6 +++++- src/nucleao-32/Makefile | 42 ++++++++------------------------------ src/nucleao-32/ao_nucleo.c | 26 ++++++----------------- src/nucleao-32/ao_pins.h | 35 ++++++++++++++++++++++++------- 5 files changed, 49 insertions(+), 61 deletions(-) diff --git a/libaltos/libaltos.h b/libaltos/libaltos.h index 8c49346f..f7fc9082 100644 --- a/libaltos/libaltos.h +++ b/libaltos/libaltos.h @@ -42,6 +42,7 @@ struct altos_device { int serial; char name[256]; char path[256]; + int (*method_1)(int x, int y); //%mutable; }; diff --git a/libaltos/libaltos.i0 b/libaltos/libaltos.i0 index d06468f5..ac45fbaf 100644 --- a/libaltos/libaltos.i0 +++ b/libaltos/libaltos.i0 @@ -2,4 +2,8 @@ %{ #include "libaltos.h" %} - +%extend altos_device { + int method_1(int x, int y) { + return ($self->method_1)(x, y); + } +} diff --git a/src/nucleao-32/Makefile b/src/nucleao-32/Makefile index fba99c88..538b98a0 100644 --- a/src/nucleao-32/Makefile +++ b/src/nucleao-32/Makefile @@ -3,7 +3,9 @@ # # -include ../stmf0/Makefile.defs +TOPDIR=.. + +include $(TOPDIR)/stmf0/Makefile.defs INC = \ ao.h \ @@ -13,8 +15,6 @@ INC = \ ao_pins.h \ ao_product.h \ ao_task.h \ - ao_lisp.h \ - ao_lisp_const.h \ stm32f0.h \ Makefile @@ -25,42 +25,24 @@ ALTOS_SRC = \ ao_romconfig.c \ ao_cmd.c \ ao_config.c \ + ao_data.c \ ao_task.c \ ao_led_stmf0.c \ - ao_beep_stm.c \ ao_dma_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ ao_mutex.c \ ao_usb_stm.c \ - ao_serial_stm.c \ ao_flash_stm.c \ - ao_lisp_atom.c \ - ao_lisp_builtin.c \ - ao_lisp_cons.c \ - ao_lisp_error.c \ - ao_lisp_eval.c \ - ao_lisp_frame.c \ - ao_lisp_int.c \ - ao_lisp_lambda.c \ - ao_lisp_lex.c \ - ao_lisp_mem.c \ - ao_lisp_poly.c \ - ao_lisp_read.c \ - ao_lisp_rep.c \ - ao_lisp_save.c \ - ao_lisp_stack.c \ - ao_lisp_string.c \ - ao_lisp_os_save.c + ao_spi_stm.c \ + ao_bmi088.c PRODUCT=Nucleo-32 PRODUCT_DEF=-DNUCLEO IDPRODUCT=0x000a -CFLAGS = $(PRODUCT_DEF) $(STMF0_CFLAGS) - -LDFLAGS=$(CFLAGS) -L$(TOPDIR)/stmf0 -Wl,-Tload.ld -n +CFLAGS = $(PRODUCT_DEF) $(STMF0_CFLAGS) $(PROFILE_DEF) PROGNAME=nucleo-32 PROG=$(PROGNAME)-$(VERSION).elf @@ -72,20 +54,14 @@ OBJ=$(SRC:.c=.o) all: $(PROG) $(HEX) $(PROG): Makefile $(OBJ) altos.ld - $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(OBJ) $(LIBS) + $(call quiet,CC) $(LDFLAGS) -o $(PROG) $(OBJ) $(LIBS) -Wl,-Map=$(PROGNAME)-$(VERSION).map $(OBJ): $(INC) -ao_product.h: ao-make-product.5c ../Version - $(call quiet,NICKLE,$<) $< -m altusmetrum.org -i $(IDPRODUCT) -p $(PRODUCT) -v $(VERSION) > $@ - -load: $(PROG) - stm-load $(PROG) - distclean: clean clean: - rm -f *.o $(PROGNAME)-*.elf $(PROGNAME)-*.ihx + rm -f *.o $(PROGNAME)-*.elf $(PROGNAME)-*.ihx $(PROGNAME)-*.map rm -f ao_product.h install: diff --git a/src/nucleao-32/ao_nucleo.c b/src/nucleao-32/ao_nucleo.c index 6b4cbaae..5854fe58 100644 --- a/src/nucleao-32/ao_nucleo.c +++ b/src/nucleao-32/ao_nucleo.c @@ -13,35 +13,21 @@ */ #include -#include -#include +#include -static void lisp_cmd() { - ao_lisp_read_eval_print(); -} - -static void beep() { - ao_beep_for(AO_BEEP_MID, AO_MS_TO_TICKS(200)); -} - -static const struct ao_cmds blink_cmds[] = { - { lisp_cmd, "l\0Run lisp interpreter" }, - { beep, "b\0Beep" }, - { 0, 0 } -}; +uint8_t ao_sensor_errors; -void main(void) +int main(void) { - ao_led_init(LEDS_AVAILABLE); + ao_led_init(); ao_clock_init(); ao_task_init(); ao_timer_init(); ao_dma_init(); ao_usb_init(); - ao_serial_init(); - ao_beep_init(); + ao_spi_init(); + ao_bmi088_init(); ao_cmd_init(); - ao_cmd_register(blink_cmds); ao_start_scheduler(); } diff --git a/src/nucleao-32/ao_pins.h b/src/nucleao-32/ao_pins.h index cee4616f..0cc91d73 100644 --- a/src/nucleao-32/ao_pins.h +++ b/src/nucleao-32/ao_pins.h @@ -47,19 +47,40 @@ #define HAS_USB 1 #define AO_USB_DIRECTIO 0 #define AO_PA11_PA12_RMP 0 -#define HAS_BEEP 1 - -#define BEEPER_TIMER 2 -#define BEEPER_CHANNEL 4 -#define BEEPER_PORT (&stm_gpioa) -#define BEEPER_PIN 3 +#define HAS_BEEP 0 #define IS_FLASH_LOADER 0 -#define HAS_SERIAL_2 1 +#define HAS_SERIAL_2 0 #define SERIAL_2_PA2_PA15 1 #define USE_SERIAL_2_FLOW 0 #define USE_SERIAL_2_STDIN 1 #define DELAY_SERIAL_2_STDIN 0 +#define HAS_SPI_1 1 +#define SPI_1_PA5_PA6_PA7 1 +#define SPI_1_OSPEEDR STM_OSPEEDR_HIGH +#define SPI_1_PB3_PB4_PB5 0 + +#define HAS_SPI_2 0 + +#define HAS_BMI088 1 +#define HAS_IMU 1 + +#define ao_data_along(packet) ((packet)->bmi088.acc.x) +#define ao_data_across(packet) (-(packet)->bmi088.acc.y) +#define ao_data_through(packet) ((packet)->bmi088.acc.z) + +#define ao_data_roll(packet) ((packet)->bmi088.gyr.x) +#define ao_data_pitch(packet) (-(packet)->bmi088.gyr.y) +#define ao_data_yaw(packet) ((packet)->bmi088.gyr.z) + +#define AO_BMI088_ACC_CS_PORT (&stm_gpioa) +#define AO_BMI088_ACC_CS_PIN 0 +#define AO_BMI088_GYR_CS_PORT (&stm_gpioa) +#define AO_BMI088_GYR_CS_PIN 1 +#define AO_BMI088_SPI_BUS (AO_SPI_1_PA5_PA6_PA7 | AO_SPI_MODE_0) + +#define AO_DATA_RING 32 + #endif /* _AO_PINS_H_ */ -- 2.30.2