1550 views|0 replies

3836

Posts

19

Resources
The OP
 

FatFs transplantation based on SPI for MSP430F5438A microcontroller [Copy link]

This post was last edited by fish001 on 2019-3-16 22:05 No matter what program you port, the most important thing is, don’t think you must check the information first, spend a week looking for information, and don’t find it until you can’t find it. Otherwise, you will refer to others’ half-written program. The direct consequence is that you can’t make up your mind to overturn it and start over. 1. Key points of FatFs porting: I believe that everyone who can see this blog knows what FatFs is. It should be version 0.11 at present. I will not say much nonsense. It is an open source file system. To put it in a comprehensive way, its function is to allow you to write programs to write SD card contents that can be read by PC (if there is something wrong, please correct me if you know it). Its advantage is that you only need to write a few underlying hardware driver functions. The upper-level functions have been written, and you can call them directly after clearing the format. The so-called "hardware driver" function tells the microcontroller which IO port needs to change in order to complete an action (such as initialization), which IO port should be high, which IO port should be low, which communication port to choose, and what to send. These basic actions combined together can complete the initialization. There are five driver functions required by FatFs, which are as follows in the diskio.h file: DSTATUS disk_initialize (BYTE pdrv); DSTATUS disk_status (BYTE pdrv); DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count); DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count); DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff); Function return value: DSTATUS is an enumeration type variable, which contains 5 elements, namely success, read/write error, write protection, not ready, parameter error: /* Results of Disk Functions */ typedef enum { RES_OK = 0, /* 0: Successful */ RES_ERROR, /* 1: R/W Error */ RES_WRPRT, /* 2: Write Protected */ RES_NOTRDY, /* 3: Not Ready */ RES_PARERR /* 4: Invalid Parameter */ } DRESULT; Actually when writing a program, it is helpful to quickly locate the problem by dividing the return value into smaller parts. However, when I ported the program, I only used success, read/write error, and parameter error to save trouble. The reason is that I did not write a special function to judge the write protection, and the probability of not being ready is very low. The input parameters of each function will be explained one by one for each function. So let's first take the initialization program DSTATUS disk_initialize (BYTE pdrv); to be specific: the steps to implement the function through TI's microcontroller MSP430F5438A A technical report written by someone at the University of Michigan, a program written for MSP430F149, but only implements single read and write, and uses high-end functions such as DMA (direct memory read) (I will upload it to the information to be completed) The official protocol specification of the SD card, this is basically too important, the name is part1_410, it seems to be only a part of the whole, but it is very detailed and clearly explained, as long as you are patient and careful, many things can be found directly, if you are concerned about the SPI mode, Chapter 7 is the key point! 2. disk_initialize function The function body of this function in diskio.c is as follows: /*---------------------------------------------------------------------------------------*/ /* Inidialize a Drive */ /*-----------------------------------------------------------------------*/ DSTATUS disk_initialize ( BYTE pdrv /* Physical drive nmuber to identify the drive */ ) { DSTATUS stat; int result; switch (pdrv) { case ATA : result = ATA_disk_initialize(); // translate the reslut code here return stat; case MMC : result = MMC_disk_initialize(); // translate the reslut code here return stat; case USB : result = USB_disk_initialize(); // translate the reslut code here return stat; } return STA_NOINIT; } It can be seen that FatFs is very "considerate" and provides initialization programs for three interface memories: ATA, MMC, and USB. But if you really think it is considerate, you are wrong... First of all, let's talk about the input parameter pdrv, which can be specifically understood as the memory number you want to operate. We usually operate only one memory for the microcontroller (the SD card in my project), so in the definition of ffconf.h: #define _VOLUMES 1 In this way, all the input parameters pdrv are 0, and the definition of ATA MMC USB is as follows: /* Definitions of physical drive number for each drive */ #define ATA 0 /* Example: Map ATA harddisk to physical drive 0 */ #define MMC 1 /* Example: Map MMC/SD card to physical drive 1 */ #define USB 2 /* Example: Map USB MSD to physical drive 2 */ MMC_disk_initialize(); Who would have thought that people could not execute this at all under the condition of a single storage device! Therefore, if you only have one disk, you must implement the ATA one, no matter what its name is. Here, I compromised when I finally implemented it and copied MMC_disk_initialize(); to ATA, which can be regarded as being lazy. Then MMC_disk_initialize();
This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list