Author Topic: Getting Started with Teensy 3.1/3.2 mk20dx hw  (Read 10771 times)

Offline Chris

  • Newbie
  • *
  • Posts: 10
    • View Profile
Getting Started with Teensy 3.1/3.2 mk20dx hw
« on: November 28, 2017, 11:39:30 PM »
Hello,
I am attempting to build in KDS IDE for mk20dx teensy 3.1/3.2 based hw.
so far i have not been able to get the project to compile properly.
the 'Bare Minimum' configuration builds but doesn't appear to work when loaded to the chip.
I am a little confused about how to configure the others. It seems the main project is missing teensy configuration in config.h

Just hoping to get some help getting started.
ultimately I am hoping to have a loader I can use which will allow for rawHID for application commands and debugging while normally appearing to the system as MSD
Is there any chance you could provide the projects you used to build the examples here http://www.utasker.com/kinetis/TEENSY_3.1.html ?
https://www.youtube.com/watch?v=K8ScSgpgQ6M was helpful to get me going but I am still missing something hopefully simple.

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Getting Started with Teensy 3.1/3.2 mk20dx hw
« Reply #1 on: November 29, 2017, 12:23:42 AM »
Chris

Are you using the Open Source or Professional version?

In the serial loader and application projects there is always a target called TEENSY_3_1.

The "bare-minimum" application will not work without a loader combined with it so it is best to start with the "flash" one since it is easiest for first steps.

The serial loader and the application on the Teensy 3.1 page were built using the Open Source version so you have all code in the project that you have.

There is also a step-by-step written guide to using KDS at http://www.utasker.com/kinetis/compilers.html#KDS  where I also add latest known issues and their workarounds.

In case of a build problem please show the console output since the reason for it will be shown there.

Regards

Mark

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Getting Started with Teensy 3.1/3.2 mk20dx hw
« Reply #2 on: November 29, 2017, 03:47:04 AM »
Chis

In the meantime I have seen that you are using the professional version and I checked the Teensy 3.1 build and had a build error (in the setup that I checked), which may be what you encountered.

In the file kinetis_PORTS.h

I modified
#if (PORTS_AVAILABLE > 3) && (defined irq_PORT_B_C_D_ID || defined irq_PORTBCD_E_ID || defined irq_PORTD_ID) && !defined NO_PORT_INTERRUPTS_PORTD // if port D support has not been removed

to
#if (PORTS_AVAILABLE > 3) && (defined irq_PORT_B_C_D_ID || defined irq_PORTBCD_E_ID || defined irq_PORTD_ID || defined irq_PORTC_D_ID) && !defined NO_PORT_INTERRUPTS_PORTD // if port D support has not been removed

to solve this.

The K20 used on the Teensy 3.1 board has shared port interrupts on ports C and D but the array of interrupts callbacks for port D bits was missing (if port interrupt were enabled). I checked in the change into the repository too.

Tell me if this was the error or whether you have something else.

Good luck

Regards

Mark


Update: In fact I made a mistake because this is true for the KL26 used on the Teensy LC and not the K20 used on the Teensy 3.1.
The correction is still useful in that case but is not an explanation of a possible build error with the Teensy 3.1.
My mistake - sorry for the false alarm!




« Last Edit: November 29, 2017, 05:55:11 PM by mark »

Offline Chris

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Getting Started with Teensy 3.1/3.2 mk20dx hw
« Reply #3 on: December 05, 2017, 10:14:25 PM »
hey mark,
Thanks for getting back so quickly!

I have been attempting to build the uTaskerV1.4_FLASH configuration based on your input but now i am getting
"../Hardware/Kinetis/CMSIS_DSP/core_cm4.h:103:8: error: #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)""
Commenting the #error make it compile but not surprisingly it doesn't run beyond enumerating a USB serial device...

Taking a glance at the MK20DX256 manual it appears to not have an FPU. considering this, I attempted to change the FPU but without any luck.

"toolchain default" results in '../arm-none-eabi/bin/ld.exe: error: uTaskerV1.4.elf uses VFP register arguments, ../arm-none-eabi/lib/armv7e-m\libm.a(lib_a-wf_sqrt.o) does not'

can you give me a direction here? this should be basic stuff but i am struggling. thanks again


Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Getting Started with Teensy 3.1/3.2 mk20dx hw
« Reply #4 on: December 06, 2017, 04:08:15 AM »
Hi Chris

Open the property settings in KDS ("Project | Properties") and check that you have set the ARM family (in Target Processor) to cortex-m4. Also check that the option "Float ABI" is set to "Toolchain default", and not to "FP instructions (hard)".

The K20N on the Teensy does not have the FPU option (K20FN) so it needs to use software library for floating point operations (in case they were used).

When built with the FPU setting one see (in the console):
Invoking: Cross ARM C Compiler
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Os
...

when without one sees:
Invoking: Cross ARM C Compiler
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -Os
...

It is also best to do a clean after changing settings to be sure that all is rebuilt correctly.

Note that the project itself knows whether there is an FPU available based on the define KINETIS_K_FPU, which sets the GCC "#define __FPU_PRESENT  1" when on. When not, this will be missing and so the GCC compiler will recognise that there is a settings mismatch, as you saw.

After this you should be OK. I just checked the KDS Teensy build with and without FPU setting and had the same error message as you - after removing (and a clean) it build.

Good luck

Mark

Offline Chris

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Getting Started with Teensy 3.1/3.2 mk20dx hw
« Reply #5 on: December 20, 2017, 08:05:53 PM »
hey mark,
Thanks again my initial problem was as simple as making sure I started from a clean build. It seems KDS is very buggy or maybe I am just not used to clean builds being so important.

Even after getting the serial loader project to build I still haven't been able to get it to function correctly.
Using my initial pull I was able to get it to compile and load with USB CDC

> bc
Checking Flash... EMPTY!
> ld
Please start S-REC download: ...

Terminated - restarting...bc
Checking Flash... EMPTY!

It appears to accept the SREC but it never actually writes the data to flash. upon reset the application area is still empty
same result if i use my blinky.srec or the example 8080 srec you provided here http://www.utasker.com/kinetis/TEENSY_3.1.html so i dont think its a matter of the srec not being valid although interestingly enough if i change the config to MSD it will take the .bin and no longer run the loader but still not blink like it does when using all the example files you provide for loader and app

I wanted to start fresh so that i could document every step but it seems substantial changes have been made to the repo in the last few weeks which make it so now i cant even get to the non-functional version from above...

clone latest repo
copy kds settings files from \uTasker-GIT-Kinetis\Applications\uTaskerV1.4\KinetisDesignStudio\Project_Settings\ to \uTasker-GIT-Kinetis\

in KDS version 3.2.0
file -> import
   General -> Existing Projects into Workspace
   select projectroot\
   
Projcect Properties
   C/C++ General -> Indexer  -- check 'enable project specific', 'Use active build configuration' **do this every time reopened
   C/C++ Build -> Settings -> Target Processor -- change arm family to 'cortex-m4', set 'Float ABI' to 'Toolchain default' for all configs
   C/C++ Build -> Settings -> Cross ARM C++ Linker -> General -- change linker script to "${uTaskerLinkerScripts}/K_256_64.ld"
   
Applications -> uTaskerSerialBoot -> Config.h
   uncomment    //#define TEENSY_3_1 
   comment    #define FRDM_K64F
   
   
Set Build configuration to 'uTaskerSerialLoader_FLASH'
Project -> Clean -> Clean All


attempt to clean up assumed in progress updates... TO NO AVAIL
comment the following lines
   /Hardware/Kinetis/kinetis_ENET.h:426: undefined reference to `fnMagicFrame'
   /uTasker/Driver.c:284: undefined reference to `fnNetworkTx'
   /stack/Ethernet.c:199: undefined reference to `fnGetEthernetPars'
   /stack/arp.c:554: undefined reference to `network'
   /stack/arp.c:518: undefined reference to `network'
   /stack/dhcp.c:483: undefined reference to `fnGetDHCP_host_name'
   /stack/dhcp.c:516: undefined reference to `network'
   /stack/dhcp.c:670: undefined reference to `network'
   /stack/arp.c:551: undefined reference to `network'
comment the following entire functions      
   extern void fnTaskEthernet(TTASKTABLE *ptrTaskTable)
   static int is_subnet(unsigned char *new_ip)
   static void fnSendDHCP(unsigned char ucDHCP_message, int iNetwork)
   extern ARP_TAB *fnGetIP_ARP(unsigned char *Search_IP, UTASK_TASK OwnerTask, USOCKET Socket)
   static void fnStateEventDHCP(unsigned char ucEvent, int iNetwork)
   extern void fnDHCP(TTASKTABLE *ptrTaskTable)
   extern signed short fnSendIPv4(unsigned char *prIP_to, unsigned char ucProtType, unsigned char ucTypeOfService, unsigned char ucTTL, unsigned char *dat, unsigned short usLen, UTASK_TASK Owner, USOCKET cSocket)
   static void fnSendARP_request(ARP_TAB *ptrARPTab)
   extern signed short fnSendTCP(USOCKET TCP_socket, unsigned char *ptrBuf, unsigned short usDataLen, unsigned char ucTempFlags)


still nothing...  I really need to get to a point where I can compile a working loader maybe i am missing something in the config.h to properly turn off the immense amount of networking errors i am getting now?

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Getting Started with Teensy 3.1/3.2 mk20dx hw
« Reply #6 on: December 20, 2017, 09:25:01 PM »
Chris

Quickly to the point of the missing Ethernet functions:
If you select the TEENSY 3.1, which has no Ethernet, these should not be included. Check whether ETH_INTERFACE is enabled somewhere.
When I check I don't get this problem so can't explain at the moment how it is on.

Search for the following in config.h in the serial loader directory:

#if !defined DEVICE_WITHOUT_ETHERNET
    #if !defined TEENSY_3_5 && !defined TEENSY_3_6 && !defined HEXIWEAR_K64F && !defined HEXIWEAR_KW40Z
        #define ETH_INTERFACE                                            // enable Ethernet interface driver
    #endif
    #if defined FRDM_K64F
      //#define ENC424J600_INTERFACE                                     // 10/100 Ethernet connected via SPI (also ENC624J600 in larger package with more parallel modes)
      //#define USE_SIMULATION_INTERFACE                                 // work with a remote simulation interface (remove when not present)
      //#define REMOTE_SIMULATION_INTERFACE                              // FRDM-K64 being used in remote simulation mode as HW interface to the simulator
      //#define NO_INTERNAL_ETHERNET                                     // disable Ethernet on the internal controller
    #endif
#elif defined TEENSY_3_1
  //#define ETH_INTERFACE                                                // enable Ethernet interface driver
  //#define ENC424J600_INTERFACE                                         // 10/100 Ethernet connected via SPI (also ENC624J600 in larger package with more parallel modes)
#endif


Since the K20 has no internal Ethernet the first block is always false.
There is a possibility to use an external Ethernet controller with the Teensy board by enabling ETH_INTERFACE and also ENC424J600_INTERFACE but there are no versions in the repository that do that (since it requires extra HW).

We need first to work out how you can have seemingly different content that the repository one to get this error.

I'll look into the other issues in the meantime.

Regards

Mark

Offline Chris

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Getting Started with Teensy 3.1/3.2 mk20dx hw
« Reply #7 on: December 20, 2017, 10:10:08 PM »
you're on point!

ok that section of my config.h matched. so just to be safe I re-cloned and re-setup the project. using the same steps. crazy enough, it doesn't give the network errors anymore but it also doesn't enumerate the USB when loaded to a board. I assume you updated the repo? otherwise i am not sure why I would be getting different results.

Offline Chris

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Getting Started with Teensy 3.1/3.2 mk20dx hw
« Reply #8 on: December 20, 2017, 10:20:45 PM »
NVM yet another KDS bug. for some reason it didnt save my change to the linker script.. now i am back to the point where It attempts to load a program via CDC s-record but doesnt actually commit to flash. steps to reproduce

#*** Testing uTasker Serial Loader ***

clone latest repo
copy kds settings files from \uTasker-GIT-Kinetis\Applications\uTaskerV1.4\KinetisDesignStudio\Project_Settings\ to \uTasker-GIT-Kinetis\

in KDS version 3.2.0
file -> import
   General -> Existing Projects into Workspace
   select projectroot\
   
Projcect Properties
   C/C++ General -> Indexer  -- check 'enable project specific', 'Use active build configuration' **do this every time reopened
   C/C++ Build -> Settings -> Target Processor -- change arm family to 'cortex-m4', set 'Float ABI' to 'Toolchain default' for all configs
   C/C++ Build -> Settings -> Cross ARM C++ Linker -> General -- change linker script to "${uTaskerLinkerScripts}/K_256_64.ld"
   
Applications -> uTaskerSerialBoot -> Config.h
   uncomment    //#define TEENSY_3_1 
   comment    #define FRDM_K64F
   
   uncomment   //#define USE_USB_CDC
   comment      #define USB_MSD_DEVICE_LOADER
   
Set Build configuration to 'uTaskerSerialLoader_FLASH'
Project -> Clean -> Clean All


***RESULTS***
bc
Checking Flash... EMPTY!
> ld
Please start S-REC download: ...

Terminated - restarting...bc
Checking Flash... EMPTY!
> bc
Checking Flash... EMPTY!
>



Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Getting Started with Teensy 3.1/3.2 mk20dx hw
« Reply #9 on: December 21, 2017, 12:46:15 AM »
Chris

Please remove this define from the TEENSY_3_1 section in config.h
#define SPECIAL_VERSION                                              // temporary special version with some specific setups

It was stopping the LED flashing and also locating the application to a different address.

Sorry if this has caused confusion - it shouldn't have been left enabled!

I just verified USB-MSD loading on the HW and will repeat with the USB-CDC case now.

Regards

Mark

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Getting Started with Teensy 3.1/3.2 mk20dx hw
« Reply #10 on: December 21, 2017, 01:07:18 AM »
Chris

To work with the USB-CDC loader the application start address needs to be changed to 0x8000 (from 0x8080).
This is because the USB-MSD setup reserves 0x80 at the start to save the file object, which can then be displayed when connecting again. The USB-CDC case doesn't insert this.

I have attached a linker script (for application) with this setup as reference.
It was necessary for me to also disable INTERMEDIATE_PROG_BUFFER setting but I will check-in a version that will do this automatically when USB-CDC is used alone (INTERMEDIATE_PROG_BUFFER is required only by SREC loading over UART).

My tests were then successful.

Regards

Mark

P.S. Note that USB-MSD and USB-CDC as composite is not supported. I would expect that USB-MSD to be the predominant use.
« Last Edit: December 21, 2017, 01:12:23 AM by mark »

Offline Chris

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Getting Started with Teensy 3.1/3.2 mk20dx hw
« Reply #11 on: December 21, 2017, 03:51:47 AM »
great success!
It would have taken me ages to sort that out without your help thank you very much!

Offline Chris

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Getting Started with Teensy 3.1/3.2 mk20dx hw
« Reply #12 on: December 22, 2017, 03:27:31 AM »
Hey Mark,
What parameters would I need to define to utilize the KBOOT HID Functionality?
I had read on the NXP community page that this was supported for teensy 3.1?

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Getting Started with Teensy 3.1/3.2 mk20dx hw
« Reply #13 on: December 22, 2017, 03:48:30 PM »
Chris

These two defines enable the KBOOT mode on USB (can be used in parallel with other USB methods):

        #define HID_LOADER                                               // Freescale HIDloader.exe or KBOOT compatible
            #define KBOOT_HID_LOADER                                     // select KBOOT mode of operation (rather than HIDloader.exe)


However I don't know whether it works with the latest KBOOT version since I think that NXP has changed some things in it (recently).
KBOOT mode hasn't generally proven to be very popular so I haven't done any testing of it for some time. Older KBOOT versions were however always good.

Regards

Mark



Offline Chris

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Getting Started with Teensy 3.1/3.2 mk20dx hw
« Reply #14 on: December 22, 2017, 07:13:53 PM »
Thanks again mark!
I can confirm working operation with the latest NXP_Kinetis_Bootloader_2.0.0 package(REV 2.0)

It does not like to identify the chip
Collecting device information......
Error: Update status failed(invalid vector<T> subscript).

but going straight to hitting the update button works as expected
Start update progress......
No device is connected!
Try to connect device......
Connected to device successfully!
Get device security state successfully(UNSECURE).
Updating image......
Update image successfully!
Reset device successfully!
Update process is completed.