It seems that everything seems good until USB connection doesn't seems to respond. A reset of the kl25z solves that.
That could indeed be caused by the same bugs I just fixed. Random disconnects were the main symptom. I saw this *extremely* rarely, though - mean time between failures was probably something like 20 hours of continuous operation, although that's based on a relatively small sample size. If you were seeing these frequently enough to be troublesome, my best guess it that you ran into something else entirely.
Usb3 doesn't seems to work well.
The original mbed USB library didn't work at all with USB 3. I fixed it a long time ago so that it worked reliably with the USB 3 chip set on my PC, and many other people have reported successful use with USB 3. I even use it exclusively with USB 3 ports on my own cab. However, the problem I fixed was very specific - a particular protocol timing/sequencing quirk that happened on my hardware and tripped up the mbed USB code. I can easily imagine that there exist other host USB chip sets with different quirks that cause different failure modes that I haven't encountered on my own setup. But I wouldn't just assume that anything you're running into is a USB 3 problem per se. The problem I ran into was incorrectly ascribed to USB 3 for a long time by a lot of people, but it wasn't truly a USB 3 problem. It was actually an Intel Haswell chip set problem, and that chip set happened to implement USB 3, so people wrongly assumed it was USB 3 that was responsible. It might be the same sort of thing in your case with a different quirky chip set.
Unfortunately, if it is indeed a problem with your specific motherboard, it's impossible for me to debug it without having your specific type of motherboard on hand to test with. I could give you advice about debugging it on your end if you're up for the job, but of course that's a significant investment of your time to learn the low-level details of USB and the mbed library code. In broad outline, what you have to do is go into the Windows Message Analyzer and watch the USB traffic on the port to find out what's failing, then track it to the point of failure and find out what the mbed code is doing wrong at the critical point with the offending message packet.
The use of Chinese solenoid (plugged via a relai board) seems to interfer with the kl25z and makes it loose connection
That's almost certainly due to electrical noise from the solenoid, or possibly even the relay board. Relays are themselves inductors and can cause significant electrical noise. *Any* problem you're seeing that you can trace to an external device like that means that you have too much electrical noise coming from the device and propagating into the logic circuitry (in your KL25Z, LedWiz, or PC motherboard).
To eliminate those sorts of problems when attaching high-current devices like solenoids, there are two things you *must* do.
The first is that you absolutely need a flyback diode on anything inductive (solenoids, motors, contactors, and relays). Use a 1N4007 diode or something similar. Attach it close to the device's power terminals.
The second is to make sure your booster circuitry is thoroughly decoupled from any logic circuitry with capacitors. The standard recommendation is a combination of a small ceramic capacitor (100nF is the usual recommendation) plus a large electrolytic (100uF to 1000uF), in parallel between power and ground near the logic circuit power supply. Your PC motherboard probably already has a ton of decoupling capacitors, so it's probably pretty immune. The KL25Z gets its power from USB, so it's usually pretty well isolated on its own, but as soon as you start connecting booster circuits to GPIO ports, the USB side of the isolation is lost because you're connecting another path to power through the GPIO ports.
The problem is probably the solenoid rather than the relay board, but there's an easy way to find out. Just disconnect the solenoid and keep the relay board in place. If the problem persists, it's the relay board. (It could be the solenoid *too* in that case, but you at least have to fix the relay board.) If the problem disappears with the solenoid unplugged, it must just be the solenoid. Whichever device is causing the problem will need additional protection to prevent it from injecting electrical noise into the rest of the circuitry - diodes and/or capacitors as above.
Another outside possibility is that you just need a bigger power supply. If your power supply is overtaxed by the inrush current surge when the solenoid and/or relays turn on, you could be getting voltage dips right at the power supply level. That can cause problems for the logic circuitry by changing the voltage levels for "on" and "off" in the digital circuitry. Most PC power supplies are so powerful and have such big capacitors built in that this doesn't seem like a likely problem, but if you're using a small PSU it might be something to look at.
Edited by mjr, 18 January 2016 - 07:26 PM.