This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

SPI3 and SD Card

Hi Does anybody have a working example of an STM32F407VG reading and or writing an SD card using SPI3.

I have tried everything but always fails on mount with fsMediaError am at my wits end, i have even tried to follow example http://www.keil.com/appnotes/files/apnt_273.pdf and still not working.

Parents
  • Blink Thread - This Flashes every Second

    /* USER CODE BEGIN 4 */
    void Blink(void const *arg){
    
            while (1){
                    osDelay(1000);
                    HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_0);
                    WriteFile();
            }
    }
    

    It calls the writefile routine which should mount the card but fails.

    int32_t fs_mc_spi_control_ss (uint32_t drive_num, uint32_t ss){
            if (ss==0) {
                    HAL_GPIO_WritePin(GPIOD,GPIO_PIN_3,GPIO_PIN_SET);
                    return 1;
            }
              else {
                            HAL_GPIO_WritePin(GPIOD,GPIO_PIN_3,GPIO_PIN_RESET);
                return 0;
                    }
    }
    
    void WriteFile()
    {
            fsStatus st;
            if (finit("") == fsOK) {
            st=fmount("");
            if (st == fsOK) HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_1); ;
            }
            FILE *f=fopen("try.txt","a");
                    if (f!=NULL) {
                            HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_2);
                            fprintf(f,"Test\n");
                            fclose(f);
                    }
    }
    
    

    The fs_mc_spi_control_ss function is setting the CS pin, I have tried reversing polarity.
    Also tried to lengthen the delay on the thread.

    Thanks so much for your time.

Reply
  • Blink Thread - This Flashes every Second

    /* USER CODE BEGIN 4 */
    void Blink(void const *arg){
    
            while (1){
                    osDelay(1000);
                    HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_0);
                    WriteFile();
            }
    }
    

    It calls the writefile routine which should mount the card but fails.

    int32_t fs_mc_spi_control_ss (uint32_t drive_num, uint32_t ss){
            if (ss==0) {
                    HAL_GPIO_WritePin(GPIOD,GPIO_PIN_3,GPIO_PIN_SET);
                    return 1;
            }
              else {
                            HAL_GPIO_WritePin(GPIOD,GPIO_PIN_3,GPIO_PIN_RESET);
                return 0;
                    }
    }
    
    void WriteFile()
    {
            fsStatus st;
            if (finit("") == fsOK) {
            st=fmount("");
            if (st == fsOK) HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_1); ;
            }
            FILE *f=fopen("try.txt","a");
                    if (f!=NULL) {
                            HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_2);
                            fprintf(f,"Test\n");
                            fclose(f);
                    }
    }
    
    

    The fs_mc_spi_control_ss function is setting the CS pin, I have tried reversing polarity.
    Also tried to lengthen the delay on the thread.

    Thanks so much for your time.

Children