none
Windows CE 7 SPI Driver Not Loaded at Startup RRS feed

  • Question

  • Hi all, 

    I am a newbie. 

    I want to develop device drivers on Windows CE 7.

    I use Adeneo BSP on TI AM33xx Development Board

    I want to drive a SPI Flash so I should use SPI driver. 

    I have written my driver and when I debug it, all functions calling correctly. But when I call the 

    CreateFile( _T("SPI1:"),
    GENERIC_READ | GENERIC_WRITE,
    FILE_SHARE_READ | FILE_SHARE_WRITE,
    NULL, OPEN_EXISTING, 0, NULL);

    deviceHandle always return invalid value. So when I debug the low level SPI driver, I seen , SPI_Init() stream function never called. 

    There is this tines in my platform.reg file 

    ;===============================================================================
    ; MCSPI driver
    #include "$(_PLATFORMROOT)\AM33x_BSP\SRC\DRIVERS\MCSPI\mcspi.reg"

    And 

    My mcspi.reg file is 

    ;-- SPI Driver -----------------------------------------------------------------
    IF BSP_AM33X_MCSPI1
    [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\SPI1]
        "Prefix"="SPI"
        "Dll"="am33x_mcspi.dll"
        "Index"=dword:1
        "Port"=dword:1
        "Order"=dword:8
        "MemBase"=multi_sz:"48030000"
        "MemLen"=multi_sz:"00000100"
        "Timeout"=dword:300
        "PowerFlags"=dword:00000103              ; send pre/post device state changes
    ; PMCLASS_PMEXT_GUID
        "IClass"=multi_sz:"{0AE2066F-89A2-4D70-8FC2-29AEFA68413C}"
    ENDIF

    [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\SPI1] this lines say to us, "SPI1 driver will be loaded at startup", isnt it ??? 

    But spi driver SPI_Init function never loaded at starttup. I havent seen any extra setting in Microsoft White Paper. 

    And additional,

    I have tried 

    ActivateDeviceEx(TEXT("Drivers\\BuiltIn\\SPI1"), NULL, 0, NULL);

    and

    LoadLibrary(TEXT("am33x_mcspi.dll"));

    functions but result is same. 

    Is there any extra setting for Driver Loading?

    Thanks

    Murat.

    Tuesday, July 31, 2012 7:15 AM

Answers

  • You already know where to enable the debug zones as you've shown in one of your replies. In that same Debug Zones dialog find device.exe and enable the debugzones for that module. That is the device manager and its debug output will show you if device manager is attempting to load your driver at all or not.

    Or just follow the million other suggestions in this thread, they will all lead to a solution.


    Good luck,

    Michel Verhagen, eMVP
    Check out my blog: http://guruce.com/blog

    GuruCE
    Microsoft Embedded Partner
    http://guruce.com
    Consultancy, training and development services.

    • Marked as answer by cakmakmurat Wednesday, August 1, 2012 11:15 AM
    Tuesday, July 31, 2012 10:00 PM
    Moderator

All replies

  • You probably forgot to add the module to the kernel (by adding a line in platform.bib under MODULES). Using KITL it'll all seem to work just fine, because KITL can load the module from your desktop machine (running Platform Builder). Once you create the final image and try it with your test application it can't find the DLL in the \Windows folder as it's not included.


    Good luck,

    Michel Verhagen, eMVP
    Check out my blog: http://guruce.com/blog

    GuruCE
    Microsoft Embedded Partner
    http://guruce.com
    Consultancy, training and development services.


    Tuesday, July 31, 2012 7:51 AM
    Moderator
  • Hi Michel,

    I have look at the  platform.bib files, there are some lines about it 

    #if (defined BSP_AM33X_MCSPI1 || defined BSP_AM33X_MCSPI2 )
    am33x_mcspi.dll $(_FLATRELEASEDIR)\am33x_mcspi.dll NK  SHK
    #endif

    When I use dumpbin.exe for am33x_mcspi.dll, I can see included functions

    SPI_Init
    SPI_Deinit
    SPI_Open
    .
    .

    etc.

    And additional When I use CreateFile("SPI1:", ...), SPI_Open file not calling. 

    Problem is Driver registration, linking error? 

    It is a standart BSP and I dont change anythink. I think it should work fine. 

    Thanks.

    Murat.

    Tuesday, July 31, 2012 8:45 AM
  • Have you selected the right item from the catalog items so that the SPI driver is included because BSP_AM33X_MCSPI1 is set ?

    Could you use viewbin on NK.bin to see if the DLL is included into image ?

    viewbin -t NK.bin > NK.txt

    Paolo

    Tuesday, July 31, 2012 8:49 AM
  • Yes, In catalog items windows SPI1 and SP2 is selected on selected BSP. 

    And I have used viewbin and there is a line about it

    7/31/2012  07:19:21       28672  am33x_mcspi.dll



    Tuesday, July 31, 2012 8:55 AM
  • Using remote tool registry editor you can see SPI driver under 

    HKEY_LOCAL_MACHINE\Drivers\Active

    ?

    And you can use process viewer to see if the driver is really loaded.
    Tuesday, July 31, 2012 9:02 AM
  • Navigate to FLAT RELEASE DIRECTORY on your desktop  and check ,

    1. Search for reginit.ini file and open it and confirm that your SPI registry entries are listed in it.

    2. Search for CE.bib file and confirm that your SPI dll is listed in it.

    If your SPI entries are listed there it should load your SPI dll at boot time.

    3. Also in VS Navigate to Build->Open Release Directory in Build Window and give command set BSP and make sure that BSP_AM33X_MCSPI1 & BSP_AM33X_MCSPI2  is set.

    Regards,

    Rakesh.

    Tuesday, July 31, 2012 9:57 AM
  • Rakesh,

    There is a line CE.bib file, like as

    am33x_mcspi.dll C:\WINCE700\OSDesigns\AM335X_OS\AM335X_OS\RelDir\AM33X_BSP_ARMV7_Release\am33x_mcspi.dll NK  SHK

    And when I apply the set BSP command on "Open Release Directory ..." result is 

    BSP_AM33XX_MCSPI1=1
    BSP_AM33XX_MCSPI2=1

    It looks like, driver included successfully.

    I am debugging SPI driver with breakpoints. It can be a problem? Maybe program not fall to breakpoints?

    Other breakpoints working fines but

    breakpoints never work in DLLMain, SPI_Init and SPI_Open(When CreateFile function called) functions in spi.c file. 

    Thanks.

    Tuesday, July 31, 2012 10:41 AM
  • Enable debugzones for the device manager and build a debug kernel so you can see why it is failing.

    Good luck,

    Michel Verhagen, eMVP
    Check out my blog: http://guruce.com/blog

    GuruCE
    Microsoft Embedded Partner
    http://guruce.com
    Consultancy, training and development services.

    Tuesday, July 31, 2012 10:42 AM
    Moderator
  • SPI driver(am33x_mcspi.dll) not in the "CE DEBUG Zones" list( Target->CE DEBUG Zones ). 

    its mean, driver not included to OS?

    As I seen, DebugZones activated on DLLMain function but DLLMain function in SPI driver, never called. 

    So Activate zone not active for this driver. 

    But all parameters shows spi driver included successfully and will be loaded at startup. 

    What's wrong? 

    Thanks.

    Murat.

    • Edited by cakmakmurat Tuesday, July 31, 2012 11:23 AM
    Tuesday, July 31, 2012 11:19 AM
  • Probably, but why don't you enable the debug zones for the device manager (as I asked previously)? That way you will be able to see WHY it is failing to load.

    Good luck,

    Michel Verhagen, eMVP
    Check out my blog: http://guruce.com/blog

    GuruCE
    Microsoft Embedded Partner
    http://guruce.com
    Consultancy, training and development services.


    Tuesday, July 31, 2012 11:21 AM
    Moderator
  • Can you also check the reginit.ini file ?  Can you show us the .def file of your SPI driver and source file ?

    Thanks/Regards,

    Rakesh.

    Tuesday, July 31, 2012 11:26 AM
  • Another way to confirm that DLL is included in runtime image (NK.bin) or not is - In visual Studio open the NK.BIN as file instead of solution and then check the registry and "All files" section. Your DLL must be under "All files" section there.

    Regards,

    Rakesh.

    Tuesday, July 31, 2012 11:44 AM
  • Michel,

    I am newbie and I know only that debug zones enables with above code : 

    extern "C" BOOL WINAPI DllMain(HANDLE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
    {
    switch(dwReason)
    {
    case DLL_PROCESS_ATTACH:
    DEBUGREGISTER((HINSTANCE) hinstDLL); // Register Debugs
    break;
    }
    }

    As I seen, DLLMain never called by Device Manager.

    Rakesh,

    Only REGEDIT4 expression is in the regedit.ini file. 

    I dont mean it. 

    am33xx_mcspi.def file content is

    LIBRARY SPI

    EXPORTS 
        SPI_Init
        SPI_Deinit
        SPI_Open
        SPI_Close
        SPI_Write
        SPI_Read
        SPI_IOControl

    Source file is really long so maybe it is not correct put the source code here. 

    SPI source code is written by Adeneo.

    İf you want, you can connect to my computer via TeamViewer etc. 

    Thanks. 

    Murat

    Tuesday, July 31, 2012 11:57 AM
  • For loading driver on boot the following registry entries :

    [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\SPI1]

        "Prefix"="SPI"
        "Dll"="am33x_mcspi.dll"
        "Index"=dword:1
        "Port"=dword:1
        "Order"=dword:8
        "MemBase"=multi_sz:"48030000"
        "MemLen"=multi_sz:"00000100"
        "Timeout"=dword:300
        "PowerFlags"=dword:00000103              ; send pre/post device state changes
    ; PMCLASS_PMEXT_GUID
        "IClass"=multi_sz:"{0AE2066F-89A2-4D70-8FC2-29AEFA68413C}"

    must be inside reginit.ini...

    Tuesday, July 31, 2012 12:20 PM
  • Scroll down the reginit.ini file and you will get full content !!  I was asking for sources file and not the full source code. Navigate to SPI driver source code , you will find file called sources.

    Regards,

    Rakesh.





    Tuesday, July 31, 2012 1:48 PM
  • Ups, all content of regedit file is in the below of file :)

    These lines are in the my reginit.ini file : 


    ;===============================================================================
    ; MCSPI driver
    ; --> Entering C:\WINCE700\platform\AM33x_BSP\SRC\DRIVERS\MCSPI\mcspi.reg
    ;-- SPI Driver -----------------------------------------------------------------
    [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\SPI1]
        "Prefix"="SPI"
        "Dll"="am33x_mcspi.dll"
        "Index"=dword:1
        "Port"=dword:1
        "Order"=dword:8
        "MemBase"=multi_sz:"48030000"
        "MemLen"=multi_sz:"00000100"
        "Timeout"=dword:300
        "PowerFlags"=dword:00000103              ; send pre/post device state changes
    ; PMCLASS_PMEXT_GUID
        "IClass"=multi_sz:"{0AE2066F-89A2-4D70-8FC2-29AEFA68413C}"

    [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\SPI2]
        "Prefix"="SPI"
        "Dll"="am33x_mcspi.dll"
        "Index"=dword:2
        "Port"=dword:2
        "Order"=dword:8
        "MemBase"=multi_sz:"481A0000"
        "MemLen"=multi_sz:"00000100"
        "Timeout"=dword:300
        "PowerFlags"=dword:00000103              ; send pre/post device state changes
    ; PMCLASS_PMEXT_GUID
        "IClass"=multi_sz:"{0AE2066F-89A2-4D70-8FC2-29AEFA68413C}"

    ; <-- Leaving C:\WINCE700\platform\AM33x_BSP\SRC\DRIVERS\MCSPI\mcspi.reg

    I think, it is correct  for loading at startup. 

    And source files content is : 

    !INCLUDE "..\sources.inc"

    TARGETNAME=common_ti_mcspi
    TARGETTYPE=LIBRARY
    SYNCHRONIZE_DRAIN=1

    DLLENTRY=_DllMainCRTStartup

    CDEFINES=$(CDEFINES) -DCEDDK_USEDDKMACRO

    SOURCES= \
        dma_init.c \
        spi.c

    Thanks.

    Murat.

    Tuesday, July 31, 2012 3:30 PM
  • I am confused, you say:

       "I have written my driver and when I debug it, all functions calling correctly. But when I call the..."

    How is it that all functions are "calling correctly" (whatever that means) but you can't actually use CreateFile to access the driver?

    Did you write this driver from scratch?  Is it the original from the BSP?  You have stated both ways.

    I would verify that the file is in the OS that is running on the board - I know that you show that it is in the nk.bin on your PC - but is that nk.bin running on the board?  hint: remote file viewer

    I would then verify that the registry settings are on the OS running on the board.  hint: remote registry editor


    Bruce Eitman (eMVP)
    Senior Engineer
    Bruce.Eitman AT Eurotech DOT com
    My BLOG http://geekswithblogs.net/bruceeitman

    Eurotech Inc.
    www.Eurotech.com

    Tuesday, July 31, 2012 5:05 PM
    Moderator
  • You already know where to enable the debug zones as you've shown in one of your replies. In that same Debug Zones dialog find device.exe and enable the debugzones for that module. That is the device manager and its debug output will show you if device manager is attempting to load your driver at all or not.

    Or just follow the million other suggestions in this thread, they will all lead to a solution.


    Good luck,

    Michel Verhagen, eMVP
    Check out my blog: http://guruce.com/blog

    GuruCE
    Microsoft Embedded Partner
    http://guruce.com
    Consultancy, training and development services.

    • Marked as answer by cakmakmurat Wednesday, August 1, 2012 11:15 AM
    Tuesday, July 31, 2012 10:00 PM
    Moderator
  • Hi Bruce,

    Sorry, OK, its not clear. 

    I use Adeneo BSP for TI AM33xx Development Board and this BSP have a SPI Driver.

    And Additional I want to develop a specific SPIFlash(SFL) Driver. 

    My SPIFlash(SFL) Driver use Adeneo SPI Driver. 

    SFL_Init() and DLLMain function of SFL called at startup

    but

    SPI_Init() and DLLMain function of SPI never called.

    When I Call CreateFile("SFL1:", ...) function SFL_Open called by device manager.

    In SFL_Open function, I call CreateFile("SPI1:", ...) function but SPI_Open() function not called and CreateFile returns Invalid Handle. 

    I am trying this states on Development Board. After building, I connect the demo board and trying on it. 

    There is test application about SPI in BSP. When I try it, SPI Stream Interface functions never called too. 

    I wrote Adeneo but nobody return me. I am waiting them. 

    Thanks.

    Murat

    Wednesday, August 1, 2012 6:52 AM
  • What is the loading order of your driver  SPIFlash(FSL) ? Check the registry of your FSL driver. The order must be above 8 as the SPI driver load order is 8 as per your registry.

    "Order"=dword:8

    Regards,

    Rakesh.


    Wednesday, August 1, 2012 7:05 AM
  • I couldnt find outputs of DEBUGZONES. Finally, I canalize debugmessages to a log file. 

    And this lines show my problem : 

    8261 PID:400002 TID:1570006 OSAXST1: >>> Loading Module 'am33x_mcspi.dll' (0x9E835DC0) at address 0xEE200000-0xEE20C000 in Process 'NK.EXE' 
    8266 PID:400002 TID:1570006 ERROR: SPI_Init: Failed to find IRQ number for this SPI controller
    8267 PID:400002 TID:1570006 OSAXST1: <<< Unloading Module 'am33x_mcspi.dll' (0x9E835DC0) at address 0xEE200000-0xEE20C000 in Process 'NK.EXE'

    I put the breakpoints but program not fall the breakpoints, interesting. Other breakpoints working.

    Thanks everybody.

    And now I must to solve this IRQ problem. Any suggestion :)

    Thanks.

    Murat.

    Wednesday, August 1, 2012 11:17 AM