element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Freedom development platform
  • Products
  • Dev Tools
  • Freedom development platform
  • More
  • Cancel
Freedom development platform
Blog FRDM-KL46Z - Getting Started #2 - Using Processor Expert
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Freedom development platform to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: shabaz
  • Date Created: 25 Aug 2013 8:44 PM Date Created
  • Views 1711 views
  • Likes 1 like
  • Comments 7 comments
  • freedom_development_platform
  • freedom-board
  • freescale
  • freedom_board
  • kl46
  • frdm
  • frdm-kl46z
  • freedom
Related
Recommended

FRDM-KL46Z - Getting Started #2 - Using Processor Expert

shabaz
shabaz
25 Aug 2013

(See here for part 1: Quick Review and Getting Started with the FRDM-KL46Z  )

 

This post is to document some quick initial experiments with using the  FRDM-KL46ZFRDM-KL46Z board from Freescale

After you’ve run the (very nice) demo, you’ll probably want to write your own code for it, to get to the classic blinking LED stage.

Is it difficult?

It contains an ARM processor so initial setup will be more tricky than small microcontrollers such as PIC/AVR where pretty much one sets up a data direction register (DDR) and then writes or reads a port register to control pins. Depending on the processor type you could be looking at configuring a peripheral identification address, a whole range of attributes (such as pull-up or deglitch modes) and initialising values. This instantly makes it look a lot more difficult to use ARM devices over smaller processors. Another point is that microcontrollers can contain more complex peripherals (such as ADCs and PWM) which may have tens of registers (each with 32 bits!) for configuration and it may take many hours to get up-to-speed with the details of it from the reference guides.

Can it be simplified?

Freescale offers a software product called Processor Expert that is supposed to help remove some of this pain by providing drag-and-drop ‘components’ which will auto-generate the appropriate set-up code.

The earlier post describes how to install CodeWarrior briefly and use it to compile an example application This current post records an attempt to use CodeWarrior with Processor Expert(called PE from now on below to start a new project Although this was done on a  FRDM-KL46ZFRDM-KL46Z board the concept should be board and processor independent(as long as it is a Freescale processor type

Getting Started - New Project Wizard

Assuming you have already installed CodeWarrior and set up a workspace location (see the post referred to earlier for more information), you can run CodeWarrior and it should display a welcome screen (if you’ve already closed the welcome screen, you can re-open it using Help->Welcome). Click on the New Project Wizard.

image

Select a project name (e.g. my-frdm-test). Then, navigate the ‘L’ series until you locate the correct microcontroller for the KL46Z board.

image

At the next step, deselect P&E and select OpenSDA:

image

Click Next until you see a ‘Rapid Application Development’ screen. Here you can enable PE:

image

You may see this message occasionally with Eclipse. Just wait for it to disappear.

image

Hardware Perspective

CodeWarrior should by now display a screen similar to this. This is called Hardware Perspective and there is also a C/C++ perspective which can be selected from the top-right.

image

Within each perspective there is a lot of content (need a big screen!) with each pane known as a view. If you move things and accidentally end up with a messed-up perspective, you can restore the original by going to Window->Reset Perspective.

The processor in the center is a BGA version which doesn’t match the FRDM board, so click next to the CPU type as shown in the screenshot above and select the 100-pin LQFP version.

image

There is an asterisk next to the processor tab name, which means the file is now modified, so save it.

image

C/C++ Perspective

If you now go to the C/C++ perspective, you’ll see a screen like this:

image

The important bits are marked. At the top left marking, you can see the open project name. This 'CodeWarrior Projects' titled pane (or View as mentioned earlier) is important because it contains the project names and files. It is possible to open or close any project visible here by right-clicking on it. When building a project (explained later), make sure that you have selected a project in this view first, before executing Project->Build Project. It is not something you need to do just yet.

In the screenshot above you can see that underneath the CodeWarrior Projects view/pane is a Components view which currently just contains the processor that was added. When selected, you’ll see the relevant attributes in the Component Inspector view. The Components Library view allows you to add additional items (such as an ADC). However, it is possible to do all this in the Hardware Perspective, so go back there for now.

Adding a Component

Back in the Hardware Perspective, the Components Library may have moved, to the bottom of the screen as shown in the screenshot below. If you can’t see it, go to Window->Show View->Components Library.

image

There are different ways of finding the feature that you want to add. In this example, go to Assistant and then scroll down to Digital input/output, double-click to see a Standard I/O folder and then double-click that to select Individual pins as shown here, and then right-click on it and select Add to Project.

image

Configuring the Component

Now that the feature has been added to the project, it can be configured using the Component Inspector which by default is at the top right:

image

The attributes like pin direction are listed, and the values can be modified by clicking on them. This is the basic view, but some hidden attributes may appear by clicking on Advanced or Expert. It is not needed in this case. There is also a graph-like icon that provides an alternate view that looks like this:

image

Clicking on the graph icon again reverts back to the original non-graph view. Use whichever one you feel comfortable with.

Looking at the  FRDM-KL46ZFRDM-KL46Z schematic it can be seen that a red LED is wired here to a pin(pin 26 marked PTE29/CMP0IN5

image

Using this information it is possible to set the attributes until they look like this (I encountered a bug in the graphical view where it would display a red exclamation point even when there was no conflict, so I had to use the non-graph view).

Notice that in the diagram you can see a symbol showing Port E is now in use on that pin (pin 26). The Components view will also show the feature that was added. Since there is an asterisk on the Component Inspector view, save the change.

image

The initial value was set to zero, which means the LED will be lit (LED cathode is being controlled according to the circuit).

Using the Component in your Code

At this point, go back to the C/C++ Perspective and click Project->Build Project (don’t forget to select the project in the left side view first). Build Project will (amongst other things) perform these steps behind the scenes:

1. It will take the output from PE, auto-generate C files and compile them

2. It will compile your own code

3. It will link up all the individually-compiled files and make a single executable file that you can download to the board.

 

At this stage, although everything above will occur, we are only interested in using the Build Project for item 1 listed above, because we want to see the auto-generated files as a result of adding the 'Individual pins' I/O component earlier.

 

You’ll see in the Generated Code folder that some new files got created:

image

To use the feature, you’ll need to know what functions and events you can make use of. There are several ways to do this. One way is to right-click on the component and select Help on Component. There is lots of information including examples for many peripherals.

image

Another way is to click on Methods in the Component Inspector and you’ll see a list of them all, as shown here:

image

Or, you could double-click on the generated code files, and inspect the comments in the header file, or look at the C source file. Yet another way is to just hover over the names in the Components view, and some help will float on top.

The main() function actually has already been created, it is in a file under Sources called ProcessorExpert.c and if you open the file you can scroll down to it and find where it says ‘Write your code here’.

image

At that location, it is possible to drag the PutVal method directly into the C file.

image

The screenshot above shows what happens when you drag it across. The floating text occurred by hovering over the method in the Components view and it shows that a single parameter (bool Val) is required. The code was tidied up to look like this (a while loop to blink with a delay):

 

/* Write your code here */

/* For example: for(;;) { } */

int ledstate=0;

int i;

while(1)

{

     Bit1_PutVal(ledstate);

     ledstate=ledstate^1;

         for (i=0; i<100000; i++);

} 

  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/

 

Then, the code was saved and the project built again.

Creating an S-Record File

An S-record file (.srec) is needed for downloading into the board, but by default CodeWarrior doesn’t produce this, and only generates an ELF (.elf) file. There is an excellent site here that shows a way to create the .srec file this but sadly it didn’t work for me; it may work for you.

The workaround is to manually generate the file. To do this open a Windows Command prompt and navigate to your workspace and then to my-frdm-test/FLASH. You will see a file called my-frdm-test.elf was created during the build process. You can type this commands to convert to the S record format:

 

"C:\Freescale\CW MCU v10.4\Cross_Tools\arm-none-eabi-gcc-4_7_3\arm-none-eabi\bin\objcopy.exe" -O srec my-frdm-test.elf my-frdm-test.srec

 

Running the Code

You can now run it on the FRDM board by just plugging in the board and dragging the file to the USB drive:

image

The LED should now flash.

I also tried another peripheral that should have been straightforward (LCD peripheral) but it failed to work for me, and the reason is due to the fact that although many of the peripherals are simple to configure using PE, one that is difficult is the processor CPU itself, where there are many options for setting the clocks for example. I suspect my LCD wasn’t being clocked properly (it was extremely faintly turned on, so it had configured to some extent) or I had mis-programmed the voltage sources for the LCD. (EDIT: I figured out the LCD in the end - will write up the Processor Expert settings for it) It would be nice for Freescale to provide the PE settings for the processor CPU for the KL46Z board, so we don’t need to wade through dozens/hundreds of pages to deduce it.

Conclusions

Processor Expert does make things simpler; in this case, the 1000-page reference manual did not need to be consulted at all to make use of I/O. Clearly that will not be the case with more sophisticated peripherals where the reference manual will be needed but it always helps to have an expert system to double check your pin assignments and config register settings make sense for a peripheral.

It will greatly reduce the risk of bugs in register programming, and will help get programs running quicker.

  • Sign in to reply

Top Comments

  • mcb1
    mcb1 over 12 years ago +1
    shabaz Very nice and clear step by step instruction. I presume the "Build-Project" is a way to piece all the bits together for the software, which then allows you to write using those pieces.? Rather like…
  • shabaz
    shabaz over 12 years ago in reply to mcb1 +1
    Hi Mark, Thanks! I wanted to document while it was fresh in my head, because I know I will have to relearn this again in a few days time if I don't! I should have mentioned that part in some more detail…
  • shabaz
    shabaz over 12 years ago in reply to mcb1 +1
    It took a few hours, but I eventually figured out the PE settings in order to use the LCD component. It turns out I was misinterpreting how to use the function that selects which segments to display. I…
  • shabaz
    shabaz over 12 years ago in reply to Former Member

    Thanks for the message! I'm glad you found it useful.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 12 years ago

    Great tutorial. Thank for your post and keep going bro

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 12 years ago in reply to mcb1

    Hehe yes, I had some bare (non-I2C) LCDs lying around, but it does make life difficult for no reason! It's a lower-priority thing for me, I'm just glad about the on-board one, since it will be very ideal for status/debug.

    So, that's very basic pin manipulations and LCD sorted, the next few useful things could be ADC/DAC and some USB devices so we can send commands or log data to a PC or become host mode (although that would require some adapter cable which I don't have).

    Agree, the lack of headers is depressing! :-)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 12 years ago in reply to shabaz

    shabaz

    I don't suppose you have a I2C display to drive.?

    Mind you with all the I/O available, saving on pins is not required......

     

     

    My KL46z's arrived today, unfortunately they didn't come with headers image

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 12 years ago in reply to mcb1

    It took a few hours, but I eventually figured out the PE settings in order to use the LCD component. It turns out I was misinterpreting how to use the function that selects which segments to display. I'll type it up in a day or two (I'm interested in driving a bigger display, so I will also try that if I get time).

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube