diff options
Diffstat (limited to '03-refactor/src/main.c')
-rw-r--r-- | 03-refactor/src/main.c | 64 |
1 files changed, 28 insertions, 36 deletions
diff --git a/03-refactor/src/main.c b/03-refactor/src/main.c index 562fda9..97449b2 100644 --- a/03-refactor/src/main.c +++ b/03-refactor/src/main.c @@ -4,39 +4,13 @@ #include "gpio.h" #include "spin.h" #include "usart.h" +#include "sio.h" -volatile uint32_t delay_amt = 20000000 / 4; - -int enable_usart2(uint32_t baud_rate) -{ - __IO gpio_port_t* port_a = enable_gpio(GPIO_PORT_A); - enable_hsi(&RCC, true); - - // Turn on the clock for the USART2 peripheral - set_usart2_clock_src(&RCC, USART_CLK_SRC_HSI16); - set_usart2_clock_enabled(&RCC, true); - - // Configure the I/O pins. Will use PA2 as TX and PA15 as RX so setup for - // alternate function - set_gpio_pin_mode(port_a, PIN_2, MODE_ALTERNATE); - set_gpio_pin_mode(port_a, PIN_15, MODE_ALTERNATE); - set_gpio_alternate_function(port_a, PIN_2, AFN_7); - set_gpio_alternate_function(port_a, PIN_15, AFN_3); - - // De-assert reset of USART2 - RCC.apb1rst1_r &= ~BIT(17); - - // Configure the USART - // disable USART first to allow setting of other control bits - // This also disables parity checking and enables 16 times oversampling +void unhandled_isr_2(); +void init(); - USART2.c1.r = 0; - USART2.c2.r = 0; - USART2.c3.r = 0; - - usart_set_divisor(&USART2, 16000000 / baud_rate); - usart_set_enabled(&USART2, USART_ENABLE_TX | USART_ENABLE_RX); -} +int in_the_data; +volatile uint32_t delay_amt = 20000000 / 4; int enable_usart1(uint32_t baud_rate) { @@ -77,14 +51,14 @@ void dwn() { int val = 19; while (val > 1) { - usart_printf(&USART2, "Value: 0x%02x\r\n", val); + usart_printf(&USART2, "Value: %2d\r\n", val); if ((val & 1) == 0) { val /= 2; } else { val = val * 3 + 1; } } - usart_printf(&USART2, "Value: 0x%02x\r\n", val); + usart_printf(&USART2, "Value: %2d\r\n", val); } /* Main function. This gets executed from the interrupt vector defined above. */ @@ -99,11 +73,29 @@ int main() set_system_clock_MHz(80); enable_usart2(115200); + int on_the_stack; + + USART2.c1.tcie = 1; + USART2.c1.txeie = 1; // pin_on(pin3); - dwn(); - usart_printf(&USART2, "Hello, %d!\r\n", -15); - for(;;); + if (is_usart2_enabled()) { + dwn(); + usart_printf(&USART2, "Hello, %d!\r\n", -15); + usart_printf(&USART2, "Hello, %022x\r\n", 0xeadbeef); + usart_printf(&USART2, "on_the_stack: %08X\r\n", (unsigned) &on_the_stack); + + int i; + + printf("isr-2: %08x\r\n", (unsigned int)(void *) unhandled_isr_2); + printf("init: %08x\r\n", (unsigned int)(void *) init); + for (i = 0; i < 20; ++ i) { + printf("isr %d: %08x\r\n", i, *(unsigned int*)(0x08000000 + i * 4)); + } + } + + // usart_printf(&USART2, "that_thing: %d\n", *(unsigned*)(0x0)); + // for(;;); } void do_thing(void(*fn)()) { |