Beginning STM32 (eBook)
XXI, 409 Seiten
Apress (Verlag)
978-1-4842-3624-6 (ISBN)
Using FreeRTOS and libopencm3 instead of the Arduino software environment, this book will help you develop multi-tasking applications that go beyond Arduino norms. In addition to the usual peripherals found in the typical Arduino device, the STM32 device includes a USB controller, RTC (Real Time Clock), DMA (Direct Memory Access controller), CAN bus and more.
Each chapter contains clear explanations of the STM32 hardware capabilities to help get you started with the device, including GPIO and several other ST Microelectronics peripherals like USB and CAN bus controller. You'll learn how to download and set up the libopencm3 + FreeRTOS development environment, using GCC. With everything set up, you'll leverage FreeRTOS to create tasks, queues, and mutexes. You'll also learn to work with the I2C bus to add GPIO using the PCF8574 chip. And how to create PWM output for RC control using hardware timers.
You'll be introduced to new concepts that are necessary to master the STM32, such as how to extend code with GCC overlays using an external Winbond ?W25Q32 flash chip. Your knowledge is tested at the end of each chapter with exercises. Upon completing this book, you'll be ready to work with any of the devices in the STM32 family.- Initialize and use the libopencm3 drivers and handle interrupts
- Use DMA to drive a SPI based OLED displaying an analog meter
- Read PWM from an RC control using hardware timers
Warren Gay ?has been an electronics enthusiast since childhood and often dragged discarded TV sets home after school. In high school he learned to program the IBM-1130 and then pursued a career in software development at Ryerson Polytechnical, in Toronto. Since then he has worked professionally for over 30 years, mainly in C/C++, under Unix and Linux. Meanwhile, the love of electronics has never faded since the early creation of his home-brewed Intel 8008 system in the 70's to the present day projects employing the Raspberry Pi. Warren also holds an advanced amateur radio license and was able to work the Mir space station (U2MIR) using packet radio in August 1991. He's authored other books including Sams Teach Yourself Linux in 24 Hours, Linux Socket Programming by Example, and Advanced Unix Programming.
Using FreeRTOS and libopencm3 instead of the Arduino software environment, this book will help you develop multi-tasking applications that go beyond Arduino norms. In addition to the usual peripherals found in the typical Arduino device, the STM32 device includes a USB controller, RTC (Real Time Clock), DMA (Direct Memory Access controller), CAN bus and more. Each chapter contains clear explanations of the STM32 hardware capabilities to help get you started with the device, including GPIO and several other ST Microelectronics peripherals like USB and CAN bus controller. You'll learn how to download and set up the libopencm3 + FreeRTOS development environment, using GCC. With everything set up, you'll leverage FreeRTOS to create tasks, queues, and mutexes. You'll also learn to work with the I2C bus to add GPIO using the PCF8574 chip. And how to create PWM output for RC control using hardware timers.You'll be introduced to new concepts that are necessary to master theSTM32, such as how to extend code with GCC overlays using an external Winbond ?W25Q32 flash chip. Your knowledge is tested at the end of each chapter with exercises. Upon completing this book, you'll be ready to work with any of the devices in the STM32 family. Beginning STM32 provides the professional, student, or hobbyist a way to learn about ARM without costing an arm!What You'll Learn Initialize and use the libopencm3 drivers and handle interruptsUse DMA to drive a SPI based OLED displaying an analog meterRead PWM from an RC control using hardware timersWho This Book Is ForExperienced embedded engineers, students, hobbyists and makers wishing to explore the ARM architecture, going beyond Arduino limits.
Warren Gay has been an electronics enthusiast since childhood and often dragged discarded TV sets home after school. In high school he learned to program the IBM-1130 and then pursued a career in software development at Ryerson Polytechnical, in Toronto. Since then he has worked professionally for over 30 years, mainly in C/C++, under Unix and Linux. Meanwhile, the love of electronics has never faded since the early creation of his home-brewed Intel 8008 system in the 70's to the present day projects employing the Raspberry Pi. Warren also holds an advanced amateur radio license and was able to work the Mir space station (U2MIR) using packet radio in August 1991. He's authored other books including Sams Teach Yourself Linux in 24 Hours, Linux Socket Programming by Example, and Advanced Unix Programming.
Table of Contents 5
About the Author 18
About the Technical Reviewer 19
Chapter 1: Introduction 20
STM32F103C8T6 21
FreeRTOS 24
libopencm3 24
No Arduino 25
No IDE 25
Development Framework 26
Assumptions About You 26
What You Need 27
ST-Link V2 Programming Unit 27
Breadboard 28
DuPont (Jumper) Wires 29
0.1 uF Bypass Capacitors 30
USB TTL Serial Adapter 31
Power Supply 33
Small Stuff 34
Summary 35
Chapter 2: Software Setup 36
Directory Conventions Used 36
Operating Software 36
Book Software 37
libopencm3 37
FreeRTOS 38
~/stm32f103c8t6/rtos/Project.mk 38
ARM Cross Compiler 39
Build the Software 42
ST-Link Tool 43
Summary 44
Chapter 3: Power Up and Blink 45
Power 45
+3.3V Regulator 47
USB Power/+5V 48
+3.3V Supply 48
One Power Source Rule 49
Ground 50
Reset 50
Showtime 50
ST-Link V2 52
st-flash Utility 54
Read STM32 54
Write Image 55
Erase Flash 56
Summary 56
Bibliography 56
Chapter 4: GPIO 57
Building miniblink 57
Flashing miniblink 58
miniblink.c Source Code 59
GPIO API 62
GPIO Configuration 64
Input Ports 66
Output Ports 67
Ducks in a Row 69
GPIO Inputs 69
Digital Output, Push/Pull 70
Digital Output, Open Drain 71
GPIO Characteristics 71
Input Voltage Thresholds 73
Output-Voltage Thresholds 73
Programmed Delays 74
The Problem with Programmed Delay 75
Summary 76
Chapter 5: FreeRTOS 77
FreeRTOS Facilities 77
Tasking 78
Message Queues 78
Semaphores and Mutexes 79
Timers 79
Event Groups 80
The blinky2 Program 80
Build and Test blinky2 84
Execution 84
FreeRTOSConfig.h 85
FreeRTOS Naming Convention 87
FreeRTOS Macros 88
Summary 89
Chapter 6: USART 91
USART/UART Peripheral 91
Asynchronous Data 92
USB Serial Adapters 92
Hookup 94
Project uart 95
Project 99
Project uart2 103
USART API 108
Include Files 110
Clocks 110
Configuration 110
DMA 111
Interrupts 111
Input/Output/Status 111
Ducks-in-a-Row 111
FreeRTOS 112
Tasks 112
Queues 113
Summary 114
Chapter 7: USB Serial 115
Blue Pill USB Issue 115
Introduction to USB 117
Pipes and Endpoints 117
USB Serial Device 119
Linux USB Serial Device 119
MacOS USB Serial Device 120
Windows USB Serial Device 121
USB GPIO 121
Demo Source Code 122
cdcacm_set_config() 123
cdc_control_request() 124
cdcacm_data_rx_cb() 125
USB Task 126
USB Receiving 128
USB Sending 128
USB Serial Demo 129
Summary 131
Bibliography 132
Chapter 8: SPI Flash 133
Introducing W25QXX 133
Serial Peripheral Interface Bus 133
Chip Select 135
Wiring and Voltages 135
SPI Circuit 136
Hardware /NSS Control 136
STM32 SPI Configuration 138
SPI Clock Rate 142
SPI Clock Modes 143
Endianess and Word Length 145
SPI I/O 146
Read SR1 146
Waiting for Ready 147
Read Manufacturer ID 148
Writing Flash 149
Flash Erase 151
Reading Flash 154
Demonstration 155
Running the Demo 157
Manufacturer ID 162
Power Down 162
Summary 163
Bibliography 163
Chapter 9: Code Overlays 164
The Linker Challenge 164
MEMORY Section 166
Entry 168
Sections 168
PROVIDE 171
Relocation 171
Defining Overlays 172
Overlay Code 174
Overlay Stubs 176
Overlay Manager 176
VMA and Load Addresses 177
Linker Symbols in Code 178
Overlay Manager Function 179
Overlay Stubs 181
Demonstration 182
Extracting Overlays 183
Upload Overlays to W25Q32 184
Overlay Demo Continued 188
Code Change Trap 190
Summary 190
Bibliography 191
Chapter 10: Real-Time Clock (RTC) 192
Demonstration Projects 192
RTC Using One Interrupt 192
RTC Configuration 193
RTC Clock Source 193
Prescaler 194
Starting Counter Value 194
RTC Flags 194
Interrupt and Setup 195
Interrupt Service Routine 196
Servicing Interrupts 198
Task Notification 198
Mutexes 200
Demonstration 201
UART1 Connections 204
Running the Demo 205
rtc_alarm_isr() 207
EXTI Controller 207
Configuring EXT17 208
Summary 209
Chapter 11: I2C 211
The I2C Bus 211
Master and Slave 212
Start and Stop 212
Data Bits 213
I2C Address 214
I2C Transactions 215
PCF8574 GPIO Extender 216
I2C Circuit 218
The PCF8574 Line 219
PCF8574 Configuration 219
PCF8574 GPIO Drive 221
Wave Shaping 222
Demo Circuit 222
EXTI Interrupt 223
I2C Software 225
Testing I2C Ready 226
Start I2C 227
I2C Write 229
I2C Read 229
I2C Restart 230
Demo Program 231
Demo Session 234
Summary 236
Chapter 12: OLED 238
OLED Display 238
Configuration 239
Display Connections 241
Display Features 241
Demo Schematic 242
AFIO 243
Graphics 245
The Pixmap 247
Pixmap Writing 248
The Meter Software 249
meter_init() 249
meter_set_value() 250
meter_redraw() 250
meter_update() 250
Main Module 251
oled_command() 251
oled_data() 252
oled_reset() 252
oled_init() 252
Demonstration 253
Summary 255
Chapter 13: OLED Using DMA 256
Challenges 256
Circuit 257
DMA Operation 257
DMA Execution 257
DMA Request Signals 258
SPI1_TX Request 262
The Demonstration 262
Initializing DMA 264
Launching DMA 265
OLED SPI/DMA Management Task 266
DMA ISR Routine 269
Restarting DMA Transfers 270
Executing the Demo 271
Further Challenges 273
Summary 274
Chapter 14: Analog-to-Digital Conversion 275
STM32F103C8T6 Resources 275
Demonstration 276
Analog Inputs PA0 and PA1 277
ADC Peripheral Configuration 277
ADC Prescaler 278
ADC Modes 278
Sample Time 278
Readying the ADC 280
Demonstration Run 280
Reading ADC 281
Computing Temperature 282
Voltage Reference 284
Analog Voltages 284
Summary 285
Bibliography 286
Chapter 15: Clock Tree 287
In the Beginning 287
RC Oscillators 288
Crystal Oscillators 289
Oscillator Power 290
Real-time Clock 290
Watchdog Clock 290
System Clock (SYSCLK) 291
SYSCLK and USB 293
AHB Bus 294
rcc_clock_setup_in_hse_8mhz_out_72mhz() 295
APB1 Peripherals 299
APB2 Peripherals 299
Timers 299
rcc_set_mco() 300
HSI Demo 300
HSE Demo 302
PLL ÷ 2 Demo 303
Summary 304
Bibliography 304
Chapter 16: PWM with Timer 2 306
PWM Signals 306
Timer 2 307
PWM Loop 311
Calculating Timer Prescale 311
30 Hz Cycle 312
Servo Hookup 313
Running the Demo 314
PWM on PB3 314
Other Timers 315
More PWM Channels 316
Summary 317
Bibliography 317
Chapter 17: PWM Input with Timer 4 318
The Servo Signal 318
Signal Voltage 319
Demo Project 319
GPIO Configuration 319
Timer 4 Configuration 319
Task1 Loop 321
ISR Routine 322
Demonstration Run 323
Session Output 325
Timer Inputs 326
Summary 328
Chapter 18: CAN Bus 329
The CAN Bus 329
Differential Signals 331
Dominant/Recessive 332
Bus Arbitration 333
Synchronization 334
Message Format 335
STM32 Limitation 336
Demonstration 337
Software Build 337
UART Interface 338
MCU Flashing 338
Demo Bus 339
Session Run 340
CAN Messages 342
Synchronicity 343
Summary 343
Bibliography 343
Chapter 19: CAN Bus Software 344
Initialization 344
can_init() 347
CAN Receive Filters 349
CAN Receive Interrupts 350
Application Receiving 354
Processing the Message 354
Sending CAN Messages 356
Summary 357
Chapter 20: New Projects 358
Project Creation 358
Makefile 359
Macro BINARY 360
Macro SRCFILES 360
Macro LDSCRIPT 361
Macro DEPS 361
Macro CLOBBER 361
Included Makefiles 362
Header Dependencies 362
Compile Options 362
Flashing 128k 363
FreeRTOS 364
rtos/opencm3.c 364
rtos/heap_4.c 365
Required Modules 365
FreeRTOSConfig.h 366
User Libraries 368
Rookie Mistakes 369
Summary 369
Bibliography 369
Chapter 21: Troubleshooting 371
Gnu GDB 371
GDB Server 371
Remote GDB 373
GDB Text User Interface 376
Peripheral GPIO Trouble 377
Alternate Function Fail 378
Peripheral Fail 379
ISR FreeRTOS Crash 379
Stack Overflow 380
Estimating Stack Size 381
When a Debugger Doesn’t Help 381
Push/Pull or Open Drain 382
Peripheral Defects 382
Resources 382
libopencm3 383
FreeRTOS Task Priorities 385
Scheduling Within libopencm3 386
Summary 387
AppendixA: Answers to Exercises 388
Chapter 4 388
Chapter 5 390
Chapter 6 391
Chapter 7 392
Chapter 8 393
Chapter 9 394
Chapter 10 395
Chapter 11 395
Chapter 12 396
Chapter 13 397
Chapter 14 398
Chapter 15 399
Chapter 16 399
Chapter 17 400
Chapter 19 400
Chapter 20 401
Appendix B: STM32F103C8T6 GPIO Pins 402
Index 410
Erscheint lt. Verlag | 1.6.2018 |
---|---|
Zusatzinfo | XXI, 409 p. 69 illus. |
Verlagsort | Berkeley |
Sprache | englisch |
Themenwelt | Informatik ► Weitere Themen ► Hardware |
Schlagworte | Arduino • Arm • ARM Cortex • Black Pill • blue pill • Can Bus • Cortex-M3 • FreeRTOS • GCC • libopencm3 • red pill • STM32 • STM32F103 • STM32F103C8T6 • stmicroelectronics • USB |
ISBN-10 | 1-4842-3624-6 / 1484236246 |
ISBN-13 | 978-1-4842-3624-6 / 9781484236246 |
Haben Sie eine Frage zum Produkt? |
![PDF](/img/icon_pdf_big.jpg)
Größe: 8,0 MB
DRM: Digitales Wasserzeichen
Dieses eBook enthält ein digitales Wasserzeichen und ist damit für Sie personalisiert. Bei einer missbräuchlichen Weitergabe des eBooks an Dritte ist eine Rückverfolgung an die Quelle möglich.
Dateiformat: PDF (Portable Document Format)
Mit einem festen Seitenlayout eignet sich die PDF besonders für Fachbücher mit Spalten, Tabellen und Abbildungen. Eine PDF kann auf fast allen Geräten angezeigt werden, ist aber für kleine Displays (Smartphone, eReader) nur eingeschränkt geeignet.
Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen dafür einen PDF-Viewer - z.B. den Adobe Reader oder Adobe Digital Editions.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen dafür einen PDF-Viewer - z.B. die kostenlose Adobe Digital Editions-App.
Zusätzliches Feature: Online Lesen
Dieses eBook können Sie zusätzlich zum Download auch online im Webbrowser lesen.
Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.
aus dem Bereich