From 9532195e65edcec7d2f55dbb71f00bb18a04dac8 Mon Sep 17 00:00:00 2001 From: Uwe Hermann Date: Mon, 6 Feb 2012 23:39:06 +0100 Subject: [PATCH] More coding-style and cosmetic fixes. --- .../stm32/f2/jobygps/miniblink/miniblink.c | 9 +++---- examples/stm32/f2/jobygps/spi_test/spi_test.c | 7 +++-- .../f2/jobygps/usart_printf/usart_printf.c | 10 +++---- lib/lm3s/libopencm3_lm3s.ld | 9 ++++--- lib/lpc13xx/libopencm3_lpc13xx.ld | 9 ++++--- lib/stm32/f1/libopencm3_stm32f1.ld | 9 ++++--- lib/stm32/f2/libopencm3_stm32f2.ld | 9 ++++--- lib/stm32/f4/libopencm3_stm32f4.ld | 9 ++++--- lib/stm32/nvic.c | 14 +++++----- lib/stm32/usart.c | 26 +++++++++---------- 10 files changed, 56 insertions(+), 55 deletions(-) diff --git a/examples/stm32/f2/jobygps/miniblink/miniblink.c b/examples/stm32/f2/jobygps/miniblink/miniblink.c index 0e9b0173..9b31d15c 100644 --- a/examples/stm32/f2/jobygps/miniblink/miniblink.c +++ b/examples/stm32/f2/jobygps/miniblink/miniblink.c @@ -24,11 +24,9 @@ void gpio_setup(void) { /* Enable GPIOC clock. */ - /* Using API functions: */ rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPCEN); /* Set GPIO3 and GPIO4 (in GPIO port C) to 'output push-pull'. */ - /* Using API functions: */ gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO3 | GPIO4); } @@ -38,12 +36,11 @@ int main(void) gpio_setup(); - gpio_set(GPIOC, GPIO3); - gpio_clear(GPIOC, GPIO4); + gpio_set(GPIOC, GPIO3); + gpio_clear(GPIOC, GPIO4); /* Blink the LEDs (PC3, PC4) on the board. */ - while (1) - { + while (1) { /* Using API function gpio_toggle(): */ gpio_toggle(GPIOC, GPIO3); gpio_toggle(GPIOC, GPIO4); diff --git a/examples/stm32/f2/jobygps/spi_test/spi_test.c b/examples/stm32/f2/jobygps/spi_test/spi_test.c index e5c9539e..2d6ab009 100644 --- a/examples/stm32/f2/jobygps/spi_test/spi_test.c +++ b/examples/stm32/f2/jobygps/spi_test/spi_test.c @@ -28,12 +28,11 @@ void clock_setup(void) { - /* Enable clocks on all the peripherals we are going to use. */ + /* Enable clocks on all the peripherals we are going to use. */ rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_SPI2EN); rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_USART1EN); - rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPCEN | \ - RCC_AHB1ENR_IOPAEN | \ - RCC_AHB1ENR_IOPBEN); + rcc_peripheral_enable_clock(&RCC_AHB1ENR, + RCC_AHB1ENR_IOPCEN | RCC_AHB1ENR_IOPAEN | RCC_AHB1ENR_IOPBEN); } void spi_setup(void) diff --git a/examples/stm32/f2/jobygps/usart_printf/usart_printf.c b/examples/stm32/f2/jobygps/usart_printf/usart_printf.c index 30957a34..26bd007e 100644 --- a/examples/stm32/f2/jobygps/usart_printf/usart_printf.c +++ b/examples/stm32/f2/jobygps/usart_printf/usart_printf.c @@ -18,19 +18,19 @@ * along with this program. If not, see . */ +#include +#include #include #include #include #include -#include -#include - void clock_setup(void) { - /* Enable clocks on all the peripherals we are going to use. */ + /* Enable clocks on all the peripherals we are going to use. */ rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_USART1EN); - rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPCEN | RCC_AHB1ENR_IOPAEN); + rcc_peripheral_enable_clock(&RCC_AHB1ENR, + RCC_AHB1ENR_IOPCEN | RCC_AHB1ENR_IOPAEN); } void usart_setup(void) diff --git a/lib/lm3s/libopencm3_lm3s.ld b/lib/lm3s/libopencm3_lm3s.ld index 67dd7bad..ca9d35ff 100644 --- a/lib/lm3s/libopencm3_lm3s.ld +++ b/lib/lm3s/libopencm3_lm3s.ld @@ -55,10 +55,11 @@ SECTIONS * You may need to fix this if you're using C++. */ /DISCARD/ : { *(.eh_frame) } - /* - * Another section used by C++ stuff, appears when using newlib with 64bit - * (long long) printf support - discard it for now. - */ + + /* + * Another section used by C++ stuff, appears when using newlib with + * 64bit (long long) printf support - discard it for now. + */ /DISCARD/ : { *(.ARM.exidx) } end = .; diff --git a/lib/lpc13xx/libopencm3_lpc13xx.ld b/lib/lpc13xx/libopencm3_lpc13xx.ld index ec8c5459..93c98e0f 100644 --- a/lib/lpc13xx/libopencm3_lpc13xx.ld +++ b/lib/lpc13xx/libopencm3_lpc13xx.ld @@ -55,10 +55,11 @@ SECTIONS * You may need to fix this if you're using C++. */ /DISCARD/ : { *(.eh_frame) } - /* - * Another section used by C++ stuff, appears when using newlib with 64bit - * (long long) printf support - discard it for now. - */ + + /* + * Another section used by C++ stuff, appears when using newlib with + * 64bit (long long) printf support - discard it for now. + */ /DISCARD/ : { *(.ARM.exidx) } end = .; diff --git a/lib/stm32/f1/libopencm3_stm32f1.ld b/lib/stm32/f1/libopencm3_stm32f1.ld index 76c5e604..52a08f54 100644 --- a/lib/stm32/f1/libopencm3_stm32f1.ld +++ b/lib/stm32/f1/libopencm3_stm32f1.ld @@ -59,10 +59,11 @@ SECTIONS * You may need to fix this if you're using C++. */ /DISCARD/ : { *(.eh_frame) } - /* - * Another section used by C++ stuff, appears when using newlib with 64bit - * (long long) printf support - discard it for now. - */ + + /* + * Another section used by C++ stuff, appears when using newlib with + * 64bit (long long) printf support - discard it for now. + */ /DISCARD/ : { *(.ARM.exidx) } . = ALIGN(4); diff --git a/lib/stm32/f2/libopencm3_stm32f2.ld b/lib/stm32/f2/libopencm3_stm32f2.ld index 76c5e604..52a08f54 100644 --- a/lib/stm32/f2/libopencm3_stm32f2.ld +++ b/lib/stm32/f2/libopencm3_stm32f2.ld @@ -59,10 +59,11 @@ SECTIONS * You may need to fix this if you're using C++. */ /DISCARD/ : { *(.eh_frame) } - /* - * Another section used by C++ stuff, appears when using newlib with 64bit - * (long long) printf support - discard it for now. - */ + + /* + * Another section used by C++ stuff, appears when using newlib with + * 64bit (long long) printf support - discard it for now. + */ /DISCARD/ : { *(.ARM.exidx) } . = ALIGN(4); diff --git a/lib/stm32/f4/libopencm3_stm32f4.ld b/lib/stm32/f4/libopencm3_stm32f4.ld index 76c5e604..52a08f54 100644 --- a/lib/stm32/f4/libopencm3_stm32f4.ld +++ b/lib/stm32/f4/libopencm3_stm32f4.ld @@ -59,10 +59,11 @@ SECTIONS * You may need to fix this if you're using C++. */ /DISCARD/ : { *(.eh_frame) } - /* - * Another section used by C++ stuff, appears when using newlib with 64bit - * (long long) printf support - discard it for now. - */ + + /* + * Another section used by C++ stuff, appears when using newlib with + * 64bit (long long) printf support - discard it for now. + */ /DISCARD/ : { *(.ARM.exidx) } . = ALIGN(4); diff --git a/lib/stm32/nvic.c b/lib/stm32/nvic.c index 502d212c..1c7f4b9e 100644 --- a/lib/stm32/nvic.c +++ b/lib/stm32/nvic.c @@ -22,37 +22,37 @@ void nvic_enable_irq(u8 irqn) { - NVIC_ISER(irqn / 32) = (1 << (irqn % 32)); + NVIC_ISER(irqn / 32) = (1 << (irqn % 32)); } void nvic_disable_irq(u8 irqn) { - NVIC_ICER(irqn / 32) = (1 << (irqn % 32)); + NVIC_ICER(irqn / 32) = (1 << (irqn % 32)); } u8 nvic_get_pending_irq(u8 irqn) { - return NVIC_ISPR(irqn / 32) & (1 << (irqn % 32)) ? 1:0; + return NVIC_ISPR(irqn / 32) & (1 << (irqn % 32)) ? 1 : 0; } void nvic_set_pending_irq(u8 irqn) { - NVIC_ISPR(irqn / 32) = (1 << (irqn % 32)); + NVIC_ISPR(irqn / 32) = (1 << (irqn % 32)); } void nvic_clear_pending_irq(u8 irqn) { - NVIC_ICPR(irqn / 32) = (1 << (irqn % 32)); + NVIC_ICPR(irqn / 32) = (1 << (irqn % 32)); } u8 nvic_get_active_irq(u8 irqn) { - return NVIC_IABR(irqn / 32) & (1 << (irqn % 32)) ? 1:0; + return NVIC_IABR(irqn / 32) & (1 << (irqn % 32)) ? 1 : 0; } u8 nvic_get_irq_enabled(u8 irqn) { - return NVIC_ISER(irqn / 32) & (1 << (irqn % 32)) ? 1:0; + return NVIC_ISER(irqn / 32) & (1 << (irqn % 32)) ? 1 : 0; } void nvic_set_priority(u8 irqn, u8 priority) diff --git a/lib/stm32/usart.c b/lib/stm32/usart.c index 7995a527..7ce0ddc6 100644 --- a/lib/stm32/usart.c +++ b/lib/stm32/usart.c @@ -47,15 +47,16 @@ void usart_set_baudrate(u32 usart, u32 baud) #endif */ - /* yes it is as simple as that. The reference manual is - * talking about factional calculation but it seems to be only - * marketting bable to sound awesome. It is nothing else but a - * simple divider to generate the correct baudrate. >_< If I - * am wrong feel free to correct me on that. :) (esden) - * - * Changed to round rather than floor (Fergus) + /* + * Yes it is as simple as that. The reference manual is + * talking about fractional calculation but it seems to be only + * marketting babble to sound awesome. It is nothing else but a + * simple divider to generate the correct baudrate. + * + * Note: We round() the value rather than floor()ing it, for more + * accurate divisor selection. */ - USART_BRR(usart) = (2*clock + baud) / (2*baud); + USART_BRR(usart) = ((2 * clock) + baud) / (2 * baud); } void usart_set_databits(u32 usart, u32 bits) @@ -151,21 +152,20 @@ u16 usart_recv_blocking(u32 usart) void usart_enable_rx_dma(u32 usart) { - USART_CR3(usart) |= USART_CR3_DMAR; + USART_CR3(usart) |= USART_CR3_DMAR; } void usart_disable_rx_dma(u32 usart) { - USART_CR3(usart) &= ~USART_CR3_DMAR; + USART_CR3(usart) &= ~USART_CR3_DMAR; } void usart_enable_tx_dma(u32 usart) { - USART_CR3(usart) |= USART_CR3_DMAT; + USART_CR3(usart) |= USART_CR3_DMAT; } void usart_disable_tx_dma(u32 usart) { - USART_CR3(usart) &= ~USART_CR3_DMAT; + USART_CR3(usart) &= ~USART_CR3_DMAT; } -