diff --git a/Makefile b/Makefile index b6c4e32cf1..3ec3af7fa1 100644 --- a/Makefile +++ b/Makefile @@ -164,8 +164,6 @@ upload_bl: bl lpc21iap: cd sw/ground_segment/lpc21iap; make - - ##### ##### diff --git a/conf/Makefile.arm7 b/conf/Makefile.arm7 index 4e0d3cf3f8..d48d548725 100644 --- a/conf/Makefile.arm7 +++ b/conf/Makefile.arm7 @@ -51,7 +51,7 @@ THUMB_IW = -mthumb-interwork # Output format. (can be srec, ihex, binary) FORMAT = ihex -FLASH_MODE=ISP +#FLASH_MODE=ISP $(TARGET).srcsnd = $(notdir $($(TARGET).srcs)) SRCARM = $($(TARGET).srcsnd) @@ -62,6 +62,7 @@ ASRCARM = crt0.S # 0 = turn off optimization. s = optimize for size. # (Note: 3 is not always the best optimization level. See avr-libc FAQ.) OPT = s +#OPT=3 CSTANDARD = -std=gnu99 diff --git a/conf/airframes/imu.xml b/conf/airframes/imu.xml index 74a2d038b8..562de2bf3f 100644 --- a/conf/airframes/imu.xml +++ b/conf/airframes/imu.xml @@ -11,13 +11,17 @@ imu.TARGETDIR = imu LPC21ISP_BAUD = 38400 LPC21ISP_XTAL = 12000 +FLASH_MODE = IAP +#FLASH_MODE = ISP + imu.CFLAGS += -DCONFIG=\"pprz_imu.h\" imu.srcs = main_imu.c sys_time.c $(SRC_ARCH)/sys_time_hw.c $(SRC_ARCH)/armVIC.c -imu.CFLAGS += -DUSE_UART0 -DUART0_BAUD=B38400 +#imu.CFLAGS += -DUSE_UART0 -DUART0_BAUD=B38400 imu.srcs += $(SRC_ARCH)/uart_hw.c -imu.CFLAGS += -DUSE_UART1 -DUART1_BAUD=B9600 +imu.CFLAGS += -DUSE_UART1 -DUART1_BAUD=B9600 -DDOWNLINK -DDOWNLINK_TRANSPORT=PprzTransport -DDOWNLINK_DEVICE=Uart1 +imu.srcs += downlink.c pprz_transport.c imu.CFLAGS += -DADC -DUSE_AD0 -DUSE_AD0_1 -DUSE_AD0_2 -DUSE_AD0_3 -DUSE_AD0_4 imu.srcs += $(SRC_ARCH)/adc_hw.c @@ -25,6 +29,10 @@ imu.srcs += $(SRC_ARCH)/adc_hw.c imu.srcs += $(SRC_ARCH)/max1167.c imu.srcs += $(SRC_ARCH)/micromag.c +imu.srcs += imu_v3.c + +imu.srcs += ahrs_new.c + diff --git a/conf/messages.xml b/conf/messages.xml index 69ccd8777a..e857f0686a 100644 --- a/conf/messages.xml +++ b/conf/messages.xml @@ -112,24 +112,6 @@ - - - - - - - - - - - - - - - - - - @@ -178,15 +160,6 @@ - - - - - - - - - @@ -264,6 +237,20 @@ + + + + + + + + + + + + + + diff --git a/sw/airborne/arm7/LPC2138-ROM-bl.ld b/sw/airborne/arm7/LPC2138-ROM-bl.ld deleted file mode 100644 index 6c9009d6aa..0000000000 --- a/sw/airborne/arm7/LPC2138-ROM-bl.ld +++ /dev/null @@ -1,143 +0,0 @@ -/***********************************************************************/ -/* ROM.ld: Linker Script File */ -/***********************************************************************/ -ENTRY(_boot) -STACK_SIZE = 0x1000; - -/* Memory Definitions */ -MEMORY -{ - ROM (rx) : ORIGIN = 0x00004000, LENGTH = 484k - RAM (rw) : ORIGIN = 0x40000000, LENGTH = 32k -} - -/* Section Definitions */ -SECTIONS -{ - /* first section is .text which is used for code */ - .text : - { - /* *crt0.o (.text) */ /* Startup code */ - KEEP(*(.init)) /* Startup code from .init-section */ - *(.text .text.*) /* remaining code */ - *(.gnu.linkonce.t.*) - *(.glue_7) - *(.glue_7t) - *(.gcc_except_table) - *(.rodata) /* read-only data (constants) */ - *(.rodata*) - *(.gnu.linkonce.r.*) - } > ROM - - /***** old: - .text : - { - *crt0.o (.text) - *(.text) - *(.rodata) - *(.rodata*) - *(.glue_7) - *(.glue_7t) - } > ROM - *****/ - - . = ALIGN(4); - - /* .ctors .dtors are used for c++ constructors/destructors */ - /* added by Martin Thomas 4/2005 based on Anglia Design example */ - .ctors : - { - PROVIDE(__ctors_start__ = .); - KEEP(*(SORT(.ctors.*))) - KEEP(*(.ctors)) - PROVIDE(__ctors_end__ = .); - } >ROM - - .dtors : - { - PROVIDE(__dtors_start__ = .); - KEEP(*(SORT(.dtors.*))) - KEEP(*(.dtors)) - PROVIDE(__dtors_end__ = .); - } >ROM - - . = ALIGN(4); - /* mthomas - end */ - - _etext = . ; - PROVIDE (etext = .); - - /* .data section which is used for initialized data */ - .data : AT (_etext) - { - _data = .; - *(.data) - *(.data.*) - *(.gnu.linkonce.d*) - SORT(CONSTRUCTORS) /* mt 4/2005 */ - . = ALIGN(4); - *(.fastrun) /* !!!! "RAM-Function" example */ - } > RAM - - . = ALIGN(4); - _edata = . ; - PROVIDE (edata = .); - - /* .bss section which is used for uninitialized data */ - .bss (NOLOAD) : - { - __bss_start = . ; - __bss_start__ = . ; - *(.bss) - *(.gnu.linkonce.b*) - *(COMMON) - . = ALIGN(4); - } > RAM - - . = ALIGN(4); - __bss_end__ = . ; - PROVIDE (__bss_end = .); - - .stack ALIGN(256) : - { - . += STACK_SIZE; - PROVIDE (_stack = .); - } > RAM - - _end = . ; - PROVIDE (end = .); - - /* Stabs debugging sections. */ - .stab 0 : { *(.stab) } - .stabstr 0 : { *(.stabstr) } - .stab.excl 0 : { *(.stab.excl) } - .stab.exclstr 0 : { *(.stab.exclstr) } - .stab.index 0 : { *(.stab.index) } - .stab.indexstr 0 : { *(.stab.indexstr) } - .comment 0 : { *(.comment) } - /* DWARF debug sections. - Symbols in the DWARF debugging sections are relative to the beginning - of the section so we begin them at 0. */ - /* DWARF 1 */ - .debug 0 : { *(.debug) } - .line 0 : { *(.line) } - /* GNU DWARF 1 extensions */ - .debug_srcinfo 0 : { *(.debug_srcinfo) } - .debug_sfnames 0 : { *(.debug_sfnames) } - /* DWARF 1.1 and DWARF 2 */ - .debug_aranges 0 : { *(.debug_aranges) } - .debug_pubnames 0 : { *(.debug_pubnames) } - /* DWARF 2 */ - .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } - .debug_abbrev 0 : { *(.debug_abbrev) } - .debug_line 0 : { *(.debug_line) } - .debug_frame 0 : { *(.debug_frame) } - .debug_str 0 : { *(.debug_str) } - .debug_loc 0 : { *(.debug_loc) } - .debug_macinfo 0 : { *(.debug_macinfo) } - /* SGI/MIPS DWARF 2 extensions */ - .debug_weaknames 0 : { *(.debug_weaknames) } - .debug_funcnames 0 : { *(.debug_funcnames) } - .debug_typenames 0 : { *(.debug_typenames) } - .debug_varnames 0 : { *(.debug_varnames) } -} diff --git a/sw/airborne/arm7/LPC2138-ROM.ld b/sw/airborne/arm7/LPC2138-ROM.ld deleted file mode 100644 index 7a0b9db6ac..0000000000 --- a/sw/airborne/arm7/LPC2138-ROM.ld +++ /dev/null @@ -1,143 +0,0 @@ -/***********************************************************************/ -/* ROM.ld: Linker Script File */ -/***********************************************************************/ -ENTRY(_boot) -STACK_SIZE = 0x400; - -/* Memory Definitions */ -MEMORY -{ - ROM (rx) : ORIGIN = 0x00000000, LENGTH = 512k - RAM (rw) : ORIGIN = 0x40000000, LENGTH = 32k -} - -/* Section Definitions */ -SECTIONS -{ - /* first section is .text which is used for code */ - .text : - { - /* *crt0.o (.text) */ /* Startup code */ - KEEP(*(.init)) /* Startup code from .init-section */ - *(.text .text.*) /* remaining code */ - *(.gnu.linkonce.t.*) - *(.glue_7) - *(.glue_7t) - *(.gcc_except_table) - *(.rodata) /* read-only data (constants) */ - *(.rodata*) - *(.gnu.linkonce.r.*) - } > ROM - - /***** old: - .text : - { - *crt0.o (.text) - *(.text) - *(.rodata) - *(.rodata*) - *(.glue_7) - *(.glue_7t) - } > ROM - *****/ - - . = ALIGN(4); - - /* .ctors .dtors are used for c++ constructors/destructors */ - /* added by Martin Thomas 4/2005 based on Anglia Design example */ - .ctors : - { - PROVIDE(__ctors_start__ = .); - KEEP(*(SORT(.ctors.*))) - KEEP(*(.ctors)) - PROVIDE(__ctors_end__ = .); - } >ROM - - .dtors : - { - PROVIDE(__dtors_start__ = .); - KEEP(*(SORT(.dtors.*))) - KEEP(*(.dtors)) - PROVIDE(__dtors_end__ = .); - } >ROM - - . = ALIGN(4); - /* mthomas - end */ - - _etext = . ; - PROVIDE (etext = .); - - /* .data section which is used for initialized data */ - .data : AT (_etext) - { - _data = .; - *(.data) - *(.data.*) - *(.gnu.linkonce.d*) - SORT(CONSTRUCTORS) /* mt 4/2005 */ - . = ALIGN(4); - *(.fastrun) /* !!!! "RAM-Function" example */ - } > RAM - - . = ALIGN(4); - _edata = . ; - PROVIDE (edata = .); - - /* .bss section which is used for uninitialized data */ - .bss (NOLOAD) : - { - __bss_start = . ; - __bss_start__ = . ; - *(.bss) - *(.gnu.linkonce.b*) - *(COMMON) - . = ALIGN(4); - } > RAM - - . = ALIGN(4); - __bss_end__ = . ; - PROVIDE (__bss_end = .); - - .stack ALIGN(256) : - { - . += STACK_SIZE; - PROVIDE (_stack = .); - } > RAM - - _end = . ; - PROVIDE (end = .); - - /* Stabs debugging sections. */ - .stab 0 : { *(.stab) } - .stabstr 0 : { *(.stabstr) } - .stab.excl 0 : { *(.stab.excl) } - .stab.exclstr 0 : { *(.stab.exclstr) } - .stab.index 0 : { *(.stab.index) } - .stab.indexstr 0 : { *(.stab.indexstr) } - .comment 0 : { *(.comment) } - /* DWARF debug sections. - Symbols in the DWARF debugging sections are relative to the beginning - of the section so we begin them at 0. */ - /* DWARF 1 */ - .debug 0 : { *(.debug) } - .line 0 : { *(.line) } - /* GNU DWARF 1 extensions */ - .debug_srcinfo 0 : { *(.debug_srcinfo) } - .debug_sfnames 0 : { *(.debug_sfnames) } - /* DWARF 1.1 and DWARF 2 */ - .debug_aranges 0 : { *(.debug_aranges) } - .debug_pubnames 0 : { *(.debug_pubnames) } - /* DWARF 2 */ - .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } - .debug_abbrev 0 : { *(.debug_abbrev) } - .debug_line 0 : { *(.debug_line) } - .debug_frame 0 : { *(.debug_frame) } - .debug_str 0 : { *(.debug_str) } - .debug_loc 0 : { *(.debug_loc) } - .debug_macinfo 0 : { *(.debug_macinfo) } - /* SGI/MIPS DWARF 2 extensions */ - .debug_weaknames 0 : { *(.debug_weaknames) } - .debug_funcnames 0 : { *(.debug_funcnames) } - .debug_typenames 0 : { *(.debug_typenames) } - .debug_varnames 0 : { *(.debug_varnames) } -} diff --git a/sw/airborne/arm7/max1167.c b/sw/airborne/arm7/max1167.c index 7b4398943e..4ce95ded1f 100644 --- a/sw/airborne/arm7/max1167.c +++ b/sw/airborne/arm7/max1167.c @@ -44,7 +44,7 @@ void EXTINT0_ISR(void) { ISR_ENTRY(); /* read dummy control byte reply */ - uint8_t foo = SSPDR; + uint8_t foo __attribute__ ((unused)) = SSPDR; /* trigger 6 bytes read */ SSPDR = 0; SSPDR = 0; diff --git a/sw/airborne/arm7/micromag.c b/sw/airborne/arm7/micromag.c index 39ba9e9da4..1d81735172 100644 --- a/sw/airborne/arm7/micromag.c +++ b/sw/airborne/arm7/micromag.c @@ -6,8 +6,8 @@ #include "micromag.h" volatile uint8_t micromag_data_available; -int16_t micromag_values[MM_NB_AXIS]; -uint8_t volatile micromag_cur_axe; +volatile int16_t micromag_values[MM_NB_AXIS]; +volatile uint8_t micromag_cur_axe; static void EXTINT2_ISR(void) __attribute__((naked)); @@ -45,7 +45,7 @@ void micromag_read( void ) { void EXTINT2_ISR(void) { ISR_ENTRY(); /* read dummy control byte reply */ - uint8_t foo = SSPDR; + uint8_t foo __attribute__ ((unused)) = SSPDR; /* trigger 2 bytes read */ SSPDR = 0; SSPDR = 0; diff --git a/sw/airborne/arm7/micromag.h b/sw/airborne/arm7/micromag.h index ffb3c00121..eba63f1cbe 100644 --- a/sw/airborne/arm7/micromag.h +++ b/sw/airborne/arm7/micromag.h @@ -12,7 +12,7 @@ extern void micromag_init( void ); extern void micromag_read( void ); extern volatile uint8_t micromag_data_available; -extern int16_t micromag_values[MM_NB_AXIS]; +extern volatile int16_t micromag_values[MM_NB_AXIS]; extern volatile uint8_t micromag_cur_axe; #define MM_SS_PIN 20 diff --git a/sw/airborne/arm7/test/bootloader/Makefile b/sw/airborne/arm7/test/bootloader/Makefile index 7b2f66ddce..75523fb35d 100644 --- a/sw/airborne/arm7/test/bootloader/Makefile +++ b/sw/airborne/arm7/test/bootloader/Makefile @@ -1,5 +1,6 @@ #PROC_AP PROC_FBW PROC_TINY -ALLFLAGS = -DPROC_AP +PROC = AP +ALLFLAGS = -DPROC_$(PROC) LIBNAME = usbstack APPNAME = bl @@ -71,7 +72,7 @@ $(APPNAME_RAM).elf: $(OBJS) $(LIBNAME).a $(LINKFILE_RAM) crt.o: crt.S @ echo ".assembling" $(CC) -c $(ASFLAGS) -Wa,-ahlms=crt.lst crt.S -o crt.o - + # Builds archive tar file arch: clean cd .. && $(TAR) --exclude={CVS,cvs} -cvzf $(PKG_NAME)-$(DATEL).tar.gz $(PKG_NAME) diff --git a/sw/airborne/arm7/uart_hw.c b/sw/airborne/arm7/uart_hw.c index 9c6bcb971d..9021739015 100644 --- a/sw/airborne/arm7/uart_hw.c +++ b/sw/airborne/arm7/uart_hw.c @@ -1,6 +1,7 @@ #include "uart.h" + #define UART0_TX_INT_MODE 1 #define UART0_RX_INT_MODE 1 @@ -9,6 +10,9 @@ #include "armVIC.h" #endif +#ifdef USE_UART0 + + #if defined(UART0_TX_INT_MODE) || defined(UART0_RX_INT_MODE) void uart0_ISR(void) __attribute__((naked)); #endif @@ -196,6 +200,8 @@ void uart0_ISR(void) ISR_EXIT(); // recover registers and return } +#endif /* USE_UART0 */ + /* * * UART1 handling functions - those are pale copies of UART0 ones diff --git a/sw/airborne/main_imu.c b/sw/airborne/main_imu.c index 2386253839..868171e047 100644 --- a/sw/airborne/main_imu.c +++ b/sw/airborne/main_imu.c @@ -10,87 +10,80 @@ #include "adc.h" #include "max1167.h" #include "micromag.h" +#include "imu_v3.h" +#include "ahrs_new.h" #include "airframe.h" +#include "messages.h" +#include "downlink.h" -static inline void imu_init( void ); -static inline void imu_periodic_task( void ); -static inline void imu_event_task( void); - -static void imu_print_accel ( void ); -static void imu_print_bat ( void ); -static void imu_init_spi1( void ); - -static void SPI1_ISR(void) __attribute__((naked)); +static inline void main_init( void ); +static inline void main_periodic_task( void ); +static inline void main_event_task( void); struct adc_buf buf_ax; struct adc_buf buf_ay; struct adc_buf buf_az; struct adc_buf buf_bat; +static void imu_print_bat ( void ); +static void imu_print_accel( void ); +static void imu_print_gyro ( void ); +static void imu_print_mag ( void ); + +static void main_init_spi1( void ); + +static void SPI1_ISR(void) __attribute__((naked)); #define SPI_SLAVE_NONE 0 -#define SPI_SLAVE_MAG 1 -#define SPI_SLAVE_MAX 2 +#define SPI_SLAVE_MAG 1 +#define SPI_SLAVE_MAX 2 uint8_t spi_cur_slave = SPI_SLAVE_NONE; #define AHRS_NB_STATE 3 uint8_t ahrs_state = 0; int main( void ) { - imu_init(); + main_init(); while (1) { if (sys_time_periodic()) - imu_periodic_task(); - imu_event_task(); + main_periodic_task(); + main_event_task(); } return 0; } -static inline void imu_init( void ) { +static inline void main_init( void ) { hw_init(); sys_time_init(); - uart0_init_tx(); uart1_init_tx(); adc_init(); - adc_buf_channel(ADC_CHANNEL_AX, &buf_ax, DEFAULT_AV_NB_SAMPLE); - adc_buf_channel(ADC_CHANNEL_AY, &buf_ay, DEFAULT_AV_NB_SAMPLE); - adc_buf_channel(ADC_CHANNEL_AZ, &buf_az, DEFAULT_AV_NB_SAMPLE); - adc_buf_channel(ADC_CHANNEL_BAT, &buf_bat, DEFAULT_AV_NB_SAMPLE); - imu_init_spi1(); + imu_init(); + main_init_spi1(); max1167_init(); micromag_init(); int_enable(); } -static inline void imu_event_task( void ) { +static inline void main_event_task( void ) { if (micromag_data_available) { micromag_data_available = FALSE; spi_cur_slave = SPI_SLAVE_NONE; - - Uart1PrintString("MAG "); - Uart1PrintHex16(micromag_values[0]); - uart1_transmit(' '); - Uart1PrintHex16(micromag_values[1]); - uart1_transmit(' '); - Uart1PrintHex16(micromag_values[2]); - uart1_transmit('\n'); + ImuUpdateMag(); + imu_print_mag(); } if (max1167_data_available) { max1167_data_available = FALSE; spi_cur_slave = SPI_SLAVE_NONE; - - Uart1PrintString("GYRO "); - Uart1PrintHex16(max1167_values[0]); - uart1_transmit(' '); - Uart1PrintHex16(max1167_values[1]); - uart1_transmit(' '); - Uart1PrintHex16(max1167_values[2]); - uart1_transmit('\n'); - + ImuUpdateGyros(); + imu_print_gyro(); + ImuUpdateAccels(); imu_print_accel(); + // DOWNLINK_SEND_IMU_SENSORS(&imu_accel[AXIS_X], &imu_accel[AXIS_Y], &imu_accel[AXIS_Z], + // &imu_gyro[AXIS_X], &imu_gyro[AXIS_Y], &imu_gyro[AXIS_Z], + // &imu_mag[AXIS_X], &imu_mag[AXIS_Y], &imu_mag[AXIS_Z]); if (ahrs_state == 2) { spi_cur_slave = SPI_SLAVE_MAG; @@ -99,13 +92,17 @@ static inline void imu_event_task( void ) { } } -static inline void imu_periodic_task( void ) { +static inline void main_periodic_task( void ) { static uint8_t foo = 0; foo++; if (!(foo % 4)) { ahrs_state++; if (ahrs_state == AHRS_NB_STATE) ahrs_state = 0; + + if (spi_cur_slave != SPI_SLAVE_NONE) + Uart1PrintString("OVERUN"); + switch (ahrs_state) { case 0: spi_cur_slave = SPI_SLAVE_MAX; @@ -124,6 +121,13 @@ static inline void imu_periodic_task( void ) { } } +static void imu_print_bat ( void ) { + Uart1PrintString("BAT "); + uint16_t val = buf_bat.sum / DEFAULT_AV_NB_SAMPLE; + Uart1PrintHex16(val); + uart1_transmit('\n'); +} + static void imu_print_accel ( void ) { Uart1PrintString("ACCEL "); uint16_t val = buf_ax.sum / DEFAULT_AV_NB_SAMPLE; @@ -137,14 +141,25 @@ static void imu_print_accel ( void ) { uart1_transmit('\n'); } -static void imu_print_bat ( void ) { - Uart1PrintString("BAT "); - uint16_t val = buf_bat.sum / DEFAULT_AV_NB_SAMPLE; - Uart1PrintHex16(val); +static void imu_print_gyro ( void ) { + Uart1PrintString("GYRO "); + Uart1PrintHex16(max1167_values[0]); + uart1_transmit(' '); + Uart1PrintHex16(max1167_values[1]); + uart1_transmit(' '); + Uart1PrintHex16(max1167_values[2]); uart1_transmit('\n'); } - +static void imu_print_mag ( void ) { + Uart1PrintString("MAG "); + Uart1PrintHex16(micromag_values[0]); + uart1_transmit(' '); + Uart1PrintHex16(micromag_values[1]); + uart1_transmit(' '); + Uart1PrintHex16(micromag_values[2]); + uart1_transmit('\n'); +} /* SSPCR0 settings */ #define SSP_DDS 0x07 << 0 /* data size : 8 bits */ @@ -159,9 +174,7 @@ static void imu_print_bat ( void ) { #define SSP_MS 0x00 << 2 /* master slave mode : master */ #define SSP_SOD 0x00 << 3 /* slave output disable : don't care when master */ - - -static void imu_init_spi1( void ) { +static void main_init_spi1( void ) { /* setup pins for SSP (SCK, MISO, MOSI) */ PINSEL1 |= 2 << 2 | 2 << 4 | 2 << 6; @@ -179,6 +192,7 @@ static void imu_init_spi1( void ) { void SPI1_ISR(void) { ISR_ENTRY(); + switch (spi_cur_slave) { case SPI_SLAVE_MAG : MmOnSpiIt(); diff --git a/sw/ground_segment/lpc21iap/README.TXT b/sw/ground_segment/lpc21iap/README.TXT index 6238d5029d..22fe9708a0 100644 --- a/sw/ground_segment/lpc21iap/README.TXT +++ b/sw/ground_segment/lpc21iap/README.TXT @@ -3,9 +3,14 @@ simple answer [preliminary] -re-make your aircraft, use $PAPARAZZI_SRC/sw/airborne/arm7/LPC2138-ROM-bl.ld instead of LPC2138-ROM.ld (rename it) +link your airborne programs using the bootloader-specific linker script +make AIRCRAFT=TJ1 LDSCRIPT=arm7/LPC2148-ROM-bl.ld clean_ac fbw.compile +make AIRCRAFT=TJ1 LDSCRIPT=arm7/LPC2148-ROM-bl.ld ap.compile + apt-get install libusb +( warning on sid I had to do apt-get install libusb-0.1-4 ) + cp $PAPARAZZI_SRC/conf/system/udev/rules/10-paparazzi.rules /etc/udev/rules.d/ cd $PAPARAZZI_SRC/sw/airborne/arm7/test/bootloader/ make