Skip to content

Commit 8cf2fbd

Browse files
author
Simon M. Burkhardt
committed
initial commit
1 parent 084578a commit 8cf2fbd

File tree

5 files changed

+279
-0
lines changed

5 files changed

+279
-0
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
# STM32-Tutorial
22
Getting started with the STM32 HAL development environment. Tutorial documents in LaTex.
3+
4+
---
5+
6+
I have just started to redo the tutorials. Please be patient.
7+
You can find the current tutorials on my website: [simonmartin.ch](https://simonmartin.ch/resources/stm32)
8+
9+
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
%%---Main Packages----------------------------------------------------------------------
2+
3+
\usepackage[english, ngerman]{babel} %Mul­tilin­gual sup­port for Plain TeX or LaTeX
4+
\usepackage[T1]{fontenc} %Stan­dard pack­age for se­lect­ing font en­codings
5+
\usepackage[utf8]{inputenc} %Ac­cept dif­fer­ent in­put en­cod­ings
6+
\usepackage{graphicx} %En­hanced sup­port for graph­ics
7+
\usepackage{float} %Im­proved in­ter­face for float­ing ob­jects
8+
9+
10+
%%---Optional Packages------------------------------------------------------------------
11+
12+
\usepackage[pdftex,dvipsnames,table]{xcolor}%Driver-in­de­pen­dent color ex­ten­sions for LaTeX
13+
\usepackage[hidelinks]{hyperref} %Ex­ten­sive sup­port for hy­per­text in LaTeX
14+
\usepackage{amsmath} %AMS math­e­mat­i­cal fa­cil­i­ties for LaTeX
15+
%\usepackage{amsthm} %Type­set­ting the­o­rems (AMS style)
16+
%\usepackage{amssymb} %Type­set­ting the­o­rems (AMS style)
17+
\usepackage{pdfpages} %In­clude PDF doc­u­ments in LaTeXmns
18+
\usepackage{todonotes} %Mark­ing things to do in a LaTeX doc­u­ment
19+
%\usepackage{siunitx} %A com­pre­hen­sive (SI) units pack­age
20+
\usepackage{listings} %Type­set source code list­ings us­ing LaTeX
21+
%\usepackage{pdflscape} %Make land­scape pages dis­play as land­scape
22+
%\usepackage{array} %Ex­tend­ing the ar­ray and tab­u­lar en­vi­ron­ments
23+
%\usepackage{imakeidx} %A pack­age for pro­duc­ing mul­ti­ple in­dexes
24+
\usepackage{subfigure} %Fig­ures di­vided into sub­fig­ures
25+
%\usepackage{booktabs} %Publi­ca­tion qual­ity ta­bles in LaTeX
26+
%\usepackage{multirow} %Create tab­u­lar cells span­ning mul­ti­ple rows
27+
%\usepackage{multicol} %In­ter­mix sin­gle and mul­ti­ple columns
28+
\usepackage{tabularx} %Tab­u­lars with ad­justable-width columns
29+
%\usepackage{xargs} %De­fine com­mands with many op­tional ar­gu­ments
30+
%\usepackage{cite} %Im­proved ci­ta­tion han­dling in LaTeX
31+
\usepackage{setspace} %Set space be­tween lines
32+
%\usepackage{textgreek} %Upright greek let­ters in text
33+
%\usepackage[bottom]{footmisc} %A range of foot­note op­tions
34+
%\usepackage{footnote} %Im­prove on LaTeX's foot­note han­dling
35+
%\usepackage{verbatim} %Reim­ple­men­ta­tion of and ex­ten­sions to LaTeX ver­ba­tim
36+
\usepackage{textcomp} %LaTeX sup­port for the Text Com­pan­ion fonts
37+
%\usepackage[pagesize]{typearea} %Set page mar­gins
38+
%\usepackage{xspace}
39+
%\usepackage{courier} %Monospaced font for listings package
40+
41+
42+
%%---My Packages------------------------------------------------------------------------
43+
44+
\usepackage[left=2cm, right=2cm, bottom=2cm, headsep=1.5cm]{geometry} % Einstellung Seitenränder
45+
\usepackage{lmodern}
46+
\usepackage{scrpage2} %Kopf- und Fusszeile
47+
\usepackage{lscape}
48+
\usepackage{tikz} %Organigramm
49+
\usetikzlibrary{trees}
50+
\usetikzlibrary{mindmap}
51+
\usetikzlibrary{positioning}
52+
\usepackage{abstract}
53+
\usepackage{etoolbox}
54+
55+
56+
%%---Definitions----------------- ------------------------------------------------------
57+
58+
%%Tabel-Definitions: (requires \usepackage{tabularx})
59+
%\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}} %column-width and alignment
60+
%\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
61+
%\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}
62+
63+
64+
%%---Settings---------------------------------------------------------------------------
65+
66+
\bibliographystyle{IEEEtran} %Defines the Bib. Style (Harvard, IEEE etc.)
67+
\graphicspath{{./images/}} %Defines the graphicspath
68+
%\geometry{twoside=false} %twoside=false disables the "bookstyle" => one sided document
69+
\setlength{\marginparwidth}{2cm}
70+
\overfullrule=5em %Creates a black rule if text goes over the margins => debugging
71+
\setlength{\parindent}{0pt}
72+
\pagestyle{scrheadings}
73+
\clearscrheadfoot
74+
\ohead{\headmark}
75+
\automark[section]{chapter}
76+
\setheadsepline{0.4pt}
77+
78+
%%Listings-Settings: (requires \usepackage{listings})
79+
% Example with Matlab Code:
80+
%\lstset{language=Matlab,%
81+
% basicstyle=\footnotesize\ttfamily,
82+
% breaklines=false,%
83+
% morekeywords={matlab2tikz},
84+
% keywordstyle=\color{blue},%
85+
% tabsize=4,
86+
% morekeywords=[2]{1}, keywordstyle=[2]{\color{black}},
87+
% identifierstyle=\color{black},%
88+
% stringstyle=\color{mylilas},
89+
% commentstyle=\color{mygreen},%
90+
% showstringspaces=false,%without this there will be a symbol in the places where there is a space
91+
% numbers=left,%
92+
% numberstyle={\tiny \color{black}},% size of the numbers
93+
% numbersep=9pt, % this defines how far the numbers are from the text
94+
% emph=[1]{switch, case, otherwise, for,end,break},emphstyle=[1]\color{red}, %some words to emphasise
95+
% %emph=[2]{word1,word2}, emphstyle=[2]{style},
96+
%}
97+
98+
\definecolor{mGreen}{rgb}{0,0.6,0}
99+
\definecolor{mGray}{rgb}{0.5,0.5,0.5}
100+
\definecolor{mPurple}{rgb}{0.58,0,0.82}
101+
\definecolor{backgroundColour}{rgb}{0.95,0.95,0.92}
102+
103+
\lstdefinestyle{CStyle}{
104+
backgroundcolor=\color{backgroundColour},
105+
commentstyle=\color{mGreen},
106+
keywordstyle=\color{magenta},
107+
numberstyle=\tiny\color{mGray},
108+
stringstyle=\color{mPurple},
109+
basicstyle=\footnotesize\ttfamily,
110+
breakatwhitespace=false,
111+
breaklines=true,
112+
captionpos=b,
113+
keepspaces=true,
114+
numbers=left,
115+
numbersep=5pt,
116+
showspaces=false,
117+
showstringspaces=false,
118+
showtabs=false,
119+
tabsize=2,
120+
language=C
121+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
\documentclass[12pt, a4paper]{article} %article, report,
2+
%book, beamer, standalone
3+
%%---PACKAGES, DEFINITIONS, SETTINGS----------------------------------------------------
4+
\input{Header} %loads all packages, definitions and settings
5+
6+
\begin{document}
7+
8+
%%---COMMANDS---------------------------------------------------------------------------
9+
% command "resumesections" to resume section numbering after using "appendix"
10+
\newcounter{savedsection}
11+
\preto\appendix{\setcounter{savedsection}{\arabic{section}}} % remembering!
12+
\newcommand\resumesections{ % the \appendix command with some tweaks
13+
\setcounter{section}{\arabic{savedsection}} % restore section number
14+
\gdef\thesection{\arabic{section}}
15+
}
16+
17+
%%---TITLEPAGE--------------------------------------------------------------------------
18+
\begin{titlepage}
19+
\thispagestyle{scrheadings}
20+
% \ihead{\includegraphics[scale=1.0]{images/FHNW_HT_10mm.jpg}}
21+
\renewcommand*{\pagemark}{}
22+
\begin{center}
23+
\vspace*{0.5cm}
24+
\textbf{\begin{Huge}STM32 Tutorial 001\end{Huge}}\\[0.2cm]
25+
\begin{figure}[h!]
26+
\centering
27+
% \includegraphics[scale=0.13]{images/Nebo-M_mobile_multiband_radar_system.jpg}
28+
\end{figure}
29+
\newcommand{\HRule}{\rule{\linewidth}{0.2mm}}
30+
\HRule \\[0.3cm]
31+
{\begin{Huge}\textbf{GPIO Operations using Hardware Abstraction Libraries (HAL)}\end{Huge}}\\[0.2cm]
32+
\HRule \\[0.3cm]
33+
\textbf{On NUCLEO F103RB}
34+
\vspace*{0.3cm}
35+
36+
Getting started in embedded software engineering on the STM32 plattform. Using STM32CubeMX, Keil uVision 5 (MDK ARM) and Hardware Abstraction Libraries (HAL). Basic understanding of the C language, especially pointers, are presumed.
37+
38+
\vspace*{1cm}
39+
Simon Burkhardt, {\today}
40+
\end{center}
41+
42+
\end{titlepage}
43+
44+
%%---TABLE of CONTENTS------------------------------------------------------------------
45+
\pagenumbering{Roman}
46+
\selectlanguage{english}
47+
\tableofcontents
48+
\clearpage
49+
50+
%%---TEXT-------------------------------------------------------------------------------
51+
%{\includegraphics[scale=1.0]{images/FHNW_HT_10mm.jpg}}
52+
\ohead{STM32 Tutorial 001 \\GPIO Operations}
53+
\cfoot{\pagemark}
54+
\pagenumbering{arabic}
55+
56+
% Elektro-Teil: Mathem. Teil, Berechnungen
57+
\include{sections/cubemx_gpio}
58+
59+
%%---BIBLIOGRAPHY-----------------------------------------------------------------------
60+
\section{Bibliography}
61+
62+
\begingroup
63+
\renewcommand{\section}[2]{}
64+
\bibliography{literature/Bibliography}
65+
\endgroup
66+
67+
68+
%%---ANHANG-----------------------------------------------------------------------------
69+
%\include{sections/Appendix}
70+
%\resumesections
71+
72+
73+
%%---NOTES for DEBUG--------------------------------------------------------------------
74+
%%requires \usepackage{todonotes})
75+
%\newpage
76+
%\listoftodos[\section{Todo-Notes}]
77+
78+
\end{document}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
\section{Configuring the MCU with STM32CubeMX}
2+
3+
You can use the STM32CubeMX tool to create the necessary config. files to enable the GPIO Pins.
4+
In this tutorial I’m going to explain how you can modify the generated GPIO configs and add additional
5+
GPIOs.
6+
7+
This tutorial uses the following equipment:
8+
- NUCLEO-F103RB Board
9+
- Keil uVision 5 with the necessary packages for Nucleo boards installed
10+
- STLink USB Driver
11+
- STM32CubeMX
12+
13+
\subsection{STM32CubeMX}
14+
15+
Generating the config. files from STM32CubeMX.
16+
17+
1. Open STM32CubeMX and open a new project. \\
18+
2. Select the Nucleo-F103RB from the Borards tab \\
19+
3. Enable FreeRTOS \\
20+
4. Set the RCC (HSE \& LSE) to Crystal/Ceramic Resonator \\
21+
5. Enable the USART2 port in Asynchronous mode \\
22+
6. Set any GPIO to Output or Input (I am using PB13, PB14 and PC4) \\
23+
7. Go to Project > Generate code \\
24+
8. Enter a project name and select MDK-ARM V5 \\
25+
9. Generate the code and open the project in Keil uVision \\
26+
27+
28+
29+
\begin{lstlisting}[style=CStyle]
30+
{
31+
32+
GPIO_InitTypeDef GPIO_InitStruct;
33+
34+
/* GPIO Ports Clock Enable */
35+
__GPIOC_CLK_ENABLE();
36+
__GPIOD_CLK_ENABLE();
37+
__GPIOA_CLK_ENABLE();
38+
__GPIOB_CLK_ENABLE();
39+
40+
/*Configure GPIO pin : B1_Pin */
41+
GPIO_InitStruct.Pin = B1_Pin;
42+
GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
43+
GPIO_InitStruct.Pull = GPIO_NOPULL;
44+
HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
45+
46+
/*Configure GPIO pin : LD2_Pin */
47+
GPIO_InitStruct.Pin = LD2_Pin;
48+
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
49+
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
50+
HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct);
51+
52+
/*Configure GPIO pin : PC4 */
53+
GPIO_InitStruct.Pin = GPIO_PIN_4;
54+
GPIO_InitStruct.Mode = GPIO_MODE_INPUT; // digital Input
55+
GPIO_InitStruct.Pull = GPIO_NOPULL;
56+
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
57+
58+
/*Configure GPIO pin : PB13 */
59+
GPIO_InitStruct.Pin = GPIO_PIN_13;
60+
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; // analog Input
61+
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
62+
63+
/*Configure GPIO pin : PB14 */
64+
GPIO_InitStruct.Pin = GPIO_PIN_14;
65+
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; // digital Output
66+
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
67+
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
68+
69+
}
70+
\end{lstlisting}
71+
72+

0 commit comments

Comments
 (0)