Joel Wigton

K22 bug in MK22F12.h for SPI configurations

Discussion created by Joel Wigton on Oct 28, 2016
Latest reply on Feb 15, 2017 by guylejeune

When you use the project generator to make a MK22F12 project, I get the following compiler warnings (though serious):


array subscript is above array bounds [-Warray-bounds]


Which is pointing to fsl_dspi.c:


#if defined(SPI0)
void SPI0_DriverIRQHandler(void)
DSPI_CommonIRQHandler(SPI0, g_dspiHandle[0]);
#if defined(SPI1)
void SPI1_DriverIRQHandler(void)
DSPI_CommonIRQHandler(SPI1, g_dspiHandle[1]);
#if defined(SPI2)
void SPI2_DriverIRQHandler(void)
DSPI_CommonIRQHandler(SPI2, g_dspiHandle[2]);


Lines 12 and 19 are the issue, because these are referencing elements 1 and 2 of the g_dspiHandle[] array, but it is only defined in that same file as static void *g_dspiHandle[FSL_FEATURE_SOC_DSPI_COUNT]; and FSL_FEATURE_SOC_DSPI_COUNT is defined elsewhere in the MK22F12_features.h file as 1!  


In other words, there is only one SPI block (SPI0) on this chip, so the SPI1 and SPI2 features should not be defined, and this error will go away.  I have confirmed that eliminating these variables (SPI1, SPI2, etc.) in MK22F12.h fixes the issue.


Please fix in future versions, thanks.