2023-02-07 08:37 PM
STM32Cube_FW_H7_V1.11.0
If you have wondered why the Board Support Package code for the STM32H743i_EVAL board is not able to properly switch the edge detection of the SD card switch using the MFX expander, it is due to an improper use of the AND function in the BSP_SD_DetectITConfig() function. At line 429, it reads:
if(((uint32_t)BSP_IO_ReadPin(0, PinDetect[Instance]) && PinDetect[Instance]) != PinDetect[Instance])
The simplification of this line is to compare the pin state with the pin location. The BSP_IO_ReadPin function returns the status of 0 when the switch closed and 32768 for when the switch is open. The pin location on the expander is also at 32768 (pin15). If the switch is closed then the code in the Detect function needs to set to a rising edge interrupt. If the switch is open then the falling edge is desired so the next time the switch changes state the expander interrupts the MCU, so the sd process code can act accordingly.
The bug is the use of "&&" instead of "&" which produces a true or false and this will always be not equal to PinDetect[Instance] which returns the pin location 32768. This will always result in the MFX expander selecting a rising edge interrupt.
the code needs to read:
if(((uint32_t)BSP_IO_ReadPin(0, PinDetect[Instance]) & PinDetect[Instance]) != PinDetect[Instance])
So when the sd switch is closed, ReadPin (=0) will not be equal to location, selecting the rising edge. When open, ReadPin (=32768) will equal the location and select the falling edge.
This same code is used in stm32h747i_eval_sd.c but the problem is at line 434.
Solved! Go to Solution.
2023-02-21 08:25 AM
Hi @[GreenGuy],
Thank you for your report.
We confirm the problem in the BSP_SD_DetectITConfig() API, this problem is introduced during the migration of STM32H743I-EVAL/ STM32H747I-EVAL drivers from V1 to V2.
This point will be fixed in the next version of the STM32CubeH7 V1.11.2 package scheduled for the end of 2023. However, this patch will be available soon on GitHub.
Internal ticket number: 145839 (This is an internal tracking number and is not accessible or usable by customers).
BeST Regards
2023-02-07 08:38 PM
Obviously this code was never tested.
2023-02-08 10:20 AM
I have entered a bug report in GitHub:
https://github.com/STMicroelectronics/stm32h743i-eval-bsp/issues/2
2023-02-21 08:25 AM
Hi @[GreenGuy],
Thank you for your report.
We confirm the problem in the BSP_SD_DetectITConfig() API, this problem is introduced during the migration of STM32H743I-EVAL/ STM32H747I-EVAL drivers from V1 to V2.
This point will be fixed in the next version of the STM32CubeH7 V1.11.2 package scheduled for the end of 2023. However, this patch will be available soon on GitHub.
Internal ticket number: 145839 (This is an internal tracking number and is not accessible or usable by customers).
BeST Regards