-
-
-
From the GitHub commits and changes of the STM drivers in Espruino (targetlibs/stm32usb/Src/) back in 2015 , it looks like GWilliams was very busy and there were a ton of changes to the STM libraries to get USB working in Espruino. SO .... clearly changing existing functionality to use more recent STM libraries is not agood idea ! So approach has to be that any Host functionality is all incremental and sits beside existing device virtual com and HID. However that also makes sense, looking at the current STM host libraries in
https://www.st.com/resource/en/user_manual/dm00105256-stm32cube-usb-host-library-stmicroelectronics.pdf... they would be a parallel set to the existing device libraries on the stack. See Attached pic.
-
-
Hi,
Quick status, having spent some time on this, Im going to make a serious attempt at adding a USB host functionality option on the Pico build for host HID support.
Approach maybe with a with a new E.USBSetHost, function that can be used in conjunction with the existing E.USBSetHID to set the mode between: USB device Virtual com (default) , USB Device with HID or USB Host for HID. ie set to host on next USB insert of the board.Will add discussion on an approach for comment after more learning on my part.
status So far:
Working thru Udemy course embedded driver development for STM32.
Learnt how to successfully build Espruino and flash to Pico on Ubunto box
Currently getting to grips with the current Pico USB build: Looking at the STM libraries currently employed, working back from STM32_USB.make, using STM Library docs. , understanding how E.USBSetHID is implemented.Found great basic USB tutorial.
https://www.st.com/content/st_com/en/support/learning/stm32-education/stm32-moocs/STM32-USB-training.htmlTrying to get hold of a STM32F407G DISC BOARD for the development as it has debug capability and USB wired up to STF32F4.... But struggling on availability, just spoke to Anglia Live sales rep to complete questionnaire on my 'project' to justify having stock allocated to me !
So told her this was a project to enhance the Espruino project , hope that is enough.If ok , will raise an issue for an enhancement 'Provide USB Host functionality on Pico' on Github to formalise the work, in case it helps with supply issue of the dev board. And then can have discussion there on the approach .
Cheers Simon -
-
I’ll investigate a bit more , Signed up to Udemy course on interfaces in embedded c, for stm32 !!! but no promises.
Out of interest , and maybe mid term answer to my problem, have you decided if, the new Espruino Wi-fi Board might support USB host ! Or use hardware that could. ? If one was going to invest time in this maybe it be better spent that way.
Thanks again for considered response.
And Happy new year. -
Thanks Gordon,
Thanks for the confirmation and the clear options. I’ve been doing some more googling and checked out the libraries and stm32 reference docs. I think it’s possible but I have to say it looks incredible complex.
On a general point this https://youtu.be/4FOkJLp_PUw
is a great youtube tutorial with stm32 that shows the logic analyser techniques (and effort ) it might take to debug such a development. -
hi,
I am trying to input data to a pico from a USB barcode reader (in either HID or virtual com mode).
OTG is not required , USB would be a dedicated input.
Happy to dig deeper and get a logic analyser on the case but USB low level signalling is a new world for me. Searching the forums :- Ive been able to move the repl to serial so that I can use the USB for connecting to the reader. And separate power supply sorted so not required to power via USB.
- I now understand that a straight USB.on("data" , function(d){...}) doesn’t respond to USB peripheral input.
- ive seen the forum answer that host mode is not supported. http://forum.espruino.com/conversations/284427/
- Ive seen the threads that use an external USB controller shield. http://forum.espruino.com/conversations/332374/#comment14698591
https://www.hackster.io/gerrit-niezen/adding-usb-host-support-to-espruino-2c494d - and I can see there is HID support to use the pico to send to a host.
So my questions here are:
- has anything moved on since the above conversations with USB peripheral input to the pico?
- is there any way forward to ustilise the USB host functionality of the STM32F401xD ?
- is an additional host controller chip/shield the only practical way to crack this? Seems a really unnecessary overhead if the STM.. can handle the host interface.
and any suggestions on investigations I could do to move this forward appreciated.
Thanks in Advance
Simon - Ive been able to move the repl to serial so that I can use the USB for connecting to the reader. And separate power supply sorted so not required to power via USB.
-
Thanks @Gordon,. I get the issue now with implementing.
I appreciate your idea on the workaround and will try it out.Really enjoying working with Espruino , Pico is great, 5v tolerance really useful.
Will be putting up on github, XState with Espruino including hierarchical states , asap.
Comming along well. -
Hello,
Im looking to use Function.name in javascript. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
while porting the Xstate library to Expruino.I believe Function.name or similiar is not available in Espruino.
Also a common polyfill uses function.toString() and Although Espruino does have Object.toString() which operates on a function , the returned string does not provide the name. (see attached).Any thoughts on the possibility of implementing function.name or a workaround to get the name of a function ?
Thanks in Advance -
So been continuing with xstate-fsm-Espruino (as above ... XState/fsm for Espruino microcontrollers) but in test scenarios was very quickly missing the hierarchical functionality I had gotten use to with full XState on the Raspberry pi. So I've started to work on putting limited state chart functionality on top of xstate-fsm for Espruino. Early tests are can add hierarchical states with a few functions that manipulate state value (using a full XState ID format Inc custom IDs)' , get state parents etc. Hopefully still not breaking minimal memory constraints of the Espruino micros. Or deviating from XState principals. Will publish when a little more proven. Great fun in any event, and learning loads from XState as an example of functional programming in JS and Espruino, But what to call xstate-fsmPlus-Espruino ???
-
@allObjects , all useful stuff above Ta,. ...not to distract from @bertjerred 's build mission but Think it may be useful here to note what happens if a setWatch interrupt occurs while the previous SetWatch function is still running. Was going to test but see you comented on the subject ( 7 yrs ago :). http://forum.espruino.com/comments/11932979/
Is it correct still that setWatch triggered functions are queued and executed by the JS Interpreter in the order in which they occurred?
(* in the simple case assuming the advanced IRQ' parameter features of set watch are not used ) -
-
also note the interrupt fires on both the contact and release of the keypad button. In this snip Im assuming on release , mpr.touched() = 0, that is : no keys are touched so dont print the value. I imangine on a keyboard this may not be the case, so will need another way to to handle this. Good luck :).
-
Pure coincidence but I was working with an MRP121 keyboard on an Espruino MDBT42Q using the interrupt method. The interrupt is actually active low and hence needs a falling edge detection on the setwatch() function. Also the direct connection of the interrupt to an Espruino pin needs the internal pullup resistor enabling. Here is a working snipet to see the approach.
// Setup pins and interface to MPR121 const sclPin = D15; const sdaPin = D14; const irqPin = D16; // interrupt from MRP121 I2C1.setup({scl:sclPin,sda:sdaPin}); // IRQ is Active Low, open Drain (ref datasheet) - make use of internal pullup pinMode(irqPin,'input_pullup'); // connect to MRP121 via Espruino MRP121 library function mprConnected() {console.log ("MPR121 Connected");} var mpr = require("MPR121").connect(I2C1, mprConnected , { address: 0x5B}); // define function for interrupt (fires on touch AND release) function touchedIRQ() { //console.log ("debug - interrupt received"); var keys = mpr.touched(); if (keys != 0) {console.log("Touched: " + keys);} } // watch the irqPin and fire the interrupt function on capacitance change // IRQ is active low, so trigger the interrupt on a 'falling edge' if (setWatch(touchedIRQ,irqPin,{repeat:true, edge: 'falling'}) === 1) { console.log( "MPR Interrupt Enabled" ); } else {console.log ("error - set watch on interrput pin NOT enabled"); }
Also Note the MPR121 keyboard im using does not have pullup resistors for the I2C: SCL and SDA, so I have added a 4.7 K resistor on my prototype board between each of: sclPin and 3.3v and sdaPin and 3.3v , I believe some MRP121 breakout boards already have these.
-
-
Hi Bert,
I think you have another option on the approach with the mpr121 that avoids polling.
The chip and the breakout boards usually have an interrupt pin that will trigger an output when ever one of the switches is touched.
If you wire this to an input pin on the Expruino then you can use a setWatch function to execute a function to read the mrp1.touched function.
https://www.espruino.com/Reference#t_l__global_setWatch -
quick status on the project above is I now have a working version published in the repository , with installation guide and the first examples !! check out the demo
https://github.com/SimonGAndrews/xstate-fsm-Espruino/blob/main/examples/030_buttonEvent/buttonEvent.gif -
Hi, progressing slowly but surely with xstate for Espruino. But got a problem trying to find a method in Espruino to return the name of a function.
- Looks like function.name is not supported
- also many of the polyfills and work arounds parse the name out of function.toString() But Espruino does not put the function name in the function.toString output.
Its not a show stopper , but any ideas would be appreciated.
- Looks like function.name is not supported
-
Thanks both @Robin and @Gordon for the positive response and helpfull advice. Robins tutorial and the features page and set alternative idea were just what was needed. Im working a fork of XState/fsm in github (xstate-fsm-Espruino) which is very much WIP.
Hoping bloat will not be an issues as Xstate is designed with that risk in mind.
I got a positive reponse from davidkpiano (author of Xstate) also on thier Discord community. https://discordapp.com/channels/795785288994652170/810916847573532742/878607258785808385
-
Hello,
Im new to Espruino but have a good background in computer science and have been working since I retired, to learn a sound microcontroller platform for some projects I have in mind. Ive honed in on the xstate finite state machine https://xstate.js.org/docs/packages/xstate-fsm/ as a great framework for structuing code for automation applications. Ive had great success with this on Raspberry pi running Node. But am trying now to find a lower total cost option. Ive had some success with xstate on low.js on esp32, but not many drivers available,extent of open source is limited and seems to have a small community.So im trying to port xstate/fsm to Espruino* whcih does not seem so limited. It is a challange for my experience. But I have got a basic port and some simple xstate machine configs to run. Generally the issues Im having with the more sophisticated examples are Javascript features failing execution in Espruino. Some ive cracked with work arounds eg (module exports format, functions with optional parameters, multiple const defs in array format) and some are proving more difficult eg Set objects.
Not sure how successfull this will be but happy to share all results, write up cases and test the work on Espruino boards (im using esp32 initially) and def would like to publish the xstate/fsm port in the tested modules.
Does this work seem benneficial to the community ??
Is there a list anywhere of what javascript features are or are not in scope at them moment and where to best ask/confirm or note any apparent gaps ?? Any pointers for using the forum or github issues appreciated.
- I appreciate there is an FSM in the existing device modules but would like a few more of the features available in xstate (eg named events, triggering specific state changes) and xstate appears to be getting lots of traction with a large community.
Regards,
Simon - I appreciate there is an FSM in the existing device modules but would like a few more of the features available in xstate (eg named events, triggering specific state changes) and xstate appears to be getting lots of traction with a large community.
-
Retired Solution Architect (Xerox - Imaging Services)
Working on implementing Xstate
https://xstate.js.org/docs/packages/xstate-fsm/
on Microcontrollers for improving Service Delivery
Initially , looks like CDC is an easier implementation and needing fewer library files.
Interested in others view , if you only had one usb class of input. HID or virtual com ?