More coding-style and cosmetic fixes.

This commit is contained in:
Uwe Hermann 2012-02-06 23:39:06 +01:00
parent 5f82f28d01
commit 9532195e65
10 changed files with 56 additions and 55 deletions

View File

@ -24,11 +24,9 @@
void gpio_setup(void) void gpio_setup(void)
{ {
/* Enable GPIOC clock. */ /* Enable GPIOC clock. */
/* Using API functions: */
rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPCEN); rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPCEN);
/* Set GPIO3 and GPIO4 (in GPIO port C) to 'output push-pull'. */ /* 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); gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO3 | GPIO4);
} }
@ -42,8 +40,7 @@ int main(void)
gpio_clear(GPIOC, GPIO4); gpio_clear(GPIOC, GPIO4);
/* Blink the LEDs (PC3, PC4) on the board. */ /* Blink the LEDs (PC3, PC4) on the board. */
while (1) while (1) {
{
/* Using API function gpio_toggle(): */ /* Using API function gpio_toggle(): */
gpio_toggle(GPIOC, GPIO3); gpio_toggle(GPIOC, GPIO3);
gpio_toggle(GPIOC, GPIO4); gpio_toggle(GPIOC, GPIO4);

View File

@ -31,9 +31,8 @@ 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_APB1ENR, RCC_APB1ENR_SPI2EN);
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_USART1EN); rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_USART1EN);
rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPCEN | \ rcc_peripheral_enable_clock(&RCC_AHB1ENR,
RCC_AHB1ENR_IOPAEN | \ RCC_AHB1ENR_IOPCEN | RCC_AHB1ENR_IOPAEN | RCC_AHB1ENR_IOPBEN);
RCC_AHB1ENR_IOPBEN);
} }
void spi_setup(void) void spi_setup(void)

View File

@ -18,19 +18,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stdio.h>
#include <errno.h>
#include <libopencm3/stm32/f2/gpio.h> #include <libopencm3/stm32/f2/gpio.h>
#include <libopencm3/stm32/usart.h> #include <libopencm3/stm32/usart.h>
#include <libopencm3/stm32/nvic.h> #include <libopencm3/stm32/nvic.h>
#include <libopencm3/stm32/f2/rcc.h> #include <libopencm3/stm32/f2/rcc.h>
#include <stdio.h>
#include <errno.h>
void clock_setup(void) 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_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) void usart_setup(void)

View File

@ -55,9 +55,10 @@ SECTIONS
* You may need to fix this if you're using C++. * You may need to fix this if you're using C++.
*/ */
/DISCARD/ : { *(.eh_frame) } /DISCARD/ : { *(.eh_frame) }
/* /*
* Another section used by C++ stuff, appears when using newlib with 64bit * Another section used by C++ stuff, appears when using newlib with
* (long long) printf support - discard it for now. * 64bit (long long) printf support - discard it for now.
*/ */
/DISCARD/ : { *(.ARM.exidx) } /DISCARD/ : { *(.ARM.exidx) }

View File

@ -55,9 +55,10 @@ SECTIONS
* You may need to fix this if you're using C++. * You may need to fix this if you're using C++.
*/ */
/DISCARD/ : { *(.eh_frame) } /DISCARD/ : { *(.eh_frame) }
/* /*
* Another section used by C++ stuff, appears when using newlib with 64bit * Another section used by C++ stuff, appears when using newlib with
* (long long) printf support - discard it for now. * 64bit (long long) printf support - discard it for now.
*/ */
/DISCARD/ : { *(.ARM.exidx) } /DISCARD/ : { *(.ARM.exidx) }

View File

@ -59,9 +59,10 @@ SECTIONS
* You may need to fix this if you're using C++. * You may need to fix this if you're using C++.
*/ */
/DISCARD/ : { *(.eh_frame) } /DISCARD/ : { *(.eh_frame) }
/* /*
* Another section used by C++ stuff, appears when using newlib with 64bit * Another section used by C++ stuff, appears when using newlib with
* (long long) printf support - discard it for now. * 64bit (long long) printf support - discard it for now.
*/ */
/DISCARD/ : { *(.ARM.exidx) } /DISCARD/ : { *(.ARM.exidx) }

View File

@ -59,9 +59,10 @@ SECTIONS
* You may need to fix this if you're using C++. * You may need to fix this if you're using C++.
*/ */
/DISCARD/ : { *(.eh_frame) } /DISCARD/ : { *(.eh_frame) }
/* /*
* Another section used by C++ stuff, appears when using newlib with 64bit * Another section used by C++ stuff, appears when using newlib with
* (long long) printf support - discard it for now. * 64bit (long long) printf support - discard it for now.
*/ */
/DISCARD/ : { *(.ARM.exidx) } /DISCARD/ : { *(.ARM.exidx) }

View File

@ -59,9 +59,10 @@ SECTIONS
* You may need to fix this if you're using C++. * You may need to fix this if you're using C++.
*/ */
/DISCARD/ : { *(.eh_frame) } /DISCARD/ : { *(.eh_frame) }
/* /*
* Another section used by C++ stuff, appears when using newlib with 64bit * Another section used by C++ stuff, appears when using newlib with
* (long long) printf support - discard it for now. * 64bit (long long) printf support - discard it for now.
*/ */
/DISCARD/ : { *(.ARM.exidx) } /DISCARD/ : { *(.ARM.exidx) }

View File

@ -47,15 +47,16 @@ void usart_set_baudrate(u32 usart, u32 baud)
#endif #endif
*/ */
/* yes it is as simple as that. The reference manual is /*
* talking about factional calculation but it seems to be only * Yes it is as simple as that. The reference manual is
* marketting bable to sound awesome. It is nothing else but a * talking about fractional calculation but it seems to be only
* simple divider to generate the correct baudrate. >_< If I * marketting babble to sound awesome. It is nothing else but a
* am wrong feel free to correct me on that. :) (esden) * simple divider to generate the correct baudrate.
* *
* Changed to round rather than floor (Fergus) * 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) void usart_set_databits(u32 usart, u32 bits)
@ -168,4 +169,3 @@ void usart_disable_tx_dma(u32 usart)
{ {
USART_CR3(usart) &= ~USART_CR3_DMAT; USART_CR3(usart) &= ~USART_CR3_DMAT;
} }