aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple/libmaple.h
blob: f893cff8053ad204ba8a16c55318f80a69628738 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/******************************************************************************
 * The MIT License
 *
 * Copyright (c) 2010 Perry Hung.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *****************************************************************************/

/**
 *  @file libmaple.h
 *
 *  @brief general include file for libmaple
 */

#ifndef _LIBMAPLE_H_
#define _LIBMAPLE_H_

#include "libmaple_types.h"

/* General configuration */
#define DEBUG_NONE      0
#define DEBUG_FAULT     1
#define DEBUG_ALL       2

#ifndef DEBUG_LEVEL
#define DEBUG_LEVEL DEBUG_ALL
#endif

/* Bitbanded Memory sections */
#define BITBAND_SRAM_REF   0x20000000
#define BITBAND_SRAM_BASE  0x22000000
#define BITBAND_PERI_REF   0x40000000
#define BITBAND_PERI_BASE  0x42000000

#define USB_CONFIG_MAX_POWER      (100 >> 1)
#define RESET_DELAY               (100)

#define ERROR_USART_NUM        USART2
#define ERROR_USART_BAUD       9600
#define ERROR_TX_PORT          GPIOA_BASE
#define ERROR_TX_PIN           2

/* MCU-specific configuration */
#if defined(MCU_STM32F103RB)
    /* e.g., LeafLabs Maple */

    /* Number of GPIO ports (GPIOA, GPIOB, etc.) */
    #define NR_GPIO_PORTS             4

    /* Total number of GPIO pins */
    #define NR_GPIO_PINS             39

    /* Number of 16-bit backup registers */
    #define NR_BKP_REGS              10

    /* Number of timer devices ports, definitely used */
    #define NR_TIMERS                 4

    /* Number of USART ports */
    #define NR_USART                  3

    /* Has an FSMC bus? */
    #define NR_FSMC                   0

    /* Has a DAC? */
    #define NR_DAC_PINS               0

    /* USB Identifier numbers */
    /* Descriptor strings must be modified by hand in
       usb/descriptors.c for now */
    #define VCOM_ID_VENDOR    0x1EAF
    #define VCOM_ID_PRODUCT   0x0004
    #define USB_DISC_BANK     GPIOC_BASE
    #define USB_DISC_PIN      12

    /* Where to put usercode (based on space reserved for bootloader) */
    #define USER_ADDR_ROM 0x08005000
    #define USER_ADDR_RAM 0x20000C00
    #define STACK_TOP     0x20000800 /* FIXME can this possibly be correct? */

    #define ERROR_LED_PORT         GPIOB_BASE
    #define ERROR_LED_PIN          12

#elif defined(MCU_STM32F103ZE)
    /* e.g., LeafLabs Maple Native */

    #define NR_GPIO_PORTS             7
    #define NR_GPIO_PINS            100
    #define NR_BKP_REGS              42
    #define NR_TIMERS                 8
    #define NR_USART                  5 /* NB: 4 and 5 are UART only */
    #define NR_FSMC                   1
    #define NR_DAC_PINS               2

    #define VCOM_ID_VENDOR    0x1EAF
    #define VCOM_ID_PRODUCT   0x0004
    #define USB_DISC_BANK     GPIOB_BASE
    #define USB_DISC_PIN      8

    #define USER_ADDR_ROM 0x08005000
    #define USER_ADDR_RAM 0x20000C00
    #define STACK_TOP     0x20000800

    #define ERROR_LED_PORT         GPIOC_BASE
    #define ERROR_LED_PIN          15

#elif defined(MCU_STM32F103CB)
    /* e.g., LeafLabs Maple Mini */

    #define NR_GPIO_PORTS 3
    #define NR_GPIO_PINS  34
    #define NR_BKP_REGS   10
    #define NR_TIMERS     4
    #define NR_USART      3
    #define NR_FSMC       0
    #define NR_DAC_PINS   0

    #define VCOM_ID_VENDOR       0x1EAF
    #define VCOM_ID_PRODUCT      0x0005
    #define USB_DISC_BANK        GPIOB_BASE
    #define USB_DISC_PIN         9

    #define USER_ADDR_ROM 0x08005000
    #define USER_ADDR_RAM 0x20000C00
    #define STACK_TOP     0x20000800

    #define ERROR_LED_PORT   GPIOB_BASE
    #define ERROR_LED_PIN    1

#elif defined(MCU_STM32F103RE)
    /* e.g., LeafLabs Maple RET6 Edition */

    #define NR_GPIO_PORTS             4
    #define NR_GPIO_PINS             39
    #define NR_BKP_REGS              42
    #define NR_TIMERS                 8
    #define NR_USART                  5 /* NB: 4 and 5 are UART only */
    #define NR_FSMC                   0
    #define NR_DAC_PINS               0 /* HACK: LED hooked up to DAC2 */

    #define VCOM_ID_VENDOR    0x1EAF
    #define VCOM_ID_PRODUCT   0x0004
    #define USB_DISC_BANK     GPIOC_BASE
    #define USB_DISC_PIN      12

    #define USER_ADDR_ROM 0x08005000
    #define USER_ADDR_RAM 0x20000C00
    #define STACK_TOP     0x20000800

    #define ERROR_LED_PORT         GPIOA_BASE
    #define ERROR_LED_PIN          5

#else

#error "No MCU type specified. Add something like -DMCU_STM32F103RB "   \
       "to your compiler arguments (probably in a Makefile)."

#endif

/* Requires board configuration info */
#include "util.h"

#endif