cancel
Showing results for 
Search instead for 
Did you mean: 

HardFault_Handler when trying to add touch functionality

I_ve_got_a_problem
Associate III

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:

I_ve_got_a_problem_0-1730728404994.png



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:

I_ve_got_a_problem_0-1730730162218.png

 



 

 

2 REPLIES 2

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Andrew Neil
Evangelist III