Lab 1 : Setup

Seneca Polytechnic
SEH500 Microprocessors and Computer Architecture

Introduction

The Freedom-K64F and Freedom-K66F are both low-cost development platforms using the NXP Kinetis series of microcontrollers based on the ARM Cortex-M4 processor.

Features K64F K66F
Microcontroller MK64FN1M0VLL12 MK66FN2M0VMD18
Speed 120 MHz 180 MHz
RAM 256 kB 256 kB
External Memory N/A microSD socket
Connectivity USB, Ethernet, Add-on Bluetooth USB, Ethernet, Add-on Bluetooth
Audio N/A Audio codec and Jacks
Sensors Accelerometer and Magnetometer
(FXOS8700CQ)
No longer populated!
Accelerometer and Magnetometer
(FXOS8700CQ)
Gyroscope (FXAS21002)
Debug OpenSDAv2
Virtual Serial Port
OpenSDAv2
Virtual Serial Port
User Components RGB LED RGB LED
Two user push buttons

Preparation

Read over the lab manual for this lab. Acquire the Freedom microcontroller board and install the necessary IDE as described in the lab manual.

Documentation of the Cortex-M4 instruction set, board user's guide, and the microcontroller reference manual can be found here:

Procedures

Firmware Update

If you are using the Freedom-K64F, you might need to update its firmware before using it with Windows 10. Even if you are not using Windows 10, updating the firmware might be a good idea.

  1. If you are using Windows OS, follow step 1-4 to disable the storage service on the Getting Started with the FRDM-K64F BUT DO NOT FOLLOW ANY OTHER STEPS.

  2. Unplug the Freedom board then hold down the "RESET SW1" button as you plug the board into your computer to enter bootloader mode.     Figure 1.1 Start in Bootloader Mode         Figure 1.1 Start in Bootloader Mode

  3. Once plugged in, if you see "BOOTLOADER", then we need to update the firmware. If you see "MAINTENANCE", then you most likely have the latest firmware and don't need to perform an update.

  4. Once in bootloader mode, copy the bootloader files below into the "BOOTLOADER" drive. The board should load the .bin file then restart into "MAINTENANCE". If the board does not restart, manually restart it by unplugging power. If "BOOTLOADER" directory is still showing, repeat the process.

    (Reference: DAPLink bootloader update)

    If the bootloader drive is not showing, try updating the bootloader using a non-Windows 10 computer. If it is still not showing up, the board might be in a bricked state. In this case, an external device must be used to flash a new bootloader. Follow the instructions here.

  5. Once you see the "MAINTENANCE" drive. Load the firmware application back onto the board using the same methods as above.

    (Reference: OpenSDA Serial and Debug Adapter)

    *** Later in the Lab, if you get an "0 SWD device available" error, this is usually due to a conflict with the firmware. To resoluve this, load the Segger Jlink OpenSDA Firmware on your board then run debug using Segger JLink as the debugger. Once a program can be uploaded onto your board, you may switch back to the DAPLink firmware.

Install IDE

  1. Install the MCUXpresso IDE from NXP (account creation required) or using Seneca MyApps. NOTE: If the board is not recognized by Windows, download the latest driver for Windows. Links to other drivers such as P&E Micro and Segger Jlink can be found here: OpenSDA Serial and Debug Adapter.

    Figure 1.2 Seneca MyApps

    Figure 1.2 Seneca MyApps

  2. Select an appropriate location to save your workspace. It must be a directory to which you have "write" permission.

    Figure 1.3 Select Workspace Directory

    Figure 1.3 Select Workspace Directory

Install SDK

  1. Once MCUXpresso opens, click "Download and Install SDK" from the quick-start menu.

    Figure 1.4 Download and Install SDK

    Figure 1.4 Download and Install SDK

  2. Filter for "K64" or "K66" depending on the version of the board you are using then install the SDK.

    Figure 1.5 Filter SDK

    Figure 1.5 Filter SDK

    Figure 1.6 Select SDK

    Figure 1.6 Select SDK

    Figure 1.7 Install SDK

    Figure 1.7 Install SDK

Import SDK Example

  1. After downloading and installing the SDK, close the welcome screen. At the bottom left Quickstart Panel, click "Import SDK example(s)...".

    Figure 1.8 Import SDK Example

    Figure 1.8 Install SDK

  2. Select the appropriate example library.

    Figure 1.9 Select Example Library

    Figure 1.9 Select Example Library

  3. Find the "hello_world" example from "demo_apps".

    Figure 1.10 Select Hello World Demo

    Figure 1.10 Select Hello World Demo

  4. Ensure "SDK Debug Console" under Project Options is selected as UART then click "Next".

    Figure 1.11 SDK Debug Console UART

    Figure 1.11 SDK Debug Console UART

  5. In the project Advanced Settings page, ensure to CLEAR the "Redirect SDK PRINTF to C library printf" option then click "Finish".

    Figure 1.12 Clear Redirect SDK PRINTF to C library printf

    Figure 1.12 Clear Redirect SDK PRINTF to C library printf

Code, Build and Debug Project

  1. By now, you should be able to see a familiar interface with a project tree on the left and a code in the middle. Take a look at the code and get an idea of what it is performing. Afterward, click "Build" at the lower left Quickstart Panel to compile the code.

    Figure 1.13 Demo Project Code

    Figure 1.13 Demo Project Code

    Figure 1.14 Build Project

    Figure 1.14 Build Project

  2. Once the project is built, click "Debug" to run the project in debug mode.

    Figure 1.15 Run in Debug Mode

    Figure 1.15 Run in Debug Mode

  3. The IDE should automatically probe for and connect to the target microcontroller board. Click "OK".

    Figure 1.16 Connect to target

    Figure 1.16 Connect to target

Serial Terminal

  1. Open a Serial terminal in the IDE by clicking on the "Terminal" tab beside the "Console" tab at the bottom of the screen. Select the appropriate COM port that the microcontroller board is connected to (check the device manager of your computer). Ensure the settings are 115200 baud rate with 8-bit data size, no parity bit, and 1 stop bit.

    Figure 1.17 Start a Serial Terminal

    Figure 1.17 Start a Serial Terminal

  2. Once the terminal is connected, press "Resume" from the debug menu and you should see "Hello World" in the serial terminal.

    Figure 1.18 Press Resume

    Figure 1.18 Press Resume

    Figure 1.19 Hello World in Serial Terminal

    Figure 1.19 Hello World in Serial Terminal

View Assembly Code

  1. Lastly, let's take a look at the assembly language code. From the project tree on the left, find the "Debug" directory. Within the directory, right-click on the .axf file then click Binary Utilities > Disassemble.

    Figure 1.20 View Disassembled Code

    Figure 1.20 View Disassembled Code

  2. A new .dis file should be created. Open the file to see the disassembled code.

    Figure 1.21 Disassembled Code

    Figure 1.21 Disassembled Code

  3. Another way to see the assembly code is to view it live during execution. To do that, at the top menu, go to "Windows > Show View > Other" and then type in Disassembly.

View the Registers Value and Memory Data during Debug

This step can only be done with a microcontroller board running during debugging.

  1. To view the register values during debugging, select the "Registers" tab beside the Project Explorer tab on the left-hand side. You should now see the register from r0-r12, sp, lr, pc, ...

  2. To view memory data, at the bottom right, select the "Memory" tab. Click the plus (+) symbol then type in the memory address you want to view. Usually, the memory area you want to view will be somewhere between 0x20000000 to 0x3FFFFFFF.

Lab Questions

Using the skills and knowledge acquired from this lab, answer the following post-lab question(s) on Blackboard.

  1. Refer to the Memory map shown in class or from Figure 4.18 of Yiu, what is the starting address and ending address of the instruction code region?

  2. In the hello_world.c example, what is the instruction address of the first line of code that it halts on once you start debugging?

Note: The instruction is at a hex address within the instruction region. You can find it in the disabled code or the Disassembly view during debug.

Hint: The main function starts at address 0x00000924.

  1. Look at the register tab, what is the value of the Program Counter (PC) when you first start debugging? Refer back to the memory map in question 1 and see if it corresponds to the proper memory region.

  2. What is the value of the Stack Pointer (SP)? Refer back to the memory map in question 1 and see if it corresponds to the proper memory region.

  3. Change the C-code to also display your name and student number within the print statement. Copy your main function onto blackboard.

  4. Run your modified code and view the result using the serial terminal. Your name and student number should now be displayed in the serial terminal. Take a screenshot of the printout and place it onto Blackboard.