Revision 58fe0e0b

View differences:

.gitignore
1
doc
2
build
3
.dep
4
*.tmp
5
*.backup
6

  
7
# Eclipse files
8
*eclipse*
9

  
10
# QtCreator files
11
*.includes
12
*.files
13
*.config
14
*.creator
15
*.creator.user
16

  
17
# Shadow files
18
*kate-swp
19
*~
20

  
21
# Backup files
22
*backup*
23
*Backup*
README.txt
1
AMiRo-OS is the operating system for the base version of the
2
Autonomous Mini Robot (AMiRo) [1,2]. It utilizes ChibiOS (a real-time
3
operating system for embedded devices developed by Giovanni di Sirio;
4
see <http://chibios.org>) as system kernel and extends it with
5
platform specific functionalities.
6

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

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

  
15
This program is distributed in the hope that it will be useful, but
16
WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
General Public License for more details.
19

  
20
You should have received a copy of the GNU General Public License
21
along with this program.  If not, see <http://www.gnu.org/licenses/>.
22

  
23
The development of this software was supported by the Excellence
24
Cluster EXC 227 Cognitive Interaction Technology. The Excellence
25
Cluster EXC 227 is a grant of the Deutsche Forschungsgemeinschaft
26
(DFG) in the context of the German Excellence Initiative.
27

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

  
38
References:
39
 [1] Herbrechtsmeier S., Rückert U., & Sitte J. (2012). "AMiRo -
40
     Autonomous Mini Robot for Research and Education". In Advances in
41
     Autonomous Mini Robots (pp. 101-112). Springer Berlin
42
     Heidelberg.
43
 [2] Schöpping T., Korthals T., Herbrechtsmeier S., & Rückert U.
44
     (2015). "AMiRo: A Mini Robot for Scientific Applications" In
45
     Advances in Computational Intelligence (pp. 199-205). Springer
46
     International Publishing.
47

  
48

  
49

  
50
#####################################################################
51
#                                                                   #
52
#     RRRRRRRR  EEEEEEEE    AAA    DDDDDDDD  MM     MM EEEEEEEE     #
53
#     RR     RR EE         AA AA   DD     DD MMM   MMM EE           #
54
#     RR     RR EE        AA   AA  DD     DD MMMM MMMM EE           #
55
#     RRRRRRRR  EEEEEE   AA     AA DD     DD MM MMM MM EEEEEE       #
56
#     RR   RR   EE       AAAAAAAAA DD     DD MM     MM EE           #
57
#     RR    RR  EE       AA     AA DD     DD MM     MM EE           #
58
#     RR     RR EEEEEEEE AA     AA DDDDDDDD  MM     MM EEEEEEEE     #
59
#                                                                   #
60
#####################################################################
61

  
62
This file will help you to setup all required software on your system,
63
compile the source code, and flash it to the AMiRo modules.
64

  
65
=====================================================================
66

  
67
CONTENTS:
68
 1  Required software
69
   1.1  gcc-arm-none-eabi
70
   1.2  ChibiOS
71
   1.3  AMiRo-BLT
72
 2  Recommended software
73
   2.1  gtkterm and hterm
74
   2.2  QtCreator
75
 3  Building and flashing
76

  
77
=====================================================================
78

  
79
1 - REQUIRED SOFTWARE
80
---------------------
81

  
82
In order to compile the source code, you need to install the GCC for
83
ARM embedded devices. Since AMiRo-OS requires ChibiOS as system
84
kernel, you need a copy of that project as well. Furthermore, AMiRo-OS
85
requires a compatible bootloader, such as provided by the AMiRo-BLT
86
project.
87

  
88
1.1 gcc-arm-none-eabi
89

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

  
96
1.2 ChibiOS
97

  
98
Since AMiRo-OS uses ChibiOS as underlying system kernel, you need to
99
acquire a copy of it as well. First, go to the directory which
100
contains the AMiRo-OS folder (but do not go into the AMiRo-OS
101
directory itself!). Now clone the GIT repository of ChibiOS and
102
checkout version 2.6.x:
103
  >$ git clone https://github.com/ChibiOS/ChibiOS.git ChibiOS
104
  >$ cd ChibiOS
105
  >$ git checkout 2e6dfc7364e7551483922ea6afbaea8f3501ab0e
106
It is highly recommended to use exactly this commit. Although newer
107
commits in the 2.6.x branch might work fine, AMiRo-OS is not
108
compatible with ChibiOS version 3 or newer.
109

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

  
119
1.3 AMiRo-BLT
120

  
121
AMiRo-BLT is an additional software project, which is developed in
122
parallel with AMiRo-OS. If you did not receive a copy of AMiRo-BLT
123
with AMiRo-OS, you can find all code and documentation at
124
<https://opensource.cit-ec.de/projects/amiro-os>. Instructions for
125
installation and how to use the software provided by AMiRo-BLT can be
126
found on the web page or in the project's readme file.
127

  
128
2 - RECOMMENDED SOFTWARE
129
------------------------
130

  
131
In order to fully use all features of AMiRo-OS it is recommended to
132
install the 'hterm' or 'gtkterm' application for accessing the robot.
133
To ease further development, this project offers support for the 
134
QtCreator IDE.
135

  
136
2.1 - gtkterm and hterm
137

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

  
145
  port	= /dev/ttyUSB0
146
  speed	= 115200
147
  bits	= 8
148
  stopbits	= 1
149
  parity	= none
150
  flow	= none
151
  wait_delay	= 0
152
  wait_char	= -1
153
  rs485_rts_time_before_tx	= 30
154
  rs485_rts_time_after_tx	= 30
155
  echo	= False
156
  crlfauto	= True
157

  
158
For hterm you must need to configure the tool analogously.
159

  
160
2.2 - QtCreator
161

  
162
In order to setup QtCreator projects for the three AMiRo base modules,
163
a script is provided in the directory ./ide/qtcreator/. It is
164
accompanied by an additional README.txt file, which contains further
165
information.
166

  
167
3 - BUILDING AND FLASHING
168
-------------------------
169

  
170
Each time you modify any part of AMiRo-OS, you need to recompile the
171
whole project for the according AMiRo module. Therefore you have to
172
use the makefiles provided in ./devices/<DeviceToRecompile>/ by simply
173
executing 'make' in the according directory. If you want to compile
174
all modules at once, you can also use the makefile in the ./devices/
175
folder.
176

  
177
After compilation, you always have to flash the generated program to
178
the robot. Therefore you need to install the SerialBoot tool provided
179
by the AMiRo-BLT project. Furthermore the tool must be accessible
180
globally under the environment variable 'SERIALBOOT'. You can do this
181
by appending the following line to your ~/.bashrc file:
182

  
183
  export SERIALBOOT=</absolute/path/to/the/SerialBoot/binary>
184

  
185
You can test the tool by calling it via the variable:
186
  >$ ${SERIALBOOT}
187
This should print some information about the tool.
188
Similar to the compilation procedure as described above, you can flash
189
either each module separately, or all modules at once by executing
190
'make flash' from the according directory.
191
Note that you must connect the programming cable either to the
192
DiWheelDrive or the PowerManagement module for flashing the operating
193
system. All other modules are powered off after reset so that only
194
these two offer a bootloader that is required for flashing.
195

  
196
=====================================================================
197

  
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) {
100

  
101
  uint8_t i;
102

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

  
106
  // perform bus clear as per I²C Specification v5 3.1.16
107
  for (i = 0x00u; i < 0x09u; i++) {
108
    palClearPad(GPIOB, scl_pad);
109
    chThdSleepMicroseconds(5);
110
    palSetPad(GPIOB, scl_pad);
111
    chThdSleepMicroseconds(5);
112
  }
113

  
114
  // reconfigure I²C SCL
115
  palSetPadMode(GPIOB, scl_pad, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
116

  
117
}
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);
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) {
68

  
69
  uint8_t i;
70

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

  
74
  // perform bus clear as per I²C Specification v5 3.1.16
75
  for (i = 0x00u; i < 0x09u; i++) {
76
    palClearPad(GPIOB, scl_pad);
77
    chThdSleepMicroseconds(5);
78
    palSetPad(GPIOB, scl_pad);
79
    chThdSleepMicroseconds(5);
80
  }
81

  
82
  // reconfigure I²C SCL
83
  palSetPadMode(GPIOB, scl_pad, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
84

  
85
}
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);
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) {
150

  
151
  uint8_t i;
152

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

  
156
  // perform bus clear as per I²C Specification v5 3.1.16
157
  for (i = 0x00u; i < 0x09u; i++) {
158
    palClearPad(GPIOB, scl_pad);
159
    chThdSleepMicroseconds(5);
160
    palSetPad(GPIOB, scl_pad);
161
    chThdSleepMicroseconds(5);
162
  }
163

  
164
  // reconfigure I²C SCL
165
  palSetPadMode(GPIOB, scl_pad, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN);
166

  
167
}
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) | \
147
                                 PIN_PUDR_FLOATING(GPIOA_SYS_REG_EN))
148

  
149
#define VAL_GPIOA_ODR           0xFFFF
150
#define VAL_GPIOA_AFRL          (PIN_AFIO_AF(GPIOA_SYS_UART_TX, 7) | \
151
                                 PIN_AFIO_AF(GPIOA_SYS_UART_RX, 7) | \
152
                                 PIN_AFIO_AF(GPIOA_SYS_SPI_SCLK, 5) | \
153
                                 PIN_AFIO_AF(GPIOA_SYS_SPI_MISO, 5) | \
154
                                 PIN_AFIO_AF(GPIOA_SYS_SPI_MOSI, 5))
155
#define VAL_GPIOA_AFRH          (PIN_AFIO_AF(GPIOA_PROG_RX, 7) | \
156
                                 PIN_AFIO_AF(GPIOA_PROG_TX, 7) | \
157
                                 PIN_AFIO_AF(GPIOA_CAN_RX, 9) | \
158
                                 PIN_AFIO_AF(GPIOA_CAN_TX, 9))
159

  
160
/*
161
 * Port B setup.
162
 */
163
#define VAL_GPIOB_MODER         (PIN_MODE_INPUT(GPIOB_IR_INT1_N) | \
164
                                 PIN_MODE_ANALOG(GPIOB_VSYS_SENSE) | \
165
                                 PIN_MODE_OUTPUT(GPIOB_POWER_EN) | \
166
                                 PIN_MODE_OUTPUT(GPIOB_SYS_UART_DN) | \
167
                                 PIN_MODE_INPUT(GPIOB_CHARGE_STAT2A) | \
168
                                 PIN_MODE_ALTERNATE(GPIOB_BUZZER) | \
169
                                 PIN_MODE_INPUT(GPIOB_GAUGE_BATLOW2) | \
170
                                 PIN_MODE_INPUT(GPIOB_GAUGE_BATGD2_N) | \
171
                                 PIN_MODE_ALTERNATE(GPIOB_GAUGE_SCL2) | \
172
                                 PIN_MODE_ALTERNATE(GPIOB_GAUGE_SDA2) | \
173
                                 PIN_MODE_ALTERNATE(GPIOB_GAUGE_SCL1) | \
174
                                 PIN_MODE_ALTERNATE(GPIOB_GAUGE_SDA1) | \
175
                                 PIN_MODE_OUTPUT(GPIOB_LED) | \
176
                                 PIN_MODE_ALTERNATE(GPIOB_BT_RTS) | \
177
                                 PIN_MODE_ALTERNATE(GPIOB_BT_CTS) | \
178
                                 PIN_MODE_OUTPUT(GPIOB_SYS_UART_UP))
179
#define VAL_GPIOB_OTYPER        (PIN_OTYPE_PUSHPULL(GPIOB_POWER_EN) | \
180
                                 PIN_OTYPE_OPENDRAIN(GPIOB_SYS_UART_DN) | \
181
                                 PIN_OTYPE_PUSHPULL(GPIOB_BUZZER) | \
182
                                 PIN_OTYPE_OPENDRAIN(GPIOB_GAUGE_SCL2) | \
183
                                 PIN_OTYPE_OPENDRAIN(GPIOB_GAUGE_SDA2) | \
184
                                 PIN_OTYPE_OPENDRAIN(GPIOB_GAUGE_SCL1) | \
185
                                 PIN_OTYPE_OPENDRAIN(GPIOB_GAUGE_SDA1) | \
186
                                 PIN_OTYPE_OPENDRAIN(GPIOB_LED) | \
187
                                 PIN_OTYPE_PUSHPULL(GPIOB_BT_CTS) | \
188
                                 PIN_OTYPE_OPENDRAIN(GPIOB_SYS_UART_UP))
189
#define VAL_GPIOB_OSPEEDR       0xFFFFFFFF
190
#define VAL_GPIOB_PUPDR         0x00000000
191
#define VAL_GPIOB_ODR           0xFFFF
192
#define VAL_GPIOB_AFRL          (PIN_AFIO_AF(GPIOB_BUZZER, 2))
193
#define VAL_GPIOB_AFRH          (PIN_AFIO_AF(GPIOB_GAUGE_SCL2, 4) | \
194
                                 PIN_AFIO_AF(GPIOB_GAUGE_SDA2, 4) | \
195
                                 PIN_AFIO_AF(GPIOB_GAUGE_SCL1, 4) | \
196
                                 PIN_AFIO_AF(GPIOB_GAUGE_SDA1, 4) | \
197
                                 PIN_AFIO_AF(GPIOB_BT_RTS, 7) | \
198
                                 PIN_AFIO_AF(GPIOB_BT_CTS, 7))
199

  
200
/*
201
 * Port C setup.
202
 */
203
#define VAL_GPIOC_MODER         (PIN_MODE_INPUT(GPIOC_CHARGE_STAT1A) | \
204
                                 PIN_MODE_INPUT(GPIOC_GAUGE_BATLOW1) | \
205
                                 PIN_MODE_INPUT(GPIOC_GAUGE_BATGD1_N) | \
206
                                 PIN_MODE_OUTPUT(GPIOC_CHARGE_EN1_N) | \
207
                                 PIN_MODE_INPUT(GPIOC_IR_INT2_N) | \
208
                                 PIN_MODE_INPUT(GPIOC_TOUCH_INT_N) | \
209
                                 PIN_MODE_INPUT(GPIOC_SYS_DONE) | \
210
                                 PIN_MODE_OUTPUT(GPIOC_SYS_PROG_N) | \
211
                                 PIN_MODE_INPUT(GPIOC_PATH_DC) | \
212
                                 PIN_MODE_OUTPUT(GPIOC_SYS_SPI_DIR) | \
213
                                 PIN_MODE_ALTERNATE(GPIOC_BT_RX) | \
214
                                 PIN_MODE_ALTERNATE(GPIOC_BT_TX) | \
215
                                 PIN_MODE_OUTPUT(GPIOC_SYS_INT_N) | \
216
                                 PIN_MODE_OUTPUT(GPIOC_SYS_PD_N) | \
217
                                 PIN_MODE_OUTPUT(GPIOC_SYS_WARMRST_N) | \
218
                                 PIN_MODE_OUTPUT(GPIOC_BT_RST))
219
#define VAL_GPIOC_OTYPER        (PIN_OTYPE_OPENDRAIN(GPIOC_CHARGE_EN1_N) | \
220
                                 PIN_OTYPE_OPENDRAIN(GPIOC_SYS_PROG_N) | \
221
                                 PIN_OTYPE_OPENDRAIN(GPIOC_SYS_SPI_DIR) | \
222
                                 PIN_OTYPE_PUSHPULL(GPIOC_BT_RX) | \
223
                                 PIN_OTYPE_OPENDRAIN(GPIOC_SYS_INT_N) | \
224
                                 PIN_OTYPE_OPENDRAIN(GPIOC_SYS_PD_N) | \
225
                                 PIN_OTYPE_OPENDRAIN(GPIOC_SYS_WARMRST_N) | \
226
                                 PIN_OTYPE_OPENDRAIN(GPIOC_BT_RST))
227
#define VAL_GPIOC_OSPEEDR       0xFFFFFFFF
228
#define VAL_GPIOC_PUPDR         0x00000000
229
#define VAL_GPIOC_ODR           0xEEFF /* emulate open drain for PATH_DC. This is required to prevent accidental shortcuts. Furthermore, pull down SYS_INT_N to indicate the OS is starting */
230
#define VAL_GPIOC_AFRL          0x00000000
231
#define VAL_GPIOC_AFRH          (PIN_AFIO_AF(GPIOC_BT_RX, 7) | \
232
                                 PIN_AFIO_AF(GPIOC_BT_TX, 7))
233

  
234
/*
235
 * Port D setup.
236
 */
237
#define VAL_GPIOD_MODER         (PIN_MODE_INPUT(0) | \
238
                                 PIN_MODE_INPUT(1) | \
239
                                 PIN_MODE_OUTPUT(GPIOD_CHARGE_EN2_N) | \
240
                                 PIN_MODE_INPUT(3) | \
241
                                 PIN_MODE_INPUT(4) | \
242
                                 PIN_MODE_INPUT(5) | \
243
                                 PIN_MODE_INPUT(6) | \
244
                                 PIN_MODE_INPUT(7) | \
245
                                 PIN_MODE_INPUT(8) | \
246
                                 PIN_MODE_INPUT(9) | \
247
                                 PIN_MODE_INPUT(10) | \
248
                                 PIN_MODE_INPUT(11) | \
249
                                 PIN_MODE_INPUT(12) | \
250
                                 PIN_MODE_INPUT(13) | \
251
                                 PIN_MODE_INPUT(14) | \
252
                                 PIN_MODE_INPUT(15))
253
#define VAL_GPIOD_OTYPER        (PIN_OTYPE_OPENDRAIN(GPIOD_CHARGE_EN2_N))
254
#define VAL_GPIOD_OSPEEDR       0xFFFFFFFF
255
#define VAL_GPIOD_PUPDR         (PIN_PUDR_PULLUP(0) | \
256
                                 PIN_PUDR_PULLUP(1) | \
257
                                 PIN_PUDR_FLOATING(GPIOD_CHARGE_EN2_N) | \
258
                                 PIN_PUDR_PULLUP(3) | \
259
                                 PIN_PUDR_PULLUP(4) | \
260
                                 PIN_PUDR_PULLUP(5) | \
261
                                 PIN_PUDR_PULLUP(6) | \
262
                                 PIN_PUDR_PULLUP(7) | \
263
                                 PIN_PUDR_PULLUP(8) | \
264
                                 PIN_PUDR_PULLUP(9) | \
265
                                 PIN_PUDR_PULLUP(10) | \
266
                                 PIN_PUDR_PULLUP(11) | \
267
                                 PIN_PUDR_PULLUP(12) | \
268
                                 PIN_PUDR_PULLUP(13) | \
269
                                 PIN_PUDR_PULLUP(14) | \
270
                                 PIN_PUDR_PULLUP(15))
271
#define VAL_GPIOD_ODR           0x0FFF
272
#define VAL_GPIOD_AFRL          0x00000000
273
#define VAL_GPIOD_AFRH          0x00000000
274

  
275
/*
276
 * Port E setup.
277
 */
278
#define VAL_GPIOE_MODER         0x00000000
279
#define VAL_GPIOE_OTYPER        0x00000000
280
#define VAL_GPIOE_OSPEEDR       0xFFFFFFFF
281
#define VAL_GPIOE_PUPDR         0xFFFFFFFF
282
#define VAL_GPIOE_ODR           0xFFFF
283
#define VAL_GPIOE_AFRL          0x00000000
284
#define VAL_GPIOE_AFRH          0x00000000
285

  
286
/*
287
 * Port F setup.
288
 * All input with pull-up.
289
 */
290
#define VAL_GPIOF_MODER         0x00000000
291
#define VAL_GPIOF_OTYPER        0x00000000
292
#define VAL_GPIOF_OSPEEDR       0xFFFFFFFF
293
#define VAL_GPIOF_PUPDR         0xFFFFFFFF
294
#define VAL_GPIOF_ODR           0xFFFF
295
#define VAL_GPIOF_AFRL          0x00000000
296
#define VAL_GPIOF_AFRH          0x00000000
297

  
298
/*
299
 * Port G setup.
300
 * All input with pull-up.
301
 */
302
#define VAL_GPIOG_MODER         0x00000000
303
#define VAL_GPIOG_OTYPER        0x00000000
304
#define VAL_GPIOG_OSPEEDR       0xFFFFFFFF
305
#define VAL_GPIOG_PUPDR         0xFFFFFFFF
306
#define VAL_GPIOG_ODR           0xFFFF
307
#define VAL_GPIOG_AFRL          0x00000000
308
#define VAL_GPIOG_AFRH          0x00000000
309

  
310
/*
311
 * Port H setup.
312
 */
313
#define VAL_GPIOH_MODER         (PIN_MODE_INPUT(GPIOH_OSC_IN) | \
314
                                 PIN_MODE_INPUT(GPIOH_OSC_OUT) | \
315
                                 PIN_MODE_INPUT(2) | \
316
                                 PIN_MODE_INPUT(3) | \
317
                                 PIN_MODE_INPUT(4) | \
318
                                 PIN_MODE_INPUT(5) | \
319
                                 PIN_MODE_INPUT(6) | \
320
                                 PIN_MODE_INPUT(7) | \
321
                                 PIN_MODE_INPUT(8) | \
322
                                 PIN_MODE_INPUT(9) | \
323
                                 PIN_MODE_INPUT(10) | \
324
                                 PIN_MODE_INPUT(11) | \
325
                                 PIN_MODE_INPUT(12) | \
326
                                 PIN_MODE_INPUT(13) | \
327
                                 PIN_MODE_INPUT(14) | \
328
                                 PIN_MODE_INPUT(15))
329
#define VAL_GPIOH_OTYPER        0x00000000
330
#define VAL_GPIOH_OSPEEDR       0xFFFFFFFF
331
#define VAL_GPIOH_PUPDR         (PIN_PUDR_FLOATING(GPIOH_OSC_IN) | \
332
                                 PIN_PUDR_FLOATING(GPIOH_OSC_OUT) | \
333
                                 PIN_PUDR_PULLUP(2) | \
334
                                 PIN_PUDR_PULLUP(3) | \
335
                                 PIN_PUDR_PULLUP(4) | \
336
                                 PIN_PUDR_PULLUP(5) | \
337
                                 PIN_PUDR_PULLUP(6) | \
338
                                 PIN_PUDR_PULLUP(7) | \
339
                                 PIN_PUDR_PULLUP(8) | \
340
                                 PIN_PUDR_PULLUP(9) | \
341
                                 PIN_PUDR_PULLUP(10) | \
342
                                 PIN_PUDR_PULLUP(11) | \
343
                                 PIN_PUDR_PULLUP(12) | \
344
                                 PIN_PUDR_PULLUP(13) | \
345
                                 PIN_PUDR_PULLUP(14) | \
346
                                 PIN_PUDR_PULLUP(15))
347
#define VAL_GPIOH_ODR           0xFFFF
348
#define VAL_GPIOH_AFRL          0x00000000
349
#define VAL_GPIOH_AFRH          0x00000000
350

  
351
/*
352
 * Port I setup.
353
 * All input with pull-up.
354
 */
355
#define VAL_GPIOI_MODER         0x00000000
356
#define VAL_GPIOI_OTYPER        0x00000000
357
#define VAL_GPIOI_OSPEEDR       0xFFFFFFFF
358
#define VAL_GPIOI_PUPDR         0xFFFFFFFF
359
#define VAL_GPIOI_ODR           0xFFFF
360
#define VAL_GPIOI_AFRL          0x00000000
361
#define VAL_GPIOI_AFRH          0x00000000
362

  
363
#if !defined(_FROM_ASM_)
364
#ifdef __cplusplus
365
extern "C" {
366
#endif
367
  void boardInit(void);
368
  void boardWriteIoPower(int value);
369
  void boardWriteLed(int value);
370
  void boardWriteSystemPower(int value);
371
  void boardWriteWarmRestart(const uint8_t value);
372
  void boardChargerSetState(uint8_t chrg_mask, uint8_t state);
373
  void boardBluetoothSetState(uint8_t state);
374
  void boardRequestShutdown(void);
375
  void boardStandby(void);
376
  void boardStop(const uint8_t lpds, const uint8_t fpds);
377
  void boardWakeup(void);
378
  void boardClearI2CBus(const uint8_t scl_pad);
379
#ifdef __cplusplus
380
}
381
#endif
382
#endif /* _FROM_ASM_ */
383

  
384
#endif /* _BOARD_H_ */
boards/PowerManagement/board.mk
1
# List of all the board related files.
2
BOARDSRC = ${AMIRO}/boards/PowerManagement/board.c \
3
           ${AMIRO}/boards/PowerManagement/wakeup.c
4

  
5
# Required include directories
6
BOARDINC = ${AMIRO}/boards/PowerManagement
7

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

  
boards/PowerManagement/wakeup.c
1
#include <ch.h>
2
#include <hal.h>
3

  
4
#include <board.h>
5
#include "wakeup.h"
6

  
7
enum wakeup_mode   wakeup_mode;
8
enum wakeup_source wakeup_source;
9

  
10
void standby_wakeup_source(void) {
11

  
12
  uint32_t csr = PWR->CSR;
13
  uint32_t gpioc_val = palReadPort(GPIOC);
14

  
15
  // default to POR
16
  wakeup_mode = WAKE_MODE_POR;
17
  wakeup_source = WAKE_SRC_UNKN;
18

  
19
  // make sure reset while powered on looks like POR
20
  PWR->CR |= (PWR_CR_CSBF);
21

  
22
  if ((csr & (PWR_CSR_SBF | PWR_CSR_WUF)) == (PWR_CSR_SBF | PWR_CSR_WUF)) {
23

  
24
    // wakeup or RTC event from standby mode
25
    // default to WKUP
26
    wakeup_mode = WAKE_MODE_STDBY;
27
    wakeup_source = WAKE_SRC_WKUP;
28

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff