![]() If it hasn’t been processed yet, the #ifndef (‘if not defined’) will evaluate true and the file will be defined and included. The #ifndef/#define/#endif statements are a common pattern in C programming they prevent the file from being included more than once. Define GPIOB pin mappings for our LED and button. Now that we have external files to include, it makes sense to define a main.h header file for those sorts of definitions: #ifndef _VVC_MAIN_H I included it as an empty file because the standard stm32f031圆.h file depends on it. The system_stm32f0xx.h file is included by ST’s files because it is used in most of their auto-generated code, but its typical contents are not relevant to our low-level project. The stm32f0xx.h file provides general definitions shared across the entire STM32F0 line of chips, and the stm32f031圆.h file has the definitions specific to our STM32F031K6 chip. Some of the device header files – like cmsis_gcc.h and the ones starting with core_cm – are “ CMSIS” files which provide some common ARM Cortex-M definitions and things like software helpers for things like setting up hardware interrupts. These supporting files are all located in the device_headers directory in the repository that I’ll link to at the end of this post. The bad news is, the definitions are all written as confusing acronyms, so it’s helpful to have your chip’s reference manual handy to check what the jumbles of letters mean. The companies which make these chips – ST Microelectronics in this case – usually also provide free header files which have definitions for which memory addresses go to which peripherals, and which bits do what. For example, in this tutorial we will set a bit to 1 in an “Output Data Register” to pull a pin’s voltage high enough to turn on an LED, and reset the same bit to 0 to pull the pin to ground and turn the LED off. The way that we read and program these peripherals is to check and set certain values at specific memory addresses. ![]() They can do things like speak common communication protocols with other chips, run actions on timers, and send general-purpose signals to the pins connected to the chip. It has a number of hardware “Peripherals” to make it easier for you write programs which interact with the real world. ![]() The STM32 chips have a lot of functionality which is not easy to represent in the standard C language. The resistor and capacitor are both optional – they’re just a very simple form of debouncing. You can find the actual pin mappings in section 6.11 of this reference document, or they’re also printed on the informational card that comes with the board. Strangely, the B1 pin is labeled ‘D6’ on the Nucleo boards I think that ST wanted to use the same footprint and labeling as the popular Arduino Nano. The 100nF capacitor across the button should help reduce noise, one side of the button connects to ground through a jumper wire, and I put a 470Ω resistor between the other side of the button and pin B1. The green ‘LD3’ LED is attached to pin B3 on the board. ‘Nucleo’ STM32F031K6 board with a button.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |