aboutsummaryrefslogtreecommitdiff
path: root/02-usart/src/kern/main.c
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2020-11-23 19:41:05 -0700
committerJosh Rahm <joshuarahm@gmail.com>2020-11-23 19:41:05 -0700
commit60b1e3055c179312eef809fe1d01f58042b64d5f (patch)
treec620b5ca1eab2d05c9396637db50d0a110328d29 /02-usart/src/kern/main.c
parent2a6ae24ba769892993ec7a173c564f59feb06495 (diff)
downloadstm32l4-60b1e3055c179312eef809fe1d01f58042b64d5f.tar.gz
stm32l4-60b1e3055c179312eef809fe1d01f58042b64d5f.tar.bz2
stm32l4-60b1e3055c179312eef809fe1d01f58042b64d5f.zip
Add new GPIO subsystem.
This gpio subsystem keeps track of the GPIO pins which have been reserved and takes care of the housekeeping with keeping them running. This gpio subsystem also knows which alternate functions belong to which pins, so it can automatically configure the pins for the alternate functions.
Diffstat (limited to '02-usart/src/kern/main.c')
-rw-r--r--02-usart/src/kern/main.c39
1 files changed, 23 insertions, 16 deletions
diff --git a/02-usart/src/kern/main.c b/02-usart/src/kern/main.c
index 0e0c89c..32166bc 100644
--- a/02-usart/src/kern/main.c
+++ b/02-usart/src/kern/main.c
@@ -10,24 +10,23 @@
#include "arch/stm32l4xxx/peripherals/irq.h"
#include "kern/dma/dma_manager.h"
+#include "kern/gpio/gpio_manager.h"
+#include "kern/gpio/sysled.h"
#include "kern/delay.h"
#include "kern/mem.h"
-#include "kern/spin.h"
#include "kern/string.h"
/** Overrides the default systick irq handler. */
void on_systick()
{
static int is_on = 0;
-
- __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_reserved_pin_t sysled = get_sysled();
if (is_on) {
- pin_off(pin3);
+ set_gpio_pin_low(sysled);
} else {
- pin_on(pin3);
+ set_gpio_pin_high(sysled);
}
is_on = ! is_on;
@@ -35,17 +34,26 @@ void on_systick()
void setup_usart2(uint32_t baud_rate)
{
- __IO gpio_port_t* port_a = enable_gpio(GPIO_PORT_A);
enable_hsi(&RCC, true);
+ int ec = 0;
+ gpio_enable_alternate_function(
+ GPIO_ALTERNATE_FUNCTION_USART2_TX, GPIO_PIN_PA2, &ec);
+
+ if (ec) {
+ unhandled_isr(ec & 0xff);
+ }
+
+ gpio_enable_alternate_function(
+ GPIO_ALTERNATE_FUNCTION_USART2_RX, GPIO_PIN_PA15, &ec);
+
+ if (ec) {
+ unhandled_isr(ec & 0xff);
+ }
+
set_usart2_clock_src(&RCC, USART_CLK_SRC_HSI16);
set_usart2_clock_enabled(&RCC, USART_CLK_SRC_HSI16);
- 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 */
regset(RCC.apb1rst1_r, rcc_usart2rst, 0);
@@ -96,14 +104,13 @@ int main()
// regset(USART2.ic_r, usart_tccf, 1);
// dma_mem2p_initiate_transfer(dma_chan, thing, strlen(thing));
- __IO gpio_port_t* port_b = enable_gpio(GPIO_PORT_B);
- gpio_output_pin_t pin3 = set_gpio_pin_output(port_b, PIN_3);
- pin_on(pin3);
+ gpio_reserved_pin_t sysled = get_sysled();
+ set_gpio_pin_high(sysled);
// usart_printf(&USART2, "Start Configuring Countdown!\n");
/* Set the countdown to start from 1,000,0000. */
- SCB.strv_r = 10000000;
+ SCB.strv_r = 1000000;
/* Enable interrupts. */
regset(SCB.stcs_r, scb_tickint, 1);