2024-12-17 06:16 AM - edited 2024-12-17 06:27 AM
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
Solved! Go to Solution.
2024-12-18 12:48 AM
@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.
2024-12-17 06:26 AM
Debugging Hard Faults - Cortex-M in general, and STM32 in particular:
2024-12-17 06:41 AM
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...
2024-12-17 06:49 AM
So the techniques presented should allow you to find where, exactly, the Fault occurs, and what Fault, exactly, it is ...
2024-12-17 07:24 AM
... and then is the configuration of the SPI1 still wrong ...
2024-12-17 07:48 AM
Primary check if all enabled interrupts have valid ISR. Because hardfault handler is default for all ...
Secondary is your code working with normal SPI call without DMA?
2024-12-17 03:00 PM - edited 2024-12-17 03:01 PM
Hello,
Yes my code is working without DMA, the STM32U575 is a little bit tricky.. i configured SPI correctly, and the TFT are initialized correctly, but GPDMA1 is not configured, after a lot of tests, it's working.
now i have a other problem, my screen in touchGFX has color red, my display shows "magenta", when my screen is green, display shows "green", and when my screen is blue, display shows black.
how can i correct this? i think its a problem with the 8 to 16 bit for the display?
btw, SPI is configured as MSB, 8-Bit.
2024-12-18 12:48 AM
@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.