ARM Microcontrollers Programming for Embedded Systems
ARM Microcontrollers Programming for Embedded Systems
STM32F4-Discovery CMSIS and HAL-API in IAR-EWARM or Keil-MDK
About the Book
For over two decades, microcontrollers have begun to take control over most of the activities that can be described by algorithms, and will become more and more indispensable - they are here to stay. Incorporating all the blocks needed to run any algorithm, microcontrollers gain, by software, an increasing amount of intelligence.
Our problem is that all these microcontrollers do not actually have their own intelligence, but they include a part of that of the man's who is writing in the non-volatile memory - the programmer.
It should be mentioned here that for embedded systems, the programming must respond to some specific, increasing requirements, making it more difficult than a classical one, achievable only by programmers with special training. The purpose of this book is to broaden their class, with individual and socially predictable beneficial consequences.
Table of Contents
i. Introduction and motivation of the domain. 10
ii. Examples of design topics 11
iii. Method, device and environment 12
1. Installing the environment and writing directly to memory 14
1.1 Presentation of a typical ARM microcontroller and a development board for it. 14
1.2 Installing and launching the IAR development environment for ARM microcontrollers. 16
1.3 IAR setting for the selected microcontroller and creation of a blank program for viewing memory and registers. 17
1.4 Direct action on memory registers for controlling LED-coupled terminals. 17
1.5 Commands on the registers in the memory space via the pointers. 22
1.6 Inclusion of the constant and macro libraries declared by the manufacturer and the use of CMSIS 25
1.7 Use of CMSIS in STM32Cube_FW_F4_Vx.x.x. 28
2. Programming with API Functions, Standard Peripheral Library (SPL) 31
2.1 General API programming features. 31
2.2 Blink LED API LED, using Standard Peripheral Drivers. 31
3. Using the CubeMX initialization code generator 38
3.1 Overview of the CubeMX initialization code generator. 38
3.2 Install the CubeMX environment. 39
3.3 Create a new project using CubeMX. 40
3.4 Control of GPIO digital pins. 43
4. Digital inputs on STM32F407VG microcontroller pins 48
4.1 Identify the User button input and track its action on the memory. 48
4.2 The CMSIS programming variant, through registers. 50
4.3 Button readout and LED control via HAL-API 54
5.1 External interrupts. Direct programming via registers. 56
5.2 External interrupts using API functions. 61
6. USART serial communication interfaces (Universal Synchronous/Asynchronous Receiver/Transmiter) 64
6.1 Generalities about RS232 communications. 64
6.5 Serial transmission program, registers programming. 67
6.6 Program for serial transmission, reception and display, using registers. 70
6.7 Serial transmission, interrupts reception and display, using registers. 71
7. Serial communications via USART using API functions 73
7.1 Serial transmission of a byte. 73
7.2 Program for serial transmission, reception and display, using API 75
7.3 Serial transmission, interrupts reception and display, using API 76
8. Analog inputs via Analogue-to-Digital Converter, registers programming 78
8.1 Integrated ADC overview.. 78
8.2 Analog-numeric conversion program, registry variant. 79
8.3 Serial transmission of conversion result. 82
8.4 Use of ADC with interrupts, registry variant. 84
9. Analog inputs via Analog-to-Digital Converter, API variant 87
9.1 Analog-Numerical conversion using API functions without ADC interrupts. 88
9.2 Analog-Numerical conversion using API functions with ADC interrupts. 91
10.1 STM32F4 microcontroller timers overview.. 94
10.2 Use timer in basic mode, registry variant. 96
10.3 Basic timer, HAL_API variant. 99
10.4 Use timer comparison outputs, registry variant. 101
10.5 Use of TIM comparison outputs, HAL_API variant. 102
11. Timer as an external source counter, using interrupts 103
11.1 Use as a counter with external ETR source, registry variant. 103
11.2 Use as a counter with external ETR source, HAL_API variant. 104
11.3 Use of Overrun and Comparison Interrupts, registry variants. 106
11.4 Using update interruptions, API variant. 109
11.5 Using update interrupts to automate a sequence. 113
12. Timers in PWM mode, registers 114
12.1 Generation of PWM signals and features for STM32F4 microcontrollers. 114
12.2 Generating PWM signals, registers variant. 119
12.3 Modifying the filling factor by ADC, registry variant. 121
13. Timers in PWM mode, API version. 123
13.1 Using timer in PWM mode with SPL-API function programming. 123
13.2 Modifying the fill factor via ADC, API programming. 126
13.3 Changing the fill factor from a terminal with API programming. 128
13.4 Modifying the fill factor from an ultrasonic sensor, API Programming. 132
14. SPI interface. Coupling with the LIS3DH accelerometer 135
14.1 Modes of SPI data transfer at STM32F4 microcontrollers. 135
14.2 Operation in Master mode. 136
14.3 LIS3DH accelerometer. 137
14.5 Displaying the 3D position in Labview.. 141
15. Interfaţa Inter-Integrated Circuit - I2C. 144
15.1 Overview of the I2C protocol 144
15.2 Operation of the I2C bus. 145
15.3 Coupling two STM32F4 Discovery boards through I2C. 147
15.4 I2C interface using HAL-API functions. 149
15.5 I2C interface using registry programming. 151
15.6 Master-Multiple slave operating. 155
16. Computer Array Network Interface - CAN.. 162
16.2 Reception in the CAN network. 164
16.3 Building a CAN network using HAL-API functions, version STM32Cube_FW_F4_V1.2x. 168
16.4 Building a CAN network using registry programming. 176
17. Interfacing STM32F4-Discovery for Internet Communications 181
17.1 The STM32F4-Discovery Program.. 183
17.2 Presentation of WiFi module for Internet connection. 185
17.3 Preparation for programming the ESP8266 module. 188
17.4 Server program for ESP8266. 188
17.5 Creating an Android application for Internet ordering of the STM32F4-Discovery Plate. 191
18. Annexes. Extracts from the STM32F4xx microcontroller documentation. 194
18.1 Memory Map and Interrupt Table for STM32f4xx Microcontrollers. 194
18.1.1 STM32F4xx register boundary addresses. 194
18.1.2 Table 62. Vector table for STM32F405xx/07xx and STM32F415xx/17xx. 196
18.2 Registers associated with buses. 199
18.2.1 RCC AHB1 peripheral clock enable register (RCC_AHB1ENR). 199
18.2.2 RCC APB2 peripheral clock enable register(RCC_APB2ENR). 201
18.3 Registers associated with some input/output ports. 203
18.3.1 GPIO port mode register (GPIOx_MODER) (x = A..I/J/K). 203
18.3.2 GPIO port output data register (GPIOx_ODR) (x = A..I/J/K) 204
18.3.3 GPIO port output type register (GPIOx_OTYPER) (x = A..I/J/K) 204
18.3.4 GPIO port input data register (GPIOx_IDR) (x = A..I/J/K) 204
18.3.5 Interrupt mask register (EXTI_IMR). 205
18.3.6 Rising trigger selection register (EXTI_RTSR). 205
18.3.7 Pending register (EXTI_PR). 206
18.3.8 GPIO alternate function low register (GPIOx_AFRL) (x = A..I/J/K). 206
18.4 Registers associated with USART. 207
18.4.1 USART Status register (USART_SR). 207
18.4.2 USART Control register 1 (USART_CR1). 209
18.4.3 Baud rate register (USART_BRR) 211
18.5 Registers associated with analog-numeric converters. 211
18.5.1 ADC control register 2 (ADC_CR2). 211
18.5.2 ADC sample time register 1 (ADC_SMPR1). 214
18.5.3 ADC regular sequence register 3 (ADC_SQR3). 214
18.5.4 ADC status register (ADC_SR). 215
18.6 Registers associated with timers. 216
18.6.1 TIMx control register 1 (TIMx_CR1). 216
18.6.2 TIMx prescaler (TIMx_PSC) 217
18.6.3 TIMx capture/compare mode register 1 (TIMx_CCMR1). 218
18.6.4 TIMx capture/compare mode register 2 (TIMx_CCMR2). 220
18.6.5 TIMx capture/compare enable register (TIMx_CCER) 222
18.6.6 TIMx slave mode control register (TIMx_SMCR) 223
18.6.7 TIMx event generation register (TIMx_EGR) 226
18.6.8 TIMx DMA/Interrupt enable register (TIMx_DIER). 227
18.6.9 TIMx status register (TIMx_SR). 228
18.7 Registers associated with I2C interface. 229
18.7.1 I2C Control register 1 (I2C_CR1). 229
18.7.2 I2C Status register 1 (I2C_SR1). 231
18.7.3 I2C Status register 2 (I2C_SR2). 234
18.8 Registers associated with CAN interface. 235
18.8.1 CAN TX mailbox identifier register (CAN_TIxR) (x=0..2). 236
18.8.2 CAN transmit status register (CAN_TSR) 236
18.8.3 CAN mailbox data length control and time stamp register (CAN_TDTxR) (x=0..2) 239
18.8.4 CAN receive FIFO mailbox identifier register (CAN_RIxR) (x=0..1). 239
18.8.5 CAN filter master register (CAN_FMR). 240
18.8.6 CAN filter mode register (CAN_FM1R). 240
18.8.7 CAN filter scale register (CAN_FS1R). 241
18.8.8 CAN filter FIFO assignment register (CAN_FFA1R) 241
18.8.9 CAN filter activation register (CAN_FA1R). 242
18.8.10 Filter bank i register x (CAN_FiRx) (i=0..27, x=1, 2). 242
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.
You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!
So, there's no reason not to click the Add to Cart button, is there?
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earnedover $14 millionwriting, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them