MapMem to read SPI0 registers on VF61

In the past I used MapMem library to read USB registers on VF61 running Win CE 6.
Now I’m trying to follow the same approach to read the registers related to SPI0 (SPI0_MCR, SPI0_TCR, SPI0_CTAR0, …). I wrote this code

void Read_Spi_Registers(void)
{
	HANDLE hMapMem = NULL;            ///< handle to the MapMem library
	BOOL success;
	DWORD	SPI0_MCR;
	DWORD *reg;

	// === Initialize MapMem library. ===
	hMapMem = Map_Init();   
	ASSERT(hMapMem != 0);

	reg = (DWORD *)Map_MapMemory((DWORD)0x4002C000, 4);
	SPI0_MCR = *reg;
	Map_UnMapMemory(reg);
	wprintf(L"SPI0_MCR =\r\n\t0x%08X\r\n", SPI0_MCR);

	// === De-Initialize MapMem library ===
	success = Map_Deinit(hMapMem);
	ASSERT(success);

	return;
}

but I get an exception.
I suspect this is related to the clock of the peripheral not enabled (the same issue described here), but I don’t find any way to get it working.
Looking at VybClk_EnableClock(), I don’t see any tVybClkId for SPI0.

After a deeper investigation, I’m not so sure the problem is in the clock, since SPI0 peripheral works as expected (I checked with an oscilloscope).

you can find the spi clock id in clk_vyb.h with the following name

clkSpi0 = 12,
clkSpi1 = 13

I made some changes in your code & now it is working fine.

void Read_Spi_Registers(void)
 {
     HANDLE hMapMem = NULL;            ///< handle to the MapMem library
     BOOL success;
     DWORD    SPI0_MCR;
     DWORD *reg;
     HANDLE hclk ;

    //===Initialize clock ====
	 hclk = VybClk_Init(NULL);
	 VybClk_EnableClock(hclk , 12, TRUE);
	
     // === Initialize MapMem library. ===
     hMapMem = Map_Init();   
     ASSERT(hMapMem != 0);
 
     reg = (DWORD *)Map_MapMemory((DWORD)0x4002C000, 4);
     SPI0_MCR = *reg;
     Map_UnMapMemory(reg);
     wprintf(L"SPI0_MCR =\r\n\t0x%08X\r\n", SPI0_MCR);

    // to deinit clock
	// VybClk_Deinit(hclk);
 
     // === De-Initialize MapMem library ===
     success = Map_Deinit(hMapMem);
     ASSERT(success);
 
     return;
}

It works. I missed the entries for clkSpi0 and clkSpi1.
Thanks