The fourth course module continues the examination of the Cortex-M4 architecture with a look at the memory mapping and processor instructions. The lab for this module deals with programming digital input and outputs using the GPIO pins.
The Cortex-M4 has a 32 bit addressable memory space (4GB). The memory is allocated into functional regions as shown below.
The Cortex-M4 Instruction Set has been optimized with 32 bit Thumb2 instructions that can execute in one instruction state. Here's a list of the instruction types included:
Lab2 Exercise - Digital Input/Output and GPIO
The Nucleo F401RE development board has a set of Arduino compatible headers. It apparently can also be programmed using the Arduino IDE but that's something that I may try after this course.
When I tried loading the LED Blinky project for this lab, I got the following error:
Not sure why because I had loaded the device specific software packs when I installed the Keil MDK. But I went back and installed the missing pack using the Pack Manager and the IDE was happy.
The purpose of this lab is to get you familiarized with the instruction syntax for controlling the GPIO and using the Reference Documentation to locate the register definitions. The USER_BUTTON is on Bit 13 of GPIO Port C. The first thing that must be done to use Port C is enable its clock. It's common in power optimized devices for resources to initialize as disabled in order to conserve power. Here is what that clock enable register definition looks like in the Reference:
And here is the corresponding code to enable the port clock:
//Enable IO port C
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOCEN;
The lab exercise is to create a program that turns the LED on when the USER_BUTTON is pressed and turns it off when the button is released. It requires enabling of the GPIO ports and setting the direction (in or out) and pullup on the pins. Here is a short video of the program operating.