stm32h with sdmmc1 doest react on anything at all - Page 1
Forum section: electronics / general

author: Woods
author_rank: Newbie
timestamp: January 26, 2024, 08:25:15 pm
content: Someone from the forum had the same problem but it wasnt solved because of lack of info:https://www.eevblog.com/forum/microcontrollers/sdmmc-with-stm32h7/msg4620277/#msg4620277I have generated a HAL Project with sdmmc1 enabled, mode "MMC1 bit"trying to send a simple cmd or even init the card nothing happening and mcu stucks in error handler which located in mmc init function:Code:if (HAL_MMC_Init(&hmmc1) != HAL_OK){Error_Handler();}Code:void Error_Handler(void){/* USER CODE BEGIN Error_Handler_Debug *//* User can add his own implementation to report the HAL error return state */__disable_irq();while (1){}/* USER CODE END Error_Handler_Debug */}if i remove the error_handleri didnt get any response in registers ( looking at it in KEIL's debug mode, registers just dont even toggle any bits) , also cant see any tries of Initialize MMC in oscillograph ( clock ,cmd and data line doesnt toggle as well).Whole code:Code:#include <stdarg.h>#include <string.h>#include <stdint.h>#include "main.h"#include "stm32h7xx_hal_rcc.h"#include "main.h"#include "usb_device.h"#include "stm32h7xx_hal.h"/* Private includes ----------------------------------------------------------*//* USER CODE BEGIN Includes */extern uint32_t SystemCoreClock;#include "usbd_cdc_if.h"#include "usb_device.h"#include "stm32h7xx_hal_mmc.h"/* USER CODE BEGIN Includes */#include "usbd_cdc_if.h"/* USER CODE END Includes */MMC_HandleTypeDef hmmc1;MMC_TypeDef hmmc2;void SystemClock_Config(void);static void MX_GPIO_Init(void);static void MX_SDMMC1_MMC_Init(void)int main(void){HAL_Init();SystemClock_Config();MX_GPIO_Init();MX_USB_DEVICE_Init();while (1){if (UserRxBufferFS == 0x97) // GOT command for emmc{UserRxBufferFS = 0;SDMMC1->POWER = 1; //check the power register( doesnt change in debug mode, why?)MX_SDMMC1_MMC_Init();SDMMC_PowerState_ON(&hmmc2); // check the power register with HAL( doesnt change aswell)SDMMC_SendCommand(&hmmc2, 0); // checking cmd line, nothing happens in oscillo}}static void MX_SDMMC1_MMC_Init(void){hmmc1.Instance = SDMMC1;hmmc1.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING;hmmc1.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE;hmmc1.Init.BusWide = SDMMC_BUS_WIDE_1B;hmmc1.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE;hmmc1.Init.ClockDiv = 0;if (HAL_MMC_Init(&hmmc1) != HAL_OK){Error_Handler();}}void SystemClock_Config(void){RCC_OscInitTypeDef RCC_OscInitStruct = {0};RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};/** Supply configuration update enable*/HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);/** Configure the main internal regulator output voltage*/__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}/** Initializes the RCC Oscillators according to the specified parameters* in the RCC_OscInitTypeDef structure.*/RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;RCC_OscInitStruct.HSEState = RCC_HSE_ON;RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;RCC_OscInitStruct.PLL.PLLM = 1;RCC_OscInitStruct.PLL.PLLN = 80;RCC_OscInitStruct.PLL.PLLP = 2;RCC_OscInitStruct.PLL.PLLQ = 4;RCC_OscInitStruct.PLL.PLLR = 2;RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3;RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;RCC_OscInitStruct.PLL.PLLFRACN = 0;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_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK){Error_Handler();}}Am i doing something wrong? i have attached screenshot of hal config

author: eutectique
author_rank: Frequent Contributor
timestamp: January 26, 2024, 08:58:10 pm
content: Why doesHAL_MMC_Init()returns whichever error code? Did you step into the function in the debugger?

author: DavidAlfa
author_rank: Super Contributor
timestamp: January 26, 2024, 11:10:13 pm
content: Try sd 1 bit?

author: DavidAlfa
author_rank: Super Contributor
timestamp: January 29, 2024, 08:05:35 pm
content: I repeat - use 1 bit SD 1 bit for SD card. MMC has slighly different init sequence, I remember it failing exactly due this.Check the clock configuration, ensure SD peripheral clock is<100MHz- CubeMX bug, now it accepts 250MHz just fine.Read:STM32H7-Peripheral-SDMMC_interface.You might also attach the project.Modify the init function so you can debug the return error:Code:if (HAL_SD_Init(&hsd1) != HAL_OK){Error_Handler();}Code:HAL_StatusTypeDef result;result = HAL_SD_Init(&hsd1);__NOP(); // Add a breakpoint here, check result valueif (result != HAL_OK){Error_Handler();}

author: Woods
author_rank: Newbie
timestamp: January 29, 2024, 08:25:42 pm
content: Quote from: DavidAlfa on January 29, 2024, 08:05:35 pmThanks David for your answer, i will try that. By the way my SD CLOCK is 160MHZ(in attached screenshot) , i can see in STM32H7-Peripheral-SDMMC_interface. that stm32h7 sdmmc can be up to 200mhz and STM32MXCUBE accepts that clock, can it be the problem?

author: DavidAlfa
author_rank: Super Contributor
timestamp: January 29, 2024, 08:29:29 pm
content: I don' think it's the problem, HAL slows down the clock for the init sequence inHAL_SD_InitCardto400KHz.Later it parses the CSD register (TRAN_SPEED bits)hereand sets theclock speedaccordingly.But you might try lowering the clock to 10MHz or even lower, a slow clock won't break anything, but it will if too fast.Optimize things when already working, not at the beginning!

author: Woods
author_rank: Newbie
timestamp: January 31, 2024, 09:37:30 pm
content: Quote from: Woods on January 29, 2024, 08:25:42 pmi made a test by your guideCode:static void MX_SDMMC1_MMC_Init(void){hmmc1.Instance = SDMMC1;hmmc1.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING;hmmc1.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE;hmmc1.Init.BusWide = SDMMC_BUS_WIDE_1B;hmmc1.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE;hmmc1.Init.ClockDiv = 0;result = HAL_MMC_Init(&hmmc1);__NOP(); // Add a breakpoint here, check result valueif (result != HAL_OK){Error_Handler();}}result give me HAL_ERROR valuebut i can see a registers changed nowand command with clock on oscio, whats strange its happned only after i added clock enabling for sdmmc1, shouldnt HAL do it by default???Code:__HAL_RCC_SDMMC1_CLK_ENABLE();MX_SDMMC1_MMC_Init();few times i have catched result give me HAL_OK.But mostly its error, i cant understand does it trying to initizalze my emmc board conencted to it or waht does it send? and which two cmds does it send on screenshots( As i know by protocol it should be SEND CMD from HoST -> Receive Repsonse from Slave)?shoudnt it be first byte cmd number in hex format? i can see only zeroes in first byte.