Upgrading to CubeMx 4.12.0 and MIDI USB

Development of new Cores using the STMCubeMX and HAL
Post Reply
User avatar
sheepdoll
Posts: 236
Joined: Fri May 22, 2015 12:58 am
Location: Silicon Valley Vortex
Contact:

Upgrading to CubeMx 4.12.0 and MIDI USB

Post by sheepdoll » Fri Jan 01, 2016 4:33 am

Having a sort of quiet day, I decided to upgrade the CubeMX. On OS X. The automatic update failed. Installing from an installer downloaded through the main STM site worked.

It looks like some of the issues with pin configurations have been fixed. I was able to activate SDIO and the FATFS Middleware. I also activated USB_FS audio class. Ideally I want a MIDI device.

The code would not compile under the Arduino IDE as It could not find the Middleware include directories. Copying the *.h files into the main Inc directory, did allow the sketch (which does nothing) to compile. I think that the USB descriptors are in one of these.

I spent the last few hours giggling about looking for examples of which header files to add the MIDI endpoints too. All I found was others asking the same question. or old 2012 code. I have no interest at the moment in Audio synth. I want to be able to parse the MIDI. This is trivial to do on the AVR (classic Arduino) but the limits of one serial USART makes it awkward to include a separate backchannel from the keyboard controller that scans the switches. I also activate outputs based on MIDI sequenced from the PC/Laptop.

I think I am the only one here who actively does work with CubeMX and HAL. Still I ask in case someone might know where to look for more information. I have the MIDI10.pdf I know the form of the endpoint descriptors I want. The ST USB documents only seem to have one instance of the word MIDI that states it is a subset of Audio class. I feel like I am going in circles, trying to find a decent MIDI example. (Other than the F1xx code that is here and is not optimized for F4 or other generic variants.)

User avatar
RogerClark
Posts: 7178
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Upgrading to CubeMx 4.12.0 and MIDI USB

Post by RogerClark » Fri Jan 01, 2016 10:18 pm

I think you may be only want looking at the HALMX version.

I would love to have time to play with it, but work and other projects don't leave me much spare time.
Also its summer here in the southern hemisphere, so i spend more time outdoors and less time on my electronics projects.

But please keep posting, as its interesting to know how things are going and what you are doing.

User avatar
sheepdoll
Posts: 236
Joined: Fri May 22, 2015 12:58 am
Location: Silicon Valley Vortex
Contact:

Re: Upgrading to CubeMx 4.12.0 and MIDI USB

Post by sheepdoll » Sat Jan 02, 2016 8:59 am

I Actually made a bit more progress over the last few days.

I switched the USB setup from Audio to CDC using CubeMX. I found the device descriptors in the c code rather than the headers. I guess that makes sense as these are string constants.

It is evident that ST does not suport the MIDI class (Yet) I did some searching and found a Github called 'Stm midi demo' the usb driver part is credited to a 'Thorsten Klose' who seems to be the author of something called MIDIBox. Probably why there is not a lot of MIDI stuff out in the wild. This does a lot and is probably what 90+% of the users want. It is cross platform ,pic,ST32,NXP LPC, etc. and sort of looks like the 'Arduino IDE' of MIDI.

Anyway with the CDC drivers, (Or even the audio drivers) the blank sketch compiles. ( I did not download to hardware to see if the devices enumerate on start. I have to connect the D+,D- and the VBUS lines to my USB breakout header. There is also question as to the need for the speed indicator resistor and the terminating resistors. Manufacture says not needed, others say manufactures are not product designers.)

Instead I started playing with the Eclipse Luna that I installed OpenOCD on last summer. There is a script called CubeMX2Makefile (on github) This will create a Makefile from the SW4STM32 configuration. You have to hunt through the Author's blog to find out how it works. Does seem to be actively updated and has improved since last June.

Surprisingly the raw script compiled all the HAL code, it did choke on setup() and loop. I modified the make files to find the stub of the Arduino_STM32 core that I was using for the headers and the stream class.

This time everything compiled, The linker barfed on HardwareSerial, which I stubbed out as it is inherited by the UARTClass. Failing on vtable and __cxa_pure_virtual(). To work around this I defined 'extern "C" void __cxa_pure_virtual() { while (1); }' as per a stack overflow answer. Still got the vtable error, which has to do with the link order.

Again I modified the makefile, to change the linker to match what Arduino is building from the board.txt and platform.txt. With some trial and error, I got the eclipse to produce a .elf in the build folder.

Next question was the OpenOCD still configured from last june. Cliking the bug icon, the mac 0s x debugger ran. I checked the settings and clicked on the openocd section. As there is no hardware connected, the system did generate an error, but it looked funny.

So I ran OpenOCD in the terminal. It was evident that a script path was not being found. I modified the script to include the whole path. There probably needs to be some Path$ setting somewhere, but my hack worked and OpenOCD gave a more reasonable error message more in line with no hardware connected.

This was enough for one day. Too late now to start an involved hardware project ...

User avatar
RogerClark
Posts: 7178
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Upgrading to CubeMx 4.12.0 and MIDI USB

Post by RogerClark » Sat Jan 02, 2016 7:54 pm

Wow. You have more patience than I do ;-)

But I'm glad someone is looking at this.

If I get time, I need to try to get Exclipse working with Arduino code, as the IDE lacks a lot of the features I have come to expect from a modern IDE.

But I normally find that setting up Exclipse is tricky, because the myriad of settings that have to be configured.

I guess it's something I will slowly get used to if I spend long enough using it.

User avatar
sheepdoll
Posts: 236
Joined: Fri May 22, 2015 12:58 am
Location: Silicon Valley Vortex
Contact:

Re: Upgrading to CubeMx 4.12.0 and MIDI USB

Post by sheepdoll » Sun Jan 03, 2016 9:00 am

Eclipse works. After a fashion.

I connected the board an pressed debug. The first time, it attempted to still run the OSX debugger. I disconnected the board and went to the debug configuration. Any time I went to attempt a new debug session, it told me that the port was in use. It was evident that openocd was still running. I killed the process, then ran openocd from terminal. Turns out you have to telnet to 4444 then issue a shutdown command.

Back in eclipse, The correct debugger seemed to run, but simply stalled at an exception vector. I switched back to Arduino and uploaded a blink sketch. That showed that the board was live. I then copied the blink sketch into eclipse ran the code and hit the same exception vector.

Noodling about with the windows, it was evident that gdb was running and I was looking at a live disassembly. a closer look at the exception vector WWDG_IRQHandler suggests that a watchdog IRQ is being activated by the eclipse makefile build, that somehow the Arduino build catches.

Setting a breakpoint at the reset vector (eclipse supposedly breaks at main()) Does show that gdb can step through the code.

There is a lot of fiddly bits to eclipse. I still need to figure out how to get the paths to the core/mapleMX section that is above the variant.

The makefile also still sets the command line compiler flags using the SW4STM32 settings. I have never found makefiles logical (And this from a postscript programmer!) Still with trial and error, I can sort of make simple changes. The tricky part is that Arduino builds a library (archive) from the core and links against this.

One other important note about my eclipse configuration. While I did install the CDT for the editor, I pointed the arm compiler toolchain at the same location that Arduino IDE uses from the Due. I did not want multiple instances of the arm toolchain. I also set my default shell path to look for these so I can run them from terminal.

zmemw16
Posts: 1449
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: Upgrading to CubeMx 4.12.0 and MIDI USB

Post by zmemw16 » Sun Jan 03, 2016 2:42 pm

somewhere, some when i've seen a note about cdt / openocd and not putting the arm compiler suite in your path.
the other recollection was that it wanted everything you need to install was under /opt; i took the defaults and
edited ./.bashrc and ./.profile as i can never remember which does what.
this is debian 8.x and gnuarmeclipse, so it probably doesn't help.
srp

User avatar
sheepdoll
Posts: 236
Joined: Fri May 22, 2015 12:58 am
Location: Silicon Valley Vortex
Contact:

Re: Upgrading to CubeMx 4.12.0 and MIDI USB

Post by sheepdoll » Mon Jan 04, 2016 6:15 am

Much better progress tonight.

Eclipse Openocd Debug is now fully operational. The issue was the c compiler flags. I changed the makefile so it uses the same flags as the ArduinoIDE. Now when I access openocd through eclipse it halts on HAL_Init() Stepping seems to work. Now the LED blinks, as that is all the test sketch does.

I was also able to find some places in the project properties where one could add in some include paths. This made some but not all of the 'unresolved' warnings go away. In the project properties section are things called filters. My guess is that these can be configured to include and exclude files from the Navigator window. I do notice that the little icons also show the source version control state. One could probably spend the better part of a lifetime, managing versions and such.

The CDT editor like Xcode seems to have some sort of auto syntax activated. Many of these warnings are rather pedantic. Obviously the code compiles and runs. Eclipse seems to want to define a big monolithic project. My workflow is to have dozens of small projects. I do not like seeing the closed projects in the workspace. The navigator window also shows every file in the folders. This makes switching between board environments awkward. Even having multiple sketches and libraries is cumbersome.

Some of these nag warnings can be useful. I was able to remove the missing destructor warning on the Serial Print stream. My exposure to C++ is minimal, I do seem to remember having been taught that all classes should define a destructor. Eclipse is still complaining about the missing HardwareSerial vtable. This may be that there is no HardwareSerial.cpp in the project. UARTClass inherits this so I did not see the need for the redundant class structure. If I was more experienced with C++ I could probably fix this.

Next will be to get the CDC USB instantiated and connected to the stream class. I also have the SDIO configured and the FATFS Middleware included. From the debugger I can see that the init code is being called and the local structures allocated.

Post Reply