Revision e545e620

View differences:

.gitignore
1
doc
2 1
build
3 2
.dep
4 3
*.tmp
.gitmodules
1
[submodule "kernel/ChibiOS"]
2
	path = kernel/ChibiOS
3
	url = https://github.com/ChibiOS/ChibiOS.git
4
	ignore = dirty
5
[submodule "bootloader/AMiRo-BLT"]
6
	path = bootloader/AMiRo-BLT
7
	url = http://openresearch.cit-ec.de/git/amiro-os.amiro-blt.git
8
[submodule "periphery-lld/AMiRo-LLD"]
9
	path = periphery-lld/AMiRo-LLD
10
	url = http://openresearch.cit-ec.de/git/amiro-os.amiro-lld.git
Makefile
1
################################################################################
2
# AMiRo-OS is an operating system designed for the Autonomous Mini Robot       #
3
# (AMiRo) platform.                                                            #
4
# Copyright (C) 2016..2018  Thomas Schöpping et al.                            #
5
#                                                                              #
6
# This program is free software: you can redistribute it and/or modify         #
7
# it under the terms of the GNU General Public License as published by         #
8
# the Free Software Foundation, either version 3 of the License, or            #
9
# (at your option) any later version.                                          #
10
#                                                                              #
11
# This program is distributed in the hope that it will be useful,              #
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of               #
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                #
14
# GNU General Public License for more details.                                 #
15
#                                                                              #
16
# You should have received a copy of the GNU General Public License            #
17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.        #
18
#                                                                              #
19
# This research/work was supported by the Cluster of Excellence Cognitive      #
20
# Interaction Technology 'CITEC' (EXC 277) at Bielefeld University, which is   #
21
# funded by the German Research Foundation (DFG).                              #
22
################################################################################
23

  
24

  
25

  
26
define HELP_TEXT
27
################################################################################
28
#                                                                              #
29
# Copyright (c) 2016..2018  Thomas Schöpping                                   #
30
#                                                                              #
31
# This is free software; see the source for copying conditions. There is NO    #
32
# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  #
33
# The development of this software was supported by the Excellence Cluster     #
34
# EXC 227 Cognitive Interaction Technology. The Excellence Cluster EXC 227 is  #
35
# a grant of the Deutsche Forschungsgemeinschaft (DFG) in the context of the   #
36
# German Excellence Initiative.                                                #
37
#                                                                              #
38
################################################################################
39

  
40
  AMiRo-OS Makefile help
41
  ======================
42

  
43
ARGUMENTS:
44

  
45
  help:
46
      Prints this text.
47

  
48
  all:
49
      Builds the binaries for all modules.
50

  
51
  flash:
52
      Flashes all binaries to the hardware.
53
      If the binaries do not exist, they are created beforehand.
54

  
55
  clean:
56
      Deletes all temporary and binary files of all modules.
57

  
58
  <module>:
59
      Builds the binary only for the specified module.
60
      Possible values for <module> are:
61
        - DiWheelDrive
62
        - PowerManagement
63
        - LightRing
64

  
65

  
66
EXAMPLES:
67

  
68
  >$$ make DiWheelDrive
69
      This command will generate the binary file for the DiWheelDrive module.
70

  
71
  >$$ make DiWheelDrive LightRing
72
      This command will generate the binary files for the two modules
73
      DiWheelDrive and LightRing.
74

  
75
  >$$ make flash -j
76
      This command will first build all missing binary files and flash all
77
      modules as soon as the binaries are ready.
78
      By the additional argument '-j' the build process will be parallelized.
79

  
80
  >$$ make clean && make all && make flash
81
      This command will first clean all thee projects. In a second step the
82
      binaries for al three modules are build from scratch. Finally all modules
83
      are updated with the latest software.
84
      The following command can be used as a shorter and faster version:
85
          >$$ make clean && make flash -j
86

  
87
################################################################################
88
endef
89
export HELP_TEXT
90

  
91
OS_BASE_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
92

  
93
help:
94
	@echo "$$HELP_TEXT"
95
	@exit
96

  
97
include $(OS_BASE_DIR)/os/modules/Makefile
README.txt
1
AMiRo-OS is the operating system for the base version of the Autonomous Mini
1
AMiRo-OS is an operating system for the base version of the Autonomous Mini
2 2
Robot (AMiRo) [1]. It utilizes ChibiOS (a real-time operating system for
3 3
embedded devices developed by Giovanni di Sirio; see <http://chibios.org>) as
4
system kernel and extends it with platform specific functionalities.
4
system kernel and extends it with platform specific configurations and further
5
functionalities and abstractions.
5 6

  
6
Copyright (C) 2016..2017  Thomas Schöpping et al.
7
Copyright (C) 2016..2018  Thomas Schöpping et al.
7 8
(a complete list of all authors is given below)
8 9

  
9 10
This program is free software: you can redistribute it and/or modify
......
24 25
University, which is funded by the German Research Foundation (DFG).
25 26

  
26 27
Authors:
27
 - Thomas Schöpping        <tschoepp[at]cit-ec.uni-bielefeld.de>
28
 - Timo Korthals           <tkorthals[at]cit-ec.uni-bielefeld.de>
29
 - Stefan Herbrechtsmeier  <sherbrec[at]cit-ec.uni-bielefeld.de>
30
 - Teerapat Chinapirom     <tchinapirom[at]cit-ec.uni-bielefeld.de>
31
 - Robert Abel
32
 - Marvin Barther
33
 - Claas Braun
34
 - Tristan Kenneweg
28
 - Thomas Schöpping          <tschoepp[at]cit-ec.uni-bielefeld.de>
29
 - Marc Rothmann
35 30

  
36 31
References:
37 32
 [1] S. Herbrechtsmeier, T. Korthals, T. Schopping and U. Rückert, "AMiRo: A
......
59 54
================================================================================
60 55

  
61 56
CONTENTS:
62
 1  Required software
63
   1.1  Git
64
   1.2  GCC ARM Embedded Toolchain
65
   1.3  ChibiOS
66
   1.4  AMiRo-BLT
67
 2  Recommended software
68
   2.1  gtkterm and hterm
69
   2.2  QtCreator
70
 3  Building and flashing
57

  
58
  1  Required software
59
    1.1  Git
60
    1.2  Bootloader & Tools
61
    1.3  System Kernel
62
    1.4  Low-Level Drivers
63
  2  Recommended software
64
    2.1  gtkterm and hterm
65
    2.2  QtCreator IDE
66
    2.3  Doxygen & Graphviz
67
  3  Building and flashing
71 68

  
72 69
================================================================================
73 70

  
......
76 73
1 - REQUIRED SOFTWARE
77 74
---------------------
78 75

  
79
In order to compile the source code, you need to install the GCC for ARM
80
embedded devices. Since AMiRo-OS requires ChibiOS as system kernel, you need a
81
copy of that project as well. Furthermore, AMiRo-OS requires a compatible
82
bootloader, such as provided by the AMiRo-BLT project.
76
In order to compile the source code, you need to install the GNU ARM Embedded
77
Toolchain. Since this project uses GNU Make for configuring and calling the
78
compiler, this tool is requried too. AMiRo-OS uses ChibiOS as system kernel,
79
so you need a copy of that project as well.
83 80

  
84 81

  
85 82
1.1 - Git
......
89 86
recent version of the tool is mandatory.
90 87

  
91 88

  
92
1.2 GCC ARM Embedded Toolchain
93
------------------------------
94

  
95
Various versions of the GCC for ARM embedded devices can be found at
96
<https://launchpad.net/gcc-arm-embedded>. It is highly recommended to use the
97
version 4.8 with update 2014-q1 since some others will cause issues. For
98
installation of the compiler toolchain, please follow the instructions that can
99
be found on the web page.
89
1.2 Bootloader & Tools
90
----------------------
100 91

  
101
If you are running a 64-bit operating system, you will have to install several
102
32-bit libraries in order to make the compiler work. The required packages are
103
libc6, libstdc++6, and libncurses5. You can run the following shell commands to
104
install the according 32-bit versions of the packages:
105
  >$ sudo dpkg --add-architecture i386 && sudo apt-get update
106
  >$ sudo apt-get install libc6:i386 libstdc++6:i386 libncurses5:i386
92
AMiRo-OS can take advantage of an installed bootloader if such exists and
93
provides an interface. By default, AMiRo-BLT is included as a Git submodule and
94
can easily be initialized via the ./setup.sh script. If requried, you can
95
replace the used bootloader by adding an according subfolder in the ./bootloader
96
directory. Note that you will have to adapt the makefiles and scripts, and
97
probably the operating system as well.
98
AMiRo-BLT furthermore has its own required and recommended software tools as
99
described in its README.txt file. Follow th instructions to initialize the
100
development environment manually or use the ./setup.sh script.
107 101

  
108 102

  
109
1.3 ChibiOS
110
-----------
103
1.3 System Kernel
104
-----------------
111 105

  
112 106
Since AMiRo-OS uses ChibiOS as underlying system kernel, you need to acquire a
113
copy of it as well. First, go to the directory which contains the AMiRo-OS
114
folder (but do not go into the AMiRo-OS directory itself!). Now clone the GIT
115
repository of ChibiOS and checkout version 2.6.x:
116
  >$ git clone https://github.com/ChibiOS/ChibiOS.git ChibiOS
117
  >$ cd ChibiOS
118
  >$ git checkout 2e6dfc7364e7551483922ea6afbaea8f3501ab0e
119
It is highly recommended to use exactly this commit. Although newer commits in
120
the 2.6.x branch might work fine, AMiRo-OS is not compatible with ChibiOS
121
version 3 or newer.
122

  
123
AMiRo-OS comes with some patches to ChibiOS, which must be applied as well
124
before compiling the project. Therefore you need to copy all files from the
125
./patches directory of AMiRo-OS to the root directory of ChibiOS. You can then
126
apply the patches via the following command:
127
  >$ for i in `ls | grep patch`; do git am --ignore-space-change --ignore-whitespace < ${i}; done
128
If the files could not be patched successfully, you are probably using an
129
incompatible version of ChibiOS (try to checkout the correct commit as denoted
130
above).
131

  
132

  
133
1.4 AMiRo-BLT
134
-------------
135

  
136
AMiRo-BLT is an additional software project, which is developed in parallel with
137
AMiRo-OS. If you did not receive a copy of AMiRo-BLT with AMiRo-OS, you can find
138
all code and documentation at <https://opensource.cit-ec.de/projects/amiro-os>.
139
Instructions for installation and how to use the software provided by AMiRo-BLT
140
can be found on the web page or in the project's readme file. It is highly
141
recommended to install AMiRo-BLT in the same directory as AMiRo-OS and ChibiOS
142
and name its root directory 'amiro-blt'.
107
copy of it as well. For the sake of compatibility, it is included in AMiRo-OS as
108
a Git submodule. It is highly recommended to use the ./setup.sh script for
109
initialization. Moreover, you have to apply the patches to ChibiOS in order to
110
make AMiRo-OS work properly. It is recommended to use the .setup.sh script for this
111
purpose.
112
If you would like to use a different kernel, you can add a subfolder in the
113
./kernel/ directory and adapt the scripts and operating system source code.
114

  
115

  
116
1.4 Low-Level Drivers
117
---------------------
118

  
119
Any required low-level drivers for the AMiRo hardware is available in an
120
additional project: AMiRo-LLD. It is included as a Git subodule and can be
121
initialized via the ./setup.sh script.
143 122

  
144 123

  
145 124

  
146 125
2 - RECOMMENDED SOFTWARE
147 126
------------------------
148 127

  
149
In order to fully use all features of AMiRo-OS it is recommended to install the
150
'hterm' or 'gtkterm' application for accessing the robot. To ease further
151
development, this project offers support for the QtCreator IDE.
128
AMiRo-OS can take advanatge of an installed bootloader, which is recommended for
129
the best experience. In order to use all features of AMiRo-OS it is also
130
recommended to install either the 'hterm' or 'gtkterm' application for accessing
131
the robot. To ease further development, this project offers support for the
132
QtCreator IDE.
152 133

  
153 134

  
154 135
2.1 - gtkterm and hterm
155 136
-----------------------
156 137

  
157
Depending on your operating system, it is recommended to install 'gtkterm' for
138
Depending on your operating system it is recommended to install 'gtkterm' for
158 139
Linux (available in the Ubuntu repositories), or 'hterm' for Windows. For
159
gtkterm you need to modify the configuration file ~/.gtktermrc (it is generated
140
gtkterm you need to modify the configuration file ~/.gtktermrc (generated
160 141
automatically when you start the application for the first time) as follows:
161 142

  
162 143
  port	= /dev/ttyUSB0
......
172 153
  echo	= False
173 154
  crlfauto	= True
174 155

  
175
For hterm you must need to configure the tool analogously.
156
For hterm you need to configure the tool analogously. With either tool the robot
157
can be reset by toggling the RTS signal on and off again, and you can access the
158
system shell of AMiRo-OS.
176 159

  
177 160

  
178
2.2 - QtCreator
179
---------------
161
2.2 - QtCreator IDE
162
-------------------
180 163

  
181
In order to setup QtCreator projects for the three AMiRo base modules, a script
182
is provided in the directory ./ide/qtcreator/. It is accompanied by an
183
additional README.txt file, which contains further information.
164
In order to setup QtCreator projects for the three AMiRo base modules, you can
165
use the provided ./setup.sh script. Further instructions for a more advanced
166
configuration of the IDE are provided in the ./tools/qtcreator/README.txt file.
167

  
168

  
169
2.3  Doxygen & Graphviz
170
-----------------------
171

  
172
In order to generate the documentation from the source code, Doxygen and
173
Graphviz are requried. It is recommended to install these tool using the
174
default versions for your system. Ubuntu users should simply run
175
  >$ sudo apt-get install doxygen graphviz
184 176

  
185 177

  
186 178

  
......
188 180
-------------------------
189 181

  
190 182
Each time you modify any part of AMiRo-OS, you need to recompile the whole
191
project for the according AMiRo module. Therefore you have to use the makefiles
192
provided in ./devices/<DeviceToRecompile>/ by simply executing 'make' in the
193
according directory. If you want to compile all modules at once, you can also
194
use the makefile in the ./devices/ folder.
195

  
196
After compilation, you always have to flash the generated program to the robot.
197
Therefore you need to install the SerialBoot tool provided by the AMiRo-BLT
198
project. By default AMiRo-OS assumes AMiRo-BLT to be installed in the same
199
folder and its root directory to be named 'amiro-blt'. If this is the case, it
200
will automatically detect the SerialBoot tool. Otherwise the tool must be
201
accessible globally under the environment variable 'SERIALBOOT'. You can make
202
it so by appending the following line to your ~/.bashrc file:
203

  
204
  export SERIALBOOT=</absolute/path/to/the/SerialBoot/binary>
205

  
206
You can test the tool by calling it via the variable:
207
  >$ ${SERIALBOOT}
208
This should print some information about the tool.
209

  
210
Similar to the compilation procedure as described above, you can flash either
211
each module separately, or all modules at once by executing 'make flash' from
212
the according directory. Note that you must connect the programming cable either
213
to the DiWheelDrive or the PowerManagement module for flashing the operating
214
system. All other modules are powered off after reset so that only these two
215
offer a bootloader that is required for flashing.
183
project for the according AMiRo module. Therefore you can use the ./Makefile by
184
simply executing 'make' and follow the instructions. Alternatively, you can
185
either use the makefiles provided per module in ./os/modules/<ModuleToCompile>
186
or - if you want to compile all modules at once - the makefile in the
187
./os/modules folder. After the build process has finished successfully, you
188
always have to flash the generated program to the robot. Therefore you need an
189
appropriate tool, such as stm32flash (if you don't use a bootloader) or
190
SerialBoot (highly recommended; provided by AMiRo-BLT). Similarly to the
191
compilation procedure as described above, you can flash either each module
192
separately, or all modules at once by executing 'make flash' from the according
193
directory.
194

  
195
When using SerialBoot, please note that you must connect the programming cable
196
either to the DiWheelDrive or the PowerManagement module for flashing the
197
operating system. All other modules are powered off after reset so that only
198
these two offer a running bootloader, which is required for flashing.
216 199

  
217 200
================================================================================
201

  
boards/DiWheelDrive/board.c
1
#include "ch.h"
2
#include "hal.h"
3

  
4
/**
5
 * @brief   PAL setup.
6
 * @details Digital I/O ports static configuration as defined in @p board.h.
7
 *          This variable is used by the HAL when initializing the PAL driver.
8
 */
9
#if HAL_USE_PAL || defined(__DOXYGEN__)
10
const PALConfig pal_default_config =
11
{
12
  {VAL_GPIOAODR, VAL_GPIOACRL, VAL_GPIOACRH},
13
  {VAL_GPIOBODR, VAL_GPIOBCRL, VAL_GPIOBCRH},
14
  {VAL_GPIOCODR, VAL_GPIOCCRL, VAL_GPIOCCRH},
15
  {VAL_GPIODODR, VAL_GPIODCRL, VAL_GPIODCRH},
16
  {VAL_GPIOEODR, VAL_GPIOECRL, VAL_GPIOECRH},
17
  {VAL_GPIOFODR, VAL_GPIOFCRL, VAL_GPIOFCRH},
18
  {VAL_GPIOGODR, VAL_GPIOGCRL, VAL_GPIOGCRH},
19
};
20

  
21
#endif
22

  
23
/*
24
 * Early initialization code.
25
 * This initialization must be performed just after stack setup and before
26
 * any other initialization.
27
 */
28
void __early_init(void) {
29

  
30
  stm32_clock_init();
31
}
32

  
33
/*
34
 * Board-specific initialization code.
35
 */
36
void boardInit(void) {
37
  /*
38
   * Several I/O pins are re-mapped:
39
   *   JTAG disabled and SWJ enabled
40
   *   TIM2 to the PA15/PB3/PA2/PA3 pins.
41
   *   TIM3 to PC6/PC7 pins.
42
   *   USART3 to the PC10/PC11 pins.
43
   *   I2C1 to the PB8/PB9 pins.
44
   */
45
  AFIO->MAPR = AFIO_MAPR_SWJ_CFG_DISABLE |
46
               AFIO_MAPR_TIM2_REMAP_PARTIALREMAP1 |
47
               AFIO_MAPR_TIM3_REMAP_FULLREMAP |
48
               AFIO_MAPR_USART3_REMAP_PARTIALREMAP |
49
               AFIO_MAPR_I2C1_REMAP;
50
}
51

  
52
inline void boardWriteIoPower(const uint8_t value)
53
{
54
    if (value) {
55
        // drive pins
56
        palSetPadMode(GPIOA, GPIOA_CAN_TX, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
57
    } else {
58
        // float pins
59
        palSetPadMode(GPIOA, GPIOA_CAN_TX, PAL_MODE_INPUT);
60
    }
61
}
62

  
63
inline void boardWriteLed(int value)
64
{
65
    palWritePad(GPIOA, GPIOA_LED, !value);
66
}
67

  
68
inline void boardRequestShutdown(void)
69
{
70
  palClearPad(GPIOC, GPIOC_SYS_PD_N);
71
}
72

  
73
inline void boardStandby(void)
74
{
75

  
76
  palSetPad(GPIOC, GPIOC_SYS_PD_N);
77
  chSysLock();
78
  // Standby
79
  // set deepsleep bit
80
  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
81
  // enable wakeup pin
82
  //PWR->CSR |= PWR_CSR_EWUP;
83
  // set PDDS, clear WUF, clear SBF
84
  PWR->CR |= (PWR_CR_CWUF | PWR_CR_PDDS | PWR_CR_CSBF);
85
  // clear RTC wakeup source flags
86
  RTC->CRL &= ~(RTC_CRL_ALRF);
87
  // Wait for Interrupt
88
  __WFI();
89

  
90
}
91

  
92
inline void boardWakeup(void) {
93

  
94
  palClearPad(GPIOC, GPIOC_SYS_PD_N);
95
  chThdSleepMicroseconds(10);
96
  palSetPad(GPIOC, GPIOC_SYS_PD_N);
97
}
98

  
99
inline void boardClearI2CBus(const uint8_t scl_pad, const uint8_t sda_pad) {
100

  
101
  uint8_t i;
102

  
103
  // configure I²C SCL and SDA open drain
104
  palSetPadMode(GPIOB, scl_pad, PAL_MODE_OUTPUT_OPENDRAIN);
105
  palSetPadMode(GPIOB, sda_pad, PAL_MODE_OUTPUT_OPENDRAIN);
106

  
107
  // perform a 2-wire software reset for the eeprom (see AT24C01BN-SH-B datasheet, chapter 3)
108
  // note: clock is ~50kHz (20us per cycle)
109
  palSetPad(GPIOB, sda_pad);
110
  palClearPad(GPIOB, scl_pad);
111
  chThdSleepMicroseconds(10);
112
  palSetPad(GPIOB, scl_pad);
113
  chThdSleepMicroseconds(5);
114
  palClearPad(GPIOB, sda_pad);
115
  chThdSleepMicroseconds(5);
116
  palClearPad(GPIOB, scl_pad);
117
  chThdSleepMicroseconds(5);
118
  palSetPad(GPIOB, sda_pad);
119
  chThdSleepMicroseconds(5);
120
  for (i = 0; i < 9; ++i) {
121
    palSetPad(GPIOB, scl_pad);
122
    chThdSleepMicroseconds(10);
123
    palClearPad(GPIOB, scl_pad);
124
    chThdSleepMicroseconds(10);
125
  }
126
  palSetPad(GPIOB, scl_pad);
127
  chThdSleepMicroseconds(5);
128
  palClearPad(GPIOB, sda_pad);
129
  chThdSleepMicroseconds(5);
130
  palClearPad(GPIOB, scl_pad);
131
  chThdSleepMicroseconds(10);
132
  palSetPad(GPIOB, scl_pad);
133
  chThdSleepMicroseconds(5);
134
  palSetPad(GPIOB, sda_pad);
135
  chThdSleepMicroseconds(5);
136
  palClearPad(GPIOB, scl_pad);
137
  chThdSleepMicroseconds(10);
138

  
139
  // perform bus clear as per I²C Specification v6 3.1.16
140
  // note: clock is 100kHz (10us per cycle)
141
  for (i = 0; i < 10; i++) {
142
    palClearPad(GPIOB, scl_pad);
143
    chThdSleepMicroseconds(5);
144
    palSetPad(GPIOB, scl_pad);
145
    chThdSleepMicroseconds(5);
146
  }
147

  
148
  // reconfigure I²C SCL
149
  palSetPadMode(GPIOB, scl_pad, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
150
  palSetPadMode(GPIOB, sda_pad, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
151

  
152
  return;
153
}
boards/DiWheelDrive/board.h
1
#ifndef _BOARD_H_
2
#define _BOARD_H_
3

  
4
/*
5
 * Setup for AMiRo DiWheelDrive board.
6
 */
7

  
8
/*
9
 * Board identifier.
10
 */
11
#define BOARD_DI_WHEEL_DRIVE
12
#define BOARD_NAME              "AMiRo DiWheelDrive"
13
#define BOARD_VERSION           "1.1"
14

  
15
/*
16
 * Board frequencies.
17
 */
18
#define STM32_LSECLK            0
19
#define STM32_HSECLK            8000000
20

  
21
/*
22
 * MCU type as defined in the ST header file stm32f1xx.h.
23
 */
24
#define STM32F10X_HD
25

  
26
/*
27
 * IO pins assignments.
28
 */
29
#define GPIOA_WKUP              0
30
#define GPIOA_LED               1
31
#define GPIOA_DRIVE_PWM1A       2
32
#define GPIOA_DRIVE_PWM1B       3
33
#define GPIOA_MOTION_SCLK       5
34
#define GPIOA_MOTION_MISO       6
35
#define GPIOA_MOTION_MOSI       7
36
#define GPIOA_PROG_RX           9
37
#define GPIOA_PROG_TX           10
38
#define GPIOA_CAN_RX            11
39
#define GPIOA_CAN_TX            12
40
#define GPIOA_SWDIO             13
41
#define GPIOA_SWCLK             14
42
#define GPIOA_DRIVE_PWM2B       15
43

  
44

  
45
#define GPIOB_DRIVE_SENSE2      1
46
#define GPIOB_POWER_EN          2
47
#define GPIOB_DRIVE_PWM2A       3
48
#define GPIOB_COMPASS_DRDY      5
49
#define GPIOB_DRIVE_ENC1A       6
50
#define GPIOB_DRIVE_ENC1B       7
51
#define GPIOB_COMPASS_SCL       8
52
#define GPIOB_COMPASS_SDA       9
53
#define GPIOB_IR_SCL            10
54
#define GPIOB_IR_SDA            11
55
#define GPIOB_IR_INT            12
56
#define GPIOB_GYRO_DRDY         13
57
#define GPIOB_SYS_UART_UP       14
58
#define GPIOB_ACCEL_INT_N       15
59

  
60
#define GPIOC_DRIVE_SENSE1      0
61
#define GPIOC_SYS_INT_N         1
62
#define GPIOC_PATH_DCSTAT       3
63
#define GPIOC_PATH_DCEN         5
64
#define GPIOC_DRIVE_ENC2B       6
65
#define GPIOC_DRIVE_ENC2A       7
66
#define GPIOC_SYS_PD_N          8
67
#define GPIOC_SYS_REG_EN        9
68
#define GPIOC_SYS_UART_RX       10
69
#define GPIOC_SYS_UART_TX       11
70
#define GPIOC_ACCEL_SS_N        13
71
#define GPIOC_GYRO_SS_N         14
72

  
73
#define GPIOD_OSC_IN            0
74
#define GPIOD_OSC_OUT           1
75
#define GPIOD_SYS_WARMRST_N     2
76

  
77
/*
78
 * I/O ports initial setup, this configuration is established soon after reset
79
 * in the initialization code.
80
 */
81
#define PIN_MODE_INPUT(n)               (0x4U << (((n) % 8) * 4))
82
#define PIN_MODE_INPUT_PULLX(n)         (0x8U << (((n) % 8) * 4))
83
#define PIN_MODE_INPUT_ANALOG(n)        (0x0U << (((n) % 8) * 4))
84
/* Push Pull output 50MHz */
85
#define PIN_MODE_OUTPUT_PUSHPULL(n)     (0x3U << (((n) % 8) * 4))
86
/* Open Drain output 50MHz */
87
#define PIN_MODE_OUTPUT_OPENDRAIN(n)    (0x7U << (((n) % 8) * 4))
88
/* Alternate Push Pull output 50MHz */
89
#define PIN_MODE_ALTERNATE_PUSHPULL(n)  (0xbU << (((n) % 8) * 4))
90
/* Alternate Open Drain output 50MHz */
91
#define PIN_MODE_ALTERNATE_OPENDRAIN(n) (0xfU << (((n) % 8) * 4))
92

  
93
/*
94
 * Port A setup.
95
 */
96
#define VAL_GPIOACRL            (PIN_MODE_INPUT(GPIOA_WKUP) | \
97
                                 PIN_MODE_OUTPUT_OPENDRAIN(GPIOA_LED) | \
98
                                 PIN_MODE_ALTERNATE_PUSHPULL(GPIOA_DRIVE_PWM1A) | \
99
                                 PIN_MODE_ALTERNATE_PUSHPULL(GPIOA_DRIVE_PWM1B) | \
100
                                 PIN_MODE_INPUT_PULLX(4) | \
101
                                 PIN_MODE_ALTERNATE_PUSHPULL(GPIOA_MOTION_SCLK) | \
102
                                 PIN_MODE_INPUT_PULLX(GPIOA_MOTION_MISO) | \
103
                                 PIN_MODE_ALTERNATE_PUSHPULL(GPIOA_MOTION_MOSI))
104
#define VAL_GPIOACRH            (PIN_MODE_INPUT_PULLX(8) | \
105
                                 PIN_MODE_ALTERNATE_PUSHPULL(GPIOA_PROG_RX) | \
106
                                 PIN_MODE_INPUT_PULLX(GPIOA_PROG_TX) | \
107
                                 PIN_MODE_INPUT_PULLX(GPIOA_CAN_RX) | \
108
                                 PIN_MODE_ALTERNATE_PUSHPULL(GPIOA_CAN_TX) | \
109
                                 PIN_MODE_INPUT_PULLX(GPIOA_SWDIO) | \
110
                                 PIN_MODE_INPUT_PULLX(GPIOA_SWCLK) | \
111
                                 PIN_MODE_ALTERNATE_PUSHPULL(GPIOA_DRIVE_PWM2B))
112
#define VAL_GPIOAODR            0xF7FF /* prevent power over CAN bug */
113

  
114
/*
115
 * Port B setup.
116
 */
117
#define VAL_GPIOBCRL            (PIN_MODE_INPUT_PULLX(0) | \
118
                                 PIN_MODE_INPUT_ANALOG(GPIOB_DRIVE_SENSE2) | \
119
                                 PIN_MODE_OUTPUT_PUSHPULL(GPIOB_POWER_EN) | \
120
                                 PIN_MODE_ALTERNATE_PUSHPULL(GPIOB_DRIVE_PWM2A) | \
121
                                 PIN_MODE_INPUT_PULLX(4) | \
122
                                 PIN_MODE_INPUT_PULLX(GPIOB_COMPASS_DRDY) | \
123
                                 PIN_MODE_INPUT(GPIOB_DRIVE_ENC1A) | \
124
                                 PIN_MODE_INPUT(GPIOB_DRIVE_ENC1B))
125
#define VAL_GPIOBCRH            (PIN_MODE_ALTERNATE_OPENDRAIN(GPIOB_COMPASS_SCL) | \
126
                                 PIN_MODE_ALTERNATE_OPENDRAIN(GPIOB_COMPASS_SDA) | \
127
                                 PIN_MODE_ALTERNATE_OPENDRAIN(GPIOB_IR_SCL) | \
128
                                 PIN_MODE_ALTERNATE_OPENDRAIN(GPIOB_IR_SDA) | \
129
                                 PIN_MODE_INPUT(GPIOB_IR_INT) | \
130
                                 PIN_MODE_INPUT_PULLX(GPIOB_GYRO_DRDY) | \
131
                                 PIN_MODE_OUTPUT_OPENDRAIN(GPIOB_SYS_UART_UP) | \
132
                                 PIN_MODE_INPUT_PULLX(GPIOB_ACCEL_INT_N))
133
#define VAL_GPIOBODR            0xFFFB /* initially the motors are not powered */
134

  
135
/*
136
 * Port C setup.
137
 */
138
#define VAL_GPIOCCRL            (PIN_MODE_INPUT_ANALOG(GPIOC_DRIVE_SENSE1) | \
139
                                 PIN_MODE_OUTPUT_OPENDRAIN(GPIOC_SYS_INT_N) | \
140
                                 PIN_MODE_INPUT_PULLX(2) | \
141
                                 PIN_MODE_INPUT(GPIOC_PATH_DCSTAT) | \
142
                                 PIN_MODE_INPUT_PULLX(4) | \
143
                                 PIN_MODE_OUTPUT_PUSHPULL(GPIOC_PATH_DCEN) | \
144
                                 PIN_MODE_INPUT(GPIOC_DRIVE_ENC2B) | \
145
                                 PIN_MODE_INPUT(GPIOC_DRIVE_ENC2A))
146
#define VAL_GPIOCCRH            (PIN_MODE_OUTPUT_OPENDRAIN(GPIOC_SYS_PD_N) | \
147
                                 PIN_MODE_INPUT(GPIOC_SYS_REG_EN) | \
148
                                 PIN_MODE_INPUT(GPIOC_SYS_UART_RX) | \
149
                                 PIN_MODE_INPUT(GPIOC_SYS_UART_TX) | \
150
                                 PIN_MODE_INPUT_PULLX(12) | \
151
                                 PIN_MODE_OUTPUT_PUSHPULL(GPIOC_ACCEL_SS_N) | \
152
                                 PIN_MODE_OUTPUT_PUSHPULL(GPIOC_GYRO_SS_N) | \
153
                                 PIN_MODE_INPUT_PULLX(15))
154
#define VAL_GPIOCODR            0xFFDD /* initially charging via the pins is disabled and SYSNIN_N indicates that the OS is busy */
155

  
156
/*
157
 * Port D setup.
158
 */
159
#define VAL_GPIODCRL            (PIN_MODE_INPUT(GPIOD_OSC_IN) | \
160
                                 PIN_MODE_INPUT(GPIOD_OSC_OUT) | \
161
                                 PIN_MODE_OUTPUT_OPENDRAIN(GPIOD_SYS_WARMRST_N) | \
162
                                 PIN_MODE_INPUT_PULLX(3) | \
163
                                 PIN_MODE_INPUT_PULLX(4) | \
164
                                 PIN_MODE_INPUT_PULLX(5) | \
165
                                 PIN_MODE_INPUT_PULLX(6) | \
166
                                 PIN_MODE_INPUT_PULLX(7))
167
#define VAL_GPIODCRH            0x88888888
168
#define VAL_GPIODODR            0xFFFF
169

  
170
/*
171
 * Port E setup.
172
 */
173
#define VAL_GPIOECRL            0x88888888 /*  PE7...PE0 */
174
#define VAL_GPIOECRH            0x88888888 /* PE15...PE8 */
175
#define VAL_GPIOEODR            0xFFFF
176

  
177
/*
178
 * Port F setup.
179
 */
180
#define VAL_GPIOFCRL            0x88888888 /*  PF7...PF0 */
181
#define VAL_GPIOFCRH            0x88888888 /* PF15...PF8 */
182
#define VAL_GPIOFODR            0xFFFF
183

  
184
/*
185
 * Port G setup.
186
 */
187
#define VAL_GPIOGCRL            0x88888888 /*  PG7...PG0 */
188
#define VAL_GPIOGCRH            0x88888888 /* PG15...PG8 */
189
#define VAL_GPIOGODR            0xFFFF
190

  
191
#if !defined(_FROM_ASM_)
192
#ifdef __cplusplus
193
extern "C" {
194
#endif
195
  void boardInit(void);
196
  void boardWriteIoPower(const uint8_t value);
197
  void boardWriteLed(int value);
198
  void boardRequestShutdown(void);
199
  void boardStandby(void);
200
  void boardWakeup(void);
201
  void boardClearI2CBus(const uint8_t scl_pad, const uint8_t sda_pad);
202
#ifdef __cplusplus
203
}
204
#endif
205
#endif /* _FROM_ASM_ */
206

  
207
#endif /* _BOARD_H_ */
boards/DiWheelDrive/board.mk
1
# List of all the board related files.
2
BOARDSRC = ${AMIRO}/boards/DiWheelDrive/board.c
3

  
4
# Required include directories
5
BOARDINC = ${AMIRO}/boards/DiWheelDrive
6

  
7
# Required linker directory
8
BOARDLD = ${AMIRO}/ports
9

  
boards/LightRing/board.c
1
#include "ch.h"
2
#include "hal.h"
3

  
4
/**
5
 * @brief   PAL setup.
6
 * @details Digital I/O ports static configuration as defined in @p board.h.
7
 *          This variable is used by the HAL when initializing the PAL driver.
8
 */
9
#if HAL_USE_PAL || defined(__DOXYGEN__)
10
const PALConfig pal_default_config =
11
{
12
  {VAL_GPIOAODR, VAL_GPIOACRL, VAL_GPIOACRH},
13
  {VAL_GPIOBODR, VAL_GPIOBCRL, VAL_GPIOBCRH},
14
  {VAL_GPIOCODR, VAL_GPIOCCRL, VAL_GPIOCCRH},
15
  {VAL_GPIODODR, VAL_GPIODCRL, VAL_GPIODCRH},
16
  {VAL_GPIOEODR, VAL_GPIOECRL, VAL_GPIOECRH},
17
  {VAL_GPIOFODR, VAL_GPIOFCRL, VAL_GPIOFCRH},
18
  {VAL_GPIOGODR, VAL_GPIOGCRL, VAL_GPIOGCRH},
19
};
20

  
21
#endif
22

  
23
/*
24
 * Early initialization code.
25
 * This initialization must be performed just after stack setup and before
26
 * any other initialization.
27
 */
28
void __early_init(void) {
29

  
30
  stm32_clock_init();
31
}
32

  
33
/*
34
 * Board-specific initialization code.
35
 */
36
void boardInit(void) {
37
  /*
38
   * Several I/O pins are re-mapped:
39
   *   JTAG disabled and SWD enabled
40
   */
41
  AFIO->MAPR = AFIO_MAPR_SWJ_CFG_JTAGDISABLE |
42
               AFIO_MAPR_USART3_REMAP_PARTIALREMAP;
43
}
44

  
45
inline void boardRequestShutdown(void)
46
{
47
  palClearPad(GPIOC, GPIOC_SYS_PD_N);
48
}
49

  
50
inline void boardStandby(void)
51
{
52

  
53
  palSetPad(GPIOC, GPIOC_SYS_PD_N);
54
  chSysLock();
55
  // Standby
56
  // set deepsleep bit
57
  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
58
  // set PDDS, clear WUF, clear SBF
59
  PWR->CR |= (PWR_CR_CWUF | PWR_CR_PDDS | PWR_CR_CSBF);
60
  // clear RTC wakeup source flags
61
  RTC->CRL &= ~(RTC_CRL_ALRF);
62
  // Wait for Interrupt
63
  __WFI();
64

  
65
}
66

  
67
inline void boardClearI2CBus(const uint8_t scl_pad, const uint8_t sda_pad) {
68

  
69
  uint8_t i;
70

  
71
  // configure I²C SCL and SDA open drain
72
  palSetPadMode(GPIOB, scl_pad, PAL_MODE_OUTPUT_OPENDRAIN);
73
  palSetPadMode(GPIOB, sda_pad, PAL_MODE_OUTPUT_OPENDRAIN);
74

  
75
  // perform a 2-wire software reset for the eeprom (see AT24C01BN-SH-B datasheet, chapter 3)
76
  // note: clock is ~50kHz (20us per cycle)
77
  palSetPad(GPIOB, sda_pad);
78
  palClearPad(GPIOB, scl_pad);
79
  chThdSleepMicroseconds(10);
80
  palSetPad(GPIOB, scl_pad);
81
  chThdSleepMicroseconds(5);
82
  palClearPad(GPIOB, sda_pad);
83
  chThdSleepMicroseconds(5);
84
  palClearPad(GPIOB, scl_pad);
85
  chThdSleepMicroseconds(5);
86
  palSetPad(GPIOB, sda_pad);
87
  chThdSleepMicroseconds(5);
88
  for (i = 0; i < 9; ++i) {
89
    palSetPad(GPIOB, scl_pad);
90
    chThdSleepMicroseconds(10);
91
    palClearPad(GPIOB, scl_pad);
92
    chThdSleepMicroseconds(10);
93
  }
94
  palSetPad(GPIOB, scl_pad);
95
  chThdSleepMicroseconds(5);
96
  palClearPad(GPIOB, sda_pad);
97
  chThdSleepMicroseconds(5);
98
  palClearPad(GPIOB, scl_pad);
99
  chThdSleepMicroseconds(10);
100
  palSetPad(GPIOB, scl_pad);
101
  chThdSleepMicroseconds(5);
102
  palSetPad(GPIOB, sda_pad);
103
  chThdSleepMicroseconds(5);
104
  palClearPad(GPIOB, scl_pad);
105
  chThdSleepMicroseconds(10);
106

  
107
  // perform bus clear as per I²C Specification v6 3.1.16
108
  // note: clock is 100kHz (10us per cycle)
109
  for (i = 0; i < 10; i++) {
110
    palClearPad(GPIOB, scl_pad);
111
    chThdSleepMicroseconds(5);
112
    palSetPad(GPIOB, scl_pad);
113
    chThdSleepMicroseconds(5);
114
  }
115

  
116
  // reconfigure I²C SCL
117
  palSetPadMode(GPIOB, scl_pad, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
118
  palSetPadMode(GPIOB, sda_pad, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
119

  
120
  return;
121
}
boards/LightRing/board.h
1
#ifndef _BOARD_H_
2
#define _BOARD_H_
3

  
4
/*
5
 * Setup for AMiRo LightRing board.
6
 */
7

  
8
/*
9
 * Board identifier.
10
 */
11
#define BOARD_LIGHT_RING
12
#define BOARD_NAME              "AMiRo LightRing"
13
#define BOARD_VERSION           "1.0"
14

  
15
/*
16
 * Board frequencies.
17
 */
18
#define STM32_LSECLK            0
19
#define STM32_HSECLK            8000000
20

  
21
/*
22
 * MCU type as defined in the ST header file stm32f1xx.h.
23
 */
24
#define STM32F10X_HD
25

  
26
/*
27
 * IO pins assignments.
28
 */
29
#define GPIOA_LASER_RX          2
30
#define GPIOA_LASER_TX          3
31
#define GPIOA_LIGHT_BLANK       4
32
#define GPIOA_LIGHT_SCLK        5
33
#define GPIOA_LIGHT_MOSI        7
34
#define GPIOA_PROG_RX           9
35
#define GPIOA_PROG_TX           10
36
#define GPIOA_CAN_RX            11
37
#define GPIOA_CAN_TX            12
38

  
39
#define GPIOB_LASER_EN          2
40
#define GPIOB_LASER_OC_N        5
41
#define GPIOB_SYS_UART_DN       6
42
#define GPIOB_WL_GDO2           8
43
#define GPIOB_WL_GDO0           9
44
#define GPIOB_MEM_SCL           10
45
#define GPIOB_MEM_SDA           11
46
#define GPIOB_WL_SS_N           12
47
#define GPIOB_WL_SCLK           13
48
#define GPIOB_WL_MISO           14
49
#define GPIOB_WL_MOSI           15
50

  
51
#define GPIOC_LIGHT_XLAT        4
52
#define GPIOC_SYS_UART_RX       10
53
#define GPIOC_SYS_UART_TX       11
54
#define GPIOC_SYS_PD_N          14
55

  
56
#define GPIOD_OSC_IN            0
57
#define GPIOD_OSC_OUT           1
58
#define GPIOD_SYS_INT_N         2
59

  
60
/*
61
 * I/O ports initial setup, this configuration is established soon after reset
62
 * in the initialization code.
63
 */
64
#define PIN_MODE_INPUT(n)               (0x4U << (((n) % 8) * 4))
65
#define PIN_MODE_INPUT_PULLX(n)         (0x8U << (((n) % 8) * 4))
66
#define PIN_MODE_INPUT_ANALOG(n)        (0x0U << (((n) % 8) * 4))
67
/* Push Pull output 50MHz */
68
#define PIN_MODE_OUTPUT_PUSHPULL(n)     (0x3U << (((n) % 8) * 4))
69
/* Open Drain output 50MHz */
70
#define PIN_MODE_OUTPUT_OPENDRAIN(n)    (0x7U << (((n) % 8) * 4))
71
/* Alternate Push Pull output 50MHz */
72
#define PIN_MODE_ALTERNATE_PUSHPULL(n)  (0xbU << (((n) % 8) * 4))
73
/* Alternate Open Drain output 50MHz */
74
#define PIN_MODE_ALTERNATE_OPENDRAIN(n) (0xfU << (((n) % 8) * 4))
75

  
76
/*
77
 * Port A setup.
78
 */
79
#define VAL_GPIOACRL            (PIN_MODE_INPUT_PULLX(0) | \
80
                                 PIN_MODE_INPUT_PULLX(1) | \
81
                                 PIN_MODE_ALTERNATE_PUSHPULL(GPIOA_LASER_RX) | \
82
                                 PIN_MODE_INPUT_PULLX(GPIOA_LASER_TX) | \
83
                                 PIN_MODE_OUTPUT_PUSHPULL(GPIOA_LIGHT_BLANK) | \
84
                                 PIN_MODE_ALTERNATE_PUSHPULL(GPIOA_LIGHT_SCLK) | \
85
                                 PIN_MODE_INPUT_PULLX(6) | \
86
                                 PIN_MODE_ALTERNATE_PUSHPULL(GPIOA_LIGHT_MOSI))
87
#define VAL_GPIOACRH            (PIN_MODE_INPUT_PULLX(8) | \
88
                                 PIN_MODE_ALTERNATE_PUSHPULL(GPIOA_PROG_RX) | \
89
                                 PIN_MODE_INPUT_PULLX(GPIOA_PROG_TX) | \
90
                                 PIN_MODE_INPUT(GPIOA_CAN_RX) | \
91
                                 PIN_MODE_ALTERNATE_PUSHPULL(GPIOA_CAN_TX) | \
92
                                 PIN_MODE_INPUT_PULLX(13) | \
93
                                 PIN_MODE_INPUT_PULLX(14) | \
94
                                 PIN_MODE_INPUT_PULLX(15))
95
#define VAL_GPIOAODR            0xFFFF
96

  
97
/*
98
 * Port B setup.
99
 */
100
#define VAL_GPIOBCRL            (PIN_MODE_INPUT_PULLX(0) | \
101
                                 PIN_MODE_INPUT_PULLX(1) | \
102
                                 PIN_MODE_OUTPUT_PUSHPULL(GPIOB_LASER_EN) | \
103
                                 PIN_MODE_INPUT_PULLX(3) | \
104
                                 PIN_MODE_INPUT_PULLX(4) | \
105
                                 PIN_MODE_INPUT(GPIOB_LASER_OC_N) | \
106
                                 PIN_MODE_OUTPUT_OPENDRAIN(GPIOB_SYS_UART_DN) | \
107
                                 PIN_MODE_INPUT_PULLX(7))
108
#define VAL_GPIOBCRH            (PIN_MODE_INPUT_PULLX(GPIOB_WL_GDO2) | \
109
                                 PIN_MODE_INPUT_PULLX(GPIOB_WL_GDO0) | \
110
                                 PIN_MODE_ALTERNATE_OPENDRAIN(GPIOB_MEM_SCL) | \
111
                                 PIN_MODE_ALTERNATE_OPENDRAIN(GPIOB_MEM_SDA) | \
112
                                 PIN_MODE_OUTPUT_PUSHPULL(GPIOB_WL_SS_N) | \
113
                                 PIN_MODE_ALTERNATE_PUSHPULL(GPIOB_WL_SCLK) | \
114
                                 PIN_MODE_INPUT(GPIOB_WL_MISO) | \
115
                                 PIN_MODE_ALTERNATE_PUSHPULL(GPIOB_WL_MOSI))
116
#define VAL_GPIOBODR            0xFFFB /* initially LASER_EN is deactivated */
117

  
118
/*
119
 * Port C setup.
120
 */
121
#define VAL_GPIOCCRL            (PIN_MODE_INPUT_PULLX(0) | \
122
                                 PIN_MODE_INPUT_PULLX(1) | \
123
                                 PIN_MODE_INPUT_PULLX(2) | \
124
                                 PIN_MODE_INPUT_PULLX(3) | \
125
                                 PIN_MODE_OUTPUT_PUSHPULL(GPIOC_LIGHT_XLAT) | \
126
                                 PIN_MODE_INPUT_PULLX(5) | \
127
                                 PIN_MODE_INPUT_PULLX(6) | \
128
                                 PIN_MODE_INPUT_PULLX(7))
129
#define VAL_GPIOCCRH            (PIN_MODE_INPUT_PULLX(8) | \
130
                                 PIN_MODE_INPUT_PULLX(9) | \
131
                                 PIN_MODE_INPUT(GPIOC_SYS_UART_RX) | \
132
                                 PIN_MODE_INPUT(GPIOC_SYS_UART_TX) | \
133
                                 PIN_MODE_INPUT_PULLX(12) | \
134
                                 PIN_MODE_INPUT_PULLX(13) | \
135
                                 PIN_MODE_OUTPUT_OPENDRAIN(GPIOC_SYS_PD_N) | \
136
                                 PIN_MODE_INPUT_PULLX(15))
137
#define VAL_GPIOCODR            0xFFFF
138

  
139
/*
140
 * Port D setup.
141
 */
142
#define VAL_GPIODCRL            (PIN_MODE_INPUT(GPIOD_OSC_IN) | \
143
                                 PIN_MODE_INPUT(GPIOD_OSC_OUT) | \
144
                                 PIN_MODE_OUTPUT_OPENDRAIN(GPIOD_SYS_INT_N) | \
145
                                 PIN_MODE_INPUT_PULLX(3) | \
146
                                 PIN_MODE_INPUT_PULLX(4) | \
147
                                 PIN_MODE_INPUT_PULLX(5) | \
148
                                 PIN_MODE_INPUT_PULLX(6) | \
149
                                 PIN_MODE_INPUT_PULLX(7))
150
#define VAL_GPIODCRH            0x88888888
151
#define VAL_GPIODODR            0xFFFB /* initially SYS_INT_N indicates that the OS is busy */
152

  
153
/*
154
 * Port E setup.
155
 */
156
#define VAL_GPIOECRL            0x88888888 /*  PE7...PE0 */
157
#define VAL_GPIOECRH            0x88888888 /* PE15...PE8 */
158
#define VAL_GPIOEODR            0xFFFF
159

  
160
/*
161
 * Port F setup.
162
 */
163
#define VAL_GPIOFCRL            0x88888888 /*  PF7...PF0 */
164
#define VAL_GPIOFCRH            0x88888888 /* PF15...PF8 */
165
#define VAL_GPIOFODR            0xFFFF
166

  
167
/*
168
 * Port G setup.
169
 */
170
#define VAL_GPIOGCRL            0x88888888 /*  PG7...PG0 */
171
#define VAL_GPIOGCRH            0x88888888 /* PG15...PG8 */
172
#define VAL_GPIOGODR            0xFFFF
173

  
174
#if !defined(_FROM_ASM_)
175
#ifdef __cplusplus
176
extern "C" {
177
#endif
178
  void boardInit(void);
179
  void boardRequestShutdown(void);
180
  void boardStandby(void);
181
  void boardClearI2CBus(const uint8_t scl_pad, const uint8_t sda_pad);
182
#ifdef __cplusplus
183
}
184
#endif
185
#endif /* _FROM_ASM_ */
186

  
187
#endif /* _BOARD_H_ */
boards/LightRing/board.mk
1
# List of all the board related files.
2
BOARDSRC = ${AMIRO}/boards/LightRing/board.c
3

  
4
# Required include directories
5
BOARDINC = ${AMIRO}/boards/LightRing
6

  
7
# Required linker directory
8
BOARDLD = ${AMIRO}/ports
9

  
boards/PowerManagement/board.c
1
#include "ch.h"
2
#include "hal.h"
3
#include "board.h"
4

  
5
/**
6
 * @brief   PAL setup.
7
 * @details Digital I/O ports static configuration as defined in @p board.h.
8
 *          This variable is used by the HAL when initializing the PAL driver.
9
 */
10
#if HAL_USE_PAL || defined(__DOXYGEN__)
11
const PALConfig pal_default_config =
12
{
13
  {VAL_GPIOA_MODER, VAL_GPIOA_OTYPER, VAL_GPIOA_OSPEEDR, VAL_GPIOA_PUPDR, VAL_GPIOA_ODR, VAL_GPIOA_AFRL, VAL_GPIOA_AFRH},
14
  {VAL_GPIOB_MODER, VAL_GPIOB_OTYPER, VAL_GPIOB_OSPEEDR, VAL_GPIOB_PUPDR, VAL_GPIOB_ODR, VAL_GPIOB_AFRL, VAL_GPIOB_AFRH},
15
  {VAL_GPIOC_MODER, VAL_GPIOC_OTYPER, VAL_GPIOC_OSPEEDR, VAL_GPIOC_PUPDR, VAL_GPIOC_ODR, VAL_GPIOC_AFRL, VAL_GPIOC_AFRH},
16
  {VAL_GPIOD_MODER, VAL_GPIOD_OTYPER, VAL_GPIOD_OSPEEDR, VAL_GPIOD_PUPDR, VAL_GPIOD_ODR, VAL_GPIOD_AFRL, VAL_GPIOD_AFRH},
17
  {VAL_GPIOE_MODER, VAL_GPIOE_OTYPER, VAL_GPIOE_OSPEEDR, VAL_GPIOE_PUPDR, VAL_GPIOE_ODR, VAL_GPIOE_AFRL, VAL_GPIOE_AFRH},
18
  {VAL_GPIOF_MODER, VAL_GPIOF_OTYPER, VAL_GPIOF_OSPEEDR, VAL_GPIOF_PUPDR, VAL_GPIOF_ODR, VAL_GPIOF_AFRL, VAL_GPIOF_AFRH},
19
  {VAL_GPIOG_MODER, VAL_GPIOG_OTYPER, VAL_GPIOG_OSPEEDR, VAL_GPIOG_PUPDR, VAL_GPIOG_ODR, VAL_GPIOG_AFRL, VAL_GPIOG_AFRH},
20
  {VAL_GPIOH_MODER, VAL_GPIOH_OTYPER, VAL_GPIOH_OSPEEDR, VAL_GPIOH_PUPDR, VAL_GPIOH_ODR, VAL_GPIOH_AFRL, VAL_GPIOH_AFRH},
21
  {VAL_GPIOI_MODER, VAL_GPIOI_OTYPER, VAL_GPIOI_OSPEEDR, VAL_GPIOI_PUPDR, VAL_GPIOI_ODR, VAL_GPIOI_AFRL, VAL_GPIOI_AFRH}
22
};
23
#endif
24

  
25
/*
26
 * Early initialization code.
27
 * This initialization must be performed just after stack setup and before
28
 * any other initialization.
29
 */
30
void __early_init(void) {
31

  
32
  stm32_clock_init();
33
}
34

  
35
/*
36
 * Board-specific initialization code.
37
 */
38
void boardInit(void) {
39

  
40
}
41

  
42
inline void boardWriteIoPower(int value)
43
{
44
    palWritePad(GPIOA, GPIOA_SYS_REG_EN, value);
45
    if (value) {
46
        // drive pins
47
        palSetPadMode(GPIOA, GPIOA_CAN_TX, PAL_MODE_ALTERNATE(9));
48
        palSetPadMode(GPIOA, GPIOA_SYS_UART_TX, PAL_MODE_ALTERNATE(7));
49
        palSetPadMode(GPIOB, GPIOB_BT_CTS, PAL_MODE_ALTERNATE(7));
50
    } else {
51
        // float pins
52
        palSetPadMode(GPIOA, GPIOA_CAN_TX, PAL_MODE_INPUT);
53
        palSetPadMode(GPIOA, GPIOA_SYS_UART_TX, PAL_MODE_INPUT);
54
        palSetPadMode(GPIOB, GPIOB_BT_CTS, PAL_MODE_INPUT);
55
    }
56
    chThdSleepMilliseconds(50);
57
}
58

  
59
inline void boardWriteLed(int value)
60
{
61
    palWritePad(GPIOB, GPIOB_LED, !value);
62
}
63

  
64
inline void boardWriteSystemPower(int value)
65
{
66
    palWritePad(GPIOB, GPIOB_POWER_EN, value);
67
    chThdSleepMilliseconds(50);
68
}
69

  
70
inline void boardWriteWarmRestart(const uint8_t value)
71
{
72
    palWritePad(GPIOC, GPIOC_SYS_WARMRST_N, ~value);
73
    chThdSleepMilliseconds(50);
74
}
75

  
76
inline void boardChargerSetState(uint8_t chrg_mask, uint8_t state)
77
{
78
  if (chrg_mask & (1u << 0))
79
    palWritePad(GPIOC, GPIOC_CHARGE_EN1_N, ~state);
80
  if (chrg_mask & (1u << 1))
81
    palWritePad(GPIOD, GPIOD_CHARGE_EN2_N, ~state);
82
}
83

  
84
inline void boardBluetoothSetState(uint8_t state)
85
{
86
    palWritePad(GPIOC, GPIOC_BT_RST, ~state);
87
}
88

  
89
inline void boardRequestShutdown(void)
90
{
91
  palClearPad(GPIOC, GPIOC_SYS_PD_N);
92
}
93

  
94
#define RTC_ISR_TAMP2F ((uint32_t)0x00004000)
95

  
96
inline void boardStandby(void)
97
{
98

  
99
  chSysLock();
100
  // set deepsleep bit
101
  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
102
  // enable wakeup pin
103
  PWR->CSR |= PWR_CSR_EWUP;
104
  // set PDDS, clear WUF, clear SBF
105
  PWR->CR |= (PWR_CR_CWUF | PWR_CR_PDDS | PWR_CR_CSBF);
106
  // clear RTC wakeup source flags
107
  RTC->ISR &= ~(RTC_ISR_ALRBF | RTC_ISR_ALRAF | RTC_ISR_WUTF | RTC_ISR_TAMP1F | RTC_ISR_TAMP2F |
108
                RTC_ISR_TSOVF | RTC_ISR_TSF);
109
  // Wait for Interrupt
110
  __WFI();
111

  
112
}
113

  
114
inline void boardStop(const uint8_t lpds, const uint8_t fpds)
115
{
116

  
117
  chSysLock();
118
  // set deepsleep bit
119
  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
120
  // enable wakeup pin
121
  //PWR->CSR |= PWR_CSR_EWUP;
122
  // clear PDDS, clear LPDS, clear FPDS
123
  PWR->CR &= ~(PWR_CR_PDDS | PWR_CR_LPDS | PWR_CR_FPDS);
124
  // clear WUF, clear SBF
125
  PWR->CR |= (PWR_CR_CWUF | PWR_CR_CSBF);
126
  if (lpds)
127
    PWR->CR |= (PWR_CR_LPDS);
128
  if (fpds)
129
    PWR->CR |= (PWR_CR_FPDS);
130
  // clear RTC wakeup source flags
131
  RTC->ISR &= ~(RTC_ISR_ALRBF | RTC_ISR_ALRAF | RTC_ISR_WUTF | RTC_ISR_TAMP1F | RTC_ISR_TAMP2F |
132
                RTC_ISR_TSOVF | RTC_ISR_TSF);
133
  // clear pending interrupts
134
  EXTI->PR = ~0;
135
  // Wait for Interrupt
136
  __WFI();
137

  
138
}
139

  
140
#undef RTC_ISR_TAMP2F
141

  
142
inline void boardWakeup(void) {
143

  
144
  palClearPad(GPIOC, GPIOC_SYS_PD_N);
145
  chThdSleepMicroseconds(10);
146
  palSetPad(GPIOC, GPIOC_SYS_PD_N);
147
}
148

  
149
inline void boardClearI2CBus(const uint8_t scl_pad, const uint8_t sda_pad) {
150

  
151
  uint8_t i;
152

  
153
  // configure I²C SCL and SDA open drain
154
  palSetPadMode(GPIOB, scl_pad, PAL_MODE_OUTPUT_OPENDRAIN);
155
  palSetPadMode(GPIOB, sda_pad, PAL_MODE_OUTPUT_OPENDRAIN);
156

  
157
  // perform a 2-wire software reset for the eeprom (see AT24C01BN-SH-B datasheet, chapter 3)
158
  // note: clock is ~50kHz (20us per cycle)
159
  palSetPad(GPIOB, sda_pad);
160
  palClearPad(GPIOB, scl_pad);
161
  chThdSleepMicroseconds(10);
162
  palSetPad(GPIOB, scl_pad);
163
  chThdSleepMicroseconds(5);
164
  palClearPad(GPIOB, sda_pad);
165
  chThdSleepMicroseconds(5);
166
  palClearPad(GPIOB, scl_pad);
167
  chThdSleepMicroseconds(5);
168
  palSetPad(GPIOB, sda_pad);
169
  chThdSleepMicroseconds(5);
170
  for (i = 0; i < 9; ++i) {
171
    palSetPad(GPIOB, scl_pad);
172
    chThdSleepMicroseconds(10);
173
    palClearPad(GPIOB, scl_pad);
174
    chThdSleepMicroseconds(10);
175
  }
176
  palSetPad(GPIOB, scl_pad);
177
  chThdSleepMicroseconds(5);
178
  palClearPad(GPIOB, sda_pad);
179
  chThdSleepMicroseconds(5);
180
  palClearPad(GPIOB, scl_pad);
181
  chThdSleepMicroseconds(10);
182
  palSetPad(GPIOB, scl_pad);
183
  chThdSleepMicroseconds(5);
184
  palSetPad(GPIOB, sda_pad);
185
  chThdSleepMicroseconds(5);
186
  palClearPad(GPIOB, scl_pad);
187
  chThdSleepMicroseconds(10);
188

  
189
  // perform bus clear as per I²C Specification v6 3.1.16
190
  // note: clock is 100kHz (10us per cycle)
191
  for (i = 0; i < 10; i++) {
192
    palClearPad(GPIOB, scl_pad);
193
    chThdSleepMicroseconds(5);
194
    palSetPad(GPIOB, scl_pad);
195
    chThdSleepMicroseconds(5);
196
  }
197

  
198
  // reconfigure I²C SCL
199
  palSetPadMode(GPIOB, scl_pad, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN);
200
  palSetPadMode(GPIOB, sda_pad, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN);
201

  
202
  return;
203
}
204

  
205
inline void boardResetBQ27500I2C(const uint8_t scl_pad, const uint8_t sda_pad) {
206

  
207
  // configure I²C SCL and SDA open drain
208
  palSetPadMode(GPIOB, scl_pad, PAL_MODE_OUTPUT_OPENDRAIN);
209
  palSetPadMode(GPIOB, sda_pad, PAL_MODE_OUTPUT_OPENDRAIN);
210

  
211
  // BQ27500: reset by holding bus low for t_BUSERR (17.3 - 21.2 seconds)
212
  palClearPad(GPIOB, scl_pad);
213
  palClearPad(GPIOB, sda_pad);
214
  chThdSleepSeconds(20);
215

  
216
  boardClearI2CBus(scl_pad, sda_pad);
217

  
218
  return;
219
}
boards/PowerManagement/board.h
1
#ifndef _BOARD_H_
2
#define _BOARD_H_
3

  
4
/*
5
 * Setup for AMiRo PowerManagement board.
6
 */
7

  
8
/*
9
 * Board identifier.
10
 */
11
#define BOARD_POWER_MANAGEMENT
12
#define BOARD_NAME              "AMiRo PowerManagement"
13
#define BOARD_VERSION           "1.1"
14

  
15
/*
16
 * Board frequencies.
17
 */
18
#define STM32_LSECLK            0
19
#define STM32_HSECLK            8000000
20

  
21
/*
22
 * Board voltages.
23
 * Required for performance limits calculation.
24
 */
25
#define STM32_VDD               330
26

  
27
/*
28
 * MCU type as defined in the ST header file stm32f4xx.h.
29
 */
30
#define STM32F40_41xxx
31

  
32
/*
33
 * IO pins assignments.
34
 */
35
#define GPIOA_WKUP              0
36
#define GPIOA_SYS_UART_TX       2
37
#define GPIOA_SYS_UART_RX       3
38
#define GPIOA_SYS_SPI_SS0_N     4
39
#define GPIOA_SYS_SPI_SCLK      5
40
#define GPIOA_SYS_SPI_MISO      6
41
#define GPIOA_SYS_SPI_MOSI      7
42
#define GPIOA_SYS_REG_EN        8
43
#define GPIOA_PROG_RX           9
44
#define GPIOA_PROG_TX           10
45
#define GPIOA_CAN_RX            11
46
#define GPIOA_CAN_TX            12
47
#define GPIOA_SYS_SPI_SS1_N     15
48

  
49
#define GPIOB_IR_INT1_N         0
50
#define GPIOB_VSYS_SENSE        1
51
#define GPIOB_POWER_EN          2
52
#define GPIOB_SYS_UART_DN       3
53
#define GPIOB_CHARGE_STAT2A     4
54
#define GPIOB_BUZZER            5
55
#define GPIOB_GAUGE_BATLOW2     6
56
#define GPIOB_GAUGE_BATGD2_N    7
57
#define GPIOB_GAUGE_SCL2        8
58
#define GPIOB_GAUGE_SDA2        9
59
#define GPIOB_GAUGE_SCL1        10
60
#define GPIOB_GAUGE_SDA1        11
61
#define GPIOB_LED               12
62
#define GPIOB_BT_RTS            13
63
#define GPIOB_BT_CTS            14
64
#define GPIOB_SYS_UART_UP       15
65

  
66
#define GPIOC_CHARGE_STAT1A     0
67
#define GPIOC_GAUGE_BATLOW1     1
68
#define GPIOC_GAUGE_BATGD1_N    2
69
#define GPIOC_CHARGE_EN1_N      3
70
#define GPIOC_IR_INT2_N         4
71
#define GPIOC_TOUCH_INT_N       5
72
#define GPIOC_SYS_DONE          6
73
#define GPIOC_SYS_PROG_N        7
74
#define GPIOC_PATH_DC           8
75
#define GPIOC_SYS_SPI_DIR       9
76
#define GPIOC_BT_RX             10
77
#define GPIOC_BT_TX             11
78
#define GPIOC_SYS_INT_N         12
79
#define GPIOC_SYS_PD_N          13
80
#define GPIOC_SYS_WARMRST_N     14
81
#define GPIOC_BT_RST            15
82

  
83
#define GPIOD_CHARGE_EN2_N      2
84

  
85
#define GPIOH_OSC_IN            0
86
#define GPIOH_OSC_OUT           1
87

  
88
/*
89
 * I/O ports initial setup, this configuration is established soon after reset
90
 * in the initialization code.
91
 */
92
#define PIN_MODE_INPUT(n)       (0U << ((n) * 2))
93
#define PIN_MODE_OUTPUT(n)      (1U << ((n) * 2))
94
#define PIN_MODE_ALTERNATE(n)   (2U << ((n) * 2))
95
#define PIN_MODE_ANALOG(n)      (3U << ((n) * 2))
96
#define PIN_OTYPE_PUSHPULL(n)   (0U << (n))
97
#define PIN_OTYPE_OPENDRAIN(n)  (1U << (n))
98
#define PIN_OSPEED_2M(n)        (0U << ((n) * 2))
99
#define PIN_OSPEED_25M(n)       (1U << ((n) * 2))
100
#define PIN_OSPEED_50M(n)       (2U << ((n) * 2))
101
#define PIN_OSPEED_100M(n)      (3U << ((n) * 2))
102
#define PIN_PUDR_FLOATING(n)    (0U << ((n) * 2))
103
#define PIN_PUDR_PULLUP(n)      (1U << ((n) * 2))
104
#define PIN_PUDR_PULLDOWN(n)    (2U << ((n) * 2))
105
#define PIN_AFIO_AF(n, v)       ((v##U) << ((n % 8) * 4))
106

  
107
/*
108
 * Port A setup.
109
 */
110
#define VAL_GPIOA_MODER         (PIN_MODE_INPUT(GPIOA_WKUP) | \
111
                                 PIN_MODE_INPUT(1) | \
112
                                 PIN_MODE_ALTERNATE(GPIOA_SYS_UART_TX) | \
113
                                 PIN_MODE_ALTERNATE(GPIOA_SYS_UART_RX) | \
114
                                 PIN_MODE_INPUT(GPIOA_SYS_SPI_SS0_N) | \
115
                                 PIN_MODE_ALTERNATE(GPIOA_SYS_SPI_SCLK) | \
116
                                 PIN_MODE_ALTERNATE(GPIOA_SYS_SPI_MOSI) | \
117
                                 PIN_MODE_ALTERNATE(GPIOA_SYS_SPI_MISO) | \
118
                                 PIN_MODE_INPUT(GPIOA_SYS_SPI_SS1_N) | \
119
                                 PIN_MODE_ALTERNATE(GPIOA_PROG_RX) | \
120
                                 PIN_MODE_ALTERNATE(GPIOA_PROG_TX) | \
121
                                 PIN_MODE_ALTERNATE(GPIOA_CAN_RX) | \
122
                                 PIN_MODE_ALTERNATE(GPIOA_CAN_TX) | \
123
                                 PIN_MODE_INPUT(13) | \
124
                                 PIN_MODE_INPUT(14) | \
125
                                 PIN_MODE_OUTPUT(GPIOA_SYS_REG_EN))
126
#define VAL_GPIOA_OTYPER        (PIN_OTYPE_PUSHPULL(GPIOA_SYS_UART_TX) | \
127
                                 PIN_OTYPE_PUSHPULL(GPIOA_SYS_SPI_SS0_N) | \
128
                                 PIN_OTYPE_PUSHPULL(GPIOA_PROG_RX) | \
129
                                 PIN_OTYPE_PUSHPULL(GPIOA_CAN_TX) | \
130
                                 PIN_OTYPE_PUSHPULL(GPIOA_SYS_REG_EN))
131
#define VAL_GPIOA_OSPEEDR       0xFFFFFFFF
132
#define VAL_GPIOA_PUPDR         (PIN_PUDR_FLOATING(GPIOA_WKUP) | \
133
                                 PIN_PUDR_PULLUP(1) | \
134
                                 PIN_PUDR_FLOATING(GPIOA_SYS_UART_TX) | \
135
                                 PIN_PUDR_FLOATING(GPIOA_SYS_UART_RX) | \
136
                                 PIN_PUDR_FLOATING(GPIOA_SYS_SPI_SS0_N) | \
137
                                 PIN_PUDR_FLOATING(GPIOA_SYS_SPI_SCLK) | \
138
                                 PIN_PUDR_FLOATING(GPIOA_SYS_SPI_MOSI) | \
139
                                 PIN_PUDR_FLOATING(GPIOA_SYS_SPI_MISO) | \
140
                                 PIN_PUDR_FLOATING(GPIOA_SYS_SPI_SS1_N) | \
141
                                 PIN_PUDR_FLOATING(GPIOA_PROG_RX) | \
142
                                 PIN_PUDR_PULLUP(GPIOA_PROG_TX) | \
143
                                 PIN_PUDR_FLOATING(GPIOA_CAN_RX) | \
144
                                 PIN_PUDR_FLOATING(GPIOA_CAN_TX) | \
145
                                 PIN_PUDR_PULLUP(13) | \
146
                                 PIN_PUDR_PULLUP(14) | \
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff