Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / NUCLEO-F103RB / module.c @ 2538f3de

History | View | Annotate | Download (7.322 KB)

1 f4da707a Thomas Schöpping
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  Thomas Schöpping et al.
4

5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14

15
You should have received a copy of the GNU General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
/**
20
 * @file
21
 * @brief   Structures and constant for the NUCLEO-F103RB module.
22
 *
23
 * @addtogroup NUCLEO-F103RB_module
24
 * @{
25
 */
26
27
#include "module.h"
28
29
/*===========================================================================*/
30
/**
31
 * @name Module specific functions
32
 * @{
33
 */
34
/*===========================================================================*/
35
36
/** @} */
37
38
/*===========================================================================*/
39
/**
40
 * @name ChibiOS/HAL configuration
41
 * @{
42
 */
43
/*===========================================================================*/
44
45
SerialConfig moduleHalProgIfConfig = {
46
  /* bit rate */ 115200,
47
  /* CR1      */ 0,
48
  /* CR1      */ 0,
49
  /* CR1      */ 0,
50
};
51
52 7de0cc90 Thomas Schöpping
#if defined(AMIROLLD_CFG_DW1000)
53 deaaa47e Cung Sang
54
/*! SPI (high and low speed) configuration for DW1000 */
55
SPIConfig moduleHalSpiUwbHsConfig = {
56
  /* circular buffer mode        */ false,
57
  /* callback function pointer   */ NULL,
58
  /* chip select line port       */ GPIOB,
59
  /* chip select line pad number */ GPIOB_PIN12,
60
  /* CR1                         */ 0,
61
  /* CR2                         */ 0,
62
};
63
64
SPIConfig moduleHalSpiUwbLsConfig = {
65
  /* circular buffer mode        */ false,
66
  /* callback function pointer   */ NULL,
67
  /* chip select line port       */ GPIOB,
68
  /* chip select line pad number */ GPIOB_PIN12,
69
  /* CR1                         */ SPI_CR1_BR_1 | SPI_CR1_BR_0,
70
  /* CR2                         */ 0,
71
};
72
73 7de0cc90 Thomas Schöpping
#endif /* defined(AMIROLLD_CFG_DW1000) */
74 deaaa47e Cung Sang
75 f4da707a Thomas Schöpping
/** @} */
76
77
/*===========================================================================*/
78
/**
79
 * @name GPIO definitions
80
 * @{
81
 */
82
/*===========================================================================*/
83
84
/**
85
 * @brief   LED output signal GPIO.
86
 */
87
static apalGpio_t _gpioLed = {
88
  /* port */ GPIOA,
89
  /* pad  */ GPIOA_LED_GREEN,
90
};
91
ROMCONST apalControlGpio_t moduleGpioLed = {
92
  /* GPIO */ &_gpioLed,
93
  /* meta */ {
94
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
95
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
96
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
97
  },
98
};
99
100 7de0cc90 Thomas Schöpping
#if defined(AMIROLLD_CFG_DW1000)
101 deaaa47e Cung Sang
102
/**
103
 * @brief   DW1000 reset output signal GPIO.
104
 */
105
static apalGpio_t _gpioDw1000Reset = {
106
  /* port */ GPIOA,
107
  /* pad  */ GPIOA_ARD_A0,   // PIN0
108
};
109
ROMCONST apalControlGpio_t moduleGpioDw1000Reset = {
110
  /* GPIO */ &_gpioDw1000Reset,
111
  /* meta */ {
112
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
113
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
114
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
115
  },
116
};
117
118
119
/**
120
 * @brief   DW1000 interrrupt input signal GPIO.
121
 */
122
static apalGpio_t _gpioDw1000Irqn = {
123
  /* port */ GPIOB,
124
  /* pad  */ GPIOB_ARD_D6,  // GPIOB_PIN10
125
};
126
ROMCONST apalControlGpio_t moduleGpioDw1000Irqn = {
127
  /* GPIO */ &_gpioDw1000Irqn,
128
  /* meta */ {
129
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
130
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
131
    /* interrupt edge */ APAL_GPIO_EDGE_RISING,
132
  },
133
};
134
135
136
/**
137
 * @brief   DW1000 SPI chip select output signal GPIO.
138
 */
139
static apalGpio_t _gpioSpiChipSelect = {
140
  /* port */ GPIOB,
141
  /* pad  */ GPIOB_PIN12,  // GPIOB_PIN10
142
};
143
ROMCONST apalControlGpio_t moduleGpioSpiChipSelect = {
144
  /* GPIO */ &_gpioSpiChipSelect,
145
  /* meta */ {
146
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
147
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
148
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
149
  },
150
};
151
152 7de0cc90 Thomas Schöpping
#endif /* defined(AMIROLLD_CFG_DW1000) */
153 deaaa47e Cung Sang
154 f4da707a Thomas Schöpping
/**
155
 * @brief   User button input signal GPIO.
156
 */
157
static apalGpio_t _gpioUserButton = {
158
  /* port */ GPIOC,
159
  /* pad  */ GPIOC_BUTTON,
160
};
161
ROMCONST apalControlGpio_t moduleGpioUserButton = {
162
  /* GPIO */ &_gpioUserButton,
163
  /* meta */ {
164
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
165
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
166
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
167
  },
168
};
169
170
/** @} */
171
172
/*===========================================================================*/
173
/**
174
 * @name AMiRo-OS core configurations
175
 * @{
176
 */
177
/*===========================================================================*/
178
179
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
180
ROMCONST char* moduleShellPrompt = "NUCLEO-F103RB";
181 7de0cc90 Thomas Schöpping
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
182 f4da707a Thomas Schöpping
183
/** @} */
184
185
/*===========================================================================*/
186
/**
187
 * @name Startup Shutdown Synchronization Protocol (SSSP)
188
 * @{
189
 */
190
/*===========================================================================*/
191
192 deaaa47e Cung Sang
193
/*===========================================================================*/
194
/**
195
 * @name Hardware specific wrappers Functions
196
 * @{
197
 */
198
/*===========================================================================*/
199
200 7de0cc90 Thomas Schöpping
#if defined(AMIROLLD_CFG_DW1000)
201 deaaa47e Cung Sang
202
/*! @brief TODO: Manual implementation of SPI configuration. Somehow, it is necessary in NUCLEO-F103RB  */
203
void dw1000_spi_init(void){
204
  palSetPadMode(GPIOB, GPIOB_PIN13, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
205
  palSetPadMode(GPIOB, GPIOB_PIN14, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
206
  palSetPadMode(GPIOB, GPIOB_PIN15, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
207
  palSetPadMode(moduleGpioSpiChipSelect.gpio->port, moduleGpioSpiChipSelect.gpio->pad, PAL_MODE_OUTPUT_PUSHPULL);
208
  apalGpioWrite(moduleGpioSpiChipSelect.gpio, APAL_GPIO_LOW);
209
}
210
211 7de0cc90 Thomas Schöpping
#endif /* defined(AMIROLLD_CFG_DW1000) */
212 f4da707a Thomas Schöpping
/** @} */
213
214
/*===========================================================================*/
215
/**
216
 * @name Low-level drivers
217
 * @{
218
 */
219
/*===========================================================================*/
220
221 7de0cc90 Thomas Schöpping
#if defined(AMIROLLD_CFG_DW1000)
222 deaaa47e Cung Sang
223
DW1000Driver moduleLldDw1000 = {
224
  /* SPI driver         */ &MODULE_HAL_SPI_UWB,
225
  /* ext interrupt      */ &moduleGpioDw1000Irqn,
226
  /* RESET DW1000       */ &moduleGpioDw1000Reset,
227
};
228
229 7de0cc90 Thomas Schöpping
#endif /* defined(AMIROLLD_CFG_DW1000) */
230 f4da707a Thomas Schöpping
/** @} */
231
232
/*===========================================================================*/
233
/**
234
 * @name Unit tests (UT)
235
 * @{
236
 */
237
/*===========================================================================*/
238
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
239
240 7de0cc90 Thomas Schöpping
#if defined(AMIROLLD_CFG_DW1000)
241 deaaa47e Cung Sang
242
/*
243
 * UwB Driver (DW1000)
244
 */
245
static int _utShellCmdCb_Dw1000(BaseSequentialStream* stream, int argc, char* argv[])
246
{
247
  (void)argc;
248
  (void)argv;
249
  aosUtRun(stream, &moduleUtAlldDw1000, NULL);
250
  return AOS_OK;
251
}
252
aos_unittest_t moduleUtAlldDw1000 = {
253
  /* info           */ "DW1000",
254
  /* name           */ "UWB System",
255
  /* test function  */ utAlldDw1000Func,
256
  /* shell command  */ {
257
    /* name     */ "unittest:Uwb",
258
    /* callback */ _utShellCmdCb_Dw1000,
259
    /* next     */ NULL,
260
  },
261
  /* data           */ &moduleLldDw1000,
262
};
263 7de0cc90 Thomas Schöpping
#endif /* defined(AMIROLLD_CFG_DW1000) */
264 deaaa47e Cung Sang
265 7de0cc90 Thomas Schöpping
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
266 f4da707a Thomas Schöpping
267
/** @} */
268
/** @} */