altos/stm: Interrupt priority is in the upper bits of the priority mask
authorKeith Packard <keithp@keithp.com>
Mon, 21 Nov 2016 04:54:10 +0000 (20:54 -0800)
committerKeith Packard <keithp@keithp.com>
Mon, 20 Feb 2017 20:31:16 +0000 (12:31 -0800)
Because the STM32L only offers 16 priority levels, the bottom four
bits of each priority mask are not used. All of the interrupt priority
settings in the system were using values < 16, making them all
effectively the same. Fix that by moving them into the upper 4 bits
and using symbolic constants everywhere.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/stm/ao_arch.h
src/stm/ao_dma_stm.c
src/stm/ao_exti_stm.c
src/stm/ao_serial_stm.c
src/stm/ao_timer.c
src/stm/ao_usb_stm.c

index 0cc29376aaf271c7002f9bef72fa7e3fb1b7307c..3d09af3c8e27de12f9fa24ce3486c18d920a4dd6 100644 (file)
@@ -122,10 +122,12 @@ extern const uint32_t ao_radio_cal;
 #define AO_TIM91011_CLK                (2 * AO_PCLK2)
 #endif
 
-#define AO_STM_NVIC_HIGH_PRIORITY      4
-#define AO_STM_NVIC_CLOCK_PRIORITY     6
-#define AO_STM_NVIC_MED_PRIORITY       8
-#define AO_STM_NVIC_LOW_PRIORITY       10
+/* The stm32l implements only 4 bits of the priority fields */
+
+#define AO_STM_NVIC_HIGH_PRIORITY      0x40
+#define AO_STM_NVIC_MED_PRIORITY       0x80
+#define AO_STM_NVIC_LOW_PRIORITY       0xC0
+#define AO_STM_NVIC_CLOCK_PRIORITY     0xf0
 
 void ao_lcd_stm_init(void);
 
index 6d77966076a88aefeac0f8a281fa81b5ebe0b662..63d6688a0c8258bea6e5a3620fec626d77c7c336 100644 (file)
@@ -155,7 +155,8 @@ ao_dma_init(void)
 
        for (index = 0; index < STM_NUM_DMA; index++) {
                stm_nvic_set_enable(STM_ISR_DMA1_CHANNEL1_POS + index);
-               stm_nvic_set_priority(STM_ISR_DMA1_CHANNEL1_POS + index, 4);
+               stm_nvic_set_priority(STM_ISR_DMA1_CHANNEL1_POS + index,
+                                     AO_STM_NVIC_MED_PRIORITY);
                ao_dma_allocated[index] = 0;
                ao_dma_mutex[index] = 0;
        }
index 3e0b3e5c84e29953833bdf235503c68932504f98..2491b609893607b2a340a455be93f59c513f860b 100644 (file)
@@ -123,7 +123,7 @@ ao_exti_set_mode(struct stm_gpio *gpio, uint8_t pin, uint8_t mode) {
        (void) gpio;
 
        uint32_t        mask = 1 << pin;
-       
+
        if (mode & AO_EXTI_MODE_RISING)
                stm_exti.rtsr |= mask;
        else
index db0be992b4fbf65d90a455dbeef5d9cc122613f3..c625471e4b1e9ce39caaf6b7c17a346be76e6953 100644 (file)
@@ -444,7 +444,7 @@ ao_serial_init(void)
        ao_usart_init(&ao_stm_usart1);
 
        stm_nvic_set_enable(STM_ISR_USART1_POS);
-       stm_nvic_set_priority(STM_ISR_USART1_POS, 4);
+       stm_nvic_set_priority(STM_ISR_USART1_POS, AO_STM_NVIC_MED_PRIORITY);
 #if USE_SERIAL_1_STDIN && !DELAY_SERIAL_1_STDIN
        ao_add_stdio(_ao_serial1_pollchar,
                     ao_serial1_putchar,
@@ -500,7 +500,7 @@ ao_serial_init(void)
 #endif
 
        stm_nvic_set_enable(STM_ISR_USART2_POS);
-       stm_nvic_set_priority(STM_ISR_USART2_POS, 4);
+       stm_nvic_set_priority(STM_ISR_USART2_POS, AO_STM_NVIC_MED_PRIORITY);
 #if USE_SERIAL_2_STDIN && !DELAY_SERIAL_2_STDIN
        ao_add_stdio(_ao_serial2_pollchar,
                     ao_serial2_putchar,
@@ -544,7 +544,7 @@ ao_serial_init(void)
        ao_usart_init(&ao_stm_usart3);
 
        stm_nvic_set_enable(STM_ISR_USART3_POS);
-       stm_nvic_set_priority(STM_ISR_USART3_POS, 4);
+       stm_nvic_set_priority(STM_ISR_USART3_POS, AO_STM_NVIC_MED_PRIORITY);
 #if USE_SERIAL_3_STDIN && !DELAY_SERIAL_3_STDIN
        ao_add_stdio(_ao_serial3_pollchar,
                     ao_serial3_putchar,
index f86a51169293e78a4fb930f8e132f19557c378e7..1576a6c91f78e38132b119b025415e0c112a3970 100644 (file)
@@ -90,6 +90,7 @@ ao_timer_init(void)
        stm_systick.csr = ((1 << STM_SYSTICK_CSR_ENABLE) |
                           (1 << STM_SYSTICK_CSR_TICKINT) |
                           (STM_SYSTICK_CSR_CLKSOURCE_HCLK_8 << STM_SYSTICK_CSR_CLKSOURCE));
+       stm_nvic.shpr15_12 |= AO_STM_NVIC_CLOCK_PRIORITY << 24;
 }
 
 #endif
index 9d72844e0c1a6710c06700f9725c13aae9d622a7..2abaf10fddefe415a2c4d5d25eeda6606facb2a4 100644 (file)
@@ -1015,7 +1015,7 @@ ao_usb_enable(void)
        ao_arch_block_interrupts();
 
        /* Route interrupts */
-       stm_nvic_set_priority(STM_ISR_USB_LP_POS, 3);
+       stm_nvic_set_priority(STM_ISR_USB_LP_POS, AO_STM_NVIC_LOW_PRIORITY);
        stm_nvic_set_enable(STM_ISR_USB_LP_POS);
 
        ao_usb_configuration = 0;