blob: f1377fe6d3576e9324e5d9cc4a1ac4fc3d465122 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (c) 2012 Travis Geiselbrecht
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23#include <err.h>
24#include <debug.h>
25#include <trace.h>
26#include <target.h>
27#include <compiler.h>
28#include <dev/gpio.h>
29#include <stm32f2xx_usart.h>
30#include <stm32f2xx_rcc.h>
31#include <stm32f2xx_gpio.h>
32//#include <stm32f10x_flash.h>
33//#include <stm32f10x_dbgmcu.h>
34#include <platform/stm32.h>
35#include <platform/gpio.h>
36#include <target/gpioconfig.h>
37
38void target_early_init(void)
39{
40 /* configure the usart3 pins */
41 gpio_config(GPIO_USART3_TX, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF_USART3) | GPIO_PULLUP);
42 gpio_config(GPIO_USART3_RX, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF_USART3) | GPIO_PULLUP);
43
44 stm32_debug_early_init();
45
46 /* configure some status leds */
47 gpio_config(GPIO_LED0, GPIO_OUTPUT);
48 gpio_config(GPIO_LED1, GPIO_OUTPUT);
49 gpio_config(GPIO_LED2, GPIO_OUTPUT);
50 gpio_config(GPIO_LED3, GPIO_OUTPUT);
51
52 stm3220g_set_led_bits(1);
53}
54
55void target_init(void)
56{
57 TRACE_ENTRY;
58
59 stm32_debug_init();
60
61 TRACE_EXIT;
62}
63
64void target_set_debug_led(unsigned int led, bool on)
65{
66 switch (led) {
67 case 0:
68 gpio_set(GPIO_LED0, on);
69 break;
70 case 1:
71 gpio_set(GPIO_LED1, on);
72 break;
73 case 2:
74 gpio_set(GPIO_LED2, on);
75 break;
76 case 3:
77 gpio_set(GPIO_LED3, on);
78 break;
79 }
80}
81
82void stm3220g_set_led_bits(unsigned int nr)
83{
84 gpio_set(GPIO_LED0, nr & 1);
85 gpio_set(GPIO_LED1, nr & 2);
86 gpio_set(GPIO_LED2, nr & 4);
87 gpio_set(GPIO_LED3, nr & 8);
88}