Thanks Mark you're a star
,
Had already done the gpio_init which sets the pin multiplexer
Then, after posting I stepped through the init and found the reference to the _bsp_init_spi2 but could not find where that was defined. (IAR cannot find the definition or reference cos its in the library, so had to use explorer "find" on the mqx directories, ugh!)
About an hour later, made a guess and changed the appropriate line to
SPI_PUSHR_PCS(2 << 0), /* Chip Select 1? */
and the hardware started working.
As ever, there is no information on any of this in MQXIOUG.pdf
Now, if you look in the DSPI IOCTRL function (buried 4 layers deep in the call stack) there is a get CS and a set CS function. These are mentioned in the documentation but with no clue about what the valid parameter values should be.
Get CS with my new init now returns 1million or so.
Set CS during runtime did not work. At all.
fragment from spi_pol_dspi.c
case IO_IOCTL_SPI_GET_CS:
if (NULL == param_ptr)
{
result = SPI_ERROR_INVALID_PARAMETER;
}
else
{
*param_ptr = SPI_PUSHR_PCS(io_info_ptr->CS);
}
break;
case IO_IOCTL_SPI_SET_CS:
if (NULL == param_ptr)
{
result = SPI_ERROR_INVALID_PARAMETER;
}
else
{
io_info_ptr->CS = SPI_PUSHR_PCS_GET(*param_ptr);
}
break;
and the two macros are
1.
#define SPI_PUSHR_PCS(x) (((uint32_t)(((uint32_t)(x))<<SPI_PUSHR_PCS_SHIFT))&SPI_PUSHR_PCS_MASK)
//from MK40X256VMD100.h
2.
#define SPI_PUSHR_PCS_GET(x) (((x) & SPI_PUSHR_PCS_MASK) >> SPI_PUSHR_PCS_SHIFT) //from spi_dspi_prv.h
Unless I am mistaken, these two IOctrl calls are wrong. SET_CS does not affect the control register, and GET_CS hits the control register, and thinks it is getting a return value from the SET macro.
Will hope for clarification from Freescale/EA, but not holding my breath.