Fengchuan: FreeRTOS Transplant on NXP's KV46MCU

Fengchuan: FreeRTOS Transplant on NXP’s KV46MCU

After analyzing the source directory structure and FreeRTOS routines, we successfully migrated the latest version of the FreeRTOS source package to the NXP kinetis series KV46MCU. Our goal was to achieve a simple example, where pressing a button would light up an LED.

Preparation

  1. We downloaded the official FreeRTOS source package version 9.0.0 and unzipped it to a local computer.
  2. We equipped ourselves with an IAR computer and Tower System platform KV46, which we had repeatedly mentioned before.

Understanding the Source Directory Structure

Before transplanting the source package, it is essential to be familiar with the source directory structure. If you are not already familiar, we recommend learning about it on your own. Our routines were based on the k60 bag, and we ported them to the kv46.

The Boot Process

We know that after the first power-on, the system will run crt0.s, a simple assembly file that can be easily tracked down. This file jumps to the start function of the .c file, which disables the watchdog, initializes the system clock, and executes the user application.

Engineering Structures

To transplant the FreeRTOS demo folder, we copied the contents of the CORTEX_Kinetis_K60_Tower_IAR folder and renamed it to CORTEX_Kinetis_Kv46_Tower_IAR. We also modified the kv46_tower.h file, deleting files associated with the network, as the network is not supported on the kv46.

Header File Modification

Since the header files for k60 and kv46 are not the same, we modified the common files to include the kv46 header file. This ensured that the project configuration was correctly set for the kv46 chip.

Project Configuration Changes

We modified the project configuration to select the kv46 chip and deleted network-related files, as the kv46 does not support network communication. We also added the TWR_KV40F256 file to the project configuration.

Linked Files

We modified the linked files to use the 512K flash configuration file, which is specific to the kv46. We copied the file from the k60 profile to our common project folder and deleted the original k60 profile.

Configuration File Modification

We modified the configuration file to specify the options for the kv46 chip.

Debug Configuration

We modified the debug configuration to ensure that the system clock function was correctly set.

System Clock Function

We modified the pll_init function, which is responsible for configuring the system clock. Since the upper and k60 kv46 clock configurations are different, we had to modify the control data manually.

System Initialization Function

We modified the sysinit function to use the serial port 1, which is the only serial port supported on the kv46.

FreeRTOS Configuration Files

We modified the FreeRTOS configuration files to ensure that the hardware platform was correctly set.

Application Modification

We modified the application to configure the hardware pin and map the LED pin.

Vectors.h Modification

We modified the vectors.h file to include the LED pin mapping and other modifications.

Compile and Test

We compiled the test program and downloaded the output file to the board. We observed that pressing the SW1 button would light up the LED, proving the successful transplantation of the project from K60 to the KV46MCU.

Conclusion

After this migration process, we have successfully transplanted the project from K60 to the KV46MCU. This demonstrates that the project can be ported to other functions, such as adding Modbus communication, ADC, and other functions. We can improve the project by adding more application modules and applying it to actual development.