9 years, 5 months ago.

Good Work

Hi:

I have been using offline toolchain with GCC_ARM, it is good that the online version. Thanks for the work.

The original Teensy 3.1 pinout diagram has a lot of ambiguous information (multiple CS, etc). There is direct corresponding library in mbed for some of the pins such as TOUCH.

  1. Suggest follow pinout for LPC1768. I find that pinout conversion used by Arduino is confusing: We do not need to have extra pin names just for different functions.
  2. Change PWM to PWM0.
  3. Remove the 'Port name and Bit', e.g., PTB16.
  4. D0 should be RX1, etc.

Startup code in mbed library did not enable USB serial peripheral. Similar code using Arduino is found in https://github.com/PaulStoffregen/cores/blob/master/teensy3/usb_dev.c

Question relating to:

The PJRC Teensy 3.1 operates at CPU frequency of 96MHz. The powerful ARM-M4 Freescale MK20DX256VLH7 MCU has 256 kB of flash memory, 64 kB of RAM memory. This platform is …

1 Answer

9 years, 5 months ago.

We hope you like it!

Not quite Mbed style drag and drop programming, however as the FRDM-K20D50M board has ceased production, this does fill the gap for the K20 MCU. Double the Flash/RAM and faster!

The USB serial mode does work with the standard Mbed code. This is a test that includes a check for adding the RTC crystal:

https://developer.mbed.org/teams/CommunityContributors/code/USBSerial-RTC-HelloWorld/

After much discussion it was decided, in order to facilitate code transportation between Freescale platforms we would keep the same Pin names and definitions as much as possible. Using the Arduino pin conventions also makes it easier to transport code form other Mbed platform vendors that have the Arduino shield pin names.

We wanted to keep as much of the original graphic design to enable Arduino users to recognise the pin layout as this was not intended to be used on Mbed. So its a balance between the two.

Moving off the development board to a prototype board requires the standard manufacture pin manes to be there, PTC5, etc. The pin names are quite extensive and can be viewed in the MBED-SRC here:

https://developer.mbed.org/users/mbed_official/code/mbed-src/file/5e59b9938d4a/targets/hal/TARGET_Freescale/TARGET_K20XX/TARGET_TEENSY3_1/PinNames.h

Other pin name definitions could be added, whilst we would not want to change the existing defines, a simple 'pull request' via GitHub would be looked at by the Mbed team for a decision.

The CAN function is not yet supported and would gladly accept help with this.

Just managed to finish the pinout. /media/uploads/yoonghm/teensy_3.1_mbed_pin.jpg

The pin name in TARGET_TEENSY3_1/PinNames.h is only for TARGET_TEENSY3_1, so it would NOT affect other platforms. The original pinout diagram by Paul Stoffregen needs improvement as one cannot differentiate which CS, SCK for which SPI, etc.

From my understanding, the Serial port (appear when you plug in a Teensy 3.1 into your Microsoft Windows) is due to the code in https://github.com/PaulStoffregen/cores/blob/master/teensy3/usb_dev.c

void usb_init(void)
{
	int i;

	//serial_begin(BAUD2DIV(115200));
	//serial_print("usb_init\n");

	usb_init_serialnumber();

	for (i=0; i <= NUM_ENDPOINTS*4; i++) {
		table[i].desc = 0;
		table[i].addr = 0;
	}

	// this basically follows the flowchart in the Kinetis
	// Quick Reference User Guide, Rev. 1, 03/2012, page 141

	// assume 48 MHz clock already running
	// SIM - enable clock
	SIM_SCGC4 |= SIM_SCGC4_USBOTG;

	// reset USB module
	//USB0_USBTRC0 = USB_USBTRC_USBRESET;
	//while ((USB0_USBTRC0 & USB_USBTRC_USBRESET) != 0) ; // wait for reset to end

	// set desc table base addr
	USB0_BDTPAGE1 = ((uint32_t)table) >> 8;
	USB0_BDTPAGE2 = ((uint32_t)table) >> 16;
	USB0_BDTPAGE3 = ((uint32_t)table) >> 24;

	// clear all ISR flags
	USB0_ISTAT = 0xFF;
	USB0_ERRSTAT = 0xFF;
	USB0_OTGISTAT = 0xFF;

	//USB0_USBTRC0 |= 0x40; // undocumented bit

	// enable USB
	USB0_CTL = USB_CTL_USBENSOFEN;
	USB0_USBCTRL = 0;

	// enable reset interrupt
	USB0_INTEN = USB_INTEN_USBRSTEN;

	// enable interrupt in NVIC...
	NVIC_SET_PRIORITY(IRQ_USBOTG, 112);
	NVIC_ENABLE_IRQ(IRQ_USBOTG);

	// enable d+ pullup
	USB0_CONTROL = USB_CONTROL_DPPULLUPNONOTG;
}

Need someone who are familiar with ARM assembly language to update system_MK20DX256.c

Thank you comment from Erik and work from Paul, the USBSerial is now working. I have updated the MBED_BLINKY to include USBDevice.

posted by HM Yoong 25 Jul 2015

Sadly you need alot more code to make USB work, that is just enabling the USB peripheral. You can add USBSerial yourself by importing the USBDevice library. That allows you to do it.

While I certainly see the benefits of having USBSerial available like other targets have USBTX and USBRX, I don't think the downsides outweigh the upsides (is alot of code which needs to be copy pasted, you can't use other stuff on the USB port anymore, and it takes quite some resources while it might not always be required). So I think it is better to stick to users importing USBDevice for their serial needs.

I do think it is a good idea if this could be added to the platform page: specifically mentioning how to print serial messages to your PC.

posted by Erik - 25 Jul 2015