Blinky LED Teensy 3.6 using KDS

Status
Not open for further replies.

forever_student

New member
Hello All,

I am trying to blink the LED on the Teensy 3.6 using the KDS (Kinetis Design Studio) but am having some difficulty. Any pointers, suggestions, or better yet, example code is much appreciated! I will try to be as complete as I can about the steps I've gone through. Please ask questions if I am not clear or thorough.

1. Installed KDS (version 3.2.0) on my mac (macOS 10.12.1) and made sure I had GNU Tools for ARM Embedded Processors
2. Started a new C project and set it up for the CPU K66F18. More specifically, "CPU_MK66FX1M0VLQ18" is defined in the project settings.
3. Skimmed the K66 Sub-family reference manual and other online resources to come up with the code below

Code:
#include "fsl_device_registers.h"

static int i = 0;

int main(void) {

	PORTC_PCR5 = PORT_PCR_MUX(0x1);   
	GPIOC_PDDR = (1<<5);
	GPIOC_PSOR=(1<<5);

	for (;;) {
		i++;
	}

	return 0;
}

4. In the Project drop down menu, I go to Properties > C/C++ Build > Settings. Then to the Toolchains tab and select the Create Flash Image box.
5. The code above builds without errors or warnings
6. I copy the .hex file from the Project Explorer window (left side) under the Debug tab and paste it in a known location (Desktop)
7. Open the Teensy Loader (1.26)
8. Reset the Teensy, select the .hex file from the Desktop, click Program, then click Reboot

What I expect to see after steps 1-8 is for the LED to be on but I have not been so fortunate.

I found two hex files online (from the PJRC site, I believe) that are called blink_fast_Teensy31 and blink_slow_Teensy31. Using the steps 7-8 I can successfully flash the Teensy and see the LED blinking. This suggests my issue is either in the project settings, code or somewhere in between.

Thank you in advance for your time and help! :)
 
Last edited:
I suppose you have a reason to use that versus Arduino. There may be a couple here who have worked with KDS, this I'm not one.

So to see - I did a search: https://www.bing.com/search?q=Kinetis%20Design%20Studio%20k66%20blink&qs=n&form=QBRE&pq=kinetis%20design%20studio%20k66%20blink

And saw this video : http://www.youtube.com/watch?v=GxTEF595tj4

There may be better starting points - but seemed like a 14 minute guided walkthrough might be a good start on similar hardware.

It is part one of three and may get you somewhere - but is using a different board that has a KDS board support package that I assume does part of what TeensyDuino install does for Arduino - providing friendly name association etc.

Also in PJRC code is the needed setup to take this bundle of potential and get it ready to run as it's default state is a boatload of disconnected parts in just ready to be told what to do condition.

For KDS - is anything done before main() is called - as there is stuff to be done. Processor speed and clocks properly set? All the stuff Paul takes care of for Teensy under Arduino?

To understand the Teensy have you done blink under Arduino? Done it with the ports as above - perhaps after doing it the Arduino way? Then you'd have a roadmap into the PJRC source tree to see what is done to make that work - i.e. the code before setup is called - and have a better understanding when you decide to move past blink.

. . . now I have a video to finish watching . . .
 
RE: Blinky LED Teensy 3.6 using KDS (or Arduino)

I suppose you have a reason to use that versus Arduino. There may be a couple here who have worked with KDS, this I'm not one.

Thank you for your reply defragster! I suppose my reasons for wanting to use KDS may be a bit naive but I wanted to work in a C environment where I had common eclipse tools. Thanks for going along with me on this.

So to see - I did a search: https://www.bing.com/search?q=Kinetis%20Design%20Studio%20k66%20blink&qs=n&form=QBRE&pq=kinetis%20design%20studio%20k66%20blink

And saw this video : http://www.youtube.com/watch?v=GxTEF595tj4

There may be better starting points - but seemed like a 14 minute guided walkthrough might be a good start on similar hardware.

It is part one of three and may get you somewhere - but is using a different board that has a KDS board support package that I assume does part of what TeensyDuino install does for Arduino - providing friendly name association etc.

That's a great tutorial! Thanks for sharing. Unfortunately, I ran into some project creation issues that weren't present in the video. More specifically, I get the error shown in the attached image when trying to create the project. I posted on the video hoping the author can give me some guidance.

Screen Shot 2016-11-12 at 10.10.43 AM.jpgScreen Shot 2016-11-12 at 10.10.43 AM.jpg

Also in PJRC code is the needed setup to take this bundle of potential and get it ready to run as it's default state is a boatload of disconnected parts in just ready to be told what to do condition.

For KDS - is anything done before main() is called - as there is stuff to be done. Processor speed and clocks properly set? All the stuff Paul takes care of for Teensy under Arduino?

Great point. I thought of this when I first couldn't get it to work. I thought I may not be initializing the stack pointer or program counter. Upon further investigation, there are startup files included in KDS. See below. I'd like to believe these are automatically running before my main but am unsure how to confirm.

Screen Shot 2016-11-12 at 10.34.56 AM.png

To understand the Teensy have you done blink under Arduino? Done it with the ports as above - perhaps after doing it the Arduino way? Then you'd have a roadmap into the PJRC source tree to see what is done to make that work - i.e. the code before setup is called - and have a better understanding when you decide to move past blink.

. . . now I have a video to finish watching . . .

That is a good idea. I've tried to do this but am met with similar issues that I have in KDS. When I try to run the Teensy example projects in Arduino (File > Examples > Teensy > Tutorial 1 > Blink) I am unable to compile for Teensy 3.6. Below is the error message I am shown.

Code:
Arduino: 1.6.8 (Mac OS X), TD: 1.30, Board: "Teensy 3.6, Serial, 180 MHz, US English"

failed MSpanList_Insert 0x30e400 0x8ca3810ede95 0x0
fatal error: MSpanList_Insert

runtime stack:
runtime.MSpanList_Insert(0x2c89d0, 0x30e400)
	/usr/local/go/src/runtime/mheap.c:692 +0x8f
runtime.MHeap_Alloc(0x2c6c20, 0x2b, 0x100000000, 0x314928)
	/usr/local/go/src/runtime/mheap.c:240 +0x66

goroutine 1 [running]:
runtime.switchtoM()
	/usr/local/go/src/runtime/asm_amd64.s:198 fp=0xc208031520 sp=0xc208031518
runtime.mallocgc(0x55b65, 0x0, 0x3, 0x7d3b1)
	/usr/local/go/src/runtime/malloc.go:199 +0x9f3 fp=0xc2080315d0 sp=0xc208031520
runtime.rawstring(0x55b65, 0x0, 0x0, 0x0, 0x0, 0x0)
	/usr/local/go/src/runtime/string.go:195 +0x93 fp=0xc208031600 sp=0xc2080315d0
runtime.slicebytetostring(0xc208298000, 0x55b65, 0x7fe00, 0x0, 0x0)
	/usr/local/go/src/runtime/string.go:69 +0x4b fp=0xc208031690 sp=0xc208031600
arduino.cc/builder/ctags.(*CTagsRunner).Run(0x2c0908, 0xc20803c510, 0x0, 0x0)
	/Users/jenkins/jenkins/workspace/arduino-builder-macosx/src/arduino.cc/builder/ctags/ctags_runner.go:72 +0x810 fp=0xc208031800 sp=0xc208031690
arduino.cc/builder.(*ContainerAddPrototypes).Run(0x2c0908, 0xc20803c510, 0x0, 0x0)
	/Users/jenkins/jenkins/workspace/arduino-builder-macosx/src/arduino.cc/builder/container_add_prototypes.go:56 +0x51a fp=0xc208031978 sp=0xc208031800
arduino.cc/builder.runCommands(0xc20803c510, 0xc208031b90, 0x1d, 0x1d, 0x1, 0x0, 0x0)
	/Users/jenkins/jenkins/workspace/arduino-builder-macosx/src/arduino.cc/builder/builder.go:187 +0x139 fp=0xc208031a08 sp=0xc208031978
arduino.cc/builder.(*Builder).Run(0xc208031d88, 0xc20803c510, 0x0, 0x0)
	/Users/jenkins/jenkins/workspace/arduino-builder-macosx/src/arduino.cc/builder/builder.go:118 +0xef7 fp=0xc208031d68 sp=0xc208031a08
arduino.cc/builder.RunBuilder(0xc20803c510, 0x0, 0x0)
	/Users/jenkins/jenkins/workspace/arduino-builder-macosx/src/arduino.cc/builder/builder.go:218 +0x49 fp=0xc208031d90 sp=0xc208031d68
main.main()
	/Users/jenkins/jenkins/workspace/arduino-builder-macosx/main.go:320 +0x1eb2 fp=0xc208031f98 sp=0xc208031d90
runtime.main()
	/usr/local/go/src/runtime/proc.go:63 +0xf3 fp=0xc208031fe0 sp=0xc208031f98
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:2232 +0x1 fp=0xc208031fe8 sp=0xc208031fe0
arduino-builder returned 2
Error compiling for board Teensy 3.6.
 
Thank you for your reply defragster! I suppose my reasons for wanting to use KDS may be a bit naive but I wanted to work in a C environment where I had common eclipse tools. Thanks for going along with me on this.

If it is only the eclipse environment, then you have to walk through all the settings. (At the moment I use Eclipse Neon.1 with some custom additions, you can find the basic instruction: https://forum.pjrc.com/threads/3656...ithout-Arduino?p=113826&viewfull=1#post113826). IMO this would also work for KDS.
You could also follow Jante's Arduino plugin for eclipse http://eclipse.baeyens.it/.

In principle, I use Paul's cores library linked into my project and GNU Arm toolchain but you could use also Paul's Arm toolchain.

Edit: just realized that, at the moment, Jante's plugin cannot be downloaded due to 'excessive downloads' so that downloads had to be blocked.
 
Last edited:
Thank you for your reply defragster! I suppose my reasons for wanting to use KDS may be a bit naive but I wanted to work in a C environment where I had common eclipse tools. Thanks for going along with me on this.

Great point. I thought of this when I first couldn't get it to work. I thought I may not be initializing the stack pointer or program counter. Upon further investigation, there are startup files included in KDS. See below. I'd like to believe these are automatically running before my main but am unsure how to confirm.

That is a good idea. I've tried to do this but am met with similar issues that I have in KDS. When I try to run the Teensy example projects in Arduino (File > Examples > Teensy > Tutorial 1 > Blink) I am unable to compile for Teensy 3.6. Below is the error message I am shown.

@forever_student - except for the c++ support - and until you add in ASM - everything done in the Arduino IDE is nothing but "C"!

I went back to the video - KDS IIRC even uses the same GCC toolchain?

And in unpausing the video after posting after the 'KDS board support package' section it goes into Processor Expert - then he proceeds into what looks like Windows style Visual Studio helper handholding to program a port bit negation on a microcontroller!?!?

So that was funny - but the mile of stuff in his program and all the VStudio style menus and options needed to get there through 'Processor Expert' just showed that the simple code in Post 1 was missing all of that - so without that I suspect there is no support of setup code done before the main().

The KDS no doubt has its place - specific support for any processor soldered to a board - then you have to inform the KDS how it is connected. The example Freedom board for K64 is shown in that video. So in that video where he starts is where you start with Teensy in Arduino. Except Paul has spent years working to perfect a USB stack and collecting (with his work and that of others here or as noted), customizing and optimizing numerous other libraries like Serial, SPI, i2c for generic buses and specific devices. The only thing not yet done would be the processor debug support - because it isn't commonly needed by Arduino users and they haven't yet published their spec and first pass for Paul to fix and improve - though the hardware is waiting for that - or already hackable to do that.

Anyhow - as WMXZ notes - some here do use Eclipse directly with Paul's work and that would be a better path if you want Eclipse. If you got KDS to blink like in the video on KDS - that is about all you'd have as far as the general utility of the Teensy hardware as supported for Arduino IDE. There are other IDE's usable or in use - Visual Studio with Visual Micro add on works and some others - but I haven't picked one yet. KurtE mentioned one the other week - I need to go find that and see if he got it working.

Probably best to get the hang of current Arduino IDE and TeensyDuino to make your Teensy work - and it is all just 'C' that can do amazing things without spending an amazing amount of time to get started. Also because the real support here is for that toolset as the common denominator.

<edit>: This is what KurtE was looking at :: Sublime-Text-as-an-Arduino-IDE-replacement
 
Last edited:
For example to BLINK the builtin LED here is a decent Teensy "Arduino" way that I use - though you can do low level Teensy port twiddle as well (thanks FrankB):
Code:
#define qBlink() (digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN) ))

OR: 
#define qBlink() {GPIOC_PTOR=32;} // Toggle LED_BUILTIN   GPIOC_PTOR = (1 << 5);
 
Thank you WMXZ and defragster for your help! I think I am going to jump into the Arduino environment for a while, then revisit the KDS with a better understanding of the K66.

Thanks again!
 
That should make for a better start. Unless you hack your Teensy you won't have the KDS debugger to show where you are. The Arduino environment and utilities with Teensy are stable enough to use a Blink and USB Serial to make incremental steps to pinpoint your problem areas. With KDS you won't have that working to fall back on - unless you find a way to get it working with the Teensy stackof stuff, I imagine even getting a simple serial port on line [Serial1 etc ] will be tough enough, so you'd need a good set of debug LEDS to track your location and progress.
 
Hi,

I know this thread is a few months old now but I just wanted to add that I now have a valid, working Kinetis Design Studio project for the Teensy 3.6 - mimicking the Blinking LED example.

I'm new to the Teensy world but very familiar with the Kinetis micro-controllers and tools. The project builds using the latest version of KDS but uploads using the standard Teensy uploader.

If anyone thinks it may be still relevant, I can upload the example project to this thread but please do let me know.

Thanks,
Kevin
 
Hi,

I know this thread is a few months old now but I just wanted to add that I now have a valid, working Kinetis Design Studio project for the Teensy 3.6 - mimicking the Blinking LED example.

I'm new to the Teensy world but very familiar with the Kinetis micro-controllers and tools. The project builds using the latest version of KDS but uploads using the standard Teensy uploader.

If anyone thinks it may be still relevant, I can upload the example project to this thread but please do let me know.

Thanks,
Kevin

Hey Kev,

I would like to see example project as i am trying to move from Arduino to KDS.
Thanks is advance
 
Please post code!

Hi,

I know this thread is a few months old now but I just wanted to add that I now have a valid, working Kinetis Design Studio project for the Teensy 3.6 - mimicking the Blinking LED example.

I'm new to the Teensy world but very familiar with the Kinetis micro-controllers and tools. The project builds using the latest version of KDS but uploads using the standard Teensy uploader.

If anyone thinks it may be still relevant, I can upload the example project to this thread but please do let me know.

Thanks,
Kevin

Please post the code for this application.
 
Status
Not open for further replies.
Back
Top