Alternative controller experiments

User avatar
Oobly

24 Sep 2015, 09:25

I believe the Freescale Kinetis MKL range can do USB fine without a crystal, you just have to initialise it to use the internal 48MHz clock and enable the USB clock recovery feature: cache.freescale.com/files/microcontrollers/doc/app_note/AN4905.pdf

"3.1 USB device mode clocking initialization using 48 MHz IRC
Follow the steps below to configure the USB module to use the 48 MHz IRC as its clock source and enable the clock
recovery feature.
1. Enable the peripheral clock to the USB module by setting the SIM_SCGC4[USBOTG] bit.
2. Select the 48 MHz IRC as the optional peripheral clock by setting the SIM_SOPT2[PLLFLLSEL] field to 0x3.
3. Configure the USB clock source to use the clock selected by the PLLFLLSEL field instead of the USB_CLKIN pin by
setting the SIM_SOPT2[USBSRC] bit.
4. The USB clock passes through a programmable fraction divider controlled by the SIM_CLKDIV2 register. The default
value of this divider is the desired divide by one, so this register should not need to be modified.
5. Enable the 48 MHz IRC clock (set USB_CLK_RECOVER_IRC_EN[IRC_EN]).
6. Enable the USB clock recovery feature by setting USB_CLK_RECOVER_CTRL[CLOCK_RECOVER_EN].
7. Continue with regular USB device mode initialization."

For this and other reasons I've been designing a board using the MKL26z chips like the TeensyLC uses, but I haven't got very far yet. I will be following this thread closely and hopefully be able to add info now and then as my design progresses. I'd rather not have to use an external chip like the Teensy does for the bootloader.

User avatar
flabbergast

24 Sep 2015, 09:40

Yes, Freescale KL2x chips can do crystal-less USB just fine (I have been just playing with a FRDM-KL25Z board). They're pretty much the same (to use) as K20x chips (e.g. Teensy 3.*, infinity keyboard, mchck); the USB peripheral is actually the same. So, you're going to either have to write your own bootloader, or adapt either the mchck or kiibohd bootloader to KL26Z. (Or buy one of the KL02Z "bootloader chips" from Paul.)

twiddle

24 Sep 2015, 09:43

For what it's worth, here's a list of the Kinetis devices with a bootloader preinstalled, either in flash for one-time use or in ROM:
http://www.freescale.com/products/arm-p ... ader:KBOOT

User avatar
flabbergast

24 Sep 2015, 11:48

Thanks, I didn't know about this page. It seems that KL27Z does have a bootloader in ROM - Good! Finally, Freescale. If it works reasonably, it might end up being the ideal chip for keyboards. Also using it should be an easy upgrade from KL26Z/Teensy LC. (Hopefully there'll be a LQFP-48 version of the KL27Z line, LQFP-64 are getting too big for my taste ;)

User avatar
Oobly

24 Sep 2015, 13:16

flabbergast wrote: Thanks, I didn't know about this page. It seems that KL27Z does have a bootloader in ROM - Good! Finally, Freescale. If it works reasonably, it might end up being the ideal chip for keyboards. Also using it should be an easy upgrade from KL26Z/Teensy LC. (Hopefully there'll be a LQFP-48 version of the KL27Z line, LQFP-64 are getting too big for my taste ;)
Wow! Awesome find. I'm probably going to switch to the 27 then, too. Another requirement for me (and the reason I switched away from ATMega32U4) is I need 2 hardware I2C/SPI lines. Lovely. They have QFN 32 and 48 pin versions, but I think only 64 pin LQFP. Or if you really want to have fun, 36 and 64 pin BGA.

User avatar
Oobly

24 Sep 2015, 14:52

Ah, bollocks! Seems the MKL27z doesn't have the voltage regulator built in like the 26z does. So it needs external 3.3v power supply. I may stick with the 26z if I can get a good bootloader working.

twiddle

24 Sep 2015, 15:09

Hey Oobly, check http://cache.freescale.com/files/32bit/ ... leExt=.pdf - thats the MKL27 I've successfully prototyped using its inbuilt regulator.
Not sure where you're looking but the datasheet I'm linking clearly shows a VREGIN pin which takes the 5V USB power rail.

User avatar
Oobly

24 Sep 2015, 15:24

twiddle wrote: Hey Oobly, check http://cache.freescale.com/files/32bit/ ... leExt=.pdf - thats the MKL27 I've successfully prototyped using its inbuilt regulator.
Not sure where you're looking but the datasheet I'm linking clearly shows a VREGIN pin which takes the 5V USB power rail.
Beautiful! I think this is the perfect chip for my use case! Thank you for the info.

User avatar
flabbergast

25 Sep 2015, 12:22

flabbergast wrote: Yes, Freescale KL2x chips can do crystal-less USB just fine (I have been just playing with a FRDM-KL25Z board).
I have to correct myself... Contrary to what I thought I've actually not been playing with KL25Z crystal-less. I'll try later today and report.

By the way, Freescale is slightly misinforming about the crystal-less USB. That application note does *not* actually apply to K20x or KL2x chips (these do not have the recover-clock-from-USB capability as far as I can tell). However, people have been successfully running USB on MK20DX* chips (mchck, infinity keyboard) without a crystal, just using the internal clock. I've been looking through the reference manuals, and this seems to be officially "out-of-spec". I'm going to try this also on the KL25Z; it should work, but again, it's not quite "officially" allowed.

EDIT: Yes, it does seem the work on KL25Z in the same way as on MK20DX*.

twiddle

26 Sep 2015, 02:56

It most definitely is out of spec from what I have heard. the IRC (internal oscillator) has too much drift to meet the USB spec, which is what the recover-clock-from-usb functionality is designed to compensate for.

User avatar
flabbergast

26 Sep 2015, 09:29

Actually checking all the reference manuals (KL25Z, KL26Z, KL27Z) it seems that 25 and 26 do *not* have the recover-clock-from-USB, but KL27Z does! (I've got some samples on the way.)

twiddle

26 Sep 2015, 09:32

No need to even check there. Go to : http://www.freescale.com/products/arm-p ... T-SELECTOR and put under USB features "USB Crystal-less(FS)". Filter based on RAM/FLASH/Pin count.

twiddle

01 Oct 2015, 03:13

So the boards arrived from Smart Prototyping:
Image

Here it is fully assembled:

Image

Now to just test that everything is working. Good news though, the USB/Battery portion of the circuit behaves as expected for sure so that is one big chunk of the BTLE design sorted.

User avatar
DiodeHead

24 Oct 2015, 20:27

hi guys :)

flabber did u have time to play with your kl27 breakuot board ?? i ordered a couple of MKL27Z256VLH4 when the post started and when it arrived i wasnt feeling very confident on making a breakout board by myself, now that i saw yours, i think ill be better off if i order yours than making my own.

do u have the schematic on hand so my ic and your pcbs can be friends forever ??

are u using the kinetis ide for this breakuot board or u have your own toolchain ??

sorry if the question where already anwsered

thanks for the hard work as always guys.

User avatar
flabbergast

25 Oct 2015, 12:04

I didn't actually have a KL27Z breakout board until yesterday (the previous pics were STM32F0xx breakouts). But yesterday I received a package from OSH Park, and here we go, MKL27ZxxxVLH4 breakout (warning: can't be used with 32k and 64k versions of KL27 chips, those don't have an internal regulator). OSH Park orderable PCB here.

I haven't played with it much yet (didn't have the time), just checked that the bootloader enumerates correctly and responds to the communication from the freescale PC-side tool.

I'm not using kinetis IDE, just a text editor and the open source GNU ARM toolchain. Mainly ChibiOS these days, but I'm still just implementing KL27 support for it.

User avatar
DiodeHead

25 Oct 2015, 14:14

thanks a lot for the schematic :)

User avatar
flabbergast

25 Oct 2015, 21:19

Just a quick warning - be careful when soldering this: I hand-solder, and apparently it's possible that during soldering the flash becomes corrupted. There are four particular bits in the flash, which when in a particular state, can irrevocably brick the chip ("flash secure" and "mass erase disabled"). This happened to me on one of these KL27Z boards.

twiddle

25 Oct 2015, 22:38

flabbergast wrote: Just a quick warning - be careful when soldering this: I hand-solder, and apparently it's possible that during soldering the flash becomes corrupted. There are four particular bits in the flash, which when in a particular state, can irrevocably brick the chip ("flash secure" and "mass erase disabled"). This happened to me on one of these KL27Z boards.
Are you sure this is the cause? It should probably be reported to freescale if so... I've hand soldered 10 or so kinetis qfps and never had that happen.

User avatar
flabbergast

25 Oct 2015, 23:07

I had exactly the same happening to me as in this thread (just with KL27Z). I also tried 2 different SWD debuggers for "mass erase" which would un-secure the chip. Didn't succeed. Then soldered another chip and that one was fine. I got both chips for free from Freescale as samples, so I don't think I should complain too much ;)

I think I fiddled with the non-working one a bit too much. Certainly when I solder a SMT diode, it lights up slightly for a short amount of time, so I think there can be some slight current flow during soldering. There's a reference to an app note in that thread, which explains Kinetis chips might try to start up when they detect some electricity, and during the inevitable fail the flash might be corrupted.

twiddle

25 Oct 2015, 23:15

Out of curiosity which debuggers did you use? I've heard J-links have special sauce that can help with unsecuring the chips.

User avatar
flabbergast

26 Oct 2015, 07:39

Yea, I'm too cheap for that ;) One "generic" CMSIS-DAP and one cheap STM32-based from ebay (it enumerates as "jlink", but I don't believe for a moment that it has anything to do with an actual jlink).

zoomx19

29 Oct 2015, 01:57

has any one tried using a raspberry pi as a controller?

twiddle

29 Oct 2015, 02:00

There are two main issues with using a raspberry pi: firstly, the size (about 4-5x the 2d area of a teensy or similar, at least) and the software that it runs.
The Raspberry pi is a SoC (system on chip) based device, I believe, and it runs a complete operating system. It isn't really designed, or cost effective, to use a $40 computer as a controller - it would be like me getting a mac mini and using that. It's way overkill.

zoomx19

29 Oct 2015, 02:13

twiddle wrote: There are two main issues with using a raspberry pi: firstly, the size (about 4-5x the 2d area of a teensy or similar, at least) and the software that it runs.
The Raspberry pi is a SoC (system on chip) based device, I believe, and it runs a complete operating system. It isn't really designed, or cost effective, to use a $40 computer as a controller - it would be like me getting a mac mini and using that. It's way overkill.
i mean maybe it can double up and be a board or a board with multiple hard drives

User avatar
DiodeHead

29 Oct 2015, 08:59

well, now that the orange pi has dropped the price a bit i still dont see as a controller, but as a developer enviroment i do, i think theres a avrdude version for the pi and his clones that u can use the pinout to programa an avr and the compiler is also aviable i think, also the io pinout could be use to experiment with diferent matrix escaning algorithms and so on before porting to a microcontroller.

at least thats my intent in the future, i dont know i would be able to install an arm toolchain for the k27 but i think is posible with the gcc-arm embedded.

https://launchpad.net/gcc-arm-embedded

User avatar
hbar

10 Nov 2015, 15:23

Raspberry Pi as a controller -- maybe not such a stupid idea if the goal is to make a keyboard with a built-in computer (in true Atari ST and Commodore Amiga style). It must be said, however, that even the Atari ST (not sure about the Amiga) had their own dedicated keyboard controllers. The keyboard would essentially be a "bus keyboard" on the Raspberry Pi, and we all remember those "bus mice" of the 1980s, so I wouldn't expect a "bus keyboard" to have a reputation any better.

Seriously, leave the keyboard to the keyboard controller that's small and cheap and energy-efficient enough for the job (the quad-core Raspberry PI isn't). You don't put FPGAs into wristwatches either.

User avatar
hbar

10 Nov 2015, 15:27

Flabbergast, maybe it's time to replace your soldering iron? I've never ever had a LED flash at me when soldering. My iron has a 4mm socket in its base than I can connect the ESD mat (and even wrist strap, for the really paranoid) to. Still, it never applies any voltage to the circuit, whether the ESD stuff is connected or not (usually it isn't).

User avatar
flabbergast

10 Nov 2015, 17:12

I guess that might be it - I need to look into this. I wondered what's going on with the LEDs...

nickw

22 Jan 2016, 09:39

Does anyone have any advice, tutorials, or example code for getting the STM32f072 running as a keyboard?
I've been messing around for weeks trying to get the code generated by stm32cubemx converted from its mouse-centric starting point into a keyboard. I followed an example on ST's youtube channel and can move the mouse pointer around, but whenever I've tried to make it into a keyboard, windows just gives me an error 10.

User avatar
flabbergast

22 Jan 2016, 10:34

I've got a working example for STM32F072 DISCOVERY board here. It does not use cubeMX, but chibios for the bottom layer. The same mid-layer USB code has been integrated also into TMK firmware, in case you want serious keyboard code.

Post Reply

Return to “Workshop”