CC3351: STM32 port with SDIO mode

Part Number: CC3351

Tool/software:

Hi, I have been testing CC3351 with STM32U5 series using SPI.

I used cc33xx_rtos_mcu_package_R7_2 packge and its SPI porting example. After some trial and error, I was able to communicate with CC3351 over SPI.

Now I want to use SDIO pins of the same. I am trying to port it with SDIO functions provided by HAL. I am failing here.

This is what I tried:

#include "sdio_adapt.h"
#include "stm32u5xx_hal.h"

extern SDIO_HandleTypeDef hsdio1;

// Add a new flag for IO-only devices

int sdioAdapt_Init() {
    hsdio1.Instance = SDMMC1;
    hsdio1.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING;
    hsdio1.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE;
    hsdio1.Init.BusWide = SDMMC_BUS_WIDE_4B;
    hsdio1.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE;
    hsdio1.Init.ClockDiv = 80 - 1;
    return HAL_SDIO_Init(&hsdio1) ;
//    if (HAL_SDIO_Init(&hsdio1) != HAL_OK) {
//        Error_Handler();
//    }
//
//    return HAL_OK;

}

int sdioAdapt_read(uint32_t address, uint8_t *data, uint32_t length) {
     HAL_StatusTypeDef ret;

        if (length == 1) {
            // CMD52 single-byte read
            HAL_SDIO_DirectCmd_TypeDef arg = {0};
            arg.Reg_Addr    = address;
            arg.ReadAfterWrite = 0;
            arg.IOFunctionNbr   = 0;      // CC3351 SDIO function (check datasheet!)

            ret = HAL_SDIO_ReadDirect(&hsdio1, &arg, data);
        } else {
            // CMD53 multi-byte read
            HAL_SDIO_ExtendedCmd_TypeDef arg = {0};
            arg.Reg_Addr    = address;
            arg.IOFunctionNbr   = 0;      // CC3351 SDIO function number
            arg.OpCode     = 1;      // incrementing address
            arg.Block_Mode  = 0;      // 0=byte mode, 1=block mode

            ret = HAL_SDIO_ReadExtended(&hsdio1, &arg, data, length, HAL_MAX_DELAY);
        }

        return (ret == HAL_OK) ? 0 : -1;
}

int sdioAdapt_write(uint32_t address, uint8_t *data, uint32_t length) {
    HAL_StatusTypeDef ret;

        if (length == 1) {
            // CMD52 single-byte write
            HAL_SDIO_DirectCmd_TypeDef arg = {0};
            arg.Reg_Addr    = address;
            arg.ReadAfterWrite = 0;
            arg.IOFunctionNbr   = 1;

            ret = HAL_SDIO_WriteDirect(&hsdio1, &arg, *data);
        } else {
            // CMD53 multi-byte write
            HAL_SDIO_ExtendedCmd_TypeDef arg = {0};
            arg.Reg_Addr    = address;
            arg.IOFunctionNbr   = 1;
            arg.OpCode     = 1;
            arg.Block_Mode  = 0;

            ret = HAL_SDIO_WriteExtended(&hsdio1, &arg, data, length, HAL_MAX_DELAY);
        }

        return (ret == HAL_OK) ? 0 : -1;
}

int sdioAdapt_deInit() {
    HAL_SDIO_DeInit(&hsdio1);
    return 0;
}

But this is not successful. I ported the same code from what worked for me in SPI mode to SDIO. I just used SDIO communication here. disable SPI port files and peripheral.

If there is anything I can refer to,would be helpful.