]> mj.ucw.cz Git - home-hw.git/blobdiff - test-opencm3/test.c
ocm3 test: debugging utilities
[home-hw.git] / test-opencm3 / test.c
index a38394cb2b1d7f255d16fed07665dcd2cee8459d..f02195d232f84c1e31e8d33e5ceb5236efdfabba 100644 (file)
@@ -1,20 +1,18 @@
-#include <stdint.h>
+#include "util.h"
 
 #include <libopencm3/cm3/nvic.h>
 #include <libopencm3/cm3/systick.h>
 #include <libopencm3/stm32/rcc.h>
 #include <libopencm3/stm32/gpio.h>
-
-typedef uint8_t byte;
-typedef uint16_t u16;
-typedef uint32_t u32;
-typedef unsigned int uint;
+#include <libopencm3/stm32/usart.h>
 
 static void clock_setup(void)
 {
        rcc_clock_setup_in_hse_8mhz_out_72mhz();
 
+       rcc_periph_clock_enable(RCC_GPIOA);
        rcc_periph_clock_enable(RCC_GPIOC);
+       rcc_periph_clock_enable(RCC_USART1);
 }
 
 static void gpio_setup(void)
@@ -43,16 +41,34 @@ static void delay_ms(uint ms)
                ;
 }
 
+static void usart_setup(void)
+{
+               gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
+
+               usart_set_baudrate(USART1, 115200);
+               usart_set_databits(USART1, 8);
+               usart_set_stopbits(USART1, USART_STOPBITS_1);
+               usart_set_mode(USART1, USART_MODE_TX);
+               usart_set_parity(USART1, USART_PARITY_NONE);
+               usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE);
+
+               usart_enable(USART1);
+}
+
 int main(void)
 {
        clock_setup();
        gpio_setup();
        tick_setup();
+       usart_setup();
 
-       /* Blink the LED (PC13) on the board. */
+       int cc = 32;
        for (;;) {
-               gpio_toggle(GPIOC, GPIO13);     /* LED on/off */
-               delay_ms(1000);
+               gpio_toggle(GPIOC, GPIO13);
+               debug_putc(cc);
+               cc++;
+               if (cc >= 126) cc = 32;
+               delay_ms(100);
        }
 
        return 0;