Coder Social home page Coder Social logo

cubeide-sd-card's Introduction

cubeide-sd-card

This project is designed as an example of a STM32CubeIDE-generated system with FatFs middleware controlling an SPI-connected MMC/SD memory card.

The project was initially created in CubeIDE, and then code written by ChaN was ported to fit the CubeIDE generator.

This is a remake of the original project provided here for CubeIDE instead of CubeMX.

I also wrote a blog post which accompanies this repository and explains how to use it.

Adoption Guide

  1. Copy the driver files FATFS/Target/user_diskio_spi.c and FATFS/Target/user_diskio_spi.h into your CubeIDE project which has been configured to use FatFS.
  2. In FATFS/Target/user_spi.c add #include "user_diskio_spi.h"
  3. In FATFS/Target/user_spi.c call USER_SPI_initialize(...) in USER_initialize(...), USER_SPI_status(...) in USER_status(...), USER_SPI_read(...) in USER_read(...), USER_SPI_write(...) in USER_write(...), and USER_SPI_ioctl(...) in USER_ioctl(...).
  • We embed in this manner to avoid conflicts with the CubeIDE code generator. Make sure these function calls are inside the USER comment blocks.
  1. In main.h ensure that you have #defines for SD_SPI_HANDLE (e.g. hspi2), SD_CS_GPIO_Port, and SD_CS_Pin.
  2. Double check what would be suitable high/low speeds for your SPI driver and the prescalars you will need to use for the SPI port. Configure these at in user_diskio_spi.c:
//(Note that the _256 is used as a mask to clear the prescalar bits as it provides binary 111 in the correct position)

#define FCLK_SLOW() { MODIFY_REG(SD_SPI_HANDLE.Instance->CR1, SPI_BAUDRATEPRESCALER_256, SPI_BAUDRATEPRESCALER_128); }	/* Set SCLK = slow, approx 280 KBits/s*/
#define FCLK_FAST() { MODIFY_REG(SD_SPI_HANDLE.Instance->CR1, SPI_BAUDRATEPRESCALER_256, SPI_BAUDRATEPRESCALER_8); }	/* Set SCLK = fast, approx 4.5 MBits/s */

You can now call the FatFS functions from your main(). For more detailed explanation of this, with examples, check out the blog post.

Additional note

Also note that if you're using this process with your own custom circuit, you may need pull-up resistors on the SCK, MISO, and MOSI lines. The SD card module I used in this post includes them internally - if you're wiring your own design, you might find you need to add them. You can also consider enabling the internal pull up resistors. More details are included here.

cubeide-sd-card's People

Contributors

kiwih avatar smartel99 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.