STM32 EEPROM Emulation vs HAL_FLASH and HAL_FLASH_EX driver - embedded

Looking to confirm options to persistently save values on an STM32H7 device.
My understanding of the high level options are:
EEPROM Emulation with eepropm.h/c (which uses the HAL_FLASH/EX drivers)
HAL_FLASH and HAL_FLASH_EX drivers, stm32h7xx_hal_flash.h/c stm32h7xx_hal_flash_ex.h/c
External storage of some kind, EEPROM, FLASH, ect.
Are there any other library options for doing this?
What is the added value of the eeprom library?
As far as I can tell, the eeprom library only provides 3 functions, and is not all that configurable. I see it as more of an example that could be modified than a library that is ready to use.
ST AN4061 App Note For reference the ST app note for STM32F0xx eeprom emulation, suggestions adding wear-leveling yourself, but also in the introduction states:
"At least two Flash memory pages to be used, more if possible for wear leveling"
This implies to me there is wear leveling.
Additionally, are these options thread safe? the HAL_FLASH driver does have interrupt options, but the eeprom library does not make it clear how to, if possible make that happen.
Options that provide wear-leveling and are thread safe would be preferred.

Related

Talk to an USB HID device from within GNU Octave

I need to control a measurement instrument from within GNU Octave. The instrument has an USB HID interface. I just need to read or change the settings of the instrument. It's not about getting measurement data from the instrument.
What options are there to do this from within GNU Octave, and how do they work?
The simplest approach would be to use an already made Octave package (like the instrument-control package). Then you could check the documentation and read /write to and from a USB device.
The package linked above (and here again) has a USB TMC set of functions if the USB device works with this library. See the function list to find out how to use the package. As far as I am aware this package only works on Linux for USBTMC (according to the wiki).
Otherwise if you are not running Linux, or the device is not supported, I cannot specifically see any other already-written set of Octave functions for communication.
However, if you have the time it could be worth writing just a singular MEX (C/C++) function to open the communication channel and read settings from the device.
You could then make this work on Windows as well. Most of this functionality is already implemented in libraries such as signal11 (just to name one...), which that library itself is already cross-platform. Using that library inparticular makes it look like a very short MEX file to write.
I hope this helps and check out the links for further information about the topics discussed :)

ISA port communication with Visual Basic

Is there any chance how I could write something to ISA card in Visual Basic .Net for Windows XP and higher? (I know Win XP and higher have restriction so U cant directly write data to port)
I have also done some research and if I understand the situation I have only 2 options:
Write driver (very problematic option :)) or
Try to use existing driver in kernel32 like driver to serial/paralel port.
If there arent any other options, how I have to modify "using of serial/paralel port" to use it for ISA port?
Modern versions of Windows will not allow direct port I/O from a user application. Your program is running in Ring 3, not Ring 0. You need some kind of driver to do the port I/O on your application's behalf.
The first thing to do would be to contact the card manufacturer and see if they made a Windows driver for your board.
If a Windows driver is not available, and you are only looking to do basic reigster reads and writes (no interrupts or DMA), there are some freely-downloadable libraries that you can download to do port I/O. Basically, the library includes a dummy "driver" that sits in Ring 0 and does the I/O for you. I have the most experience with WinIO.
WinIO has a C/C++ API, nothing .Net/CLR. You will need to use P/Invoke to call the WinIO functions from managed code.
If you search around, you may find a toolkit similar to WinIO that provides APIs for managed code. (Edit: Here is one I have bookmarked called DirectIO.)
The biggest problem with WinIO is that you are limited to basic register reads/writes. If you need interrupts or DMA, you are out of luck. At that point, you will need to write a "real" driver.
Writing a driver can be a pretty major task for the uninitiated (there is a lot you will screw up). You will need to start by getting a copy of the Windows Driver Kit, and studying Microsoft's Kernel Mode Driver Framework. You could also look into purchasing a copy of Jungo WinDriver. WinDriver is a third party tool that simplifies driver development considerably, but it is quite expensive for a one-off project.

Making my own application for my USB MIDI device

I want to try and make my own application for my Novation Nocturn, which is a USB DJ controller surface. The application software interacts with it to send out MIDI messages to software like Traktor, Ableton and Cubase.
I'm aware of libusb, but that's as far as I've got. I've successfully installed it to interact with my device but stopped there.
I'm after some suitable reading material basically. USB specs, MIDI specs and such. If I'm honest the full USB 2.0 spec looks like it holds loads of stuff I don't need.
Just looking for something interesting to do now that I've finished my degree (Computer Science). My current programming knowledge is C++ and mainly C#.
Could do with some direction on how to get stuck into this task.
edit:
Update to include some info from the Device Manager on the Nocturn.
Hardware IDs:
USB\VID_1235&PID_000A&REV_0009
USB\VID_1235&PID_000A
Compatible IDs:
USB\Class_FF&SubClass_00&Prot_00
USB\Class_FF&SubClass_00
USB\Class_FF
Device Class:
MEDIA
USB MIDI is probably one abstraction layer lower than you want to deal with. I'd suggest finding a good MIDI framework and interacting with the device via MIDI instead.
For C++, Juce is probably the way to go, as you didn't mention a target platform or any other specific requirements.
If you want to go the .NET route, the easiest way to get started is with the C# MIDI Toolkit code:
http://www.codeproject.com/KB/audio-video/MIDIToolkit.aspx
In there, you'll find all the basics for opening an device, reading input, and writing output. Alternatively, NAudio has some MIDI classes, but they are somewhat incomplete.
As you develop, you'll want a reference for the MIDI spec handy.
A tool that you will find invaluable is MIDI-OX. In fact, I suggest that before you start coding, you fire up MIDI-OX and use it to sniff the messages coming from the Novation. It will give you a good idea of what the Novation sends. You can use it in conjunction with MIDI Yoke (a configurable virtual MIDI port) to insert itself between the Novation, and Ableton Live (or whatever software you normally use with your Novation) so you can see all of the messages in normal use.
Done... Kidding, but I've started on this in Python - I personally want linux support. I am teaching myself python, but I only dabble in programming.
You can see basic functionality at https://github.com/dewert/nocturn-linux-midi. The guy who reverse engineered it (i.e. the leap I wouldn't have been able to make myself) doesn't seem to be doing any more with it. His code is at https://github.com/timoahummel/nocturn-game
I am using PyPortMIDI and PyUSB, both of which I believe are wrappers for the C equivalents. I think this is all ok on Windows, but haven't tried.
What is currently on my github is crap, but it is proof-of-concept. I'm working on doing it properly now, with threading and proper configuration options.
The driver for the Nocturn makes it appear to system as a MIDI device, even though it isn't a USB MIDI device at the hardware level. The Automap software works entirely at the MIDI level, receiving MIDI instructions and sending different instructions in response - it is separate from the driver and not neccesary.
Alternatively, look at https://github.com/timoahummel/nocturn-game for an example of talking to it directly over USB from Python. You can probably port this to another language with libusb bindings.
Old thread, but I've just recently started looking into this.
I had a look at the Python application that dewert has written. Interestingly, it turns out that the data that the Nocturn emits is in fact MIDI, although it doesn't register itself as a USB MIDI device.
But looking at the actual data coming from the device, it actually emits control change messages (0xB0 controller value) for everything. Also the control commands that are sent to it are also control change messages, albeit only the data bytes, as the Nocturn seems to support MIDI running status (i.e. when sending multiple control change messages, it is not necessary to repeat the data byte).
Indeed, the looking at the magical initialization data it is actually just a bunch of control changes: it starts with 0xb0 and from there on the data comes in twos. For instance the last two bytes in the init string are 0x7f 0x00 which simply turn off the LED for the rightmost forward button. (There is something subtle happening as a result of the initialization being sent though, as the Nocturn sometimes emits some messages which appear to be some form of timeout events, and that behavior changes depending on whether the initialization string has been sent or not.)
Using MIDI-like messages makes sense, as Novation would be well aware of the MIDI protocol, so it would be easiest for them to use it for the communication even if the device is not strictly a MIDI device.
Note though that the incrementors just send the values 1 or 127, i.e. +1 or -1 step, so even with some trivial mapping software it's not really useful as it is. (Actually, if turned quickly, one can get 3 or 125 for instance, with the 125 corresponding to -3.) The only controller which sends a continuous value is the slider, which emits an 8 bit value when moved.
I suppose you'll want to know about USB classes in general and USB MIDI class in particular. The latter is the best what you can hope for in case you don't posess documentation for some proprietary protocol (whether it's used there instead).

Porting issues to VxWorks

I am posting details to my previous questions. I need to port a c/c++ codebase that already supports Linux/Mac, to VxWorks. The application uses socket, pthread, mutex and critical section handling APIs.
I am pretty new to VxWorks. Could you let me know what are the possible issues that could arise?
VxWorks provides for standard socket operations so that should be fine.
There is a pthread compatibility library that is also part of the OS. You simply have to include the pthread component.
Without more details on the mutex and critical section handling APIs, it's hard to provide details.
VxWorks has its own API for mutex and critical section, but it also provides a POSIX interface. Different versions of VxWorks match to different version of the POSIX standard.
Depending on what version of VxWorks you are using, heavy C++ STL use might be problematic (especially if you are using an old version of vxWorks).
In C++, you have to be careful of static class instances. It works fine, but I believe it increases the program size since they have to be instantiated statically and are put in the .data segment I believe.
If you have lots of dynamic C++ objects being created and destroyed, it will put more pressure on your heap. If your embedded system has a small memory footprint that might be a problem.
If you create objects on the stack, don't forget to account for this (you have to do the same in C with structs) when you create your threads (which have a fixed size stack initialized at creation time).

MPSOC : Which OS do you use and why?

I'm working on MPSOC, specially STM ST40 (SH4 base) and ST231 and I'm wondering which OS i can use on these to port a parallel application, I already had a look at STLinux which is the STM distribution of a Linux platform for their MPSOC (which unfortunately doesn't work well for ST231 coprocessors) and I also had a look at OS21 which is a task based OS.
Any information about other RTOS are warmly welcome! (specially those with libc and pthreads :)
Those 4 came to my mind:
MicroC/OS-II: Its free and simple, but i think there are too few good resources available
LibeRTOS: I can recommend that. I used it several times for different projects. It's good it's fast and the dual kernel concept is really well done.
RTLinux: Can't tell you much about that one. Only used it once for a very small project and didn't get deep "behind the scenes" But it was fast and reliable. (and very expensive)
VxWorks: Awesome OS... From Wikipedia:
multitasking kernel with preemptive and round-robin scheduling and fast interrupt response
Memory protection to isolate user applications from the kernel
SMP support
Fast, flexible inter-process communication including TIPC
Error handling framework
Binary, counting, and mutual exclusion semaphores with priority inheritance
Local and distributed message queues
Full ANSI C compliance and enhanced C++ features for exception handling and template support
POSIX PSE52 certified conformance
File system.
IPv6 Networking stack
VxSim simulator
Supports: C/C++/JAVA
If money is no problem: Use VxWorks! You can do anything: Upgrade your fridge, built a war machine or fly to Mars ;-)
Otherwise check out LibeRTOS...
If you really want ot use an RTOS, be prepared to use a native API that is way more efficient and streamlined than pthreads...
I have used Micrium's µC/OS-II on several projects, on SH4 and a couple of different ColdFires. I continue to recommend it for new projects today.
Micrium has just announced a major upgrade to be called µC/OS-III that will add unlimited preemptively scheduled threads, as well as a round-robin scheduler for equal priority threads. It doesn't appear to be for sale yet, however.
If you need the capabilities, they also have a FAT file system, a PEG graphical UI library, USB device and host, and TCP/IP available for additional license fees.
Source code to everything is included in the price, and I've always found their support to be friendly and knowledgeable.
With the processors you mention you seem to be into set-top boxes.
You have the choice between the ST Linux distro, which is not very stable and the OSXX distro, which is proprietary for ST, but much more stable and with nice tools for debugging and the like (I'm not so sure about OSCC and libc/pthreads)
Barebones/AMP - because it allows 100% control and it allows the lowest latency.
Using Linux or FreeRTOS is very comfortable but it comes with a price tag.