adafruit / Adafruit-Feather-STM32F405-Express-PCB

PCB files for the Adafruit Adafruit Feather STM32F405 Express
Other
12 stars 6 forks source link

STM32F405 Express, PCB error about SD card detection #1

Open dombru54 opened 2 years ago

dombru54 commented 2 years ago

Hello,

With your STM32F405 Feather Express card, the PB12 pin (cardDetect) is always to 0 (GND). This is due to a short circuit with the card reader double pin 10 cardReader_STM32F405-Feather-Express

Error in the card reader manufacturer's datasheet and red correction image

With actual PCB, cut ground track with a scalpel, at the edge of the metal case cardReader_STM32F405-Feather-Express_modif-eagle cardReader_STM32F405-Feather-Express_modif-scalpel

Thanks to make a revision of this board .

ladyada commented 2 years ago

thanks for the note - we'll fix this on the next PCB run!

javiBajoCero commented 1 year ago

Howdy @dombru54 , thanks for your work, i just purchased two feathers from here, and i quickly found the same problem (fixed with your same solution) image

WhatsApp-Video-2023-04-13-at-19 32 40

I dont see any Hardware revision markings in my boards, so there is no way for me to guess if either berrybase had old stock or this error wasnt fixed yet (for sure isnt fixed in adafruits repo).

dombru54 commented 1 year ago

@javiBajoCero , It is with great pleasure that I welcome your return, my friend. I also invite you to see another of my work on the Oled feather https://github.com/adafruit/Adafruit-OLED-FeatherWing-PCB/issues/10 Best regards

dombru54 commented 1 year ago

@javiBajoCero , In addition, if you work with STM32CubeIDE, you must modify : ".....\STM32CubeIDE\workspace_1.8.0\project\FATFS\Target\fatfs_platform.c"


uint8_t BSP_PlatformIsDetected(void) {
    uint8_t status = SD_PRESENT;
    /* Check SD card detect pin */
    if(HAL_GPIO_ReadPin(SD_DETECT_GPIO_PORT, SD_DETECT_PIN) != GPIO_PIN_RESET)
    {
        status = SD_NOT_PRESENT;
    }
    /* USER CODE BEGIN 1 */
    /* user code can be inserted here */
    // Correction de l'erreur génèrée dans le code par MX, au dessus
    if(HAL_GPIO_ReadPin(SD_DETECT_GPIO_PORT, SD_DETECT_PIN) == GPIO_PIN_SET){   // carte présente = 1 (SET)
        status = SD_PRESENT;
    }
    /* USER CODE END 1 */
    return status;
javiBajoCero commented 1 year ago

Thanks for your advice, i was trying to make SD+SDIO(4bits) work but, two days later, still nothing. (for context i have developed SD+SPI projects in the past)

It doesnt work for me with STM32 HAL CUbeMX based, not even when i switched to arduino to test my sanity image

I know statistically im messing up something in my code but seeing they missed this SD detection Gpio, im starting to be afraid they didnt tested the SD at all . image

If you have any more clues or repos with working code let me know

dombru54 commented 1 year ago

@javiBajoCero , All the SDIO 4 bits mode works on the Feather ! but .... "two days later, still nothing." .... normal ... ;>) .... SDIO is very poorly documented. I struggled for more than a week before having all the elements !!! 1) SDIO clock is based on USB clock at 48MHz. image

image

2) After, you must use a divider with ClockDiv = 3 , especially not another value ... for me SDIO_CK = SDIOCLK / (2 + CLKDIV) => SDIO_CK = 48MHz/(2+3) = 9.6 MHz

  static void MX_SDIO_SD_Init(void) {
  hsd.Instance = SDIO;
  hsd.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;
  hsd.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE;
  hsd.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE;
  hsd.Init.BusWide = SDIO_BUS_WIDE_1B;
  hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
  hsd.Init.ClockDiv = 3; }
dombru54 commented 1 year ago

@javiBajoCero ,

3) For good precision, it is more than recommended to use the 2 quartz, therefore the 2 LSE and HSE modes.


void SystemClock_Config(void) {
  .......
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.LSEState = RCC_LSE_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  .......
dombru54 commented 1 year ago

@javiBajoCero , Feather has a trap about its serigraphy, 2 "Bats" with 2 different functions, one for powering on LiPo connector and the other on backing up the RTC. image

image

dombru54 commented 1 year ago

@javiBajoCero ,

  1. For the SDIO to work, you must activate the USB pins, maybe to run USB clock. Here is the complete pinout of my cubeMX project :

image

javiBajoCero commented 1 year ago

Hi @dombru54 , first thanks for all of your tips, they are gold!

I got it to work yesterday, my problems were ;

About your tips:

  1. SDIO clock is based on USB clock at 48MHz.

I see youre using a super old version of cubeMX, why is that?

In my Cube version i cannot se any SDIO dedicated box in the clock graphic config tool. I tought the SDIO was clocked with the APB2 peripheral clock. image image i am not enabling the USB and SDIO works as expected.

2.After, you must use a divider with ClockDiv = 3 , especially not another value ... for me

bingo, this was one of the problems i had, apparently SDIO really dislikes being clocked further than 24Mhz as my APB2 is clocked to 84Mhz by using a divide factor of 4 i get 14Mhz for the SDIO and it works. image

3.For good precision, it is more than recommended to use the 2 quartz, therefore the 2 LSE and HSE modes.

I had this present since the start, always HSE (xtal), my last job consisted in 2 painfull years of mitigating the cathastrophic decision someone had using a HSI for automotive CANbus connected systems. (because it worked for them in the lab)

4.4. For the SDIO to work, you must activate the USB pins, maybe to run USB clock.

Thanks for sharing your design!, i didnt need to enable the USB for my progect to work tough, check it out in here https://github.com/javiBajoCero/featherSDcardTests image image

dombru54 commented 1 year ago

Hello @javiBajoCero , Thanks for sharing your experience.

  1. I don't have an old version, it's a copy of web image ... ;>) ... the "Clock configuration" is not complete, it lacks sharing modes between LSE and MSI, for example ... but also SDIO clock ...

image

  1. I'm happy for you, Thanks for RM0090, but i'm surprised. page 1022 : image

  2. HSE is also very important for the PDM bus with microphones (ultrasonic acoustic spectrum aliasing of decimation).

  3. Thank you for this surprising information.

Hope to read you soon

dombru54 commented 1 year ago

Hello @javiBajoCero ,

  1. see AN3988 : https://www.st.com/resource/en/application_note/an3988-clock-configuration-tool-for-stm32f40xx41xx427x437x-microcontrollers-stmicroelectronics.pdf see "Clock configuration tool" STSW-STM32091 : https://www.st.com/en/development-tools/stsw-stm32091.html it's an Excel sheet : "STM32F4xx_Clock_Configuration_V1.1.0.xls"

image

SYL

javiBajoCero commented 1 year ago

Its my first time working with stm32's F4 family, so i was just clicking my way with cubeMx doing all the clock configs.

SDIO is indeed very poorly documented. It seems SDIO uses indeed two different clocks comming from two different places, one for the APB interface and another for the "adapter". image image

  1. see AN3988

    So my guess is , cubeMX is enabling the SDIOCLK somwhere for me. No clue of where PLL48CLK is, there is a lack of consistent naming in these stm ap notes. image image It looks to me , somewhere, there is a PLL48CLK from which USB and SDIO clocks would come from, USB would only work with sharp 48Mhz so if enabled, all the rest of peripherals whose clock comes from PLL48CLK will need to work with 48Mhz as well. image No idea where PLL48CLK is but for sure is available without initialising USB.

dombru54 commented 1 year ago

Hello @javiBajoCero , In one of your repo first page, you can add our sharing ... a gold mine .... ;>) ... SYL

dombru54 commented 1 year ago

Hello @javiBajoCero , if you like "Feather factor form", you must absolutely see the great "Swan Blues Wireless", STM32L4R5 : https://blues.io/products/swan/ https://www.hackster.io/news/swan-from-blues-wireless-is-the-most-expandable-feather-compatible-board-to-date-01132f5a0a91 https://github.com/gauteh/swan-stm32l4r5-quickstart https://blog.adafruit.com/2021/09/30/the-blues-wireless-swan-a-feather-board-based-on-the-stm32l4r5-feather-blueswireless/

Version 1.7 : image Multi-layers board, V1.7, it exists Version 3.0 : image

javiBajoCero commented 1 year ago

In one of your repo first page, you can add our sharing ... a gold mine .... ;>) ...

I didnt understood that sorry.

"Swan Blues Wireless"

this looks very nice!!! i will stick with adafruit feather tough. I just wanted some hardware to test my code before spending money manufacturing my own thing. I dont care much about the form factor, i just wanted some STMf4 with a Sd card and neopixel.

dombru54 commented 1 year ago

Hello @javiBajoCero , In one of your repo first page, you can add our sharing ... a gold mine .... ;>) ...

Sorry, most directly, you could insert the link to this issue in the file "readme.md" of https://github.com/javiBajoCero/featherSDcardTests ... This might help a reader of your repo.

Neopixel ... I understand why : https://www.hackster.io/javier-munoz-saez/coding-your-own-neopixel-driver-baremetal-stm32-b6b4d0

You say : "fatfs library doesnt like to be breakpointed by the debugger" : strange, maybe due to an interraction between Debugger clock and SDIO clocks ... I never had this problem.

SYS

aspence commented 12 months ago

Hi all!

Trying to use the SD card on this board over SDIO within ST32duino. We can program the board and get data from an MSA311 over the qic connect, but we can't get SD.begin() to work. Initially, it would hang for a long time at this step (multiple seconds), and then fail. We think we found the letter "B" with a circle around it on the board, suggesting this was a Rev B board with the card detect trace error. We cut that trace with an exacto. Now, it fails much more quickly. Our hypotheses as to the problem are:

  1. We are not initializing the library correctly
  2. We are not formatting the SD card correctly
  3. There is still a wiring error.

Details of each are:

  1. Our code is along the lines of

    include

setup: SD.setDX(PC8,PC9,PC10,PC11); SD.setCK(PC12); SD.setCMD(PD2); if (!SD.begin(PB12)) { // detect Serial.println('failure to init'); while(1); }

we are not including a PinName library - but it compiles so I assume that's ok...

  1. We have a 120gb SD card. In windows, we erased all partitions and created a single 3.5 gb fat32 partition. we did not alter the partition table.

  2. The fact that the boot time/error time changed after we cut the trace suggested it did something, but it still gives an error on startup. We dont have a known good SD card around to try.

It would be very useful to hear from anyone who has gotten this working with code similar to the above for setting the pins, and with just cutting the trace.

If we need to mess with changing things in libraries or adjusting clock timings, then i think we'll just stack an adalogger feather wing on it and communicate with the SD card via SPI or something simpler.

Thank you for any input!

dombru54 commented 12 months ago

Hello,

I think that if the card had been revised, I would have been warned.

First, verify PB12 pin (cardDetect) with voltmeter.

Sorry, i don't know STM32duino, i just use STM32codeIDE. Maybe, you must modify a part of your library ... (insert correction code between user code balises) as this :

".....\STM32CubeIDE\workspace_1.8.0\project\FATFS\Target\fatfs_platform.c"

uint8_t BSP_PlatformIsDetected(void) {
    uint8_t status = SD_PRESENT;
    /* Check SD card detect pin */
    if(HAL_GPIO_ReadPin(SD_DETECT_GPIO_PORT, SD_DETECT_PIN) != GPIO_PIN_RESET)
    {
        status = SD_NOT_PRESENT;
    }
    /* USER CODE BEGIN 1 */
    /* user code can be inserted here */
    // Correction de l'erreur génèrée dans le code par MX, au dessus
    if(HAL_GPIO_ReadPin(SD_DETECT_GPIO_PORT, SD_DETECT_PIN) == GPIO_PIN_SET){   // carte présente = 1 (SET)
        status = SD_PRESENT;
    }
    /* USER CODE END 1 */
    return status;
timurkelin commented 1 month ago

Hi @javiBajoCero,

Did you finally manage to make the SD card work?

I'm at the same standpoint. I started the discussion and shared my observations in here: https://forums.adafruit.com/viewtopic.php?p=1031343#p1031343

javiBajoCero commented 1 month ago

Hi @javiBajoCero,

Did you finally manage to make the SD card work?

I'm at the same standpoint. I started the discussion and shared my observations in here: https://forums.adafruit.com/viewtopic.php?p=1031343#p1031343

yup, i managed https://github.com/javiBajoCero/featherSDcardTests