Skip to content

Commit fe980c7

Browse files
authored
Merge pull request #4406 from thread-liu/master
[update] stm32mp1 sdio wifi.
2 parents 0a54f4c + 53dea16 commit fe980c7

File tree

7 files changed

+385
-46
lines changed

7 files changed

+385
-46
lines changed

bsp/stm32/libraries/STM32MPxx_HAL/SConscript

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ if GetDepend(['BSP_USING_CRYP']):
119119
src += ['STM32MP1xx_HAL_Driver/Src/stm32mp1xx_hal_cryp.c']
120120
src += ['STM32MP1xx_HAL_Driver/Src/stm32mp1xx_hal_cryp_ex.c']
121121

122+
if GetDepend(['BSP_USING_RTC']):
123+
src += ['STM32MP1xx_HAL_Driver/Src/stm32mp1xx_hal_rtc.c']
124+
src += ['STM32MP1xx_HAL_Driver/Src/stm32mp1xx_hal_rtc_ex.c']
125+
122126
path = [cwd + '/STM32MP1xx_HAL_Driver/Inc',
123127
cwd + '/CMSIS/Device/ST/STM32MP1xx/Include',
124128
cwd + '/CMSIS/Core/Include',

bsp/stm32/stm32mp157a-st-discovery/board/CubeMX_Config/CM4/Inc/stm32mp1xx_hal_conf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
#define HAL_SAI_MODULE_ENABLED
6161
#define HAL_SD_MODULE_ENABLED
6262
/*#define HAL_MMC_MODULE_ENABLED */
63-
/*#define HAL_RTC_MODULE_ENABLED */
63+
#define HAL_RTC_MODULE_ENABLED
6464
/*#define HAL_SMBUS_MODULE_ENABLED */
6565
/*#define HAL_SPDIFRX_MODULE_ENABLED */
6666
#define HAL_SPI_MODULE_ENABLED

bsp/stm32/stm32mp157a-st-discovery/board/CubeMX_Config/CM4/Src/stm32mp1xx_hal_msp.c

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,66 @@ void HAL_SD_MspInit(SD_HandleTypeDef* hsd)
10031003

10041004
/* USER CODE END SDMMC1_MspInit 1 */
10051005
}
1006+
if(hsd->Instance==SDMMC2)
1007+
{
1008+
/* USER CODE BEGIN SDMMC2_MspInit 0 */
1009+
if (IS_ENGINEERING_BOOT_MODE())
1010+
{
1011+
/** Initializes the peripherals clock
1012+
*/
1013+
PeriphClkInit.Sdmmc12ClockSelection = RCC_SDMMC12CLKSOURCE_PLL4;
1014+
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_SDMMC12;
1015+
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
1016+
{
1017+
Error_Handler();
1018+
}
1019+
}
1020+
/* USER CODE END SDMMC2_MspInit 0 */
1021+
/* Peripheral clock enable */
1022+
__HAL_RCC_SDMMC2_CLK_ENABLE();
1023+
1024+
__HAL_RCC_GPIOB_CLK_ENABLE();
1025+
__HAL_RCC_GPIOE_CLK_ENABLE();
1026+
__HAL_RCC_GPIOG_CLK_ENABLE();
1027+
/**SDMMC2 GPIO Configuration
1028+
PB14 ------> SDMMC2_D0
1029+
PB15 ------> SDMMC2_D1
1030+
PB3 ------> SDMMC2_D2
1031+
PB4 ------> SDMMC2_D3
1032+
PE3 ------> SDMMC2_CK
1033+
PG6 ------> SDMMC2_CMD
1034+
*/
1035+
GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_14|GPIO_PIN_15;
1036+
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
1037+
GPIO_InitStruct.Pull = GPIO_NOPULL;
1038+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
1039+
GPIO_InitStruct.Alternate = GPIO_AF9_SDIO2;
1040+
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
1041+
1042+
GPIO_InitStruct.Pin = GPIO_PIN_3;
1043+
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
1044+
GPIO_InitStruct.Pull = GPIO_NOPULL;
1045+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
1046+
GPIO_InitStruct.Alternate = GPIO_AF9_SDIO2;
1047+
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
1048+
1049+
GPIO_InitStruct.Pin = GPIO_PIN_6;
1050+
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
1051+
GPIO_InitStruct.Pull = GPIO_NOPULL;
1052+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
1053+
GPIO_InitStruct.Alternate = GPIO_AF10_SDIO2;
1054+
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
10061055

1056+
__HAL_RCC_SDMMC2_FORCE_RESET();
1057+
__HAL_RCC_SDMMC2_RELEASE_RESET();
1058+
1059+
/* SDMMC2 interrupt Init */
1060+
HAL_NVIC_SetPriority(SDMMC2_IRQn, 2, 0);
1061+
HAL_NVIC_EnableIRQ(SDMMC2_IRQn);
1062+
/* USER CODE BEGIN SDMMC2_MspInit 1 */
1063+
1064+
/* USER CODE END SDMMC2_MspInit 1 */
1065+
}
10071066
}
10081067

10091068
/**
@@ -1312,6 +1371,65 @@ void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef* hcryp)
13121371

13131372
}
13141373
#endif
1374+
1375+
/**
1376+
* @brief RTC MSP Initialization
1377+
* This function configures the hardware resources used in this example
1378+
* @param hrtc: RTC handle pointer
1379+
* @retval None
1380+
*/
1381+
void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
1382+
{
1383+
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
1384+
if(hrtc->Instance==RTC)
1385+
{
1386+
/* USER CODE BEGIN SDMMC1_MspInit 0 */
1387+
if (IS_ENGINEERING_BOOT_MODE())
1388+
{
1389+
/** Initializes the peripherals clock
1390+
*/
1391+
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
1392+
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
1393+
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
1394+
{
1395+
Error_Handler();
1396+
}
1397+
}
1398+
/* USER CODE BEGIN RTC_MspInit 0 */
1399+
1400+
/* USER CODE END RTC_MspInit 0 */
1401+
/* Peripheral clock enable */
1402+
__HAL_RCC_RTC_ENABLE();
1403+
1404+
/* USER CODE BEGIN RTC_MspInit 1 */
1405+
1406+
/* USER CODE END RTC_MspInit 1 */
1407+
}
1408+
1409+
}
1410+
1411+
/**
1412+
* @brief RTC MSP De-Initialization
1413+
* This function freeze the hardware resources used in this example
1414+
* @param hrtc: RTC handle pointer
1415+
* @retval None
1416+
*/
1417+
void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
1418+
{
1419+
if(hrtc->Instance==RTC)
1420+
{
1421+
/* USER CODE BEGIN RTC_MspDeInit 0 */
1422+
1423+
/* USER CODE END RTC_MspDeInit 0 */
1424+
/* Peripheral clock disable */
1425+
__HAL_RCC_RTC_DISABLE();
1426+
1427+
/* USER CODE BEGIN RTC_MspDeInit 1 */
1428+
1429+
/* USER CODE END RTC_MspDeInit 1 */
1430+
}
1431+
1432+
}
13151433
/**
13161434
* @brief This function is executed in case of error occurrence.
13171435
* @retval None

bsp/stm32/stm32mp157a-st-discovery/board/Kconfig

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,23 @@ menu "Onboard Peripheral Drivers"
5858
select RT_USING_LWIP
5959

6060
config BSP_USING_SDMMC
61-
bool "Enable SDMMC (SD card)"
61+
bool "Enable SDMMC (sd card or sdio wifi)"
62+
default n
6263
select RT_USING_SDIO
6364
select RT_USING_DFS
6465
select RT_USING_DFS_ELMFAT
66+
if BSP_USING_SDMMC
67+
config BSP_USING_SDIO1
68+
bool "Enable SDIO1 (sd card)"
69+
default n
70+
config BSP_USING_SDIO2
71+
select BSP_USING_RTC
72+
bool "Enable SDIO2 (sdio wifi)"
73+
default n
74+
endif
75+
76+
config BSP_USING_RTC
77+
bool "Enable RTC"
6578
default n
6679

6780
menuconfig BSP_USING_AUDIO

bsp/stm32/stm32mp157a-st-discovery/board/ports/drv_sdio.c

Lines changed: 92 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@
1010

1111
#include "board.h"
1212
#include "drv_sdio.h"
13+
14+
#ifdef BSP_USING_SDIO1
1315
#include <dfs_fs.h>
16+
#endif
1417

1518
#ifdef BSP_USING_SDMMC
1619

17-
//#define DRV_DEBUG
20+
#ifdef BSP_USING_SDIO2
21+
#define DRV_DEBUG
22+
#endif
23+
1824
#define DBG_TAG "drv.sdio"
1925
#ifdef DRV_DEBUG
2026
#define DBG_LVL DBG_LOG
@@ -23,8 +29,9 @@
2329
#endif /* DRV_DEBUG */
2430
#include <rtdbg.h>
2531

26-
static SD_HandleTypeDef hsd;
27-
static struct rt_mmcsd_host *host;
32+
static struct rt_mmcsd_host *host1;
33+
static struct rt_mmcsd_host *host2;
34+
2835
#define SDIO_TX_RX_COMPLETE_TIMEOUT_LOOPS (100000)
2936

3037
#define RTHW_SDIO_LOCK(_sdio) rt_mutex_take(&_sdio->mutex, RT_WAITING_FOREVER)
@@ -47,13 +54,14 @@ struct rthw_sdio
4754
};
4855

4956
/* SYSRAM SDMMC1/2 accesses */
57+
#define SDCARD_ADDR 0x2FFC0000
5058
#if defined(__CC_ARM) || defined(__CLANG_ARM)
51-
rt_uint8_t cache_buf[SDIO_BUFF_SIZE] __attribute__((at(0x2FFC0000)));
59+
__attribute__((at(SDCARD_ADDR))) static rt_uint8_t cache_buf[SDIO_BUFF_SIZE];
60+
#elif defined ( __GNUC__ )
61+
static rt_uint8_t cache_buf[SDIO_BUFF_SIZE] __attribute__((section(".SdCardSection")));
5262
#elif defined(__ICCARM__)
53-
#pragma location=0x2FFC0000
54-
rt_uint8_t cache_buf[SDIO_BUFF_SIZE];
55-
#elif defined(__GNUC__)
56-
rt_uint8_t cache_buf[SDIO_BUFF_SIZE] __attribute__((at(0x2FFC0000)));
63+
#pragma location = SDCARD_ADDR
64+
__no_init static rt_uint8_t cache_buf[SDIO_BUFF_SIZE];
5765
#endif
5866

5967
/**
@@ -461,10 +469,20 @@ struct rt_mmcsd_host *sdio_host_create(struct stm32_sdio_des *sdio_des)
461469

462470
rt_memcpy(&sdio->sdio_des, sdio_des, sizeof(struct stm32_sdio_des));
463471

464-
sdio->sdio_des.hw_sdio = (struct stm32_sdio *)SDIO_BASE_ADDRESS;
472+
if(sdio_des->hsd.Instance == SDMMC1)
473+
{
474+
sdio->sdio_des.hw_sdio = (struct stm32_sdio *)SDIO1_BASE_ADDRESS;
475+
rt_event_init(&sdio->event, "sdio1", RT_IPC_FLAG_FIFO);
476+
rt_mutex_init(&sdio->mutex, "sdio1", RT_IPC_FLAG_FIFO);
477+
}
478+
479+
if(sdio_des->hsd.Instance == SDMMC2)
480+
{
481+
sdio->sdio_des.hw_sdio = (struct stm32_sdio *)SDIO2_BASE_ADDRESS;
482+
rt_event_init(&sdio->event, "sdio2", RT_IPC_FLAG_FIFO);
483+
rt_mutex_init(&sdio->mutex, "sdio2", RT_IPC_FLAG_FIFO);
484+
}
465485

466-
rt_event_init(&sdio->event, "sdio", RT_IPC_FLAG_FIFO);
467-
rt_mutex_init(&sdio->mutex, "sdio", RT_IPC_FLAG_FIFO);
468486
/* set host default attributes */
469487
host->ops = &ops;
470488
host->freq_min = 400 * 1000;
@@ -503,29 +521,83 @@ void SDMMC1_IRQHandler(void)
503521
{
504522
rt_interrupt_enter();
505523
/* Process All SDIO Interrupt Sources */
506-
rthw_sdio_irq_process(host);
524+
rthw_sdio_irq_process(host1);
507525

508526
rt_interrupt_leave();
509527
}
510528

529+
void SDMMC2_IRQHandler(void)
530+
{
531+
/* enter interrupt */
532+
rt_interrupt_enter();
533+
/* Process All SDIO Interrupt Sources */
534+
rthw_sdio_irq_process(host2);
535+
/* leave interrupt */
536+
rt_interrupt_leave();
537+
}
538+
539+
#ifdef BSP_USING_SDIO2
540+
static RTC_HandleTypeDef hrtc;
541+
static void MX_RTC_Init(void)
542+
{
543+
hrtc.Instance = RTC;
544+
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
545+
hrtc.Init.AsynchPrediv = 127;
546+
hrtc.Init.SynchPrediv = 255;
547+
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
548+
hrtc.Instance->CFGR = 0x02 << 1;
549+
if (HAL_RTC_Init(&hrtc) != HAL_OK)
550+
{
551+
Error_Handler();
552+
}
553+
}
554+
static int LBEE5KL1DX_init(void)
555+
{
556+
#define LBEE5KL1DX_WL_REG_ON GET_PIN(H, 4)
557+
558+
/* enable the WLAN REG pin */
559+
rt_pin_mode(LBEE5KL1DX_WL_REG_ON, PIN_MODE_OUTPUT);
560+
rt_pin_write(LBEE5KL1DX_WL_REG_ON, PIN_HIGH);
561+
562+
return 0;
563+
}
564+
#endif
565+
511566
int rt_hw_sdio_init(void)
512567
{
513-
struct stm32_sdio_des sdio_des;
514-
515-
hsd.Instance = SDMMC1;
516-
HAL_SD_MspInit(&hsd);
568+
#ifdef BSP_USING_SDIO1
569+
struct stm32_sdio_des sdio_des1;
570+
sdio_des1.hsd.Instance = SDMMC1;
571+
HAL_SD_MspInit(&sdio_des1.hsd);
517572

518-
host = sdio_host_create(&sdio_des);
519-
if (host == RT_NULL)
573+
host1 = sdio_host_create(&sdio_des1);
574+
if (host1 == RT_NULL)
520575
{
521576
LOG_E("host create fail");
522577
return RT_NULL;
523578
}
579+
#endif
524580

581+
#ifdef BSP_USING_SDIO2
582+
MX_RTC_Init();
583+
LBEE5KL1DX_init();
584+
585+
struct stm32_sdio_des sdio_des2;
586+
sdio_des2.hsd.Instance = SDMMC2;
587+
HAL_SD_MspInit(&sdio_des2.hsd);
588+
589+
host2 = sdio_host_create(&sdio_des2);
590+
if (host2 == RT_NULL)
591+
{
592+
LOG_E("host2 create fail");
593+
return RT_NULL;
594+
}
595+
#endif
525596
return RT_EOK;
526597
}
527598
INIT_DEVICE_EXPORT(rt_hw_sdio_init);
528599

600+
#ifdef BSP_USING_SDIO1
529601
int mnt_init(void)
530602
{
531603
rt_device_t sd = RT_NULL;
@@ -552,4 +624,6 @@ int mnt_init(void)
552624
}
553625
INIT_ENV_EXPORT(mnt_init);
554626

627+
#endif /* BSP_USING_SDIO1 */
628+
555629
#endif /* BSP_USING_SDMMC */

bsp/stm32/stm32mp157a-st-discovery/board/ports/drv_sdio.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
#include <drivers/mmcsd_core.h>
2020
#include <drivers/sdio.h>
2121

22-
#define SDIO_BUFF_SIZE 4096
23-
#define SDIO_ALIGN_LEN 32
22+
#ifndef SDIO1_BASE_ADDRESS
23+
#define SDIO1_BASE_ADDRESS (SDMMC1)
24+
#endif
2425

25-
#ifndef SDIO_BASE_ADDRESS
26-
#define SDIO_BASE_ADDRESS (SDMMC1)
26+
#ifndef SDIO2_BASE_ADDRESS
27+
#define SDIO2_BASE_ADDRESS (SDMMC2)
2728
#endif
2829

2930
#ifndef SDIO_CLOCK_FREQ
@@ -39,7 +40,7 @@
3940
#endif
4041

4142
#ifndef SDIO_MAX_FREQ
42-
#define SDIO_MAX_FREQ (50 * 1000 * 1000)
43+
#define SDIO_MAX_FREQ (25 * 1000 * 1000)
4344
#endif
4445

4546
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
@@ -102,6 +103,7 @@ struct stm32_sdio_des
102103
{
103104
struct stm32_sdio *hw_sdio;
104105
sdio_clk_get clk_get;
106+
SD_HandleTypeDef hsd;
105107
};
106108

107109
/* stm32 sdio dirver class */

0 commit comments

Comments
 (0)