Gay | Beginning STM32 | E-Book | www2.sack.de
E-Book

E-Book, Englisch, 418 Seiten

Gay Beginning STM32

Developing with FreeRTOS, libopencm3 and GCC
1. ed
ISBN: 978-1-4842-3624-6
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark

Developing with FreeRTOS, libopencm3 and GCC

E-Book, Englisch, 418 Seiten

ISBN: 978-1-4842-3624-6
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark



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. 
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 interrupts
Use DMA to drive a SPI based OLED displaying an analog meter
Read PWM from an RC control using hardware timers
Who This Book Is For
Experienced 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.

Gay Beginning STM32 jetzt bestellen!

Autoren/Hrsg.


Weitere Infos & Material


1;Table of Contents;5
2;About the Author;18
3;About the Technical Reviewer;19
4;Chapter 1: Introduction;20
4.1;STM32F103C8T6;21
4.2;FreeRTOS;24
4.3;libopencm3;24
4.4;No Arduino;25
4.5;No IDE;25
4.6;Development Framework;26
4.7;Assumptions About You;26
4.8;What You Need;27
4.8.1;ST-Link V2 Programming Unit;27
4.8.2;Breadboard;28
4.8.3;DuPont (Jumper) Wires;29
4.8.4;0.1 uF Bypass Capacitors;30
4.8.5;USB TTL Serial Adapter;31
4.8.6;Power Supply;33
4.8.7;Small Stuff;34
4.9;Summary;35
5;Chapter 2: Software Setup;36
5.1;Directory Conventions Used;36
5.2;Operating Software;36
5.3;Book Software;37
5.3.1;libopencm3;37
5.3.2;FreeRTOS;38
5.3.3;~/stm32f103c8t6/rtos/Project.mk;38
5.4;ARM Cross Compiler;39
5.5;Build the Software;42
5.6;ST-Link Tool;43
5.7;Summary;44
6;Chapter 3: Power Up and Blink;45
6.1;Power;45
6.1.1;+3.3V Regulator;47
6.1.2;USB Power/+5V;48
6.1.3;+3.3V Supply;48
6.1.4;One Power Source Rule;49
6.2;Ground;50
6.3;Reset;50
6.4;Showtime;50
6.5;ST-Link V2;52
6.6;st-flash Utility;54
6.6.1;Read STM32;54
6.6.2;Write Image;55
6.6.3;Erase Flash;56
6.7;Summary;56
6.8;Bibliography;56
7;Chapter 4: GPIO;57
7.1;Building miniblink;57
7.2;Flashing miniblink;58
7.3;miniblink.c Source Code;59
7.4;GPIO API;62
7.4.1;GPIO Configuration;64
7.4.1.1;Input Ports;66
7.4.1.2;Output Ports;67
7.5;Ducks in a Row;69
7.5.1;GPIO Inputs;69
7.5.2;Digital Output, Push/Pull;70
7.5.3;Digital Output, Open Drain;71
7.6;GPIO Characteristics;71
7.6.1;Input Voltage Thresholds;73
7.6.2;Output-Voltage Thresholds;73
7.7;Programmed Delays;74
7.7.1;The Problem with Programmed Delay;75
7.8;Summary;76
8;Chapter 5: FreeRTOS;77
8.1;FreeRTOS Facilities;77
8.1.1;Tasking;78
8.1.2;Message Queues;78
8.1.3;Semaphores and Mutexes;79
8.1.4;Timers;79
8.1.5;Event Groups;80
8.2;The blinky2 Program;80
8.2.1;Build and Test blinky2;84
8.2.2;Execution;84
8.3;FreeRTOSConfig.h;85
8.4;FreeRTOS Naming Convention;87
8.4.1;FreeRTOS Macros;88
8.5;Summary;89
9;Chapter 6: USART;91
9.1;USART/UART Peripheral;91
9.1.1;Asynchronous Data;92
9.2;USB Serial Adapters;92
9.2.1;Hookup;94
9.3;Project uart;95
9.4;Project;99
9.5;Project uart2;103
9.6;USART API;108
9.6.1;Include Files;110
9.6.2;Clocks;110
9.6.3;Configuration;110
9.6.4;DMA;111
9.6.5;Interrupts;111
9.6.6;Input/Output/Status;111
9.7;Ducks-in-a-Row;111
9.8;FreeRTOS;112
9.8.1;Tasks;112
9.8.2;Queues;113
9.9;Summary;114
10;Chapter 7: USB Serial;115
10.1;Blue Pill USB Issue;115
10.2;Introduction to USB;117
10.2.1;Pipes and Endpoints;117
10.3;USB Serial Device;119
10.3.1;Linux USB Serial Device;119
10.3.2;MacOS USB Serial Device;120
10.3.3;Windows USB Serial Device;121
10.3.4;USB GPIO;121
10.4;Demo Source Code;122
10.4.1;cdcacm_set_config();123
10.4.2;cdc_control_request();124
10.4.3;cdcacm_data_rx_cb();125
10.4.4;USB Task;126
10.4.5;USB Receiving;128
10.4.6;USB Sending;128
10.5;USB Serial Demo;129
10.6;Summary;131
10.7;Bibliography;132
11;Chapter 8: SPI Flash;133
11.1;Introducing W25QXX;133
11.2;Serial Peripheral Interface Bus;133
11.2.1;Chip Select;135
11.2.2;Wiring and Voltages;135
11.3;SPI Circuit;136
11.3.1;Hardware /NSS Control;136
11.4;STM32 SPI Configuration;138
11.4.1;SPI Clock Rate;142
11.4.2;SPI Clock Modes;143
11.4.3;Endianess and Word Length;145
11.5;SPI I/O;146
11.5.1;Read SR1;146
11.5.2;Waiting for Ready;147
11.5.3;Read Manufacturer ID;148
11.5.4;Writing Flash;149
11.5.5;Flash Erase;151
11.5.6;Reading Flash;154
11.6;Demonstration;155
11.6.1;Running the Demo;157
11.6.2;Manufacturer ID;162
11.6.3;Power Down;162
11.6.4;Summary;163
11.7;Bibliography;163
12;Chapter 9: Code Overlays;164
12.1;The Linker Challenge;164
12.1.1;MEMORY Section;166
12.1.2;Entry;168
12.1.3;Sections;168
12.1.4;PROVIDE;171
12.1.5;Relocation;171
12.2;Defining Overlays;172
12.2.1;Overlay Code;174
12.2.2;Overlay Stubs;176
12.2.3;Overlay Manager;176
12.2.4;VMA and Load Addresses;177
12.2.5;Linker Symbols in Code;178
12.2.6;Overlay Manager Function;179
12.2.7;Overlay Stubs;181
12.3;Demonstration;182
12.3.1;Extracting Overlays;183
12.3.2;Upload Overlays to W25Q32;184
12.3.3;Overlay Demo Continued;188
12.3.4;Code Change Trap;190
12.4;Summary;190
12.5;Bibliography;191
13;Chapter 10: Real-Time Clock (RTC);192
13.1;Demonstration Projects;192
13.2;RTC Using One Interrupt;192
13.2.1;RTC Configuration;193
13.2.1.1;RTC Clock Source;193
13.2.1.2;Prescaler;194
13.2.1.3;Starting Counter Value;194
13.2.1.4;RTC Flags;194
13.2.2;Interrupt and Setup;195
13.2.3;Interrupt Service Routine;196
13.2.3.1;Servicing Interrupts;198
13.2.4;Task Notification;198
13.2.5;Mutexes;200
13.3;Demonstration;201
13.3.1;UART1 Connections;204
13.3.2;Running the Demo;205
13.4;rtc_alarm_isr();207
13.4.1;EXTI Controller;207
13.4.1.1;Configuring EXT17;208
13.5;Summary;209
14;Chapter 11: I2C;211
14.1;The I2C Bus;211
14.1.1;Master and Slave;212
14.1.2;Start and Stop;212
14.1.3;Data Bits;213
14.1.4;I2C Address;214
14.1.5;I2C Transactions;215
14.2;PCF8574 GPIO Extender;216
14.3;I2C Circuit;218
14.3.1;The PCF8574 Line;219
14.4;PCF8574 Configuration;219
14.4.1;PCF8574 GPIO Drive;221
14.4.2;Wave Shaping;222
14.5;Demo Circuit;222
14.5.1;EXTI Interrupt;223
14.6;I2C Software;225
14.6.1;Testing I2C Ready;226
14.6.2;Start I2C;227
14.6.3;I2C Write;229
14.6.4;I2C Read;229
14.6.5;I2C Restart;230
14.7;Demo Program;231
14.7.1;Demo Session;234
14.8;Summary;236
15;Chapter 12: OLED;238
15.1;OLED Display;238
15.1.1;Configuration;239
15.1.2;Display Connections;241
15.2;Display Features;241
15.3;Demo Schematic;242
15.4;AFIO;243
15.5;Graphics;245
15.5.1;The Pixmap;247
15.5.2;Pixmap Writing;248
15.5.3;The Meter Software;249
15.5.3.1;meter_init();249
15.5.3.2;meter_set_value();250
15.5.3.3;meter_redraw();250
15.5.3.4;meter_update();250
15.5.4;Main Module;251
15.5.4.1;oled_command();251
15.5.4.2;oled_data();252
15.5.4.3;oled_reset();252
15.5.4.4;oled_init();252
15.6;Demonstration;253
15.7;Summary;255
16;Chapter 13: OLED Using DMA;256
16.1;Challenges;256
16.1.1;Circuit;257
16.2;DMA Operation;257
16.2.1;DMA Execution;257
16.2.1.1;DMA Request Signals;258
16.2.1.2;SPI1_TX Request;262
16.3;The Demonstration;262
16.3.1;Initializing DMA;264
16.3.2;Launching DMA;265
16.3.3;OLED SPI/DMA Management Task;266
16.3.4;DMA ISR Routine;269
16.3.5;Restarting DMA Transfers;270
16.4;Executing the Demo;271
16.4.1;Further Challenges;273
16.5;Summary;274
17;Chapter 14: Analog-to-Digital Conversion;275
17.1;STM32F103C8T6 Resources;275
17.2;Demonstration;276
17.2.1;Analog Inputs PA0 and PA1;277
17.2.2;ADC Peripheral Configuration;277
17.2.2.1;ADC Prescaler;278
17.2.2.2;ADC Modes;278
17.2.2.3;Sample Time;278
17.2.2.4;Readying the ADC;280
17.3;Demonstration Run;280
17.3.1;Reading ADC;281
17.3.1.1;Computing Temperature;282
17.3.1.2;Voltage Reference;284
17.4;Analog Voltages;284
17.5;Summary;285
17.6;Bibliography;286
18;Chapter 15: Clock Tree;287
18.1;In the Beginning;287
18.1.1;RC Oscillators;288
18.1.2;Crystal Oscillators;289
18.1.3;Oscillator Power;290
18.2;Real-time Clock;290
18.3;Watchdog Clock;290
18.4;System Clock (SYSCLK);291
18.4.1;SYSCLK and USB;293
18.5;AHB Bus;294
18.5.1;rcc_clock_setup_in_hse_8mhz_out_72mhz();295
18.5.2;APB1 Peripherals;299
18.5.3;APB2 Peripherals;299
18.5.4;Timers;299
18.6;rcc_set_mco();300
18.7;HSI Demo;300
18.8;HSE Demo;302
18.9;PLL ÷ 2 Demo;303
18.10;Summary;304
18.11;Bibliography;304
19;Chapter 16: PWM with Timer 2;306
19.1;PWM Signals;306
19.2;Timer 2;307
19.3;PWM Loop;311
19.3.1;Calculating Timer Prescale;311
19.3.2;30 Hz Cycle;312
19.4;Servo Hookup;313
19.5;Running the Demo;314
19.6;PWM on PB3;314
19.7;Other Timers;315
19.7.1;More PWM Channels;316
19.8;Summary;317
19.9;Bibliography;317
20;Chapter 17: PWM Input with Timer 4;318
20.1;The Servo Signal;318
20.2;Signal Voltage;319
20.3;Demo Project;319
20.3.1;GPIO Configuration;319
20.3.2;Timer 4 Configuration;319
20.3.3;Task1 Loop;321
20.3.4;ISR Routine;322
20.4;Demonstration Run;323
20.4.1;Session Output;325
20.5;Timer Inputs;326
20.6;Summary;328
21;Chapter 18: CAN Bus;329
21.1;The CAN Bus;329
21.2;Differential Signals;331
21.2.1;Dominant/Recessive;332
21.3;Bus Arbitration;333
21.3.1;Synchronization;334
21.3.2;Message Format;335
21.4;STM32 Limitation;336
21.5;Demonstration;337
21.5.1;Software Build;337
21.5.2;UART Interface;338
21.5.3;MCU Flashing;338
21.5.4;Demo Bus;339
21.6;Session Run;340
21.6.1;CAN Messages;342
21.6.2;Synchronicity;343
21.7;Summary;343
21.8;Bibliography;343
22;Chapter 19: CAN Bus Software;344
22.1;Initialization;344
22.1.1;can_init();347
22.1.2;CAN Receive Filters;349
22.1.3;CAN Receive Interrupts;350
22.1.4;Application Receiving;354
22.1.4.1;Processing the Message;354
22.1.5;Sending CAN Messages;356
22.2;Summary;357
23;Chapter 20: New Projects;358
23.1;Project Creation;358
23.1.1;Makefile;359
23.1.1.1;Macro BINARY;360
23.1.1.2;Macro SRCFILES;360
23.1.1.3;Macro LDSCRIPT;361
23.1.1.4;Macro DEPS;361
23.1.1.5;Macro CLOBBER;361
23.1.2;Included Makefiles;362
23.1.3;Header Dependencies;362
23.1.4;Compile Options;362
23.1.5;Flashing 128k;363
23.2;FreeRTOS;364
23.2.1;rtos/opencm3.c;364
23.2.2;rtos/heap_4.c;365
23.2.3;Required Modules;365
23.3;FreeRTOSConfig.h;366
23.4;User Libraries;368
23.5;Rookie Mistakes;369
23.6;Summary;369
23.7;Bibliography;369
24;Chapter 21: Troubleshooting;371
24.1;Gnu GDB;371
24.1.1;GDB Server;371
24.1.2;Remote GDB;373
24.1.3;GDB Text User Interface;376
24.2;Peripheral GPIO Trouble;377
24.3;Alternate Function Fail;378
24.4;Peripheral Fail;379
24.5;ISR FreeRTOS Crash;379
24.6;Stack Overflow;380
24.7;Estimating Stack Size;381
24.8;When a Debugger Doesn’t Help;381
24.9;Push/Pull or Open Drain;382
24.10;Peripheral Defects;382
24.11;Resources;382
24.11.1;libopencm3;383
24.12;FreeRTOS Task Priorities;385
24.12.1;Scheduling Within libopencm3;386
24.13;Summary;387
25;AppendixA: Answers to Exercises;388
25.1;Chapter 4;388
25.2;Chapter 5;390
25.3;Chapter 6;391
25.4;Chapter 7;392
25.5;Chapter 8;393
25.6;Chapter 9;394
25.7;Chapter 10;395
25.8;Chapter 11;395
25.9;Chapter 12;396
25.10;Chapter 13;397
25.11;Chapter 14;398
25.12;Chapter 15;399
25.13;Chapter 16;399
25.14;Chapter 17;400
25.15;Chapter 19;400
25.16;Chapter 20;401
26;Appendix B: STM32F103C8T6 GPIO Pins;402
27;Index;410



Ihre Fragen, Wünsche oder Anmerkungen
Vorname*
Nachname*
Ihre E-Mail-Adresse*
Kundennr.
Ihre Nachricht*
Lediglich mit * gekennzeichnete Felder sind Pflichtfelder.
Wenn Sie die im Kontaktformular eingegebenen Daten durch Klick auf den nachfolgenden Button übersenden, erklären Sie sich damit einverstanden, dass wir Ihr Angaben für die Beantwortung Ihrer Anfrage verwenden. Selbstverständlich werden Ihre Daten vertraulich behandelt und nicht an Dritte weitergegeben. Sie können der Verwendung Ihrer Daten jederzeit widersprechen. Das Datenhandling bei Sack Fachmedien erklären wir Ihnen in unserer Datenschutzerklärung.