2024-11-04 05:55 AM - edited 2024-11-04 06:22 AM
We have a custom template project created in cubeMX for the board STM32H735-DK that was created only to have some functionalities,
now I have taken that template and added the screen functionality and now im trying to add the touch functionality,
I have copied the BSP folder to the drivers folder and copied the STM32TouchController.cpp file (i've changed it a bit because I'm not using CMSIS_v2 and the configASSERT(0) doesn't compile)
STM32TouchController.cpp:
#include <STM32TouchController.hpp>
#include <stm32h735g_discovery_ts.h>
#include <TouchGFXHAL.hpp>
void STM32TouchController::init()
{
TS_Init_t hTS;
hTS.Orientation = TS_SWAP_XY;
hTS.Accuracy = 0;
hTS.Width = touchgfx::HAL::FRAME_BUFFER_WIDTH;
hTS.Height = touchgfx::HAL::FRAME_BUFFER_HEIGHT;
BSP_TS_Init(0, &hTS);
}
bool STM32TouchController::sampleTouch(int32_t& x, int32_t& y)
{
TS_State_t TS_State = { 0 };
// This should never fail !!
//if (BSP_TS_GetState(0, &TS_State) != BSP_ERROR_NONE)
//{
//configASSERT(0);
//}
if (BSP_TS_GetState(0, &TS_State) == BSP_ERROR_NONE)
{
if (TS_State.TouchDetected)
{
x = TS_State.TouchX;
y = TS_State.TouchY;
return true;
}
}
return false;
}
Debug variables before BSP_TS_GetState(0, &TS_State); error:
My problem is that get to HardFault_Handler(void) from the file stm32h7xx_it.c just after executing the following line:
stm32h735g_discovery_ts.c:
if(Ts_Drv->GetState(Ts_CompObj[Instance], &state) < 0)
Debug variables before Ts_Drv->GetState(Ts_CompObj[Instance], &state); error:
2024-11-04 06:21 AM - edited 2024-11-04 06:24 AM
Ok, so debug the Hard Fault, look at the registers (processor) and code (disassembly)
>> if(Ts_Drv->GetState(Ts_CompObj[Instance], &state) < 0)
Suggestive that TS_DRV isn't a valid pointer, INSTANCE is out of range, or STATE pointer isn't valid
Add some sanity checking.
If calling from Interrupt or Callback, check pointers/handles being passed in.
Perhaps get a HardFault_Handler() that outputs actionable data.
2024-11-04 06:24 AM
On debugging Hard Faults - both Cortex-M in general, and STM32 in particular;