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 <lk/compiler.h>
12 #include <dev/gpio.h>
13 #include <stm32f4xx_usart.h>
14 #include <stm32f4xx_rcc.h>
15 #include <stm32f4xx_gpio.h>
16 #include <platform/stm32.h>
17 #include <platform/gpio.h>
18 #include <target.h>
19 #include <target/debugconfig.h>
20 #include <target/gpioconfig.h>
21
target_early_init(void)22 void target_early_init(void) {
23 #ifdef DEBUG_UART
24 #if DEBUG_UART == 1
25 gpio_config(GPIO_USART1_TX, GPIO_STM32_AF |
26 GPIO_STM32_AFn(GPIO_AF_USART1) | GPIO_PULLUP);
27 gpio_config(GPIO_USART1_RX, GPIO_STM32_AF |
28 GPIO_STM32_AFn(GPIO_AF_USART1) | GPIO_PULLUP);
29 #else // !DEBUG_UART == 1
30 #warn DEBUG_UART only supports USART1!!!
31 #endif // DEBUG_UART
32 #endif // defined DEBUG_UART
33
34 stm32_debug_early_init();
35
36 /* configure some status leds */
37 gpio_config(GPIO_LED0, GPIO_OUTPUT);
38 gpio_config(GPIO_LED1, GPIO_OUTPUT);
39 gpio_config(GPIO_LED2, GPIO_OUTPUT);
40 gpio_config(GPIO_LED3, GPIO_OUTPUT);
41 }
42
target_init(void)43 void target_init(void) {
44 TRACE_ENTRY;
45
46 stm32_debug_init();
47
48 TRACE_EXIT;
49 }
50
target_set_debug_led(unsigned int led,bool on)51 void target_set_debug_led(unsigned int led, bool on) {
52 switch (led) {
53 case 0:
54 gpio_set(GPIO_LED0, on);
55 break;
56 case 1:
57 gpio_set(GPIO_LED1, on);
58 break;
59 case 2:
60 gpio_set(GPIO_LED2, on);
61 break;
62 case 3:
63 gpio_set(GPIO_LED3, on);
64 break;
65 }
66 }
67