summaryrefslogtreecommitdiff
path: root/bsp/n32/n32hxxx/libraries/N32_Drivers/drivers/drv_sdmmc.h
blob: 1b3f93a893f7f099cad62addc5c104d58a92469b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 * Copyright (c) 2006-2026, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2026-07-10     Claude       N32 SDMMC driver with rt_mmcsd_host_ops
 */

#ifndef __DRV_SDMMC_H__
#define __DRV_SDMMC_H__

#include <rtthread.h>
#include "n32h7xx_sdmmc.h"         /* BEFORE mmcsd_cmd.h — avoids SWITCH macro clash */
#include <drivers/mmcsd_host.h>
#include <drivers/mmcsd_cmd.h>

#ifdef __cplusplus
extern "C" {
#endif

/* ── SDMMC clock frequencies ─────────────────────────────────────────── */
#define SD_XIN_CLK           100000000U   /* SDMMC module base clock (Hz) */
#define SD_INIT_FREQ         400000U      /* Identification mode: 400 kHz */
#define SD_NORMAL_SPEED_FREQ 25000000U    /* Default speed: 25 MHz       */
#define SD_HIGH_SPEED_FREQ   50000000U    /* High speed: 50 MHz          */

#ifndef SDIO_MAX_FREQ
#define SDIO_MAX_FREQ SD_HIGH_SPEED_FREQ
#endif

/* ── Data buffer ─────────────────────────────────────────────────────── */
#ifndef SDIO_BUFF_SIZE
#define SDIO_BUFF_SIZE 4096
#endif

#ifndef SDIO_ALIGN_LEN
#define SDIO_ALIGN_LEN 32
#endif

/* ── N32 per-instance descriptor ─────────────────────────────────────── */
struct n32_sdio_config
{
    SDHOST_Module *sdhost;        /* SDHOST register base        */
    SDMMC_Module *sdmmc;         /* SDMMC wrapper register base */
    IRQn_Type irqn;          /* IRQ number                  */
    uint32_t clkfb_val;     /* AFIO clock feedback select  */
    uint32_t pwrctrl_val;   /* PWR power control bit       */
    uint32_t lpclk_en;      /* RCC LP clock enable bit     */
    uint32_t periphrst_val; /* RCC peripheral reset mask   */
    const char *name;          /* device name ("sd0")         */
};

struct n32_sdio
{
    struct n32_sdio_config cfg;
    struct rt_mmcsd_host *host;
};

/* ── Public API ──────────────────────────────────────────────────────── */
int n32_hw_sdio_init(void);

#ifdef __cplusplus
}
#endif

#endif /* __DRV_SDMMC_H__ */