teensy_loader_cli on OSX: "Error opening HID Manager"

Status
Not open for further replies.

formatc1702

New member
Hi,

when using the teensy_loader_cli tool on OS X (just built from source), I receive the following:

Code:
$ ./teensy_loader_cli -mmcu=mk20dx256 -w -s -v ~/Desktop/firmware.hex 
Teensy Loader, Command Line, Version 2.0
Read "/Users/daro/Desktop/firmware.hex": 11332 bytes, 4.3% usage
Error opening HID Manager
Soft reboot is not implemented for OSX
Waiting for Teensy device...
 (hint: press the reset button)

Uploading via Arduino IDE + Teensyduino works fine!

What am I doing wrong? Any help would be greatly appreciated.
(And yes, I did press the reset button :p )

Here is some more info on my system:
Teensy 3.2
OS X 10.11.6
Teensy Loader CLI just cloned from GitHub and built from source
XCode is installed,
Code:
$ xcrun --version
xcrun version 29

Specifically, I am running this code from PlatformIO, but the same error appears if I manually launch the tool.
Nonetheless:
PlatformIO-IDE 1.4.0
PlatformIO-IDE-Terminal 2.2.0
Atom 1.9.9

EDIT:

I saw the tip under System Specific Setup about changing the line in the makefile to
Code:
SDK ?= /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
but it seems the line
Code:
SDK ?= $(shell xcrun --show-sdk-path)
is smarter and seems to be returning the correct path:

Code:
$ xcrun --show-sdk-path
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk
 
Last edited:
OK guys, I did a bit of hacking and found an ugly solution, that works for me.

I took the teensy_loader_cli source code and simply edited the init_hid_manager() function that was throwing the error:

Code:
void init_hid_manager(void)
{
	CFMutableDictionaryRef dict;
	IOReturn ret;

	if (hid_manager) return;
	hid_manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
	if (hid_manager == NULL || CFGetTypeID(hid_manager) != IOHIDManagerGetTypeID()) {
		if (hid_manager) CFRelease(hid_manager);
		printf_verbose("no HID Manager - maybe this is a pre-Leopard (10.5) system?\n");
		return;
	}
	dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
		&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
	if (!dict) return;
	IOHIDManagerSetDeviceMatching(hid_manager, dict);
	CFRelease(dict);
	IOHIDManagerScheduleWithRunLoop(hid_manager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
	IOHIDManagerRegisterDeviceMatchingCallback(hid_manager, attach_callback, NULL);
	IOHIDManagerRegisterDeviceRemovalCallback(hid_manager, detach_callback, NULL);
	ret = IOHIDManagerOpen(hid_manager, kIOHIDOptionsTypeNone);

  /////////////////////////////
	//// MY EDIT STARTS HERE ////
  /////////////////////////////

	// if (ret != kIOReturnSuccess) {
	// 	IOHIDManagerUnscheduleFromRunLoop(hid_manager,
	// 		CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
	// 	CFRelease(hid_manager);
	// 	printf_verbose("Error opening HID Manager you stupid bananaface\n");
	// }
	printf_verbose("Ignoring error if ret != kIOReturnSuccess because YOLO!\n");
}

It's the ugliest fix, but it works, and I am quite happy considering...

1*snTXFElFuQLSFDnvZKJ6IA.png
 
Last edited:
Hi there,

Thanks for initiating this thread. I am experiencing the same error using the teensy_loader_cli. Indeed for use with PlatformIO but clearly the error appears in the teensy cli tool itself.

The quick-fix suggested does not work here. Stuck with Error opening HID Manager or Unknown MCU type.

How to move forward to a stable solution for the teensy_loader_cli?

Greetings,
Arne.


Arduino @ 1.8.1
Teensyduino @ 1.35-beta1
OSX 10.12.2
Tested with TeensyLC board and Teensy3.1 board

Teensy Loader Original
Code:
./teensy_loader_cli -mmcu=mk20dx256 -w -s -v "~/Desktop/firmware.hex"
Teensy Loader, Command Line, Version 2.1
Read "~/Desktop/firmware.hex": 11856 bytes, 4.5% usage
[B]Error opening HID Manager[/B]
Soft reboot is not implemented for OSX
Waiting for Teensy device...
 (hint: press the reset button)

Teensy Loader Commented Error Suggestion
Code:
./teensy_loader_cli_commented -mmcu=mk20dx256 -w -s -v "~/Desktop/firmware.hex"
Unknown MCU type "mk20dx256"
Supported MCUs are:
 - at90usb162
 - atmega32u4
 - at90usb646
 - at90usb1286
 
I'm not familiar with tennsy. Your second error message shows your teensy_loader_cli do not support "mk20dx256".
 
Dear Paul,

Yes, normal uploading from Arduino & Teensy Loader indeed works.

For use with PlatformIO it would be very convenient to use the teensy_loader_cli.

Many thanks for your attention.

Best,
Arne.
 
I've been having this problem with my Teensy 3.6 on Mac OS 10.12.2. About every other upload from PlatformIO would fail.

I just built teensy_loader_cli source from master, replaced the copy in ~/.platformio/packages/tool-teensy, and it appears to work flawlessly now.
 
hi thinbits thanks for your comment.

compiled teensy_loader_cli from source again (without modifications) and indeed the Error opening HID Manager does no longer appear. nice!

however, still stuck at error Unknown MCU type during uploads. any suggestions?

Code:
[Sun Jan 22 12:48:15 2017] Processing teensy31 (platform: teensy, board: teensy31, framework: arduino)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
Collected 85 compatible libraries
Looking for dependencies...
Project does not have dependencies
Linking .pioenvs/teensy31/firmware.elf

Checking program size
text       data     bss     dec     hex filename
11464       168    2292   13924    3664 .pioenvs/teensy31/firmware.elf
Building .pioenvs/teensy31/firmware.hex
Uploading .pioenvs/teensy31/firmware.hex
Unknown MCU type "mk20dx256"
Supported MCUs are:
- at90usb162
- atmega32u4
- at90usb646
- at90usb1286
*** [upload] Error 1
========================== [ERROR] Took 2.34 seconds ==========================
 
Looks like that would happen if neither USE_LIBUSB, USE_APPLE_IOKIT, nor USE_WIN32 were defined when the source was built.

Maybe make sure the top of the makefile looks like the following. I think it defaults to building for a different platform.

Code:
#OS ?= LINUX
#OS ?= WINDOWS
OS ?= MACOSX
#OS ?= BSD
 
hi thinbits thanks for the reply

you are right it seems USE_LIBUSB needs to be defined as seen in teensy_loader_cli.c line 1012

Code:
static const struct {
	const char *name;
	int code_size;
	int block_size;
} MCUs[] = {
	{"at90usb162",   15872,   128},
	{"atmega32u4",   32256,   128},
	{"at90usb646",   64512,   256},
	{"at90usb1286", 130048,   256},
#if defined([B]USE_LIBUSB[/B])
	{"mkl26z64",     63488,   512},
	{"mk20dx128",   131072,  1024},
	{"mk20dx256",   262144,  1024},
#endif
	{NULL, 0, 0},
};

tried your suggestion with the makefile, setting os to MACOSX. but no luck.

also tried in platformio.ini to set libusb but no effect.
Code:
build_flags = -D USE_LIBUSB

getting closer... question is where to define USE_LIBUSB?
 
What you posted doesn't look like the code I'm looking at.

The makefile, if USE_LIBUSB isn't defined, will attempt to run
Code:
xcrun --show-sdk-path
and use
Code:
USE_APPLE_IOKIT
when compiling the source. This is in lines 33:43 in the makefile. You would need Xcode to be installed for this to work. If it's not installed, it looks like the makefile would exit with an error on MacOS.

Also, in my copy of the source, the list of supported CPUs looks like the following, which is different than what you posted.
Code:
static const struct {
	const char *name;
	int code_size;
	int block_size;
} MCUs[] = {
	{"at90usb162",   15872,   128},
	{"atmega32u4",   32256,   128},
	{"at90usb646",   64512,   256},
	{"at90usb1286", 130048,   256},
#if defined(USE_LIBUSB) || defined(USE_APPLE_IOKIT) || defined(USE_WIN32)
	{"mkl26z64",     63488,   512},
	{"mk20dx128",   131072,  1024},
	{"mk20dx256",   262144,  1024},
	{"mk66fx1m0",  1048576,  1024},
	{"mk64fx512",   524288,  1024},
#endif
	{NULL, 0, 0},
};

Are you sure you have the latest code from the master branch?
 
thanks for the sharp notice. just started from scratch with the master branch at https://github.com/PaulStoffregen/teensy_loader_cli/.

before building set Makefile to
Code:
OS ?= MACOSX

back to initial error with Error opening HID Manager

Code:
[Sun Jan 22 21:11:34 2017] Processing teensy31 (platform: teensy, board: teensy31, framework: arduino)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
Collected 85 compatible libraries
Looking for dependencies...
Project does not have dependencies
Linking .pioenvs/teensy31/firmware.elf

Checking program size
text       data     bss     dec     hex filename
11464       168    2292   13924    3664 .pioenvs/teensy31/firmware.elf
Building .pioenvs/teensy31/firmware.hex
Uploading .pioenvs/teensy31/firmware.hex
Teensy Loader, Command Line, Version 2.1
Read ".pioenvs/teensy31/firmware.hex": 11632 bytes, 4.4% usage
[B]Error opening HID Manager[/B]
Soft reboot is not implemented for OSX
Waiting for Teensy device...
(hint: press the reset button)
 
also found this in the Makefile:

Code:
# uncomment this to use libusb on Macintosh, instead of Apple's HID manager via IOKit
# this is technically not the "correct" way to support Macs, but it's been reported to
# work.
#USE_LIBUSB ?= YES

then first need to install libusb on my system in order to try building with this. bumping into some issue here with linking as described here https://stackoverflow.com/questions/36559482/brew-install-libusb-linking-failed
 
Code:
static const struct {
	const char *name;
	int code_size;
	int block_size;
} MCUs[] = {
	{"at90usb162",   15872,   128},
	{"atmega32u4",   32256,   128},
	{"at90usb646",   64512,   256},
	{"at90usb1286", 130048,   256},
#if defined([B]USE_LIBUSB[/B])
	{"mkl26z64",     63488,   512},
	{"mk20dx128",   131072,  1024},
	{"mk20dx256",   262144,  1024},
#endif
	{NULL, 0, 0},
};

Looks like you're using an old version of the code.

Get the latest directly from github:

https://github.com/PaulStoffregen/teensy_loader_cli
 
I am experiencing this issue with the latest master available. Double-checked with a clean build from scratch.

Code:
macarne:teensy_loader_cli arne$ git log -1 --stat
commit fe52c697707e11b3891e43fc02e662399d749e62
Merge: 049fe21 7723ab4
Author: Paul Stoffregen <paul@pjrc.com>
Date:   Sat Jan 7 09:40:21 2017 -0800

    Merge pull request #34 from neonsoftware/osx-message

    In case of missing macOS SDK (Xcode), make instructs the user and exits
 
I ended up using Teensy Loader with PlatformIO.

PlatformIO checks the ~/.platformio/packages/tool-teensy folder for existence of teensy_loader_cli. By deleting/renaming this file it skips to the Teensy Loader implementation.

See source below in ~/.platformio/platforms/teensy/builder/main.py

Code:
if any([
        isfile(
            join(
                platform.get_package_dir("tool-teensy") or "",
                "teensy_loader_cli%s" % b)) for b in ("", ".exe")
]):
    env.Append(
        UPLOADER="teensy_loader_cli",
        UPLOADERFLAGS=[
            "-mmcu=$BOARD_MCU",
            "-w",  # wait for device to apear
            "-s",  # soft reboot if device not online
            "-v"  # verbose output
        ],
        UPLOADHEXCMD='$UPLOADER $UPLOADERFLAGS $SOURCES')
else:
    env.Append(
        REBOOTER="teensy_reboot",
        UPLOADER="teensy_post_compile",
        UPLOADERFLAGS=[
            "-file=firmware", '-path=$BUILD_DIR',
            '-tools=%s' % (platform.get_package_dir("tool-teensy") or "")
        ],
        UPLOADHEXCMD='$UPLOADER $UPLOADERFLAGS')
 
I've just tried to use platformio and the loading is erratic, only works sometimes... Is there a way to have them bundle a proper binary? I'm on OSX.
 
Status
Not open for further replies.
Back
Top