2009-12-12 11:14 AM
STVP / STM8S-Discovery crashes Windows
2011-05-17 06:05 AM
I hope I'm doing something stupid, but if I try to get STVP to communicate with my STM8S-Discovery board it crashes Windows - the crash report says it's due to a driver fault.
I'm running XP Pro SP3 and STVP 3.1.3 I installed STVP then plugged the Discovery in. The STM8S-Discovery User Manual (UM0817) says: ''The driver for ST-Link is installed automatically when the USB is connected.'' Windows configures the device as a USB mass-storage device using a generic Microsoft driver, which is not what I expected. Though it does contain 3 Internet shortcuts to STM web pages, so someone evidently expected it to be accessed as a disk sometimes. The STM8S-Discovery runs the Discover program OK (flashing green LED changes speed when you touch the pad), but there's no sign of activity on the ST-Link part of the board. If I try to read anything from the device - in particular the option bytes as per section 4 of UM0834: ''Developing and debugging your STM8S-DISCOVERY application code'' - Windows crashes immediately. Any suggestions? [ This message was edited by: smh on 30-11-2009 01:12 ]2011-05-17 06:05 AM
Perhaps I can tempt someone to reply to some direct questions:
2011-05-17 06:05 AM
Pretty quiet board. I just got the board and I managed to compile the example. As far as I see the only driver is the generic USB disk driver. I did not install anything. There may be something else but it isn't registered in Windows. This comes from someone who is far from an expert and would be more comfortable doing this on linux or mac. BTW this is running on WinXP via VMWare on a Mac.
When it uploaded and communicated with the board the LED flashed like nuts so I know it was working.2011-05-17 06:05 AM
A bit more info, in case anyone at ST is interested:
2011-05-17 06:05 AM
Thanks for the feedback.
I just tried on a different computer and it communicates OK - flashing red LED as you say. So now I have to figure out why my main machine crashes so horribly: both machines are XP Pro SP3 / AMD and as far as I can see both are using the same driver versions for USB Storage Device and Disk Drive.2011-05-17 06:05 AM
A bit more info:
When you start debugging in STVD it appears to spawn gdb7.exe, with the command line: gdb7.exe --quiet --command=swim\gdbswim_stlink.ini Issuing this command from a command shell starts up gdb OK gdbswim_stlink.ini defines four user commands for gdb: emulator-reset-port emulator-reset-port-mcu emulator-reset-hotplug-port emulator-reset-keepswim-port-mcu And the following command in gdb crashes Windows: (gdb) emulator-reset-port 0 This is the definition of emulator-reset-port:Code:
define emulator-reset-port target gdi -dll swimstm_swim.dll -stlink3 -port $arg0 This pulls in stm_swim.dll, which in turn loads STLinkIIIUSBDriver.dll I guess STLinkIIIUSBDriver.dll is searching through the attached disks to find an stlink device, and something in that search process is blowing up my RAID driver. So, if I knew how this search is being done, I could write a small program to reproduce the problem and report the bug to NVidia...2011-05-17 06:05 AM
Hi there.
Great work with the troubleshooting that you've done so far! I'm relatively new to microcontrollers, but have worked in software quite a bit. The mods at this forum may not want us to go in-depth with hooking into their code, but if they are unwilling to support you as a customer, you should be able to troubleshoot and correct the issue yourself. After taking a quick look at the DLL you mentioned, there are only 8 named exports, so writing a small shim to log the functions as they're called and the parameters they're called with shouldn't be too much trouble. If you're using windebug or another Ring0-based debugger you may be able to breakpoint the functions and avoid that. The exported functions are indeed for enumerating and opening storage devices. The thing that I question is that this may not be an Nvidia problem, but instead the STLINK functions mistaking your RAID controller for something else and Opening/Sending an unsupported call or an allocation of the resource is failing (since it is the wrong type of device) and there is no error-checking to avoid a null-pointer in the driver. I would suggest shimming the USBDriver.dll and logging the STMass_* exports to determine the last values and the function where the fault occurs. Patching in a work-around would be possible at that point, but it would be nice if the ST guys could facilitate this by throwing out a Debug version of the file for you to be able to avoid writing an intermediate DLL and then creating a properly patched build.2011-05-17 06:05 AM
I've used windbg to trace a bit more of what's going on. By setting a breakpoint when STLinkIIIUSBDriver.dll is loaded, I can see the exports and set breakpoints on them all, then trace into the code looking for tell-tale kernel calls.
The crash occurs when STLinkIIIUSBDriver!STMass_SendCommand calls kernel32!DeviceIoControl on the D: drive. It's already been through the same process on C: without problems. (C: and D: are both partitions on the RAID disk). I'm now trying to work out which DeviceIoControl function is being called. dwIoControlCode = 0x000007a8. The parameters to the same call for the C: drive looked slightly suspect to me, see below, but the call succeeded. Unfortunately I didn't catch all the values on the call to D: this time round. Parameters for DeviceIoControl call on C:Code:
88 07 c3 00 handle (0x00c30788) <- refers to \.C: a8 07 00 00 dwIoControlCode (0×000007a8) <- what function is this? 45 f9 12 00 lpInBuffer (0x0012f945) <- valid data memory 88 13 00 00 nInBufferSize (5000) 01 06 f1 80 lpOutBuffer (0x08f10601) <- Garbage ? 00 00 00 00 nOutBufferSize 0x0 00 00 00 00 lpBytesReturned (NULL) 00 00 00 00 lpOverlapped (NULL) MSDN says this about lpOverlapped and lpBytesReturned: ''If lpOverlapped is NULL, lpBytesReturned cannot be NULL. Even when an operation returns no output data and lpOutBuffer is NULL, DeviceIoControl makes use of lpBytesReturned. After such an operation, the value of lpBytesReturned is meaningless''. This is a painful process, especially because running the program too far crashes Windows and I have to set everything up again. Please, is there someone from ST listening prepared to make this task a bit easier by checking over the code (even telling me what the DeviceIoControl function is would be a help) or publishing the codeefragment that is searching for the ST-Link device?2011-05-17 06:05 AM
That is very odd.
Does the gdb reset-port command still pertain to what you said with: ''The crash happens whether or not the board is connected to the PC. ''? If so, have a go at setting a breakpoint on the enum_getdevice function (bp 10017945) from windbg. Step over the call and see if eax is returning 0 when the board's not connected. There are notes within the DLL for what the various IOCTL ''errors'' could be (look for ''Cmd (status ='' in stm_swim.dll). There are no hard-coded calls with the parameter that you posted in the USB Driver DLL that I could outright see, but I would still be curious if the enumeration function is erroneously reporting that you have a device when none is present. Why ''SendCommand'' to an unsupported device? Also, if you could give the return eip from the stack on the fatal DeviceIOControl call, that could help as well. I absolutely agree that ST should facilitate troubleshooting this, however.