Arduino Leonardo programming (HID)

Any bugs you encounter with Flowcode should be discussed here.
mnfisher
Valued Contributor
Posts: 938
http://meble-kuchenne.info.pl
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 502 times

Arduino Leonardo programming (HID)

Post by mnfisher »

I'm sure this has been mentioned before - but don't seem to find a solution.

The upload script needs to open a com port at 1200 baud to kick the Leonardo into it's boot loader (see, for example, https://nicholaskell.wordpress.com/tag/leonardo/ ) - instead it currently 'asks' the user to hit 'reset' on the board - however - the required com port only shows up for a few seconds when the Leonardo is plugged in.. For example - my system gives COM6 for a few seconds before changing to COM5.. If I'm quick I can set Flowcode to use COM6 and then program the Leonardo ok - but there should be a better way here (allow the user to type a com port rather than selecting it from a list?)

I'm trying to get the HID code working. Without success. I add the USB_HID component to my project - set compiler batch file to avra_usb.bat and added HID to the parameters list (as per v7) - but get lots of 'file not found' messages - a clip:
D:\Projects\Arduino SCADA>del "D:\Projects\Arduino SCADA\usb_specific_request.o"
Could Not Find D:\Projects\Arduino SCADA\usb_specific_request.o

D:\Projects\Arduino SCADA>del "D:\Projects\Arduino SCADA\usb_descriptors.o"
Could Not Find D:\Projects\Arduino SCADA\usb_descriptors.o

D:\Projects\Arduino SCADA>del "D:\Projects\Arduino SCADA\power_drv.o"
Could Not Find D:\Projects\Arduino SCADA\power_drv.o
Using the 'standard' AVRISPmkII config I get:
D:\Projects\Arduino SCADA\Useless.c:649:20: fatal error: config.h: No such file or directory
compilation terminated.
What else do I need to add to my project?

Martin

AndreasR
Posts: 13
Joined: Tue Feb 09, 2021 5:16 pm
Been thanked: 2 times

Re: Arduino Leonardo programming (HID)

Post by AndreasR »

Hi Martin,
i think this is not a problem of the Leonardo but it may be a problem of the HID macro.
I have the same problem in a very small programm.
A Leonardo should play some keycodes to the USB connection, not more.
I tried to compile it to chip and got the same error.
"D:\temp\USB_HID_Keyboard.c:399:20: fatal error: config.h: No such file or directory"

I tried a Mega 2560 and got again the same error message.
By the way i' m using FC9 with all updates since.
I will write a bug report and let us show what happens.
Andreas

Steve-Matrix
Matrix Staff
Posts: 1234
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 167 times
Been thanked: 277 times

Re: Arduino Leonardo programming (HID)

Post by Steve-Matrix »

mnfisher wrote:
Sun Jun 20, 2021 9:05 pm
...the required com port only shows up for a few seconds when the Leonardo is plugged in.. For example - my system gives COM6 for a few seconds before changing to COM5.. If I'm quick I can set Flowcode to use COM6 and then program the Leonardo ok - but there should be a better way here (allow the user to type a com port rather than selecting it from a list?)
Hi Martin,

Sorry for the late reply - I've only just noticed your issue. Regarding that issue, Leigh has listed some steps here: https://www.matrixtsl.com/mmforums/view ... 61#p105961

It's not ideal, but should work. Your suggestion of typing in a COM port is good one and I'll look at allowing that in a later version of Flowcode.

Regarding the HID issue, hopefully someone else can help with that one...

mnfisher
Valued Contributor
Posts: 938
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 502 times

Re: Arduino Leonardo programming (HID)

Post by mnfisher »

Thanks Steve,

I got around by using a standalone programmer.. (Didn't solve the HID problem though :-( )

I notice something slightly odd (whilst having a go at automatic programming for Leonardo and Micro) - when programmed with a 'fresh' bootloader - the Leonardo initially shows one com port (in my case com7) when in the bootloader - and then after a few seconds a second com port (com3) when in 'program execution'.
It is possible to 'kick' the Leonardo into the bootloader by opening the com port at 1200 baud - I used the following Python :

Code: Select all

def OpenPort():
    ser = serial.Serial(baudrate=1200)
    try:
        ser.port = "COM3"
        ser.open()
    except serial.SerialException:
        ser.close()
    time.sleep(1)
    ser.close()
This works well - and is how the Arduino IDE automatically programs the Leonardo (and Micro) without having to press 'reset''

If I program the Leonardo from the Arduino IDE this 'second' com port stays present - but if I program it from Flowcode - it disappears. I can still use the reset button, but to 'reinstate' automatic programming from the ArduinoIDE I have to reflash the bootloader. It's not really a problem (unless you swap between the two environments) - but it's interesting that the FC 'runtime' code on the Leonardo differs from the 'Árduino runtime' (and if so - is this intentional?)

Martin

Steve-Matrix
Matrix Staff
Posts: 1234
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 167 times
Been thanked: 277 times

Re: Arduino Leonardo programming (HID)

Post by Steve-Matrix »

Hi Martin,

Thanks for the additional info.

It could be that Flowcode replaces the bootloader when it reprograms the chip on the Leonardo board, but I'm not 100%. Ben or Leigh should have a better idea about that - I don't get too involved in that side of things. Unfortunately, I also have to defer to their expertise about the HID issue.

Sorry I'm not much help :oops:

BenR
Matrix Staff
Posts: 1706
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: Arduino Leonardo programming (HID)

Post by BenR »

Hello,

USB compilation on AVR is not as nice and clean as it could be, we have an alternative build script that brings in the various USB libraries.

The details of USB compilation on AVR are included below.

I've just uploaded a new compiler batch file via the update system that you will require and you will also need to use the v8 AVR compiler as the v9 one seems to do things a bit differently and will need investigation.

Let us know how you're getting on.


To compile to an AVR device using USB you must point the compiler to a different batch file to allow it to include the various USB libraries in the compilation.

Simply click on Build -> Compiler Options.

Click on the AVR -> Default item and then click the save icon at the top right hand side of the window.

Give the new setting a name e.g. AVRUSB and click OK.

Click on the new item AVR -> AVRUSB and ensure that it is ticked as the default compiler for the AVR platform.


Change the compiler location to this.
$(fcddir)AVR\batchfiles\avra_usb.bat


Change the compiler Parameters to one of the following based on your USB type.
$(chip:l) "$(outdir)" "$(target)" Serial "$(compileravr)"
$(chip:l) "$(outdir)" "$(target)" HID "$(compileravr)"

AndreasR
Posts: 13
Joined: Tue Feb 09, 2021 5:16 pm
Been thanked: 2 times

Re: Arduino Leonardo programming (HID)

Post by AndreasR »

Hi Ben,
your advisory does not work :-(

I had done the modifications u wrote
and tried both compiler parameters.
The errors i got are identical.
Please see the attachments.

Hope u have another idea to cutoff this node
Andreas
Attachments
PS4-KeySim.msg.txt
(19.21 KiB) Downloaded 115 times
compiler options.png
compiler options.png (23.26 KiB) Viewed 4137 times

BenR
Matrix Staff
Posts: 1706
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: Arduino Leonardo programming (HID)

Post by BenR »

Hello,

Your using the v9 AVR compiler there.

C:\Program Files (x86)\Flowcode\Common\Compilers\avrv5\

Do you have the v8 AVR compiler installed?

C:\Program Files (x86)\Flowcode\Common\Compilers\avr\

You can set the compiler path in the Locations tab of the Global options.

I got the same results in the AVRv5 compiler so we will have to investigate this and find a solution however the older compiler should work fine.

You can download it from here if you don't have it installed
https://www.matrixtsl.com/flowcode/down ... er_AVR.msi

AndreasR
Posts: 13
Joined: Tue Feb 09, 2021 5:16 pm
Been thanked: 2 times

Re: Arduino Leonardo programming (HID)

Post by AndreasR »

Hi Ben,
sorry i forgot to change the compiler.
I changed it now and compiled to hex but,,,
Here is the error code.
PS4-KeySim.msg.txt
(8.9 KiB) Downloaded 126 times
Andreas

AndreasR
Posts: 13
Joined: Tue Feb 09, 2021 5:16 pm
Been thanked: 2 times

Re: Arduino Leonardo programming (HID)

Post by AndreasR »

Ben, here's another information for you.
Yu wrote about FC 8 compiler and that it maybe working fine.
So i tried FC8 (got a licence too) that i have installed.
I wrote the small programm into a new FC8 project and tried to compile.
Errors came too.
See the attachment.

So i only can hope that this chapter will be closed by you :|
Andreas
Attachments
FC8-PS4-KeySim.msg.txt
(2.97 KiB) Downloaded 114 times

Post Reply