Skip to main content
Sany
Associate III
Dec 17, 2024 2:16 PM UTC
Solved

STM32U575 and TouchGFX ends in FaultHandler

Hello Everyone,

 

I have a STM32U575 CPU, with a ILI9341 LCD Display, this works fine with a STM32F4, but i am upgraded my PCB to a STM32U575 and got Problems with the SPI...

my main.c code:

 

int main(void)
{

 /* USER CODE BEGIN 1 */

 /* USER CODE END 1 */

 /* MCU Configuration--------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();

 /* USER CODE BEGIN Init */

 /* USER CODE END Init */

 /* Configure the system clock */
 SystemClock_Config();

 /* USER CODE BEGIN SysInit */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */
 MX_GPIO_Init();
 MX_GPDMA1_Init();
 MX_CRC_Init();
 MX_SPI1_Init();
 MX_UART4_Init();
 MX_UART5_Init();
 MX_USB_OTG_FS_USB_Init();
 MX_I2C1_Init();
 MX_USART3_UART_Init();
 MX_TIM2_Init();
 MX_ICACHE_Init();
 MX_RTC_Init();
 MX_TouchGFX_Init();
 /* USER CODE BEGIN 2 */
 HAL_GPIO_WritePin(LCD_BACKLIGHT_GPIO_Port, LCD_BACKLIGHT_Pin, GPIO_PIN_SET);

 ILI9341_Init();

 HAL_TIM_Base_Start_IT(&htim2);
 /* USER CODE END 2 */

 /* Infinite loop */
 /* USER CODE BEGIN WHILE */
 while (1)
 {
 /* USER CODE END WHILE */

 MX_TouchGFX_Process();
 /* USER CODE BEGIN 3 */
 }
 /* USER CODE END 3 */
}

/**
 * @brief System Clock Configuration
 * @retval None
 */
void SystemClock_Config(void)
{
 RCC_OscInitTypeDef RCC_OscInitStruct = {0};
 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 /** Configure the main internal regulator output voltage
 */
 if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE2) != HAL_OK)
 {
 Error_Handler();
 }

 /** Initializes the CPU, AHB and APB buses clocks
 */
 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_LSI
 |RCC_OSCILLATORTYPE_MSI;
 RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
 RCC_OscInitStruct.LSIState = RCC_LSI_ON;
 RCC_OscInitStruct.MSIState = RCC_MSI_ON;
 RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
 RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_0;
 RCC_OscInitStruct.LSIDiv = RCC_LSI_DIV1;
 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
 RCC_OscInitStruct.PLL.PLLMBOOST = RCC_PLLMBOOST_DIV4;
 RCC_OscInitStruct.PLL.PLLM = 3;
 RCC_OscInitStruct.PLL.PLLN = 12;
 RCC_OscInitStruct.PLL.PLLP = 2;
 RCC_OscInitStruct.PLL.PLLQ = 2;
 RCC_OscInitStruct.PLL.PLLR = 2;
 RCC_OscInitStruct.PLL.PLLRGE = RCC_PLLVCIRANGE_1;
 RCC_OscInitStruct.PLL.PLLFRACN = 4096;
 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
 {
 Error_Handler();
 }

 /** Initializes the CPU, AHB and APB buses clocks
 */
 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
 |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
 |RCC_CLOCKTYPE_PCLK3;
 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
 RCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV1;

 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK)
 {
 Error_Handler();
 }
}

/**
 * @brief CRC Initialization Function
 * None
 * @retval None
 */
static void MX_CRC_Init(void)
{

 /* USER CODE BEGIN CRC_Init 0 */

 /* USER CODE END CRC_Init 0 */

 /* USER CODE BEGIN CRC_Init 1 */

 /* USER CODE END CRC_Init 1 */
 hcrc.Instance = CRC;
 hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE;
 hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE;
 hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE;
 hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE;
 hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES;
 if (HAL_CRC_Init(&hcrc) != HAL_OK)
 {
 Error_Handler();
 }
 /* USER CODE BEGIN CRC_Init 2 */

 /* USER CODE END CRC_Init 2 */

}

 

 

the ILI9341.c file:

 

// Call this function after ILI9341_SetWindow
// This function is non blocked
// The variable for Callback is open. User should set by himself
void ILI9341_DrawBitmap(uint16_t w, uint16_t h, uint8_t *s)
{
	// Enable to access GRAM
	LCD_WR_REG(0x2c);

	DC_H();
#if 0
	__HAL_SPI_DISABLE(&hspi1);
	hspi1.Instance->CR2 |= SPI_DATASIZE_16BIT; // Set 16 bit mode
	__HAL_SPI_ENABLE(&hspi1);
#endif
	ConvHL(s, (int32_t)w*h*2);
	HAL_SPI_Transmit_DMA(&hspi1, (uint8_t*)s, w * h *2); <= Runs in HardFault_Handler
#if 0
	__HAL_SPI_DISABLE(&hspi1);
	hspi1.Instance->CR2 &= ~(SPI_DATASIZE_16BIT); // Set 8 bit mode
	__HAL_SPI_ENABLE(&hspi1);
#endif
}

 

HAL_SPI_Transmit_DMA runs in HardFault_Handler...

What is wrong with my SPI1 Configuration?
Must i enable DMA?  And how can i enable The DMA for SPI1?

 

Thank you,

Daniel

 

This topic has been closed for replies.
Andrew Neil
Andrew NeilBest answer
Super User
Dec 18, 2024 8:48 AM UTC

@Sany wrote:

after a lot of tests, it's working.


Great - now please mark the solution:
https://community.st.com/t5/community-guidelines/help-others-to-solve-their-issues/ta-p/575256

 


@Sany wrote:

now i have a other problem, .


Please start a separate thread for a different question. You can always include a link to this one, for reference, if it helps.

Give a link here to your new thread - so that people can find it.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.

7 replies

Andrew Neil
Super User
Dec 17, 2024 2:26 PM UTC
A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Sany
SanyAuthor
Associate III
Dec 17, 2024 2:41 PM UTC

Thank you, but i found out, the HardFault_Handler is called by

HAL_SPI_Transmit_DMA(&hspi1, (uint8_t*)s, w * h *2);

i think, SPI1 is not correctly configured, but i have a problem with my configuration of GPDMA1...

Andrew Neil
Super User
Dec 17, 2024 2:49 PM UTC

So the techniques presented should allow you to find where, exactly, the Fault occurs, and what Fault, exactly, it is ...

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.