Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MCI driver: correct bus clock divider return value when divider equals 1 #24

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ARM.CMSIS-Driver_STM32.pdsc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
- Added VLAN and multicast address hash filtering
GPIO driver:
- Replaced POSITION_VAL macro with CMSIS implementation
MCI driver:
- Corrected bus clock divider return value when divider equals 1
</release>
</releases>

Expand Down Expand Up @@ -96,7 +98,7 @@
<file category="source" name="Drivers/I2C_STM32.c"/>
</files>
</component>
<component Cvendor="Keil" Cclass="CMSIS Driver" Cgroup="MCI" Capiversion="2.4.0" Cversion="3.1.0" condition="CMSIS Driver requirements">
<component Cvendor="Keil" Cclass="CMSIS Driver" Cgroup="MCI" Capiversion="2.4.0" Cversion="3.2.0" condition="CMSIS Driver requirements">
<description>MCI Driver for STM32 devices</description>
<RTE_Components_h> <!-- the following content goes into file 'RTE_Components.h' -->
#define RTE_Drivers_MCI1 /* Driver MCI1 */
Expand Down
32 changes: 19 additions & 13 deletions Drivers/MCI_STM32.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Arm Limited. All rights reserved.
* Copyright (c) 2024-2025 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -17,8 +17,8 @@
*
* -----------------------------------------------------------------------------
*
* $Date: 14. October 2024
* $Revision: V3.1
* $Date: 3. February 2025
* $Revision: V3.2
*
* Project: MCI Driver for STMicroelectronics STM32 devices
*
Expand Down Expand Up @@ -176,7 +176,7 @@ This driver requires the following configuration in CubeMX:
#endif

/* Driver Version */
#define ARM_MCI_DRV_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(3,1)
#define ARM_MCI_DRV_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(3,2)


/**
Expand Down Expand Up @@ -1051,18 +1051,24 @@ static int32_t Control (uint32_t control, uint32_t arg, MCI_RESOURCES *mci) {

switch (control) {
case ARM_MCI_BUS_SPEED:
/* Determine clock divider and set bus speed */
clkdiv = ((mci->info->ker_clk - 1U) / arg) + 1U;
clkdiv = clkdiv & 0x3FFU;
if (arg == 0U) {
/* Invalid argument, bus speed not configured */
bps = 0U;
}
else {
/* Determine clock divider and set bus speed */
clkdiv = ((mci->info->ker_clk - 1U) / arg) + 1U;
clkdiv = clkdiv & 0x3FFU;

/* Set new clock divider */
MCI_Set_ClockDivider(mci, clkdiv);
/* Set new clock divider */
MCI_Set_ClockDivider(mci, clkdiv);

/* Calculate actual clock (in bps) */
bps = mci->info->ker_clk / MCI_Get_ClockDivider(mci);
/* Calculate actual clock (in bps) */
bps = mci->info->ker_clk / MCI_Get_ClockDivider(mci);

/* Bus speed configured */
mci->info->flags |= MCI_SETUP;
/* Bus speed configured */
mci->info->flags |= MCI_SETUP;
}
return ((int32_t)bps);

case ARM_MCI_BUS_SPEED_MODE:
Expand Down
6 changes: 3 additions & 3 deletions Drivers/MCI_STM32.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Arm Limited. All rights reserved.
* Copyright (c) 2024-2025 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -17,8 +17,8 @@
*
* -----------------------------------------------------------------------------
*
* $Date: 20. June 2024
* $Revision: 3.0
* $Date: 3. February 2025
* $Revision: 3.2
*
* Project: MCI Driver for STMicroelectronics STM32 devices
*
Expand Down
2 changes: 1 addition & 1 deletion Drivers/MCI_STM32_SDIO.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Arm Limited. All rights reserved.
* Copyright (c) 2024-2025 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down
6 changes: 5 additions & 1 deletion Drivers/MCI_STM32_SDMMC.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Arm Limited. All rights reserved.
* Copyright (c) 2024-2025 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -504,6 +504,10 @@ __STATIC_INLINE uint32_t MCI_Get_ClockDivider (MCI_RESOURCES *mci) {
}
#else
divider = (mci->reg->CLKCR & 0x3FFU) << 1U;

if (divider == 0U) {
divider = 1U;
}
#endif
return (divider);
}
Expand Down