1 /*
2  * Copyright (c) 2012 Travis Geiselbrecht
3  *
4  * Use of this source code is governed by a MIT-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/MIT
7  */
8 #include <lk/err.h>
9 #include <lk/debug.h>
10 #include <lk/trace.h>
11 #include <target.h>
12 #include <lk/compiler.h>
13 #include <dev/gpio.h>
14 #include <stm32f10x_usart.h>
15 #include <stm32f10x_rcc.h>
16 #include <stm32f10x_gpio.h>
17 #include <stm32f10x_flash.h>
18 #include <stm32f10x_dbgmcu.h>
19 #include <platform/stm32.h>
20 #include <platform/gpio.h>
21 #include <target/gpioconfig.h>
22 
target_early_init(void)23 void target_early_init(void) {
24     /* configure the usart3 pins */
25     GPIO_PinRemapConfig(GPIO_FullRemap_USART3, ENABLE);
26 
27     gpio_config(GPIO(GPIO_PORT_D, 8), GPIO_STM32_AF);
28     gpio_config(GPIO(GPIO_PORT_D, 9), GPIO_INPUT);
29 
30     stm32_debug_early_init();
31 
32     /* configure some status leds */
33     gpio_set(GPIO_LED0, 0);
34     gpio_set(GPIO_LED1, 0);
35 
36     gpio_config(GPIO_LED0, GPIO_OUTPUT);
37     gpio_config(GPIO_LED1, GPIO_OUTPUT);
38 }
39 
target_init(void)40 void target_init(void) {
41     TRACE_ENTRY;
42 
43     stm32_debug_init();
44 
45     TRACE_EXIT;
46 }
47 
target_set_debug_led(unsigned int led,bool on)48 void target_set_debug_led(unsigned int led, bool on) {
49     switch (led) {
50         case 0:
51             gpio_set(GPIO_LED0, on);
52             break;
53         case 1:
54             gpio_set(GPIO_LED1, on);
55             break;
56     }
57 }
58 
59