The code in the attached file is nearly identical to that of an SDK example LPC54018_spi_int_b2b_master_transfer. When I run this code in a new C project, it runs without error. But when I run the identical code in a new C++ project, it gets hung up waiting for flag masterFinished to become true, and never gets into function masterCallback.
Notice the ‘extern C’ surrounds the prototype of masterCallback in order to prevent mangling. I also verified that the functions SPI_MasterTransferCreateHandle, SPI_MasterTransferNonBlocking and SPI_MasterTransferHandleIRQ used in this program are all C extern’d in fsl_spi.h. What else would hang up the calling of masterCallback?
Solved! Go to Solution.
I found my code error. I added a *.cpp file to the project that contained a second definition for SPI9 in an IRQ handler I had written for a different project. Because it was named FLEXCOMM9_IRQHandler(), I didn’t recognize that it had effectively redefined SPI9 which I had been defined in the SPI_MasterInit() function I had intended for use in the masterCallback(). So instead of calling the latter function main called FLEXCOMM9_IRQHandler() instead.
It took me a long time to find this problem because FLEXCOMM9_IRQHandler redefined SPI9 in a file that I wrote in the past. What troubleshooting process could I have implemented that would have allowed me to see that SPI9 defined in main was pointing to the wrong handler? I didn’t see a difference when I compared the vector tables between my working C project and my failed C++ project.
Thank you for that document, Alexis_A. I made some changes based on it, mainly format changes, but that didn't resolve the issue. I've resolved this problem in another MCUXpresso project successfully using the extern C construct, but this time that was not enough. There is only one function that is involved in this case, so it should be simple. The only thing I can imagine is an SDK bug. No?
Hello @jmueckl,
Since this is only present when you integrate this in the C++ code, I don't think this is an SDK bug. I will suggest checking if the configuration is done correctly after the initialization (check the registers in the peripherals view) comparing it with the C SDK example.
Also, have you tried looking with an oscilloscope or logic analyzer to check if there's any activity in the bus?
Best Regards,
Alexis Andalon
When I step through the code and analyze the addresses, data and registers resulting from each function call, I see no difference between the C and the C++ project implementations. However, when I put a breakpoint in the function SPI_MasterTransferHandleIRQ(), which is in fsl_spi.c, the function is only called in the C implementation, and not called in the C++ implementation.
The Clock and MOSI signals look as I expect on an oscilloscope for the C project. But in the case of C++ project, only the clock signal wiggles 8 times, and nothing happens after that.
Have you checked the vector table in both implementations in the startup file (.c for C and .cpp for C++).
Can you export and post the whole (C++) project, including any dependencies so I can try and build it here.
Sorry, but that does not help at all. To be able to help, I need a complete, buildable project, with all dependencies... You can create such a package from the Quickstart panel:
I found my code error. I added a *.cpp file to the project that contained a second definition for SPI9 in an IRQ handler I had written for a different project. Because it was named FLEXCOMM9_IRQHandler(), I didn’t recognize that it had effectively redefined SPI9 which I had been defined in the SPI_MasterInit() function I had intended for use in the masterCallback(). So instead of calling the latter function main called FLEXCOMM9_IRQHandler() instead.
It took me a long time to find this problem because FLEXCOMM9_IRQHandler redefined SPI9 in a file that I wrote in the past. What troubleshooting process could I have implemented that would have allowed me to see that SPI9 defined in main was pointing to the wrong handler? I didn’t see a difference when I compared the vector tables between my working C project and my failed C++ project.