How to develop a stream interface driver for iMX7 WINCE700

Hi,

I need to develop a stream interface driver. How do I go about developing it using the Toradex SDK and the libraries. I am using the iMX7 Dual SoM and have VS2008.

Thanks
Deepak

Dear @kapeed

This is a simple question with a complex answer. There is for example a 280-pages book available about this topic:

I’m afraid it is not possible to wrap up all this information in an answer on the community. I hope the book is a good starting point for you.

Regards, Andy

Hi Andy,

I am familiar with design of stream interface drivers for Windows CE, though not an expert.
I have designed and developed stream interface drivers for Windows Ce in previous projects, but that time I was using the Platform Builder and
had the BSP source code. The driver always had been a part of the Platform, and was included in the OS Image(nk.bin).
These drivers would be loaded either automatically or through the application. The device drivers were designed to loaded in the Kernel space.

I have doubts arising in the current case where what I have VS2008, Toradex SDK and libraries and the Toradex Colibri SoM and Eval board.

With my current understanding, the Toradex SDK allows developing only applications and the interaction with the hardware is achieved through the
Toradex libraries.

In this context how do I develop a device driver?

The second part of my query is, one of the tasks of our embedded system requires extremely low latency handling in the order of 25 uSec.
There are some architectural design tricks that could reduce the latency requirement, yet the latency would be in the range of 40~50uSec.
We need to develop an IST that would be handling this task, the IST would be transferring data over the external memory interface.
My understanding is that if the IST operates within the Kernel Space we have a better chance of meeting the latency requirement since address translation time from user space memory address to kernel space memory would get saved.

Then this requires that the IST be a part of kernel space driver. Is it possible to develop a Kernel Space driver using the Toradex SDK and just the VS2008?

Thanks
Deepak

Hi Andy,

Can you please help me out here.

Dear @kapeed

There’s a lot of options I want to explain you, which are all kind of related. Let’s see if I manage to put all this down in a structured way…

Platform Builder vs Visual Studio

It is possible to write a stream driver using Visual Studio without Platform Builder. The basic steps are:

  1. Create a regular DLL which exports the standard functions required by every stream driver
  2. Copy the DLL onto the Colibri, into the folder \Flashdisk\System\.
  3. Use the registry editor on the target to add the required settings in [HKLM\Drivers\BuiltIn\YourDriver] (you can also import a *.reg file)
  4. Save the registry
  5. Reboot the target, your driver gets loaded

Our SDK was not implemented with driver development in mind, therefore you might need some minor tweaks to use it for driver development:

  • Not all required header files are included in the SDK. For many functions it will be sufficient to just declare the function prototype in order to make such functions available to your code.
  • Not all import libraries are included in the SDK. If declaring the prototype is not sufficient and the linker throws an error, you will need to “manually” load the function by calling LoadLibrary() and GetProcAddress()

The big drawback of not having Platform Builder is, that there is no way to attach a debugger the driver code. You can use DEBUGMSG() to print out information to the debug port.

Driver?

I want to bring up the question whether you need and want a driver at all. Compared to most BSPs, the Toradex BSP offers support to access pretty much all resources from your application in user mode, including

I don’t know your application, but chances are usually high that you can avoid kernel mode switches and thus be more efficient by writing everything in user mode.

IST vs ISR

Your latency requirement of 25µs is pretty tough. You probably should target an ISR instead of an IST.

M4

The Colibri iMX7 features an additional Cortex-M4 core which is not used by the operating system. Did you think about putting your time-critical process into this CPU? You can run it barebone, or with a lightweight OS such as FreeRTOS.

Regards,
Andy

Hi Andy,

Thanks for your guidance.

Since you asked whether we really need a device driver, there is a back story to it. We had previously written a printer control system application over our custom board using iMX51 and WINCE700. We are now porting the same application to a Toradex based designed.

We had used printf messages for testing our application. Since the control system has headless and in motion, we had written a device driver that used to route this printf messages over a raw TCP socket connection. We used SetStdioPath to redirect the formatted printf strings to our device driver.

Same approach we are trying to use with the Toradex system. The device driver does not access any hardware registers or Physical memory. Just waits for an incoming connection requests and routes all the messages to the remote client.

For accessing the hardware we are very happy with the Toradex libraries as they give almost complete control for the application developer.

Is there a better way of achieving this?

Thanks a regards
Deepak Kukreja

Dear @kapeed

From what I understood (I must admit I didn’t completely understand everything) I still think you could go without a driver. This might not affect the latency, but could decrease system complexity.

However, as you already had a working solution with your driver which is completely hardware-independent, you should be able to even use the binary driver DLL and load it on our hardware.

Regards, Andy

Hi Kapeed,
you can develop a driver using VS2008 and our SDK, there are two issues but may not be blocking:

  • you may not have include files for all the functions you need, usually copying the prototype from the reference is enough to access them
  • you can’t debug your driver with the interactive debugger, you have to add RETAILMSG calls to print messages on the debug console
    You can build your code as a DLL. Remember to export your functions using a def file and extern “C” to prevent C++ name decoration to get in the way.
    On the system you have to load your driver using ActivateDeviceEx from an application or by loading it from builtin registry key but only after the local filesystem has been mounted. On Tegra this is granted, on imx6/7 and vybrid you should load your driver after the Wait4Flash one.

Hi Valter, Thanks, I will be trying this approach. There is one piece that seems missing though, shouldn’t there be something analogous to the bib file entry that we create for a regular device driver when using the Platform Builder? In your suggested approach how would we be specifying to the Device Manager whether to load the driver in Kernel Mode or User Mode?

One more thing is, is there any restriction on the location in the devices’ file system where the dll is to be copied?

Thanks
Deepak

Dera @kapeed

The .bib entry just makes sure the driver ends up in the image. This is not required if you copy it as a .dll file onto the device. The driver is loaded by the Kernel, and therefore works in Kernel mode automatically, there’s no choice about this.

It is preferable to copy the driver to * \Flashdisk\System\ *, because this is part of the system path.
You can copy the driver to any random location, but then you need to specify the full path in the registry setting "Dll"="<yourpath>\yourdriver.dll".

Regards, Andy