Author Topic: stm32h with sdmmc1 doest react on anything at all  (Read 968 times)

0 Members and 1 Guest are viewing this topic.

Offline WoodsTopic starter

  • Newbie
  • Posts: 3
  • Country: nz
stm32h with sdmmc1 doest react on anything at all
« on: January 26, 2024, 08:25:15 pm »
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/#msg4620277
I 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: [Select]
  if (HAL_MMC_Init(&hmmc1) != HAL_OK)
  {
    Error_Handler();
  }
Code: [Select]
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_handler
i 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: [Select]
#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[0] == 0x97)   // GOT command for emmc
     { 
      UserRxBufferFS[0] = 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
« Last Edit: January 26, 2024, 08:29:11 pm by Woods »
 

Offline eutectique

  • Frequent Contributor
  • **
  • Posts: 392
  • Country: be
Re: stm32h with sdmmc1 doest react on anything at all
« Reply #1 on: January 26, 2024, 08:58:10 pm »
Why does HAL_MMC_Init() returns whichever error code? Did you step into the function in the debugger?
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5912
  • Country: es
Re: stm32h with sdmmc1 doest react on anything at all
« Reply #2 on: January 26, 2024, 11:10:13 pm »
Try sd 1 bit?
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5912
  • Country: es
Re: stm32h with sdmmc1 doest react on anything at all
« Reply #3 on: January 29, 2024, 08:05:35 pm »
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: [Select]
  if (HAL_SD_Init(&hsd1) != HAL_OK)
  {
    Error_Handler();
  }
Code: [Select]
  HAL_StatusTypeDef result;

  result = HAL_SD_Init(&hsd1);
  __NOP();                                             // Add a breakpoint here, check result value

  if (result != HAL_OK)
  {
    Error_Handler();
  }
« Last Edit: January 29, 2024, 08:39:30 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 
The following users thanked this post: Woods

Offline WoodsTopic starter

  • Newbie
  • Posts: 3
  • Country: nz
Re: stm32h with sdmmc1 doest react on anything at all
« Reply #4 on: January 29, 2024, 08:25:42 pm »
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.

Read: STM32H7-Peripheral-SDMMC_interface.

You might also attach the project.

Modify the init function so you can debug the return error:
Code: [Select]
  if (HAL_SD_Init(&hsd1) != HAL_OK)
  {
    Error_Handler();
  }
Code: [Select]
  HAL_StatusTypeDef result;

  result = HAL_SD_Init(&hsd1);
  __NOP();                                             // Add a breakpoint here, check result value

  if (result != HAL_OK)
  {
    Error_Handler();
  }
Thanks 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?
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5912
  • Country: es
Re: stm32h with sdmmc1 doest react on anything at all
« Reply #5 on: January 29, 2024, 08:29:29 pm »
I don' think it's the problem, HAL slows down the clock for the init sequence in HAL_SD_InitCard to 400KHz.
Later it parses the CSD register (TRAN_SPEED bits) here and sets the clock speed accordingly.

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!
« Last Edit: January 29, 2024, 08:53:48 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 
The following users thanked this post: Woods

Offline WoodsTopic starter

  • Newbie
  • Posts: 3
  • Country: nz
Re: stm32h with sdmmc1 doest react on anything at all
« Reply #6 on: January 31, 2024, 09:37:30 pm »
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.

Read: STM32H7-Peripheral-SDMMC_interface.

You might also attach the project.

Modify the init function so you can debug the return error:
Code: [Select]
  if (HAL_SD_Init(&hsd1) != HAL_OK)
  {
    Error_Handler();
  }
Code: [Select]
  HAL_StatusTypeDef result;

  result = HAL_SD_Init(&hsd1);
  __NOP();                                             // Add a breakpoint here, check result value

  if (result != HAL_OK)
  {
    Error_Handler();
  }
Thanks 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?
i made a test by your guide
Code: [Select]
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 value

  if (result != HAL_OK)
  {
    Error_Handler();
  }

}
result give me HAL_ERROR value
but i can see a registers changed now
and command with clock on oscio, whats strange its happned only after i  added clock enabling for sdmmc1, shouldnt HAL do it by default???
Code: [Select]
[b]__HAL_RCC_SDMMC1_CLK_ENABLE[/b]();   
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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf