aboutsummaryrefslogtreecommitdiff
path: root/03-refactor/src/main.c
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2019-01-02 23:08:37 -0700
committerJosh Rahm <joshuarahm@gmail.com>2019-01-03 21:23:46 -0700
commit33a15696519e161cd823baaf4214d1ed452a410a (patch)
treee3491b0b7b7c570b36c1e4c5235e2d026c651b2c /03-refactor/src/main.c
parent109cdf120ea85f46d664e77c44ea2a311fd49ba2 (diff)
downloadstm32l4-33a15696519e161cd823baaf4214d1ed452a410a.tar.gz
stm32l4-33a15696519e161cd823baaf4214d1ed452a410a.tar.bz2
stm32l4-33a15696519e161cd823baaf4214d1ed452a410a.zip
Add primitive printf functionality to the USART.
Diffstat (limited to '03-refactor/src/main.c')
-rw-r--r--03-refactor/src/main.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/03-refactor/src/main.c b/03-refactor/src/main.c
index 0545087..562fda9 100644
--- a/03-refactor/src/main.c
+++ b/03-refactor/src/main.c
@@ -73,21 +73,39 @@ int enable_usart1(uint32_t baud_rate)
asm volatile(" cpsie i ");
}
+void dwn() {
+ int val = 19;
+
+ while (val > 1) {
+ usart_printf(&USART2, "Value: 0x%02x\r\n", val);
+ if ((val & 1) == 0) {
+ val /= 2;
+ } else {
+ val = val * 3 + 1;
+ }
+ }
+ usart_printf(&USART2, "Value: 0x%02x\r\n", val);
+}
+
/* Main function. This gets executed from the interrupt vector defined above. */
int main()
{
/* Enable the GPIO port B. */
-
- __IO gpio_port_t* port_b = enable_gpio(GPIO_PORT_B);
- gpio_output_pin_t pin3 = set_gpio_pin_output(port_b, PIN_3);
- gpio_output_pin_t pin1 = set_gpio_pin_output(port_b, PIN_1);
+ // __IO gpio_port_t* port_b = enable_gpio(GPIO_PORT_B);
+ // gpio_output_pin_t pin3 = set_gpio_pin_output(port_b, PIN_3);
+ // gpio_output_pin_t pin1 = set_gpio_pin_output(port_b, PIN_1);
/* Enable a higher clock frequency. */
set_system_clock_MHz(80);
enable_usart2(115200);
- pin_on(pin3);
- usart_transmit_str(&USART2, "Hello, World\n");
+ // pin_on(pin3);
+ dwn();
+ usart_printf(&USART2, "Hello, %d!\r\n", -15);
for(;;);
}
+
+void do_thing(void(*fn)()) {
+ fn();
+}