2020-05-22 01:04 AM
Hi, I'm working on a project with STM32F746 MCU and I used stmpe811 for touch controller but my code always going into hard fault error during initialization. I attached my project on the drive also I added the initialization part of code. Please help me.
Thank you.
https://drive.google.com/open?id=1HeUqoFNDb-q1m6BLhI72yCxR0O-dKmj0
uint8_t BSP_TS_Init(uint16_t XSize, uint16_t YSize)
{
uint8_t ret = TS_ERROR;
/* Initialize x and y positions boundaries */
TsXBoundary = XSize;
TsYBoundary = YSize;
/* Read ID and verify if the IO expander is ready */
/**
*Problem is in here. TS_I2C_ADDRESS = 0x82 (Get it from datasheet)
* STMPE811_ID = 0x0811 (It was already in library I didn't change.)
*My program is skipping this part and going Hard fault handler.
*on working program (with STM32F429 Discovery board) program goes into this conditional
*/
if(stmpe811_ts_drv.ReadID(TS_I2C_ADDRESS) == STMPE811_ID)
{
/* Initialize the TS driver structure */
TsDrv = &stmpe811_ts_drv;
ret = TS_OK;
}
if(ret == TS_OK)
{
/* Initialize the LL TS Driver */
TsDrv->Init(TS_I2C_ADDRESS);
TsDrv->Start(TS_I2C_ADDRESS);
}
return ret;
}
2020-05-22 04:09 AM
Debug as usually - in the hardfault driver, observe content of stack (r0, r1, r2, r3, r12, LR, pc, xPSR), based on pc find out in disasm where the fault happened, from content of registers and the code in vicinity of the offending one find out why.
JW
2020-05-22 04:23 AM
Thanks for your reply. I've done what you said and on pc this (0x80012ae <HardFault_Handler>) is writing as a value but I don't know how itl helps I don't really have experience. So can you help me?
2020-05-22 04:28 AM
Not the current state of PC, but the one stored on stack.
There are several websites dealing with debugging Cortex-M code. Read. Learn. Experiment.
JW
2020-05-22 04:28 AM
Step through your code, what line triggers the hard fault?
2020-05-22 05:28 AM
I don't exactly know what line trigger the hard fault but after every step code goes into TIM6_DAC_IRQHandler and after goes back to the previous line. But I don't use timer6 or DMA.