diff options
Diffstat (limited to 'src/stm')
| -rw-r--r-- | src/stm/Makefile-flash.defs | 10 | ||||
| -rw-r--r-- | src/stm/Makefile.defs | 9 | ||||
| -rw-r--r-- | src/stm/altos-512.ld | 4 | ||||
| -rw-r--r-- | src/stm/altos-loader.ld | 4 | ||||
| -rw-r--r-- | src/stm/altos-ram.ld | 4 | ||||
| -rw-r--r-- | src/stm/altos.ld | 4 | ||||
| -rw-r--r-- | src/stm/ao_adc_single_stm.c | 2 | ||||
| -rw-r--r-- | src/stm/ao_adc_stm.c | 27 | ||||
| -rw-r--r-- | src/stm/ao_arch.h | 24 | ||||
| -rw-r--r-- | src/stm/ao_arch_funcs.h | 30 | ||||
| -rw-r--r-- | src/stm/ao_beep_stm.c | 166 | ||||
| -rw-r--r-- | src/stm/ao_eeprom_stm.c | 6 | ||||
| -rw-r--r-- | src/stm/ao_flash_stm_pins.h | 20 | ||||
| -rw-r--r-- | src/stm/ao_i2c_stm.c | 6 | ||||
| -rw-r--r-- | src/stm/ao_interrupt.c | 4 | ||||
| -rw-r--r-- | src/stm/ao_lcd_stm.c | 9 | ||||
| -rw-r--r-- | src/stm/ao_led.c | 216 | ||||
| -rw-r--r-- | src/stm/ao_led_stm.c | 144 | ||||
| -rw-r--r-- | src/stm/ao_pwm_stm.c | 6 | ||||
| -rw-r--r-- | src/stm/ao_romconfig.c | 29 | ||||
| -rw-r--r-- | src/stm/ao_serial_stm.c | 8 | ||||
| -rw-r--r-- | src/stm/ao_spi_stm.c | 31 | ||||
| -rw-r--r-- | src/stm/ao_timer.c | 4 | ||||
| -rw-r--r-- | src/stm/ao_usb_stm.c | 2 | ||||
| -rw-r--r-- | src/stm/stm32l.h | 15 |
25 files changed, 339 insertions, 445 deletions
diff --git a/src/stm/Makefile-flash.defs b/src/stm/Makefile-flash.defs index dde51a68..66ad1637 100644 --- a/src/stm/Makefile-flash.defs +++ b/src/stm/Makefile-flash.defs @@ -12,10 +12,14 @@ endif include $(TOPDIR)/Makedefs CC=$(ARM_CC) -LIBS=$(PDCLIB_LIBS_M3) -lgcc +LIBS=-L$(NEWLIB_NANO)/arm-none-eabi/lib/thumb/v7-m -lc -lm -lgcc -AO_CFLAGS=-I. -I$(TOPDIR)/stm -I$(TOPDIR)/kernel -I$(TOPDIR)/drivers -I$(TOPDIR)/product -I$(TOPDIR) $(PDCLIB_INCLUDES) -STM_CFLAGS=-std=gnu99 -mlittle-endian -mcpu=cortex-m3 -mthumb -ffreestanding -nostdlib $(AO_CFLAGS) $(SAT_CFLAGS) +AO_CFLAGS=-I. -I$(TOPDIR)/stm -I$(TOPDIR)/kernel -I$(TOPDIR)/drivers \ + -DNEWLIB_INTEGER_PRINTF_SCANF \ + -I$(TOPDIR)/product -I$(TOPDIR) -isystem $(NEWLIB_NANO)/arm-none-eabi/include + +STM_CFLAGS=-std=gnu99 -mlittle-endian -mcpu=cortex-m3 -mthumb \ + -ffreestanding -nostdlib $(AO_CFLAGS) $(SAT_CFLAGS) LDFLAGS=-L$(TOPDIR)/stm -Wl,-Taltos-loader.ld diff --git a/src/stm/Makefile.defs b/src/stm/Makefile.defs index 4d0d27c7..8173b349 100644 --- a/src/stm/Makefile.defs +++ b/src/stm/Makefile.defs @@ -22,15 +22,18 @@ endif include $(TOPDIR)/Makedefs CC=$(ARM_CC) -LIBS=$(PDCLIB_LIBS_M3) -lgcc +LIBS=-L$(NEWLIB_NANO)/arm-none-eabi/lib/thumb/v7-m -lm -lc -lgcc WARN_FLAGS=-Wall -Wextra -Werror -AO_CFLAGS=-I. -I../stm -I../kernel -I../drivers -I../math -I../draw -I../lisp -I.. $(PDCLIB_INCLUDES) +AO_CFLAGS=-I. -I../stm -I../kernel -I../drivers -I../math -I../draw \ + -DNEWLIB_INTEGER_PRINTF_SCANF \ + -I../lisp -I.. -isystem $(NEWLIB_NANO)/arm-none-eabi/include + STM_CFLAGS=-std=gnu99 -mlittle-endian -mcpu=cortex-m3 -mthumb -Wcast-align \ -ffreestanding -nostdlib $(AO_CFLAGS) $(WARN_FLAGS) -LDFLAGS=-L../stm -Wl,-Taltos.ld +LDFLAGS=-L../stm -Wl,-Taltos.ld -nostartfiles -Wl,-Map=$(PROGNAME).map NICKLE=nickle ELFTOHEX=$(TOPDIR)/../ao-tools/ao-elftohex/ao-elftohex diff --git a/src/stm/altos-512.ld b/src/stm/altos-512.ld index 78c41685..97a9c437 100644 --- a/src/stm/altos-512.ld +++ b/src/stm/altos-512.ld @@ -74,10 +74,10 @@ SECTIONS { /* Data -- relocated to RAM, but written to ROM */ .data : { - __data_start__ = .; + _start__ = .; *(.data) /* initialized data */ . = ALIGN(4); - __data_end__ = .; + _end__ = .; } >ram AT>rom .bss : { diff --git a/src/stm/altos-loader.ld b/src/stm/altos-loader.ld index 806b4842..1ebbc7a2 100644 --- a/src/stm/altos-loader.ld +++ b/src/stm/altos-loader.ld @@ -65,7 +65,7 @@ SECTIONS { */ .textram BLOCK(8): { - __data_start__ = .; + _start__ = .; __text_ram_start__ = .; *(.ramtext) __text_ram_end = .; @@ -76,7 +76,7 @@ SECTIONS { */ .data BLOCK(8): { *(.data) /* initialized data */ - __data_end__ = .; + _end__ = .; } >ram AT>rom diff --git a/src/stm/altos-ram.ld b/src/stm/altos-ram.ld index 098454e1..d8f072a7 100644 --- a/src/stm/altos-ram.ld +++ b/src/stm/altos-ram.ld @@ -42,13 +42,13 @@ SECTIONS { __text_end__ = .; } > ram - __data_start__ = .; + _start__ = .; /* Data -- relocated to RAM, but written to ROM */ .data : AT (ADDR(.ARM.exidx) + SIZEOF (.ARM.exidx)) { *(.data) /* initialized data */ - __data_end__ = .; + _end__ = .; __bss_start__ = .; } >ram diff --git a/src/stm/altos.ld b/src/stm/altos.ld index 6a8c7113..e352ed36 100644 --- a/src/stm/altos.ld +++ b/src/stm/altos.ld @@ -74,10 +74,10 @@ SECTIONS { /* Data -- relocated to RAM, but written to ROM */ .data : { - __data_start__ = .; + _start__ = .; *(.data) /* initialized data */ . = ALIGN(4); - __data_end__ = .; + _end__ = .; } >ram AT>rom .bss : { diff --git a/src/stm/ao_adc_single_stm.c b/src/stm/ao_adc_single_stm.c index 8a7fda4a..5737cd50 100644 --- a/src/stm/ao_adc_single_stm.c +++ b/src/stm/ao_adc_single_stm.c @@ -95,7 +95,7 @@ ao_adc_dump(void) AO_ADC_DUMP(&packet); } -__code struct ao_cmds ao_adc_cmds[] = { +const struct ao_cmds ao_adc_cmds[] = { { ao_adc_dump, "a\0Display current ADC values" }, { 0, NULL }, }; diff --git a/src/stm/ao_adc_stm.c b/src/stm/ao_adc_stm.c index 24912bb2..ffdcccc0 100644 --- a/src/stm/ao_adc_stm.c +++ b/src/stm/ao_adc_stm.c @@ -45,26 +45,7 @@ static void ao_adc_done(int index) (void) index; AO_DATA_PRESENT(AO_DATA_ADC); ao_dma_done_transfer(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC1)); - if (ao_data_present == AO_DATA_ALL) { -#if HAS_MS5607 - ao_data_ring[ao_data_head].ms5607_raw = ao_ms5607_current; -#endif -#if HAS_MMA655X - ao_data_ring[ao_data_head].mma655x = ao_mma655x_current; -#endif -#if HAS_HMC5883 - ao_data_ring[ao_data_head].hmc5883 = ao_hmc5883_current; -#endif -#if HAS_MPU6000 - ao_data_ring[ao_data_head].mpu6000 = ao_mpu6000_current; -#endif -#if HAS_MPU9250 - ao_data_ring[ao_data_head].mpu9250 = ao_mpu9250_current; -#endif - ao_data_ring[ao_data_head].tick = ao_tick_count; - ao_data_head = ao_data_ring_next(ao_data_head); - ao_wakeup((void *) &ao_data_head); - } + ao_data_fill(ao_data_head); ao_adc_ready = 1; } @@ -100,7 +81,7 @@ ao_adc_poll(void) * Fetch a copy of the most recent ADC data */ void -ao_adc_get(__xdata struct ao_adc *packet) +ao_adc_get(struct ao_adc *packet) { #if HAS_FLIGHT uint8_t i = ao_data_ring_prev(ao_sample_data); @@ -177,7 +158,7 @@ static const char *ao_adc_name[AO_NUM_ADC] = { #endif static void -ao_adc_dump(void) __reentrant +ao_adc_dump(void) { struct ao_data packet; #ifndef AO_ADC_DUMP @@ -203,7 +184,7 @@ ao_adc_dump(void) __reentrant #endif } -__code struct ao_cmds ao_adc_cmds[] = { +const struct ao_cmds ao_adc_cmds[] = { { ao_adc_dump, "a\0Display current ADC values" }, { 0, NULL }, }; diff --git a/src/stm/ao_arch.h b/src/stm/ao_arch.h index 679dba44..e56375ca 100644 --- a/src/stm/ao_arch.h +++ b/src/stm/ao_arch.h @@ -41,11 +41,6 @@ #define ao_arch_naked_declare __attribute__((naked)) #define ao_arch_naked_define -#define __pdata -#define __data -#define __xdata -#define __code const -#define __reentrant #define __interrupt(n) #define __at(n) @@ -57,28 +52,11 @@ #define ao_arch_interrupt(n) /* nothing */ -#undef putchar -#undef getchar -#define putchar(c) ao_putchar(c) -#define getchar ao_getchar - -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 AO_ROMCONFIG_SYMBOL __attribute__((section(".romconfig"))) const #define ao_arch_task_members\ uint32_t *sp; /* saved stack pointer */ diff --git a/src/stm/ao_arch_funcs.h b/src/stm/ao_arch_funcs.h index 522059bc..7fe6a732 100644 --- a/src/stm/ao_arch_funcs.h +++ b/src/stm/ao_arch_funcs.h @@ -39,6 +39,9 @@ #define AO_SPI_SPEED_200kHz AO_SPI_SPEED_125kHz +#define AO_SPI_CPOL_BIT 4 +#define AO_SPI_CPHA_BIT 5 + #define AO_SPI_CONFIG_1 0x00 #define AO_SPI_1_CONFIG_PA5_PA6_PA7 AO_SPI_CONFIG_1 #define AO_SPI_2_CONFIG_PB13_PB14_PB15 AO_SPI_CONFIG_1 @@ -64,6 +67,15 @@ #define AO_SPI_INDEX(id) ((id) & AO_SPI_INDEX_MASK) #define AO_SPI_CONFIG(id) ((id) & AO_SPI_CONFIG_MASK) +#define AO_SPI_PIN_CONFIG(id) ((id) & (AO_SPI_INDEX_MASK | AO_SPI_CONFIG_MASK)) +#define AO_SPI_CPOL(id) ((uint32_t) (((id) >> AO_SPI_CPOL_BIT) & 1)) +#define AO_SPI_CPHA(id) ((uint32_t) (((id) >> AO_SPI_CPHA_BIT) & 1)) + +#define AO_SPI_MAKE_MODE(pol,pha) (((pol) << AO_SPI_CPOL_BIT) | ((pha) << AO_SPI_CPHA_BIT)) +#define AO_SPI_MODE_0 AO_SPI_MAKE_MODE(0,0) +#define AO_SPI_MODE_1 AO_SPI_MAKE_MODE(0,1) +#define AO_SPI_MODE_2 AO_SPI_MAKE_MODE(1,0) +#define AO_SPI_MODE_3 AO_SPI_MAKE_MODE(1,1) uint8_t ao_spi_try_get(uint8_t spi_index, uint32_t speed, uint8_t task_id); @@ -166,8 +178,8 @@ ao_spi_try_get_mask(struct stm_gpio *reg, uint16_t mask, uint8_t bus, uint32_t s ao_spi_put(bus); \ } while (0) -#define ao_spi_get_bit(reg,bit,pin,bus,speed) ao_spi_get_mask(reg,(1<<bit),bus,speed) -#define ao_spi_put_bit(reg,bit,pin,bus) ao_spi_put_mask(reg,(1<<bit),bus) +#define ao_spi_get_bit(reg,bit,bus,speed) ao_spi_get_mask(reg,(1<<bit),bus,speed) +#define ao_spi_put_bit(reg,bit,bus) ao_spi_put_mask(reg,(1<<bit),bus) #define ao_enable_port(port) do { \ if ((port) == &stm_gpioa) \ @@ -196,9 +208,9 @@ ao_spi_try_get_mask(struct stm_gpio *reg, uint16_t mask, uint8_t bus, uint32_t s } while (0) -#define ao_gpio_set(port, bit, pin, v) stm_gpio_set(port, bit, v) +#define ao_gpio_set(port, bit, v) stm_gpio_set(port, bit, v) -#define ao_gpio_get(port, bit, pin) stm_gpio_get(port, bit) +#define ao_gpio_get(port, bit) stm_gpio_get(port, bit) #define ao_gpio_set_bits(port, bits) stm_gpio_set_bits(port, bits) @@ -208,9 +220,9 @@ ao_spi_try_get_mask(struct stm_gpio *reg, uint16_t mask, uint8_t bus, uint32_t s #define ao_gpio_get_all(port) stm_gpio_get_all(port) -#define ao_enable_output(port,bit,pin,v) do { \ +#define ao_enable_output(port,bit,v) do { \ ao_enable_port(port); \ - ao_gpio_set(port, bit, pin, v); \ + ao_gpio_set(port, bit, v); \ stm_moder_set(port, bit, STM_MODER_OUTPUT);\ } while (0) @@ -223,7 +235,7 @@ ao_spi_try_get_mask(struct stm_gpio *reg, uint16_t mask, uint8_t bus, uint32_t s #define AO_OUTPUT_PUSH_PULL STM_OTYPER_PUSH_PULL #define AO_OUTPUT_OPEN_DRAIN STM_OTYPER_OPEN_DRAIN -#define ao_gpio_set_output_mode(port,bit,pin,mode) \ +#define ao_gpio_set_output_mode(port,bit,mode) \ stm_otyper_set(port, pin, mode) #define ao_gpio_set_mode(port,bit,mode) do { \ @@ -248,8 +260,8 @@ ao_spi_try_get_mask(struct stm_gpio *reg, uint16_t mask, uint8_t bus, uint32_t s stm_moder_set(port, bit, STM_MODER_INPUT); \ } while (0) -#define ao_set_output(port, bit, pin, v) do { \ - ao_gpio_set(port, bit, pin, v); \ +#define ao_set_output(port, bit, v) do { \ + ao_gpio_set(port, bit, v); \ stm_moder_set(port, bit, STM_MODER_OUTPUT); \ } while (0) diff --git a/src/stm/ao_beep_stm.c b/src/stm/ao_beep_stm.c index 0b4e6012..2746d7f8 100644 --- a/src/stm/ao_beep_stm.c +++ b/src/stm/ao_beep_stm.c @@ -18,37 +18,59 @@ #include "ao.h" -#ifndef BEEPER_CHANNEL -#define BEEPER_CHANNEL 1 +#if BEEPER_TIMER == 2 +#define stm_beeper stm_tim2 +#define RCC_BEEPER STM_RCC_APB1ENR_TIM2EN +#define BEEPER_AFR STM_AFR_AF1 +#elif BEEPER_TIMER == 3 +#define stm_beeper stm_tim3 +#define RCC_BEEPER STM_RCC_APB1ENR_TIM3EN +#define BEEPER_AFR STM_AFR_AF2 +#elif BEEPER_TIMER == 4 +#define stm_beeper stm_tim4 +#define RCC_BEEPER STM_RCC_APB1ENR_TIM4EN +#define BEEPER_AFR STM_AFR_AF2 +#else +#error BEEPER_TIMER must be 2, 3 or 4 #endif void ao_beep(uint8_t beep) { if (beep == 0) { - stm_tim3.cr1 = 0; - stm_rcc.apb1enr &= ~(1 << STM_RCC_APB1ENR_TIM3EN); + stm_beeper.cr1 = 0; + stm_rcc.apb1enr &= ~(1 << RCC_BEEPER); } else { - stm_rcc.apb1enr |= (1 << STM_RCC_APB1ENR_TIM3EN); + stm_rcc.apb1enr |= (1 << RCC_BEEPER); - stm_tim3.cr2 = ((0 << STM_TIM234_CR2_TI1S) | + stm_beeper.cr2 = ((0 << STM_TIM234_CR2_TI1S) | (STM_TIM234_CR2_MMS_RESET << STM_TIM234_CR2_MMS) | (0 << STM_TIM234_CR2_CCDS)); /* Set prescaler to match cc1111 clocks */ - stm_tim3.psc = AO_TIM23467_CLK / 750000; + stm_beeper.psc = AO_TIM23467_CLK / 750000; /* 1. Select the counter clock (internal, external, prescaler). * * Setting SMCR to zero means use the internal clock */ - stm_tim3.smcr = 0; + stm_beeper.smcr = 0; /* 2. Write the desired data in the TIMx_ARR and TIMx_CCRx registers. */ - stm_tim3.arr = beep; - stm_tim3.ccr1 = beep; + stm_beeper.arr = beep; +#if BEEPER_CHANNEL == 1 + stm_beeper.ccr1 = beep; +#elif BEEPER_CHANNEL == 2 + stm_beeper.ccr2 = beep; +#elif BEEPER_CHANNEL == 3 + stm_beeper.ccr3 = beep; +#elif BEEPER_CHANNEL == 4 + stm_beeper.ccr4 = beep; +#else +#error invalid BEEPER_CHANNEL +#endif /* 3. Set the CCxIE and/or CCxDE bits if an interrupt and/or a * DMA request is to be generated. @@ -61,63 +83,56 @@ ao_beep(uint8_t beep) * is enabled and active high. */ -#if BEEPER_CHANNEL == 1 - stm_tim3.ccmr1 = ((0 << STM_TIM234_CCMR1_OC2CE) | - (STM_TIM234_CCMR1_OC2M_FROZEN << STM_TIM234_CCMR1_OC2M) | - (0 << STM_TIM234_CCMR1_OC2PE) | - (0 << STM_TIM234_CCMR1_OC2FE) | - (STM_TIM234_CCMR1_CC2S_OUTPUT << STM_TIM234_CCMR1_CC2S) | - - (0 << STM_TIM234_CCMR1_OC1CE) | - (STM_TIM234_CCMR1_OC1M_TOGGLE << STM_TIM234_CCMR1_OC1M) | - (0 << STM_TIM234_CCMR1_OC1PE) | - (0 << STM_TIM234_CCMR1_OC1FE) | - (STM_TIM234_CCMR1_CC1S_OUTPUT << STM_TIM234_CCMR1_CC1S)); - - stm_tim3.ccer = ((0 << STM_TIM234_CCER_CC4NP) | - (0 << STM_TIM234_CCER_CC4P) | - (0 << STM_TIM234_CCER_CC4E) | - (0 << STM_TIM234_CCER_CC3NP) | - (0 << STM_TIM234_CCER_CC3P) | - (0 << STM_TIM234_CCER_CC3E) | - (0 << STM_TIM234_CCER_CC2NP) | - (0 << STM_TIM234_CCER_CC2P) | - (0 << STM_TIM234_CCER_CC2E) | - (0 << STM_TIM234_CCER_CC1NP) | - (0 << STM_TIM234_CCER_CC1P) | - (1 << STM_TIM234_CCER_CC1E)); +#define OC1M (BEEPER_CHANNEL == 1 ? STM_TIM234_CCMR1_OC1M_TOGGLE : STM_TIM234_CCMR1_OC1M_FROZEN) +#define OC2M (BEEPER_CHANNEL == 2 ? STM_TIM234_CCMR1_OC2M_TOGGLE : STM_TIM234_CCMR1_OC2M_FROZEN) +#define OC3M (BEEPER_CHANNEL == 3 ? STM_TIM234_CCMR2_OC3M_TOGGLE : STM_TIM234_CCMR2_OC3M_FROZEN) +#define OC4M (BEEPER_CHANNEL == 4 ? STM_TIM234_CCMR2_OC4M_TOGGLE : STM_TIM234_CCMR2_OC4M_FROZEN) + +#define CCER(n) (BEEPER_CHANNEL == (n) ? 1 : 0) + +#if BEEPER_CHANNEL == 1 || BEEPER_CHANNEL == 2 + stm_beeper.ccmr1 = ((0 << STM_TIM234_CCMR1_OC2CE) | + (OC2M << STM_TIM234_CCMR1_OC2M) | + (0 << STM_TIM234_CCMR1_OC2PE) | + (0 << STM_TIM234_CCMR1_OC2FE) | + (STM_TIM234_CCMR1_CC2S_OUTPUT << STM_TIM234_CCMR1_CC2S) | + + (0 << STM_TIM234_CCMR1_OC1CE) | + (OC1M << STM_TIM234_CCMR1_OC1M) | + (0 << STM_TIM234_CCMR1_OC1PE) | + (0 << STM_TIM234_CCMR1_OC1FE) | + (STM_TIM234_CCMR1_CC1S_OUTPUT << STM_TIM234_CCMR1_CC1S)); +#elif BEEPER_CHANNEL == 3 || BEEPER_CHANNEL == 4 + stm_beeper.ccmr2 = ((0 << STM_TIM234_CCMR2_OC4CE) | + (OC4M << STM_TIM234_CCMR2_OC4M) | + (0 << STM_TIM234_CCMR2_OC4PE) | + (0 << STM_TIM234_CCMR2_OC4FE) | + (STM_TIM234_CCMR2_CC4S_OUTPUT << STM_TIM234_CCMR2_CC4S) | + + (0 << STM_TIM234_CCMR2_OC3CE) | + (OC3M << STM_TIM234_CCMR2_OC3M) | + (0 << STM_TIM234_CCMR2_OC3PE) | + (0 << STM_TIM234_CCMR2_OC3FE) | + (STM_TIM234_CCMR2_CC3S_OUTPUT << STM_TIM234_CCMR2_CC3S)); +#else +#error invalid BEEPER_CHANNEL #endif -#if BEEPER_CHANNEL == 4 - stm_tim3.ccmr2 = ((0 << STM_TIM234_CCMR2_OC4CE) | - (STM_TIM234_CCMR2_OC4M_TOGGLE << STM_TIM234_CCMR2_OC4M) | - (0 << STM_TIM234_CCMR2_OC4PE) | - (0 << STM_TIM234_CCMR2_OC4FE) | - (STM_TIM234_CCMR2_CC4S_OUTPUT << STM_TIM234_CCMR2_CC4S) | - - (0 << STM_TIM234_CCMR2_OC3CE) | - (STM_TIM234_CCMR2_OC3M_FROZEN << STM_TIM234_CCMR2_OC3M) | - (0 << STM_TIM234_CCMR2_OC3PE) | - (0 << STM_TIM234_CCMR2_OC3FE) | - (STM_TIM234_CCMR2_CC3S_OUTPUT << STM_TIM234_CCMR2_CC3S)); - - stm_tim3.ccer = ((0 << STM_TIM234_CCER_CC4NP) | - (0 << STM_TIM234_CCER_CC4P) | - (1 << STM_TIM234_CCER_CC4E) | - (0 << STM_TIM234_CCER_CC3NP) | - (0 << STM_TIM234_CCER_CC3P) | - (0 << STM_TIM234_CCER_CC3E) | - (0 << STM_TIM234_CCER_CC2NP) | - (0 << STM_TIM234_CCER_CC2P) | - (0 << STM_TIM234_CCER_CC2E) | - (0 << STM_TIM234_CCER_CC1NP) | - (0 << STM_TIM234_CCER_CC1P) | - (0 << STM_TIM234_CCER_CC1E)); -#endif - + stm_beeper.ccer = ((0 << STM_TIM234_CCER_CC4NP) | + (0 << STM_TIM234_CCER_CC4P) | + (CCER(4) << STM_TIM234_CCER_CC4E) | + (0 << STM_TIM234_CCER_CC3NP) | + (0 << STM_TIM234_CCER_CC3P) | + (CCER(3) << STM_TIM234_CCER_CC3E) | + (0 << STM_TIM234_CCER_CC2NP) | + (0 << STM_TIM234_CCER_CC2P) | + (CCER(2) << STM_TIM234_CCER_CC2E) | + (0 << STM_TIM234_CCER_CC1NP) | + (0 << STM_TIM234_CCER_CC1P) | + (CCER(1) << STM_TIM234_CCER_CC1E)); /* 5. Enable the counter by setting the CEN bit in the TIMx_CR1 register. */ - stm_tim3.cr1 = ((STM_TIM234_CR1_CKD_1 << STM_TIM234_CR1_CKD) | + stm_beeper.cr1 = ((STM_TIM234_CR1_CKD_1 << STM_TIM234_CR1_CKD) | (0 << STM_TIM234_CR1_ARPE) | (STM_TIM234_CR1_CMS_EDGE << STM_TIM234_CR1_CMS) | (0 << STM_TIM234_CR1_DIR) | @@ -127,12 +142,12 @@ ao_beep(uint8_t beep) (1 << STM_TIM234_CR1_CEN)); /* Update the values */ - stm_tim3.egr = (1 << STM_TIM234_EGR_UG); + stm_beeper.egr = (1 << STM_TIM234_EGR_UG); } } void -ao_beep_for(uint8_t beep, uint16_t ticks) __reentrant +ao_beep_for(uint8_t beep, uint16_t ticks) { ao_beep(beep); ao_delay(ticks); @@ -142,24 +157,9 @@ ao_beep_for(uint8_t beep, uint16_t ticks) __reentrant void ao_beep_init(void) { -#if BEEPER_CHANNEL == 1 - - /* Our beeper is on PC6, which is hooked to TIM3_CH1. - */ - stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_GPIOCEN); - - stm_afr_set(&stm_gpioc, 6, STM_AFR_AF2); -#endif -#if BEEPER_CHANNEL == 4 - - /* Our beeper is on PB1, which is hooked to TIM3_CH4. - */ - stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_GPIOBEN); - - stm_afr_set(&stm_gpiob, 1, STM_AFR_AF2); -#endif + ao_enable_port(BEEPER_PORT); + stm_afr_set(BEEPER_PORT, BEEPER_PIN, BEEPER_AFR); /* Leave the timer off until requested */ - - stm_rcc.apb1enr &= ~(1 << STM_RCC_APB1ENR_TIM3EN); + stm_rcc.apb1enr &= ~(1 << RCC_BEEPER); } diff --git a/src/stm/ao_eeprom_stm.c b/src/stm/ao_eeprom_stm.c index 4f477122..d3e3338d 100644 --- a/src/stm/ao_eeprom_stm.c +++ b/src/stm/ao_eeprom_stm.c @@ -117,10 +117,10 @@ ao_intflash_read(uint16_t pos) */ uint8_t -ao_eeprom_write(ao_pos_t pos32, __xdata void *v, uint16_t len) +ao_eeprom_write(ao_pos_t pos32, void *v, uint16_t len) { uint16_t pos = pos32; - __xdata uint8_t *d = v; + uint8_t *d = v; if (pos >= ao_eeprom_total || pos + len > ao_eeprom_total) return 0; @@ -151,7 +151,7 @@ ao_eeprom_write(ao_pos_t pos32, __xdata void *v, uint16_t len) * Read from eeprom */ uint8_t -ao_eeprom_read(ao_pos_t pos, __xdata void *v, uint16_t len) +ao_eeprom_read(ao_pos_t pos, void *v, uint16_t len) { uint8_t *d = v; diff --git a/src/stm/ao_flash_stm_pins.h b/src/stm/ao_flash_stm_pins.h index d5893c80..b82046d7 100644 --- a/src/stm/ao_flash_stm_pins.h +++ b/src/stm/ao_flash_stm_pins.h @@ -21,6 +21,10 @@ #include <ao_flash_pins.h> +#ifndef AO_PLLMUL + +#if AO_HSE == 8000000 + /* PLLVCO = 96MHz (so that USB will work) */ #define AO_PLLMUL 12 #define AO_RCC_CFGR_PLLMUL (STM_RCC_CFGR_PLLMUL_12) @@ -29,6 +33,22 @@ #define AO_PLLDIV 3 #define AO_RCC_CFGR_PLLDIV (STM_RCC_CFGR_PLLDIV_3) +#endif + +#if AO_HSE == 16000000 + +/* PLLVCO = 96MHz (so that USB will work) */ +#define AO_PLLMUL 6 +#define AO_RCC_CFGR_PLLMUL (STM_RCC_CFGR_PLLMUL_6) + +/* SYSCLK = 32MHz */ +#define AO_PLLDIV 3 +#define AO_RCC_CFGR_PLLDIV (STM_RCC_CFGR_PLLDIV_3) + +#endif + +#endif + /* HCLK = 32MHZ (CPU clock) */ #define AO_AHB_PRESCALER 1 #define AO_RCC_CFGR_HPRE_DIV STM_RCC_CFGR_HPRE_DIV_1 diff --git a/src/stm/ao_i2c_stm.c b/src/stm/ao_i2c_stm.c index 59cad495..23805aa8 100644 --- a/src/stm/ao_i2c_stm.c +++ b/src/stm/ao_i2c_stm.c @@ -275,7 +275,7 @@ ao_i2c_send(void *block, uint16_t len, uint8_t index, uint8_t stop) stm_i2c->cr1 = AO_STM_I2C_CR1 | (1 << STM_I2C_CR1_STOP); ao_i2c_wait_stop(index); } - return TRUE; + return true; } void @@ -300,10 +300,10 @@ uint8_t ao_i2c_recv(void *block, uint16_t len, uint8_t index, uint8_t stop) { struct stm_i2c *stm_i2c = ao_i2c_stm_info[index].stm_i2c; - uint8_t ret = TRUE; + uint8_t ret = true; if (len == 0) - return TRUE; + return true; if (len == 1) { ao_i2c_recv_data[index] = block; ao_i2c_recv_len[index] = 1; diff --git a/src/stm/ao_interrupt.c b/src/stm/ao_interrupt.c index eb1ed0b5..d8be3667 100644 --- a/src/stm/ao_interrupt.c +++ b/src/stm/ao_interrupt.c @@ -24,7 +24,7 @@ extern void main(void); extern char __stack__; extern char __text_start__, __text_end__; -extern char __data_start__, __data_end__; +extern char _start__, _end__; extern char __bss_start__, __bss_end__; /* Interrupt functions */ @@ -83,7 +83,7 @@ void start(void) #endif /* Set interrupt vector table offset */ stm_nvic.vto = (uint32_t) &stm_interrupt_vector; - memcpy(&__data_start__, &__text_end__, &__data_end__ - &__data_start__); + memcpy(&_start__, &__text_end__, &_end__ - &_start__); memset(&__bss_start__, '\0', &__bss_end__ - &__bss_start__); main(); } diff --git a/src/stm/ao_lcd_stm.c b/src/stm/ao_lcd_stm.c index 10d5d620..1947012b 100644 --- a/src/stm/ao_lcd_stm.c +++ b/src/stm/ao_lcd_stm.c @@ -326,12 +326,9 @@ ao_lcd_stm_seg_set(void) { int com, seg, val; int n, bit; - ao_cmd_decimal(); - com = ao_cmd_lex_i; - ao_cmd_decimal(); - seg = ao_cmd_lex_u32; - ao_cmd_decimal(); - val = ao_cmd_lex_i; + com = ao_cmd_decimal(); + seg = ao_cmd_decimal(); + val = ao_cmd_decimal(); printf ("com: %d seg: %d val: %d\n", com, seg, val); ao_lcd_set(com, seg, val); ao_lcd_flush(); diff --git a/src/stm/ao_led.c b/src/stm/ao_led.c deleted file mode 100644 index a7033dbb..00000000 --- a/src/stm/ao_led.c +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright © 2012 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" - -#if LED_PER_LED -static const struct { - struct stm_gpio *port; - uint16_t pin; -} ao_leds[] = { -#ifdef LED_0_PORT - [0] { LED_0_PORT, LED_0_PIN }, -#endif -#ifdef LED_1_PORT - [1] { LED_1_PORT, LED_1_PIN }, -#endif -#ifdef LED_2_PORT - [2] { LED_2_PORT, LED_2_PIN }, -#endif -#ifdef LED_3_PORT - [3] { LED_3_PORT, LED_3_PIN }, -#endif -#ifdef LED_4_PORT - [4] { LED_4_PORT, LED_4_PIN }, -#endif -#ifdef LED_5_PORT - [5] { LED_5_PORT, LED_5_PIN }, -#endif -#ifdef LED_6_PORT - [6] { LED_6_PORT, LED_6_PIN }, -#endif -#ifdef LED_7_PORT - [7] { LED_7_PORT, LED_7_PIN }, -#endif -#ifdef LED_8_PORT - [8] { LED_8_PORT, LED_8_PIN }, -#endif -#ifdef LED_9_PORT - [9] { LED_9_PORT, LED_9_PIN }, -#endif -#ifdef LED_10_PORT - [10] { LED_10_PORT, LED_10_PIN }, -#endif -#ifdef LED_11_PORT - [11] { LED_11_PORT, LED_11_PIN }, -#endif -#ifdef LED_12_PORT - [12] { LED_12_PORT, LED_12_PIN }, -#endif -#ifdef LED_13_PORT - [13] { LED_13_PORT, LED_13_PIN }, -#endif -#ifdef LED_14_PORT - [14] { LED_14_PORT, LED_14_PIN }, -#endif -#ifdef LED_15_PORT - [15] { LED_15_PORT, LED_15_PIN }, -#endif -}; -#define N_LED (sizeof (ao_leds)/sizeof(ao_leds[0])) -#endif -static AO_LED_TYPE ao_led_enable; - -void -ao_led_on(AO_LED_TYPE colors) -{ -#ifdef LED_PER_LED - AO_LED_TYPE i; - for (i = 0; i < N_LED; i++) - if (colors & (1 << i)) - ao_gpio_set(ao_leds[i].port, ao_leds[i].pin, foo, 1); -#else -#ifdef LED_PORT - LED_PORT->bsrr = (colors & ao_led_enable); -#else -#ifdef LED_PORT_0 - LED_PORT_0->bsrr = ((colors & ao_led_enable) & LED_PORT_0_MASK) << LED_PORT_0_SHIFT; -#endif -#ifdef LED_PORT_1 - LED_PORT_1->bsrr = ((colors & ao_led_enable) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT; -#endif -#endif -#endif -} - -void -ao_led_off(AO_LED_TYPE colors) -{ -#ifdef LED_PER_LED - AO_LED_TYPE i; - for (i = 0; i < N_LED; i++) - if (colors & (1 << i)) - ao_gpio_set(ao_leds[i].port, ao_leds[i].pin, foo, 0); -#else -#ifdef LED_PORT - LED_PORT->bsrr = (uint32_t) (colors & ao_led_enable) << 16; -#else -#ifdef LED_PORT_0 - LED_PORT_0->bsrr = ((uint32_t) (colors & ao_led_enable) & LED_PORT_0_MASK) << (LED_PORT_0_SHIFT + 16); -#endif -#ifdef LED_PORT_1 - LED_PORT_1->bsrr = ((uint32_t) (colors & ao_led_enable) & LED_PORT_1_MASK) << (LED_PORT_1_SHIFT + 16); -#endif -#endif -#endif -} - -void -ao_led_set(AO_LED_TYPE colors) -{ - AO_LED_TYPE on = colors & ao_led_enable; - AO_LED_TYPE off = ~colors & ao_led_enable; - - ao_led_off(off); - ao_led_on(on); -} - -void -ao_led_toggle(AO_LED_TYPE colors) -{ -#ifdef LED_PER_LED - AO_LED_TYPE i; - for (i = 0; i < N_LED; i++) - if (colors & (1 << i)) - ao_gpio_set(ao_leds[i].port, ao_leds[i].pin, foo, ~ao_gpio_get(ao_leds[i].port, ao_leds[i].pin, foo)); -#else -#ifdef LED_PORT - LED_PORT->odr ^= (colors & ao_led_enable); -#else -#ifdef LED_PORT_0 - LED_PORT_0->odr ^= ((colors & ao_led_enable) & LED_PORT_0_MASK) << LED_PORT_0_SHIFT; -#endif -#ifdef LED_PORT_1 - LED_PORT_1->odr ^= ((colors & ao_led_enable) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT; -#endif -#endif -#endif -} - -void -ao_led_for(AO_LED_TYPE colors, AO_LED_TYPE ticks) __reentrant -{ - ao_led_on(colors); - ao_delay(ticks); - ao_led_off(colors); -} - -#define init_led_pin(port, bit) do { \ - stm_moder_set(port, bit, STM_MODER_OUTPUT); \ - stm_otyper_set(port, bit, STM_OTYPER_PUSH_PULL); \ - } while (0) - -void -ao_led_init(AO_LED_TYPE enable) -{ - AO_LED_TYPE bit; - - ao_led_enable = enable; -#if LED_PER_LED - for (bit = 0; bit < N_LED; bit++) - ao_enable_output(ao_leds[bit].port, ao_leds[bit].pin, foo, 0); -#else -#ifdef LED_PORT - stm_rcc.ahbenr |= (1 << LED_PORT_ENABLE); - LED_PORT->odr &= ~enable; -#else -#ifdef LED_PORT_0 - stm_rcc.ahbenr |= (1 << LED_PORT_0_ENABLE); - LED_PORT_0->odr &= ~((enable & ao_led_enable) & LED_PORT_0_MASK) << LED_PORT_0_SHIFT; -#endif -#ifdef LED_PORT_1 - stm_rcc.ahbenr |= (1 << LED_PORT_1_ENABLE); - LED_PORT_1->odr &= ~((enable & ao_led_enable) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT; -#endif -#ifdef LED_PORT_2 - stm_rcc.ahbenr |= (1 << LED_PORT_1_ENABLE); - LED_PORT_1->odr &= ~((enable & ao_led_enable) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT; -#endif -#endif - for (bit = 0; bit < 16; bit++) { - if (enable & (1 << bit)) { -#ifdef LED_PORT - init_led_pin(LED_PORT, bit); -#else -#ifdef LED_PORT_0 - if (LED_PORT_0_MASK & (1 << bit)) - init_led_pin(LED_PORT_0, bit + LED_PORT_0_SHIFT); -#endif -#ifdef LED_PORT_1 - if (LED_PORT_1_MASK & (1 << bit)) - init_led_pin(LED_PORT_1, bit + LED_PORT_1_SHIFT); -#endif -#ifdef LED_PORT_2 - if (LED_PORT_2_MASK & (1 << bit)) - init_led_pin(LED_PORT_2, bit + LED_PORT_2_SHIFT); -#endif -#endif - } - } -#endif -} diff --git a/src/stm/ao_led_stm.c b/src/stm/ao_led_stm.c new file mode 100644 index 00000000..7dcbb661 --- /dev/null +++ b/src/stm/ao_led_stm.c @@ -0,0 +1,144 @@ +/* + * Copyright © 2012 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" + +#if LED_PER_LED +#error LED_PER_LED support is in ao_led.c now +#endif + +void +ao_led_on(AO_LED_TYPE colors) +{ +#ifdef LED_PORT + LED_PORT->bsrr = (colors & LEDS_AVAILABLE); +#else +#ifdef LED_PORT_0 + LED_PORT_0->bsrr = ((colors & LEDS_AVAILABLE) & LED_PORT_0_MASK) << LED_PORT_0_SHIFT; +#endif +#ifdef LED_PORT_1 + LED_PORT_1->bsrr = ((colors & LEDS_AVAILABLE) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT; +#endif +#ifdef LED_PORT_2 + LED_PORT_2->bsrr = ((colors & LEDS_AVAILABLE) & LED_PORT_2_MASK) << LED_PORT_2_SHIFT; +#endif +#endif +} + +void +ao_led_off(AO_LED_TYPE colors) +{ +#ifdef LED_PORT + LED_PORT->bsrr = (uint32_t) (colors & LEDS_AVAILABLE) << 16; +#else +#ifdef LED_PORT_0 + LED_PORT_0->bsrr = ((uint32_t) (colors & LEDS_AVAILABLE) & LED_PORT_0_MASK) << (LED_PORT_0_SHIFT + 16); +#endif +#ifdef LED_PORT_1 + LED_PORT_1->bsrr = ((uint32_t) (colors & LEDS_AVAILABLE) & LED_PORT_1_MASK) << (LED_PORT_1_SHIFT + 16); +#endif +#ifdef LED_PORT_2 + LED_PORT_2->bsrr = ((uint32_t) (colors & LEDS_AVAILABLE) & LED_PORT_2_MASK) << (LED_PORT_2_SHIFT + 16); +#endif +#endif +} + +void +ao_led_set(AO_LED_TYPE colors) +{ + AO_LED_TYPE on = colors & LEDS_AVAILABLE; + AO_LED_TYPE off = ~colors & LEDS_AVAILABLE; + + ao_led_off(off); + ao_led_on(on); +} + +void +ao_led_toggle(AO_LED_TYPE colors) +{ +#ifdef LED_PORT + LED_PORT->odr ^= (colors & LEDS_AVAILABLE); +#else +#ifdef LED_PORT_0 + LED_PORT_0->odr ^= ((colors & LEDS_AVAILABLE) & LED_PORT_0_MASK) << LED_PORT_0_SHIFT; +#endif +#ifdef LED_PORT_1 + LED_PORT_1->odr ^= ((colors & LEDS_AVAILABLE) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT; +#endif +#ifdef LED_PORT_2 + LED_PORT_2->odr ^= ((colors & LEDS_AVAILABLE) & LED_PORT_2_MASK) << LED_PORT_2_SHIFT; +#endif +#endif +} + +void +ao_led_for(AO_LED_TYPE colors, AO_LED_TYPE ticks) +{ + ao_led_on(colors); + ao_delay(ticks); + ao_led_off(colors); +} + +#define init_led_pin(port, bit) do { \ + stm_moder_set(port, bit, STM_MODER_OUTPUT); \ + stm_otyper_set(port, bit, STM_OTYPER_PUSH_PULL); \ + } while (0) + +void +ao_led_init(void) +{ + AO_LED_TYPE bit; + +#ifdef LED_PORT + stm_rcc.ahbenr |= (1 << LED_PORT_ENABLE); + LED_PORT->odr &= ~LEDS_AVAILABLE; +#else +#ifdef LED_PORT_0 + stm_rcc.ahbenr |= (1 << LED_PORT_0_ENABLE); + LED_PORT_0->odr &= (uint32_t) ~(LEDS_AVAILABLE & LED_PORT_0_MASK) << LED_PORT_0_SHIFT; +#endif +#ifdef LED_PORT_1 + stm_rcc.ahbenr |= (1 << LED_PORT_1_ENABLE); + LED_PORT_1->odr &= (uint32_t) ~(LEDS_AVAILABLE & LED_PORT_1_MASK) << LED_PORT_1_SHIFT; +#endif +#ifdef LED_PORT_2 + stm_rcc.ahbenr |= (1 << LED_PORT_2_ENABLE); + LED_PORT_2->odr &= (uint32_t) ~(LEDS_AVAILABLE & LED_PORT_2_MASK) << LED_PORT_2_SHIFT; +#endif +#endif + for (bit = 0; bit < sizeof (AO_LED_TYPE) * 8; bit++) { + if (LEDS_AVAILABLE & (1 << bit)) { +#ifdef LED_PORT + init_led_pin(LED_PORT, bit); +#else +#ifdef LED_PORT_0 + if (LED_PORT_0_MASK & (1 << bit)) + init_led_pin(LED_PORT_0, bit + LED_PORT_0_SHIFT); +#endif +#ifdef LED_PORT_1 + if (LED_PORT_1_MASK & (1 << bit)) + init_led_pin(LED_PORT_1, bit + LED_PORT_1_SHIFT); +#endif +#ifdef LED_PORT_2 + if (LED_PORT_2_MASK & (1 << bit)) + init_led_pin(LED_PORT_2, bit + LED_PORT_2_SHIFT); +#endif +#endif + } + } +} diff --git a/src/stm/ao_pwm_stm.c b/src/stm/ao_pwm_stm.c index 53000a17..341f8887 100644 --- a/src/stm/ao_pwm_stm.c +++ b/src/stm/ao_pwm_stm.c @@ -107,10 +107,8 @@ ao_pwm_cmd(void) uint8_t ch; uint16_t val; - ao_cmd_decimal(); - ch = ao_cmd_lex_u32; - ao_cmd_decimal(); - val = ao_cmd_lex_u32; + ch = ao_cmd_decimal(); + val = ao_cmd_decimal(); if (ao_cmd_status != ao_cmd_success) return; diff --git a/src/stm/ao_romconfig.c b/src/stm/ao_romconfig.c deleted file mode 100644 index 63a48bec..00000000 --- a/src/stm/ao_romconfig.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright © 2011 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" - -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; -#ifndef AO_RADIO_CAL_DEFAULT -#define AO_RADIO_CAL_DEFAULT 0x01020304 -#endif -#if HAS_RADIO -AO_ROMCONFIG_SYMBOL (0) uint32_t ao_radio_cal = AO_RADIO_CAL_DEFAULT; -#endif diff --git a/src/stm/ao_serial_stm.c b/src/stm/ao_serial_stm.c index 2afee5b5..c1a2f1bd 100644 --- a/src/stm/ao_serial_stm.c +++ b/src/stm/ao_serial_stm.c @@ -33,7 +33,7 @@ _ao_usart_tx_start(struct ao_stm_usart *usart) { if (!ao_fifo_empty(usart->tx_fifo)) { #if HAS_SERIAL_SW_FLOW - if (usart->gpio_cts && ao_gpio_get(usart->gpio_cts, usart->pin_cts, foo) == 1) { + if (usart->gpio_cts && ao_gpio_get(usart->gpio_cts, usart->pin_cts) == 1) { ao_exti_enable(usart->gpio_cts, usart->pin_cts); return 0; } @@ -73,7 +73,7 @@ _ao_usart_rx(struct ao_stm_usart *usart, int is_stdin) * for it to drain a bunch */ if (usart->gpio_rts && ao_fifo_mostly(usart->rx_fifo)) { - ao_gpio_set(usart->gpio_rts, usart->pin_rts, usart->pin_rts, 1); + ao_gpio_set(usart->gpio_rts, usart->pin_rts, 1); usart->rts = 0; } #endif @@ -118,7 +118,7 @@ _ao_usart_pollchar(struct ao_stm_usart *usart) #if HAS_SERIAL_SW_FLOW /* If we've cleared RTS, check if there's space now and turn it back on */ if (usart->gpio_rts && usart->rts == 0 && ao_fifo_barely(usart->rx_fifo)) { - ao_gpio_set(usart->gpio_rts, usart->pin_rts, foo, 0); + ao_gpio_set(usart->gpio_rts, usart->pin_rts, 0); usart->rts = 1; } #endif @@ -403,7 +403,7 @@ ao_serial_set_sw_rts_cts(struct ao_stm_usart *usart, { /* Pull RTS low to note that there's space in the FIFO */ - ao_enable_output(port_rts, pin_rts, foo, 0); + ao_enable_output(port_rts, pin_rts, 0); usart->gpio_rts = port_rts; usart->pin_rts = pin_rts; usart->rts = 1; diff --git a/src/stm/ao_spi_stm.c b/src/stm/ao_spi_stm.c index 05078f3b..1a04a289 100644 --- a/src/stm/ao_spi_stm.c +++ b/src/stm/ao_spi_stm.c @@ -25,7 +25,7 @@ struct ao_spi_stm_info { }; static uint8_t ao_spi_mutex[STM_NUM_SPI]; -static uint8_t ao_spi_index[STM_NUM_SPI]; +static uint8_t ao_spi_pin_config[STM_NUM_SPI]; static const struct ao_spi_stm_info ao_spi_stm_info[STM_NUM_SPI] = { { @@ -285,11 +285,11 @@ ao_spi_duplex(const void *out, void *in, uint16_t len, uint8_t spi_index) } static void -ao_spi_disable_index(uint8_t spi_index) +ao_spi_disable_pin_config(uint8_t spi_pin_config) { /* Disable current config */ - switch (spi_index) { + switch (spi_pin_config) { case AO_SPI_1_PA5_PA6_PA7: stm_gpio_set(&stm_gpioa, 5, 1); stm_moder_set(&stm_gpioa, 5, STM_MODER_OUTPUT); @@ -324,11 +324,11 @@ ao_spi_disable_index(uint8_t spi_index) } static void -ao_spi_enable_index(uint8_t spi_index) +ao_spi_enable_pin_config(uint8_t spi_pin_config) { /* Enable new config */ - switch (spi_index) { + switch (spi_pin_config) { case AO_SPI_1_PA5_PA6_PA7: stm_afr_set(&stm_gpioa, 5, STM_AFR_AF5); stm_afr_set(&stm_gpioa, 6, STM_AFR_AF5); @@ -360,23 +360,26 @@ ao_spi_enable_index(uint8_t spi_index) static void ao_spi_config(uint8_t spi_index, uint32_t speed) { + uint8_t spi_pin_config = AO_SPI_PIN_CONFIG(spi_index); uint8_t id = AO_SPI_INDEX(spi_index); struct stm_spi *stm_spi = ao_spi_stm_info[id].stm_spi; - if (spi_index != ao_spi_index[id]) { + if (spi_pin_config != ao_spi_pin_config[id]) { /* Disable old config */ - ao_spi_disable_index(ao_spi_index[id]); + ao_spi_disable_pin_config(ao_spi_pin_config[id]); /* Enable new config */ - ao_spi_enable_index(spi_index); + ao_spi_enable_pin_config(spi_pin_config); /* Remember current config */ - ao_spi_index[id] = spi_index; + ao_spi_pin_config[id] = spi_pin_config; } + + /* Turn the SPI transceiver on and set the mode */ stm_spi->cr1 = ((0 << STM_SPI_CR1_BIDIMODE) | /* Three wire mode */ (0 << STM_SPI_CR1_BIDIOE) | (0 << STM_SPI_CR1_CRCEN) | /* CRC disabled */ @@ -389,8 +392,8 @@ ao_spi_config(uint8_t spi_index, uint32_t speed) (1 << STM_SPI_CR1_SPE) | /* Enable SPI unit */ (speed << STM_SPI_CR1_BR) | /* baud rate to pclk/4 */ (1 << STM_SPI_CR1_MSTR) | - (0 << STM_SPI_CR1_CPOL) | /* Format 0 */ - (0 << STM_SPI_CR1_CPHA)); + (AO_SPI_CPOL(spi_index) << STM_SPI_CR1_CPOL) | /* Format */ + (AO_SPI_CPHA(spi_index) << STM_SPI_CR1_CPHA)); validate_spi(stm_spi, 13, 0); } @@ -430,7 +433,7 @@ ao_spi_channel_init(uint8_t spi_index) uint8_t id = AO_SPI_INDEX(spi_index); struct stm_spi *stm_spi = ao_spi_stm_info[id].stm_spi; - ao_spi_disable_index(spi_index); + ao_spi_disable_pin_config(AO_SPI_PIN_CONFIG(spi_index)); stm_spi->cr1 = 0; stm_spi->cr2 = ((0 << STM_SPI_CR2_TXEIE) | @@ -512,7 +515,7 @@ ao_spi_init(void) stm_ospeedr_set(&stm_gpioe, 15, SPI_1_OSPEEDR); # endif stm_rcc.apb2enr |= (1 << STM_RCC_APB2ENR_SPI1EN); - ao_spi_index[0] = AO_SPI_CONFIG_NONE; + ao_spi_pin_config[0] = AO_SPI_CONFIG_NONE; ao_spi_channel_init(0); #endif @@ -530,7 +533,7 @@ ao_spi_init(void) stm_ospeedr_set(&stm_gpiod, 4, SPI_2_OSPEEDR); # endif stm_rcc.apb1enr |= (1 << STM_RCC_APB1ENR_SPI2EN); - ao_spi_index[1] = AO_SPI_CONFIG_NONE; + ao_spi_pin_config[1] = AO_SPI_CONFIG_NONE; ao_spi_channel_init(1); #endif #if DEBUG diff --git a/src/stm/ao_timer.c b/src/stm/ao_timer.c index 9d118b72..9e9436cf 100644 --- a/src/stm/ao_timer.c +++ b/src/stm/ao_timer.c @@ -39,8 +39,8 @@ ao_time(void) #endif #if AO_DATA_ALL -volatile __data uint8_t ao_data_interval = 1; -volatile __data uint8_t ao_data_count; +volatile uint8_t ao_data_interval = 1; +volatile uint8_t ao_data_count; #endif void stm_systick_isr(void) diff --git a/src/stm/ao_usb_stm.c b/src/stm/ao_usb_stm.c index b06814d2..d7cbd5b7 100644 --- a/src/stm/ao_usb_stm.c +++ b/src/stm/ao_usb_stm.c @@ -1079,7 +1079,7 @@ ao_usb_irq(void) control_count, out_count, in_count, int_count, reset_count); } -__code struct ao_cmds ao_usb_cmds[] = { +const struct ao_cmds ao_usb_cmds[] = { { ao_usb_irq, "I\0Show USB interrupt counts" }, { 0, NULL } }; diff --git a/src/stm/stm32l.h b/src/stm/stm32l.h index 1da817e7..0109ec81 100644 --- a/src/stm/stm32l.h +++ b/src/stm/stm32l.h @@ -241,15 +241,14 @@ stm_gpio_get_all(struct stm_gpio *gpio) { * ao_enable_gpio macro will expand into a huge pile of code * as the compiler won't do correct constant folding and * dead-code elimination + */ - extern struct stm_gpio stm_gpioa; - extern struct stm_gpio stm_gpiob; - extern struct stm_gpio stm_gpioc; - extern struct stm_gpio stm_gpiod; - extern struct stm_gpio stm_gpioe; - extern struct stm_gpio stm_gpioh; - -*/ +extern struct stm_gpio stm_gpioa; +extern struct stm_gpio stm_gpiob; +extern struct stm_gpio stm_gpioc; +extern struct stm_gpio stm_gpiod; +extern struct stm_gpio stm_gpioe; +extern struct stm_gpio stm_gpioh; #define stm_gpioh (*((struct stm_gpio *) 0x40021400)) #define stm_gpioe (*((struct stm_gpio *) 0x40021000)) |
