GEX thesis source code, full text, references

ch.hardware_realization.tex 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. \chapter{Hardware Realization} \label{sec:hwreal}
  2. \section{GEX on a STM32 Discovery Board}
  3. It has been proposed earlier in the text that STM32 Nucleo and Discovery development boards might serve as the hardware platform for this project. Indeed, a Discovery board with the STM32F072 was used to develop a major part of the GEX firmware, and the firmware remains compatible with it. This inexpensive board may be used to try GEX without any custom hardware.
  4. \subsection{Discovery STM32F072 Configuration and Pin Mapping}
  5. The Discovery board is fitted with four \glspl{LED} on \gls{GPIO} pins PC6 through PC9, in a compass arrangement. The ``north'' \gls{LED}, PC6, is used as the status indicator. The ``User'' button, connected to PA0, is mapped as the Lock button, controlling the settings storage.
  6. We advise the reader, as a potential user of the board, to review its schematic diagram (found in the documentation~\cite{disco-f072}) and ensure the solder-jumpers on the back side are configured correctly:
  7. \begin{itemize}
  8. \item Jumpers SB20 and SB23 must be closed to enable the User \gls{USB} connector.
  9. \item Jumper SB17 must be open and SB19 closed to use the 8\,MHz clock signal provided by the on-board ST-Link programmer; the internal USB-synchronized 48\,MHz oscillator will be used if the clock signal is not provided (SB19 open).
  10. \item Jumpers SB27 through SB32 should be closed to connect the \gls{GPIO} pins normally dedicated to the touch sensing strip to the board's header.
  11. \end{itemize}
  12. Capacitors C26, C27, and C28 are sampling capacitors for the \gls{TSC}. There are, unfortunately, no jumpers available to disconnect them, and they interfere in high-speed signals on the used pins (PA3, PA7, and PB1). The only solution, when those pins are needed for another purpose, is to desolder the capacitors.
  13. An accelerometer \gls{IC} L3GD20 is fitted on the board, attached to SPI2 on pins PB13 (\gls{SCK}), PB14 (\gls{MISO}), and PB15 (\gls{MOSI}), with \gls{NSS} on pin PC0, and pins PC1 and PC2 used for interrupt flags. This chip cannot be disconnected or disabled and it is difficult to remove; care must be taken to avoid its interference on the used pins.
  14. \section{GEX Hub}
  15. GEX Hub was the first custom \gls{PCB} designed for GEX. It uses the same microcontroller as the Discovery board, thus the firmware modifications needed to make it work with this new platform were minimal. The schematic diagram is attached in \hyperref[apx:gex_hub]{Appendix A}.
  16. The Hub board provides access to all the \gls{GPIO} pins\footnote{With the exception of pins used by USB and the Lock button.} through three flat-cable connectors (IDC), one for each port; they also contain a ground and power supply connection to make the attachment of external boards or a breadboard easier, requiring just one cable. The use of flat cables, however, is not mandatory---the flat cable connectors are based on the standard 2.54\,mm-pitch pin headers, allowing the user to use widely available ``jumper wires''.
  17. \begin{figure}[h]
  18. \centering
  19. \begin{subfigure}{.5\textwidth}
  20. \centering
  21. \includegraphics[width=.98\linewidth]{img/photo-hub1.jpg}
  22. \caption{\label{fig:gexhub1}Revision 1}
  23. \end{subfigure}%
  24. \begin{subfigure}{.5\textwidth}
  25. \centering
  26. \includegraphics[width=.98\linewidth]{img/photo-hub2.jpg}
  27. \caption{\label{fig:gexhub2}Revision 2}
  28. \end{subfigure}
  29. \caption[The GEX Hub module]{\label{fig:gexhub} Two revisions of the GEX Hub module, rev. 2 shown with the boot jumper and one flat cable.}
  30. \end{figure}
  31. \subsection{GEX Hub Errata}
  32. The first revision of the Hub board (\cref{fig:gexhub1}) proved functional and helped us validate the power supply design and test the firmware, but contained one layout error that had to be manually fixed---the boot jumper and the programming header footprints, on the left side of the board, had too fine pitch and could not be populated.
  33. An updated revision 2 of the board (\cref{fig:gexhub2}), manufactured together with the GEX Zero \glspl{PCB} (\cref{sec:gzero}), removes the two problematic footprints altogether; a reorganization in the \gls{GPIO} connectors allowed them to be moved together with the other pins.
  34. The Boot jumper was meant to be closed during normal operation, to avoid it getting lost. Since revision 2 moved the boot pin into the top connector, this had to be changed; the jumper logic was inverted by changing its pull-up resistor to a pull-down. The bootloader is now activated by inserting a jumper into the connector, shorting the Boot pin (labeled ``B'') to the adjacent 3.3\,V pin.
  35. A restart is required, in all cases, for the boot jumper changes to take effect. Revision 2 adds a flat reset button on the back side of the board for this purpose, making the firmware update process more straightforward.
  36. \begin{figure}[h]
  37. \centering
  38. \includegraphics[width=.9\textwidth]{img/photo-zero-pi-compare.jpg}
  39. \caption[GEX Zero compared to Raspberry Pi Zero]{\label{fig:zpicompare}Comparison of Raspberry Pi Zero (top) with GEZ Zero (bottom), before soldering the header, buttons, and the wireless module.}
  40. \end{figure}
  41. \begin{figure}[h]
  42. \centering
  43. \includegraphics[width=.85\textwidth]{img/photo-zero-picase.jpg} \\
  44. \vspace{1mm}
  45. \includegraphics[width=.85\textwidth]{img/photo-zero-transparent.jpg}
  46. \caption[The GEX Zero module]{\label{fig:gexzcases}GEX Zero in the official Raspberry Pi Zero case, and an aftermarket acrylic case. The acrylic case is a better choice, as the button and the side connector are easier accessible, and the pin-out diagram on the back side of the board can be read without removing it.}
  47. \end{figure}
  48. \section{GEX Zero}\label{sec:gzero}
  49. Our desire to re-use the form factor of the Raspberry Pi (RPi) Zero to exploit the existing accessory market has been mentioned already in \cref{sec:formfactors}. It was brought to fruition with GEX Zero, the second realized GEX prototype (\cref{fig:gexzcases}). Its design involved several challenges given by constraints imposed by this form factor:
  50. \begin{itemize}
  51. \item It had to be a one-sided board, with no components on the bottom; this is needed for acrylic cases which sit flatly against the \gls{PCB}, with a cut-out for the pin header.
  52. \item Buttons and the USB connector had to exactly align with connectors on the RPi Zero to fit the openings in its cases.
  53. \item The board size was fixed, and rather small; we used only two layers to save production cost, but this proved a significant challenge when routing connections to the pin header.
  54. \item To make use of the Raspberry Pi add-on boards, called HATs or pHATs, a particular organization of the pin header was required. We will discuss this in more detail below.
  55. \end{itemize}
  56. \subsection{Pin Assignment}
  57. Like our STM32 microcontroller, the Broadcom processor on the RPi multiplexes its \gls{GPIO} pins with alternate functions, and, likewise, each function is available only on a small selection of pins. The usual alternate function assignments of the RPi \gls{GPIO} header can be found in~\cite{piheader} and~\cite{piheaderxyz}.
  58. \begin{figure}[h]
  59. \centering
  60. %\includegraphics[width=.85\textwidth]{img/photo-zero-naked.jpg} \\
  61. %\vspace{1mm}
  62. \includegraphics[width=.85\textwidth]{img/photo-zero-naked-bottom.jpg}
  63. \caption[GEX Zero back side]{\label{fig:gexz}Pin assignment diagram on the back side of GEX Zero}
  64. \end{figure}
  65. \iffalse
  66. {
  67. \def\ptcw{.07\textwidth}
  68. \def\rpnl{\newline \footnotesize}
  69. \begin{table}[h]
  70. \begin{tabular}{
  71. W{\ptcw}W{\ptcw}W{\ptcw}W{\ptcw}|W{\ptcw}
  72. W{\ptcw}W{\ptcw}W{\ptcw}|W{\ptcw}W{\ptcw}
  73. }
  74. \toprule
  75. \textbf{\color{blue}39} \rpnl
  76. GND
  77. &
  78. \textbf{37} \rpnl
  79. $\ast$
  80. &
  81. \textbf{35} \rpnl
  82. SPI\newline
  83. \null~MISO
  84. &
  85. \textbf{33} \rpnl
  86. PWM
  87. &
  88. \textbf{31} \rpnl
  89. $\ast$
  90. &
  91. \textbf{29} \rpnl
  92. $\ast$
  93. &
  94. \textbf{27} \rpnl
  95. \IIC\newline
  96. \null~SDA
  97. &
  98. \textbf{\color{blue}25} \rpnl
  99. GND
  100. &
  101. \textbf{23} \rpnl
  102. SPI\newline
  103. \null~SCK
  104. &
  105. \textbf{21} \rpnl
  106. SPI\newline
  107. \null~MISO
  108. \\
  109. \midrule
  110. \textbf{40} \rpnl
  111. SPI\newline
  112. \null~SCK
  113. &
  114. \textbf{38} \rpnl
  115. SPI\newline
  116. \null~MOSI
  117. &
  118. \textbf{36} \rpnl
  119. UART\newline
  120. \null~CTS
  121. &
  122. \textbf{\color{blue}34} \rpnl
  123. GND
  124. &
  125. \textbf{32} \rpnl
  126. PWM
  127. &
  128. \textbf{\color{blue}30} \rpnl
  129. GND
  130. &
  131. \textbf{28} \rpnl
  132. \IIC\newline
  133. \null~SCL
  134. &
  135. \textbf{26} \rpnl
  136. $\ast$
  137. &
  138. \textbf{24} \rpnl
  139. $\ast$
  140. &
  141. \textbf{22} \rpnl
  142. $\ast$
  143. \\
  144. \bottomrule
  145. \end{tabular}
  146. \\[2mm]
  147. \begin{tabular}{
  148. W{\ptcw}W{\ptcw}|W{\ptcw}W{\ptcw}W{\ptcw}
  149. W{\ptcw}|W{\ptcw}W{\ptcw}W{\ptcw}W{\ptcw}
  150. }
  151. \toprule
  152. \textbf{19} \rpnl
  153. SPI\newline
  154. \null~MOSI
  155. &
  156. \textbf{\color{red}17} \rpnl
  157. 3.3\,V
  158. &
  159. \textbf{15} \rpnl
  160. $\ast$
  161. &
  162. \textbf{13} \rpnl
  163. $\ast$
  164. &
  165. \textbf{11} \rpnl
  166. UART\newline
  167. \null~RTS
  168. &
  169. \textbf{\color{blue}9} \rpnl
  170. GND
  171. &
  172. \textbf{7} \rpnl
  173. $\ast$
  174. &
  175. \textbf{5} \rpnl
  176. \IIC\newline
  177. \null~SCL
  178. &
  179. \textbf{3} \rpnl
  180. \IIC\newline
  181. \null~SDA
  182. &
  183. \textbf{\color{red}1} \rpnl
  184. 3.3\,V
  185. \\
  186. \midrule
  187. \textbf{\color{blue}20} \rpnl
  188. GND
  189. &
  190. \textbf{18} \rpnl
  191. $\ast$
  192. &
  193. \textbf{16} \rpnl
  194. $\ast$
  195. &
  196. \textbf{\color{blue}14} \rpnl
  197. GND
  198. &
  199. \textbf{12} \rpnl
  200. PWM
  201. &
  202. \textbf{10} \rpnl
  203. UART\newline
  204. \null~RX
  205. &
  206. \textbf{8} \rpnl
  207. UART\newline
  208. \null~TX
  209. &
  210. \textbf{\color{blue}6} \rpnl
  211. GND
  212. &
  213. \textbf{\color{red}4} \rpnl
  214. 5\,V
  215. &
  216. \textbf{\color{red}2} \rpnl
  217. 5\,V
  218. \\
  219. \bottomrule
  220. \end{tabular}
  221. \caption[Raspberry Pi GPIO header]{\label{tbl:pi_assignmenets}Raspberry Pi GPIO header (split into two lines), top view of the board, oriented with the USB connectors facing away from the user. ``$\ast$''~marks pins without important alternate functions.}
  222. \end{table}
  223. }
  224. \fi
  225. The GEX Zero pin header's alternate functions had to match those on the RPi Zero header, so that the existing add-on boards can be used without modifications. By inspecting the alternate function tables in the STM32F072 datasheet~\cite{f072-ds}, we found a layout that fulfills this requirement almost perfectly. The final assignment is shown in \cref{tbl:gz_rpi_compare}, and the full schematic diagram is attached in \hyperref[apx:gex_zero]{Appendix B}.
  226. \begin{table}
  227. \begin{tabularx}{\textwidth}{W{.1\textwidth}XX|W{.1\textwidth}XX}
  228. \toprule
  229. \textbf{Pin} & \textbf{RPi} & \textbf{GEX Zero} &
  230. \textbf{Pin} & \textbf{RPi} & \textbf{GEX Zero} \\
  231. \midrule
  232. \textbf{1} & \leavevmode\color{red}3.3\,V & -- &
  233. \textbf{2} & \leavevmode\color{red}5\,V & -- \\
  234. \textbf{3} & \IIC SDA & PB7 (SDA1) &
  235. \textbf{4} & \leavevmode\color{red}5\,V & -- \\
  236. \textbf{5} & \IIC SCL & PB6 (SCL1) &
  237. \textbf{6} & \leavevmode\color{blue}GND & -- \\
  238. \textbf{7} & $\ast$ & PA8 (MCO) &
  239. \textbf{8} & UART TX & PB10 (TX3) \\
  240. \midrule
  241. \textbf{9} & \leavevmode\color{blue}GND & --
  242. & \textbf{10} & UART RX & PB11 (RX3) \\
  243. \textbf{11} & UART RTS & PB1 (RTS3)
  244. & \textbf{12} & PWM & PB8 \\
  245. \textbf{13} & $\ast$ & PA10
  246. & \textbf{14} & \leavevmode\color{blue}GND & -- \\
  247. \textbf{15} & $\ast$ & PB9
  248. & \textbf{16} & $\ast$ & PA0 (FCAP)\\
  249. \midrule
  250. \textbf{17} & \leavevmode\color{red}3.3\,V & --
  251. & \textbf{18} & $\ast$ & PA1 \\
  252. \textbf{19} & SPI MOSI & PB5 (MOSI1)
  253. & \textbf{20} & \leavevmode\color{blue}GND & -- \\
  254. \textbf{21} & SPI MISO & PB4 (MISO1)
  255. & \textbf{22} & $\ast$ & PA2 (TX2) \\
  256. \textbf{23} & SPI SCK & PB3 (SCK1)
  257. & \textbf{24} & $\ast$ & PA3 (RX2) \\
  258. \midrule
  259. \textbf{25} & \leavevmode\color{blue}GND & --
  260. & \textbf{26} & $\ast$ & PA4 (DAC$_1$) \\
  261. \textbf{27} & ID \IIC SDA & PB2
  262. & \textbf{28} & ID \IIC SCL & PA5 (DAC$_2$) \\
  263. \textbf{29} & $\ast$ & PC10 (TX4)
  264. & \textbf{30} & \leavevmode\color{blue}GND & -- \\
  265. \textbf{31} & $\ast$ & PC11 (RX4)
  266. & \textbf{32} & PWM & PA7 \\
  267. \midrule
  268. \textbf{33} & PWM & PB0
  269. & \textbf{34} & \leavevmode\color{blue}GND & -- \\
  270. \textbf{35} & SPI MISO & PB14~(MISO2)
  271. & \textbf{36} & $\ast$ & PA6 (CTS3) \\
  272. \textbf{37} & $\ast$ & PB12
  273. & \textbf{38} & SPI MOSI & PB15~(MOSI2)\\
  274. \textbf{39} & \leavevmode\color{blue}GND & --
  275. & \textbf{40} & SPI SCK & PB13 (SCK2)\\
  276. \bottomrule
  277. \end{tabularx}
  278. \caption[Comparison of the RPI Zero and GEX Zero GPIO headers]{\label{tbl:gz_rpi_compare}
  279. Comparison of the RPi Zero and GEX Zero GPIO header pin assignments. Names in parentheses represent STM32F072 alternate functions (e.g., MISO1 is MISO of the first SPI peripheral). ``$\ast$''~marks pins without important alternate functions that could be assigned arbitrarily in the GEX Zero header. All power pins are identical in both headers.
  280. }
  281. \end{table}
  282. \gls{GPIO} ports A and B are fully exposed in the header, with the exception of pins PA11 and PA12 that are routed to the USB connector. The remaining positions were filled pith pins from port C. The omitted ``ID \IIC'' port on pins 27 and 28 is used by the RPi Zero to read configuration from an EEPROM chip on some add-on boards. As this is the only use of the \IIC port, its lack is not a big limitation.
  283. \section{GEX Zero Errata}
  284. The GEX Hub \gls{PCB} had to be updated to correct some layout mistakes.
  285. Unfortunately, neither GEX Zero \gls{PCB} was flawless in the first revision. The errors should not interfere much in the usage of the module; nonetheless, they were fixed in the schematic for any future production of the board.
  286. \begin{itemize}
  287. \item The \IIC pull-up resistor R8 is connected to PA8 instead of PB7. This can be fixed by cutting the trace near the \gls{GPIO} header and rewiring it, or using an external 1.8\,k$\Omega$ pull-up resistor on PB7, when the \IIC connection is required.
  288. \item Pins PB14 and PB15 are swapped in the \gls{GPIO} header, making the SPI port incompatible with add-on boards using this interface. Luckily, there is another SPI port on the header, which is routed correctly, somewhat mitigating this mistake.
  289. \end{itemize}
  290. \section{Wireless Gateway} \label{sec:rfgateway}
  291. The wireless gateway was designed as a ``\gls{USB} dongle'', using the \gls{USB} type A connector (\cref{fig:gwxgw}). It is fitted with an STM32F103 microcontroller, selected for its low cost and availability in small packages (in this case LQFP48)\footnote{ Ironically, the STM32F103 is more powerful than the \gls{MCU} used in GEX Zero and GEX Hub. Porting GEX to this platform is planned for future development.}. The nRF24L01+ module is partly sticking outside the board outline, allowing the \gls{PCB} to be smaller (and thus cheaper to manufacture), while reducing interference between components and copper plating on the board and the antenna. The schematic diagram of the wireless gateway is attached in \hyperref[apx:gex_wgw]{Appendix C}.
  292. Beyond the use with GEX, the gateway is a versatile tool which could be programmed with a different firmware and serve other purposes, e.g., as a wireless connection between two computers, to scan the radio spectrum for interference in order to find a clear channel, or to communicate with other devices that use the nRF24L01+ transceiver. The chosen microcontroller, unfortunately, does not include a USB bootloader, so a SWD programmer is required to change the firmware; SWD is routed to the pin header next to the wireless module.
  293. \begin{figure}[h]
  294. \centering
  295. \includegraphics[width=.9\textwidth]{img/photo-rfdongle.jpg}
  296. \caption{\label{fig:gwxgw}The wireless gateway (top and bottom side)}
  297. \end{figure}