Home
V850E2/ML4 MultiMediaCard SPI Mode Device Driver Adoption
Contents
1. V850E2 ML4 MultiMediaCard SPI Mode Device Driver Adoption Guide 8 3 Functions No Function Name Overview 1 0 main Initializes the microcontroller clock and CPU port LEDs and runs the sample program 1 1 PORT Init Initializes the CSIH ports and DETECT pin 1 2 CSIH1 Init Initializes the CSIH module 1 3 R_init_portpins Initializes the LED ports 1 4 tfat_sample Runs the TFAT file system sample program 1 4 1 R_mmc_Init_Driver Initializes MMC driver processing e This is an API function 1 4 2 R_init_card_detect_chat Initializes card insertion removal detection memory 1 4 3 R_tfat_disk_initialize Initializes the card e This is an API function 1 4 3 1 R_card_insertion_chk Detects card insertion 1 4 3 2 R mmc Init Slot Initializes card control RAM and ports initializes the card and switches the card state from MMC mode to SPI mode 1 4 4 R tfat disk read Reads data from a card e This is an API function 1 4 4 1 R mmc Read Data Reads data in 512 byte units from a card 1 4 5 R tfat disk write Writes data to a card e This is an API function 1 4 5 1 R mmc Write Data Writes data in 512 byte units to a card 1 4 6 R error Function that is run when an error is detected R01AN1026EJ0101 Rev 1 01 Jul 23 2012 Page 28 of 31 34 NE SAS V850E2 ML4 MultiMediaCard SPI Mode Device Driver Adoption Guide 8 4 Function Chart 1 0 main 1 1 PORT Init 1 2 CSIH1 Init 1 3 R init portpins 1
2. Item Description Prototype DSTATUS R ffat disk initialize void Arguments None Description Initializes a MultiMediaCard MMC This function calls the MMC driver MMC insertion check function R mmc Chk Detect and the MMC slot initialization function R mmc Init Slot This function may be called as many times as needed until it returns normally Return value Returns the initialization result TFAT RES OK Initialization completed normally TFAT STA NODISK No MMC inserted TFAT STA NOINIT Uninitialized state 7 2 2 FAT file system working area register R_tfat_f_mount Item Description Prototype FRESULT R_tfat_f_mount uint8_t drv FATFS fs Arguments uint8_t drv Logical drive number FATFS fs Pointer to working area Description Registers a FAT file system working area on the MMC If there are any open files or directories on the target drive those all become invalid This function always completes normally regardless of the state of the drive Return value Returns the registration state TFAT_FR_OK Normal completion 7 2 3 File open R_tfat_f_open Item Description Prototype FRESULT R_tfat_f_open FIL fp const uint8 t path uint8_t mode Arguments FIL fp Pointer to a structure object const uint8_t path Pointer to a character string that specifies the file to open uint8_t mode Access open mode flag Description Opens an existing file or creates a new file If this functio
3. When use the card which does not support a multi block command please define it amp Use single block commands in the case of the card which does not support multiple block commands y define MMC SBLK CMD Support single block commands xf PRE SET 3 Supported media definition The MMC SUPPORT MMC macro must be defined Please define the media to support define MMC SUPPORT MMC MMC SET RO1AN1026EJ0101 Rev 1 01 Page 13 of 31 Jul 23 2012 RENESAS V850E2 ML4 MultiMediaCard SPI Mode Device Driver Adoption Guide 4 2 2 r_mmc_user_setting h Microcontroller specific settings 1 Selection of the microcontroller used The file r mmc user setting h depends on the microcontroller used Include the mmc user setting h file in the directory indicated below according to the environment used If there is no file that matches the environment used the user must create the appropriate file Microcontroller Used Communications Environment Include Directory under the source directory V850E2 ML4 mmc_driver V850E2 ML4 2 Communication module channel number definition Define the MMC CSIH CHANNEL macro if CSIH is used to be the number of the communication module used When the V850E2 MLA CSIH is used CSIH Channel Select CSIHx x 0 or 1 define MMC CSIH CHANNEL 1 SET 3 Used control port definitions Define these macros to match the DETECT signal
4. V850E2M El JTAG e Emulator software V850E2 Debugger V1 00 00 Evaluation board V850E2 ML4 CPU board catalog number ROK0F4022C000BR 6 2 2 Included files When an MMC driver is embedded include the header files r mtl com h and r mmc h The file r mtl com h must be included first RO1AN1026EJ0101 Rev 1 01 Page 19 of 31 Jul 23 2012 RENESAS V850E2 ML4 6 3 ROM RAM and Stack Sizes MultiMediaCard SPI Mode Device Driver Adoption Guide The ROM RAM and stack sizes used by this program are listed below ROM and RAM Sizes Classification section name ROM text data Size About 30 8 KB RAM sbss About 12 0 KB Stack Sizes MMC driver Function Stack Size bytes R_mmc_Init_Driver 16 RH mmc Init Slot 136 RH mmc Detach 16 RH mmc Chk Detect 8 R mmc Read Data 124 R mmc Write Data 132 Stack Sizes TFAT library Function Stack Size bytes R tfat f mount 0 R tfat f open 224 R tfat f close 64 R tfat f read 84 R tfat f write 128 R tfat f Iseek 112 R tfat f truncate 96 R tfat f sync 56 R tfat f opendir 148 R tfat f readdir 80 R tfat f getfree 100 R tfat f stat 164 R tfat f mkdir 228 R tfat f unlink 172 RH tfat f chmod 164 RH tfat f utime 160 R tfat f rename 236 R tfat f forward 80 R01AN1026EJ0101 Rev 1 01 Page 20 of 31 Jul 23 2012 RENESAS V850E2 MLA MultiMediaCard SPI Mode Device Driver Adoption Guide 6 4 No
5. CG_macrodriver h State control definitions header file tfat_sample lt DIR gt TFAT test sample program directory r sample tfat c MMC driver operation verification sample program r tfat drv if cr tfat drv if h TFAT driver source file r data file h Write data definitions header file r target io h Peripheral I O definitions header file Library lt DIR gt Library directory r_tfat_lib h TFAT file system header file libt at v850e2m lib MMC driver TFAT file system library sample lt DIR gt Sample project directory TFAT_MMC_sample_for_V850E2ML4 mipj Project file R01AN1026EJ0101 Rev 1 01 Page 3 of 31 Jul 23 2012 RENESAS V850E2 MLA MultiMediaCard SPI Mode Device Driver Adoption Guide 2 Program Type Definitions This program defines the following integer types Datatype Typedef unsigned char uint8 t unsigned short uint16_t unsigned long uint32 t signed char int8 t signed short int16 t signed long int32 t RO1AN1026EJ0101 Rev 1 01 Page 4 of 31 Jul 23 2012 RENESAS V850E2 ML4 3 Device Driver 3 1 Device Driver Functions Overview Initialization Functions Function R_mmc_Init_Driver Device Manipulation Functions Function R_mmc_Init_Slot MultiMediaCard SPI Mode Device Driver Adoption Guide Functional Overview MMC driver initialization Functional Overview MMC slot initialization R_mmc_Detach MMC slot
6. NOCHK TIMEOUT omits detecting timeout during communication If user omits detecting timeout please define this macro y If this macro is defined processing speed would be increased y 4 define MMC NOCHK TIMEOUT No Check Communication Timeout SET xy If MMC_NOCHK_TIMEOUT would be not defined please set timeout time MMC_T_SCI_WAIT is unit of measuring timeout Please select value from r mtl tim h Please set value of timeout time unit to MMC SCI TX WAIT transmitting and MMC SCI RX WAIT receiving as SCI transmit amp receive completion waiting polling time SET defin MC T SCI WAIT uint32 t MTL T 100US SCI transmission completion waiting time 50 1ms 50ms xA AE SET x7 defin MC SCI TX WAIT uint32 t MTL T 1MS 50 SCI receive completion waiting time 50 1ms 50ms X ge SET x defin MC SCI RX WAIT uint32 t MTL T 1MS 50 RO1AN1026EJ0101 Rev 1 01 Page 15 of 31 Jul 23 2012 RENESAS V850E2 ML4 MultiMediaCard SPI Mode Device Driver Adoption Guide 5 Communication baud rate definitions The user must define the communication baud rate If the definitions for the SIO used are modified SFR settings for each SIO register will be required Refer to the microcontroller datasheet and set the SFRs appropriately for the system In particular it is nece
7. V850E2 ML4 This software has a FAT file system function Of the V850E2 ML4 built in communication functions this software uses the clock synchronous serial interface CSIH and implements MMC access in SPI mode MMC driver specifications e MMC System Specification Version 3 x e Only SPI mode is used e This is a block type device driver that uses a sector size of 512 bytes The READ MULTIPLE BLOCK and WRITE MULTIPLE BLOCK commands are used When the mounted card is not supported the multiple block access this device driver uses the READ SINGLE BLOCK and WRITE SINGLE BLOCK commands e The driver does not depend on the OS e MMC driver described by this manual V850E2M V 1 00 Release00 TFAT Library Specifications e FAT types FATI2 and FAT16 e Supports 8 3 type filenames 8 character file name plus 3 character extension e Number of drives 1 e Sector size 512 bytes e The TFAT library is dedicated for the V850E2M core It does not support other cores e g V850 or V850ES Note The TFAT library may be updated Download the latest version from the Renesas Electronics Corporation web site See related application note 1 RO1AN1026EJ0101 Rev 1 01 Page 2 of 31 Jul 23 2012 RENESAS V850E2 ML4 1 3 File Structure The figure below shows the directory and file structure MultiMediaCard SPI Mode Device Driver Adoption Guide Directory Structure Directory Name File Name Notes doc lt DIR gt Docume
8. clock frequency and the number of wait states The user must provide a macro appropriate for the environment if one is not present Define the counter value for the timer i Specify according to the user MCU clock and wait requirements y Set the reference value to 10 more than the actual calculated value B d Macro definitions n d ifdef MTL TIM V850E2 50 OMHz Setting for 50 0MHz no wait Compile Option optimize 2 size define MTL T 250NS 2 loop times of 250ns Af of ER SET x defin L_T_500NS 5 loop times of 500ns Xf JRE GET Oy defin L T 1US i loop times of lus X RE SET ex defin L T 2US 24 loop times of 2us Af og SET 7 define MTL T 4US 49 loop times of 4us Af qoekcSwT Ox defin L T 5US 61 loop times of 5us Xf JRE SET y defin L T 10US 124 loop times of 10us Aff SET 3 7 defin L_T_20US 249 loop times of 20us ogGe SET define MTL_T_30US 374 loop times of 30us J gp SET BRT defin L_T_50US 624 loop times of 50us Af RE SET RET defin L_T_100US 1249 loop times of 100us SET defin L T 200US 2499 loop times of 200us Af gox SET 7 define MTL T 300US 3749 loop times of 300us J 5 SET defin L T 400US 4999 loop times of 400us
9. is not intended Renesas Electronics shall not be in any way liable for any damages or losses incurred by you or third parties arising from the use of any Renesas Electronics product for which the product is not intended by Renesas Electronics 6 You should use the Renesas Electronics products described in this document within the range specified by Renesas Electronics especially with respect to the maximum rating operating supply voltage range movement power voltage range heat radiation characteristics installation and other product characteristics Renesas Electronics shall have no liability for malfunctions or damages arising out of the use of Renesas Electronics products beyond such specified ranges 7 Although Renesas Electronics endeavors to improve the quality and reliability of its products semiconductor products have specific characteristics such as the occurrence of failure at a certain rate and malfunctions under certain use conditions Further Renesas Electronics products are not subject to radiation resistance design Please be sure to implement safety measures to guard them against the possibility of physical injury and injury or damage caused by fire in the event of the failure of a Renesas Electronics product such as safety design for hardware and software including but not limited to redundancy fire control and malfunction prevention appropriate treatment for aging degradation or any other appropriate measures Because the evaluation o
10. stop processing R_mmc_Chk_Detect Data Access and Manipulation Functions MMC insertion check Function Functional Overview R_mmc_Read_Data Data read R_mmc_Write_Data Data write R mmc Get Mmclnfo Internally Used Commands Command Index MMC information obtaining Command Name CMDO GO IDLE STATE CMD1 SEND OP COND CMD9 SEND CSD CMD10 SEND CID CMD12 STOP TRANSMISSION CMD13 SEND_STATUS CMD17 READ_SINGLE_BLOCK CMD18 READ_MULTIPLE_BLOCK CMD24 WRITE_BLOCK CMD25 WRITE_MULTIPLE_BLOCK CMD58 READ_OCR CMD59 CRC_ON_OFF Note Unsupported functions must be supported by the user RO1AN1026EJ0101 Rev 1 01 Jul 23 2012 Page 5 of 31 ztENESAS V850E2 ML4 MultiMediaCard SPI Mode Device Driver Adoption Guide 3 2 Function Descriptions 3 2 1 MMC driver initialization R mmc Init Driver Item Description Prototype void R mmc Init Driver void Arguments None Description Initializes the MMC driver Initializes the MMC control SFR and initializes the RAM and control ports for each slot This function must be called once and only once at system startup Return value None 3 2 2 MMC slot initialization R mmc Init Slot Item Description Prototype int t R mmc Init Slot uint8 t SlotNo Arguments uint8 t SlotNo The slot number Description Initializes RAM and ports for the slot specified by the argument It also performs MMC initialization Thi
11. to a card insertion the application should provide power to the card Turn off power to the card before removing the card If multiple cards are used on the same SPI bus provide a CS pin port and a CardDetect port for each card RO1AN1026EJ0101 Rev 1 01 Page 18 of 31 Jul 23 2012 RENESAS V850E2 MLA MultiMediaCard SPI Mode Device Driver Adoption Guide 6 Notes on Application Creation 6 1 Usage Notes e When using this program the software must be set up to match the hardware used e Only remove the memory card after setting the memory card to the inactive state setting the signals between the microcontroller and the memory card to the high impedance state and stopping power supply to the device The device may be damaged if it is removed while operating e fcircuits that support hot swapping have not been implemented and a hot swap is performed the power supply and other circuits may become unstable and the microcontroller may transition to the reset state 6 2 Notes on Embedding 6 2 1 Development environment Development host Windows XP Windows NT 4 0 Windows 200 Windows ME Window 98 or Windows 95 The following Renesas development environment is used Use versions at least as recent as the ones listed below when developing a user application Software Tools e Integrated development environment CubeSuite V1 00 01 e C compiler CubeSuite CX Compiler V1 20 Debugging Tools e Emulator debugger
12. xf JRE SET 7 defin L T 1MS 12499 loop times of 1ms SET ndif R01AN1026EJ0101 Rev 1 01 Page 12 of 31 Jul 23 2012 RENESAS V850E2 ML4 MultiMediaCard SPI Mode Device Driver Adoption Guide 4 2 MMC Driver Variable Data Settings The items in this section must be set to match the resources of each system The places that must be set are indicated by the comment SET in each file Selections are indicated within each file and detailed explanations are added 4 2 1 r mmc h driver common definitions 1 Device count and device number definitions Define the number of memory card slots Multiple devices are not supported since it is expected that only one MMC slot will be used with the V850E2 ML4 Define number of required card slots 1 N slots Define slot number in accordance with the number of card slots to be connected Define number of slots devices define MMC_SLOT_NUM 1 1 slots SET Define slot number define MMC SLOTO 0 Slot 0 ef JEF SET f define MMC SLOTI1 1 Slot 1 ef f SET 2 Definitions for cards that do not support multiblock commands in SPI mode For cards that do not support the MULTIPLE BLOCK commands the default setting is to support these cards by using the READ SINGLE BLOCK and WRITE SINGLE BLOCK commands Therefore we recommend using these settings without change
13. 026EJ0101 Rev 1 01 Page 8 of 31 Jul 23 2012 RENESAS V850E2 MLA MultiMediaCard SPI Mode Device Driver Adoption Guide 3 2 7 MMC information obtaining R mmc Get Mmclnfo Item Description Prototype int16_t R mmc Get Mmclnfo uint8 t SlotNo MMC INFO pMmcinfo Arguments uint8 t SlotNo The slot number MMC INFO pMmclnfo MMC information storage buffer pointer Description Returns the MMC information Stores the MMC information in the MMC information buffer pMmclnfo pMmclinfo Card Card type MMC_CARD_UNDETECT Card not detected MMC_CARD_MMC MMC MMC_CARD_OTHER Other card pMmclinfo W Protect Write protected state MMC NO PROTECT Write protection released MMC W PROTECT SOFT Software write protection pMmclinfo MemSize Card capacity in bytes pMmclnfo MaxBlkNum Maximum block number maximum block number for the media If pMmcInfo MemSize is OXFFFFFFFF pMmclnfo MaxBlkNum 1 indicates the number of blocks the media holds 1 block 512 bytes If it is necessary to calculate the card s capacity use the formula pMmclInfo MaxBlkNum 1 x 512 Return value Returns the write result MMC OK Normal completion MMC ERR PARAM Parameter error MMC ERR OTHER Other error RO1AN1026EJ0101 Rev 1 01 Page 9 of 31 Jul 23 2012 RENESAS V850E2 MLA MultiMediaCard SPI Mode Device Driver Adoption Guide 3 3 Data Structures This section presents the data structures used MMC information structure definition ty
14. 4 tfat sample 1 4 1 R mmc lnit Driver 1 4 2 R init card detect chat 1 4 3 R tfat disk initialize 1 4 4 R tfat disk read 1 4 5 R tfat disk write 1 4 6 R error 1 4 3 1 R card insertion chk 1 4 3 2 R mmc Init Slot 1 4 4 1 R mmc Read Data 1 4 5 1 R mmc Write Data RO1AN1026EJ0101 Rev 1 01 Jul 23 2012 34 NE SAS Page 29 of 31 V850E2 MLA MultiMediaCard SPI Mode Device Driver Adoption Guide 9 Reference Documents e Hardware Manual V850E2 MLA User s Manual Hardware R01UHO262EJ The latest version can be downloaded from the Renesas Electronics Web site e Software manual V850E2M User s Manual Architecture RO1US0001EJ Download the latest version from the Renesas Electronics Corporation web site e Related application notes 1 V850E2M M3S TFAT Tiny FAT File System Software Adoption Guide R01 AN1028EJ0100 RO1AN1026EJ0101 Rev 1 01 Page 30 of 31 Jul 23 2012 RENESAS V850E2 MLA MultiMediaCard SPI Mode Device Driver Adoption Guide Website and Support Renesas Electronics Website http www renesas com Inquiries http www renesas com inquiry All trademarks and registered trademarks are the property of their respective owners RO1AN1026EJ0101 Rev 1 01 Page 31 of 31 Jul 23 2012 RENESAS Revision Record Description Rev Date Page Summary 1 00 Mar 27 12 First edition issued 1 01 Jul 23 12 Changed source project setting port initi
15. 434 NE SAS APPLICATION NOTE V850E2 MLA RO1AN1026EJ0101 Rev 1 01 MultiMediaCard SPI Mode Device Driver Adoption Guide Jul 23 2012 Introduction This application note describes the V850E2 ML4 MultiMediaCard device driver and its use Target Device V850E2 ML4 uPD70F4022 Contents EET 2 2 Program Type Definitlons aterert esperti dede edo usi obere bere dca deese ede o 4 3e DeViCe DIiVG E 5 4 Settings Example eee Eua eee tacet Le eee d deese oL et end eda ccce Eta diene 11 5 Microcontroller Connection and Used Microcontroller Resources ssee 17 6 Notes on Application Creation esses eee nnns en nennen sinn inneren ns 19 Z2 TEATADA dudtcc ttem MIU I EAD M EMI MM NAMES 22 8 Sample Pfogram iae cinerea ned rk pae tegen ud UE S Ta apa uv RR ud dua gea LE Ru kae teas 26 9 Reference Documents eeeseesisessesseesee esee ener eren nnne nini tr tr A AASS n ennt 30 RO1AN1026EJ0101 Rev 1 01 Page 1 of 31 Jul 23 2012 RENESAS V850E2 MLA MultiMediaCard SPI Mode Device Driver Adoption Guide 1 Overview 1 1 Purpose This application note presents an example of control in SPI mode of a MultiMediaCard MMC by the V850E2 ML4 This application note presents an example of application creation 1 2 Functional Overview This device driver MMC driver is software that implements communication with an MMC on the
16. CT uint8_t 0x00 None setting defin C_W_PROTECT_SOFT uint8_t 0x02 Software write protection RO1AN1026EJ0101 Rev 1 01 Page 10 of 31 Jul 23 2012 RENESAS V850E2 MLA MultiMediaCard SPI Mode Device Driver Adoption Guide 4 Settings Example 4 1 Common Function r mtl XXX Variable Data Settings The items in this section must be set to match the resources of each system The places that must be set are indicated by the comment SET in each file Selections are indicated within each file and detailed explanations are added 4 1 1 r mtl com h This is the header file for the shared common functions Separate Copies ofr mtl com h for each microcontroller and for each system clock must be provided Include the appropriate version ofr mtl com h for the environment used The corresponding files must be provided by the user when different microcontrollers are used or if the system is operated using different clocks Microcontroller Used System Clock Include Directory under the source directory V850E2 ML4 50 MHz common V850E2_50MHz 1 Loop timer definition Ifthe software loop timer is used include the file r_mtl_tim h This timer is mainly used for assuring the wait times required by device drivers If the software loop timer is not used comment out the include directive shown below In the example below the software loop time is used When this driver is used include this header file Also define the mac
17. ERR PARAM Parameter error MMC ERR HARD Hardware error MMC ERR CRC CRC error MMC_ERR_OTHER Other error RO1AN1026EJ0101 Rev 1 01 Page 7 of 31 Jul 23 2012 RENESAS V850E2 MLA MultiMediaCard SPI Mode Device Driver Adoption Guide 3 2 6 Data write R mmc Write Data Item Description Prototype int t RH mmc Write Data uint8 t SlotNo uint32 t BIKNo uint32 t BIkCnt uint8 t pData uint8 t Mode Arguments uint8 t SlotNo The slot number uint32 t BIKNo Write start block number uint32 t BlkCnt Number of blocks to write uint8 t pData Write data storage buffer pointer uint8 t Mode Write data transfer mode Description Writes data in block units 512 bytes to the MMC Writes the specified number of blocks of data starting with the specified block The transfer mode Mode must be MMC MODE NORMAL mode in which data is transferred to the data storage buffer argument pData Writing to the MMC is only possible when the card type Mmclnfo Card in the MMC information transferred from the function R mmc Get Mmclnfo is not MMC CARD UNDETECT The maximum block number is pMmclnfo MaxBlkNum passed from the function RH mmc Get Mmolnfo The maximum number of blocks is pMmclnfo MaxBlkNum 1 Return value Returns the MMC information acquisition result MMC OK Normal completion MMC ERR PARAM Parameter error MMC ERR HARD Hardware error MMC ERR WP Write protection error MMC ERR OTHER Other error RO1AN1
18. MMC FALSE The MMC insertion detection pin is not active Chattering exclusion is not performed in this processing Chattering exclusion should be performed as needed at a higher level in the application We recommend verifying media insertion by poling at a fixed period Return value Returns the result of the check MMC OK Normal completion MMC ERR PARAM Parameter error 3 2 5 Data read R mmc Read Data Item Description Prototype int t H mmc Read Data uint8 t SlotNo uint32 t BIKNo uint32 t BlkCnt uint8 t pData uint8 t Mode Arguments uint8 t SlotNo The slot number uint32 t BIKNo Read start block number uint32 t BlkOnt Number of blocks to read uint8 t pData Read data storage buffer pointer uint8 t Mode Read data transfer mode Description Reads data in block units 512 bytes from the MMC Reads the specified number of blocks of data starting with the specified block The transfer mode Mode must be MMC MODE NORMAL mode in which data is transferred to the data storage buffer argument pData Reading from the MMC is only possible when the card type Mmcinfo Card in the MMC information transferred from the function R mmc Get Mmclnfo is not MMC CARD UNDETECT The maximum block number is pMmclnfo MaxBlkNum passed from the function RH mmc Get Mmolnfo The maximum number of blocks is pMmclnfo MaxBlkNum 1 Return value Returns the result of the read operation MMC OK Normal completion MMC
19. T FR RW ERROR Read or write error TFAT FR NOT READY Drive initialization failure 7 2 5 File write R tfat f write Item Description Prototype FRESULT R tfat f write FIL fp const void buff uint16 t btw uint16 t bw Arguments FIL fp Pointer to a structure object const void buff Pointer to a data storage buffer uint16 t btw Number of bytes to write uint16 t bw Pointer to byte count storage variable Description Writes data to a file This function calls the MMC driver function R tfat disc write The write start position is the current read write pointer The read write pointer is advanced by just the number of bytes written We recommend verifying bw to determine whether or not the requested number of bytes were written after this function completes normally If bw is smaller than btw it indicates that the MMC was full Return value Returns the result TFAT FR OK Normal completion TFAT FR DENIED Illegal object manipulation TFAT FR RW ERROR Read or write error RO1AN1026EJ0101 Rev 1 01 Page 24 of 31 Jul 23 2012 RENESAS V850E2 MLA MultiMediaCard SPI Mode Device Driver Adoption Guide 7 2 6 File close R tfat f close Item Description Prototype FRESULT R tfat f close FIL fp Arguments FIL fp Pointer to a structure object Description Closes an open file For files to which something has been written the cached state data in the read write buffers the modified FAT is returned to
20. al setting and card clock operations A 1 General Precautions in the Handling of MPU MCU Products The following usage notes are applicable to all MPU MCU products from Renesas For detailed usage notes on the products covered by this manual refer to the relevant sections of the manual If the descriptions under General Precautions in the Handling of MPU MCU Products and in the body of the manual differ from each other the description in the body of the manual takes precedence 1 Handling of Unused Pins Handle unused pins in accord with the directions given under Handling of Unused Pins in the manual The input pins of CMOS products are generally in the high impedance state In operation with an unused pin in the open circuit state extra electromagnetic noise is induced in the vicinity of LSI an associated shoot through current flows internally and malfunctions occur due to the false recognition of the pin state as an input signal become possible Unused pins should be handled as described under Handling of Unused Pins in the manual 2 Processing at Power on The state of the product is undefined at the moment when power is supplied The states of internal circuits in the LSI are indeterminate and the states of register settings and pins are undefined at the moment when power is supplied In a finished product where the reset signal is applied to the external reset pin the states of pins are not guarant
21. card detection and CS signal card select used Define the control port define MMC CS PORT P2 CS Port Setting SET define MMC CS BIT 0x0020U CS Bit Select SET define MMC DETECT PORT PPR7 Note DETECT Port Setting SET define MMC DETECT BIT 0x0001U DETECT Bit Select SFE SET Note This is a read only register that is used when the I O port is in input mode See the V850E2 ML4 hardware manual for details RO1AN1026EJ0101 Rev 1 01 Page 14 of 31 Jul 23 2012 RENESAS V850E2 ML4 MultiMediaCard SPI Mode Device Driver Adoption Guide 4 Communication timeout detection processing definitions The timeout detection processing used during communication may be omitted If omitted define the macro MMC NOCHK TIMEOUT Defining this macro has the advantage that the processing speed is increased The program may however stop if an error occurs in the communication function If not omitted set the timeout time e The time units are set with MMC T SPI WAIT Select the macro to set from r mtl tim h e Define the timeout time for data transmission with the MMC SPI TX WAIT transmission macro e Define the timeout time for data reception with the MMC SPI RX WAIT reception macro e The set value of each timeout time macro will have the value timeout time units y Macro MMC
22. eed from the moment when power is supplied until the reset process is completed In a similar way the states of pins in a product that is reset by an on chip power on reset function are not guaranteed from the moment when power is supplied until the power reaches the level at which resetting has been specified 3 Prohibition of Access to Reserved Addresses Access to reserved addresses is prohibited The reserved addresses are provided for the possible future expansion of functions Do not access these addresses the correct operation of LSI is not guaranteed if they are accessed 4 Clock Signals After applying a reset only release the reset line after the operating clock signal has become stable When switching the clock signal during program execution wait until the target clock signal has stabilized When the clock signal is generated with an external resonator or from an external oscillator during a reset ensure that the reset line is only released after full stabilization of the clock signal Moreover when switching to a clock signal produced with an external resonator or by an external oscillator while program execution is in progress wait until the target clock signal is stable 5 Differences between Products Before changing from one product to another i e to one with a different type number confirm that the change will not lead to problems The characteristics of MPU MCU in the same group but having different t
23. er modify copy or otherwise misappropriate any Renesas Electronics product whether in whole or in part Renesas Electronics assumes no responsibility for any losses incurred by you or third parties arising from such alteration modification copy or otherwise misappropriation of Renesas Electronics product 5 Renesas Electronics products are classified according to the following two quality grades Standard and High Quality The recommended applications for each Renesas Electronics product depends on the product s quality grade as indicated below Standard Computers office equipment communications equipment test and measurement equipment audio and visual equipment home electronic appliances machine tools personal electronic equipment and industrial robots etc High Quality Transportation equipment automobiles trains ships etc traffic control systems anti disaster systems anti crime systems and safety equipment etc Renesas Electronics products are neither intended nor authorized for use in products or systems that may pose a direct threat to human life or bodily injury artificial life support devices or systems surgical implantations etc or may cause serious property damages nuclear reactor control systems military equipment etc You must check the quality grade of each Renesas Electronics product before using it in a particular application You may not use any Renesas Electronics product for any application for which it
24. f microcomputer software alone is very difficult please evaluate the safety of the final products or systems manufactured by you 8 Please contact a Renesas Electronics sales office for details as to environmental matters such as the environmental compatibility of each Renesas Electronics product Please use Renesas Electronics products in compliance with all applicable laws and regulations that regulate the inclusion or use of controlled substances including without limitation the EU RoHS Directive Renesas Electronics assumes no liability for damages or losses occurring as a result of your noncompliance with applicable laws and regulations 9 Renesas Electronics products and technology may not be used for or incorporated into any products or systems whose manufacture use or sale is prohibited under any applicable domestic or foreign laws or regulations You should not use Renesas Electronics products or technology described in this document for any purpose relating to military applications or use by the military including but not limited to the development of weapons of mass destruction When exporting the Renesas Electronics products or technology described in this document you should comply with the applicable export control laws and regulations and follow the procedures required by such laws and regulations 10 It is the responsibility of the buyer or distributor of Renesas Electronics products who distributes disposes of or otherwise places the
25. n succeeds a file object is created and can then be used to access the file Before starting a file access it is necessary to provide a FAT file system working area and after that initialization all file functions will use that area for that drive Return value Returns the result TFAT_FR_OK Normal completion TFAT FR NO FILE File not found TFAT FR EXIST Object with same name exists TFAT FR DENIED Illegal object manipulation TFAT FR RW ERROR Read or write error RO1AN1026EJ0101 Rev 1 01 Page 23 of 31 Jul 23 2012 RENESAS V850E2 MLA MultiMediaCard SPI Mode Device Driver Adoption Guide 7 2 4 File data read R tfat f read Item Description Prototype FRESULT R tfat f read FIL fp void buff uint16 t btr uint16 t br Arguments FIL fp Pointer to a structure object void buff Pointer to a data storage buffer uint16 t btr Number of bytes to read uint16 t br Pointer to byte count storage variable Description Reads data from a file This function calls the MMC driver function R tfat disc read The read start position is the current read write pointer The read write pointer is advanced by just the number of bytes read We recommend checking br after this function completes normally If br is smaller than btr it indicates that end of file was reached during the file read operation Return value Returns the result TFAT FR OK Normal completion TFAT FR DENIED Illegal object manipulation TFA
26. nt directory r01an10266j1011 v850e2ml4 pdf Application note this document source lt DIR gt MMC driver source program common lt DIR gt Common functions directory r_mtl_com c Common functions log recording r mtl com2 h Common function definitions r mtl endi c Common functions endian related r mtl mem c Common functions standard library functions r mtl str c Common functions standard library functions r mtl tim c Common functions software loop timer r mtl tim h Common functions software loop timer definitions r mtl com h V850E2 ML4 operation definition header file mmc_driver lt DIR gt MMC device driver directory r mmc h MMC driver common definitions r mmc io c r mmc io h MMC driver SPI mode I O module r mmc spi c MMC driver SPI mode communication module using SPI r mmc mmc c r mmc sub cr mmc sub h MMC driver SPI mode MMC module MMC driver SPI mode sub module r mmc usr c MMC driver SPI mode API source program V850E2_ML4 lt DIR gt V850E2_ML4 SFR definitions for SPI directory r_mmc_sfr h MMC driver SFR definitions r mmc user config h MMC user definitions header file code lt DIR gt CSIH module directory CG_main c The main function CG_port c CG_port h CSIH port initialization module CG_serial c CG_serial h CSIH operation control module CG_serial_user c CSIH user settings module
27. pedef struct uint8_t Card Card type S uint8 t WProtect Write protection status uint32 t MemSize Card capacity uint32 t MaxBlkNum The number of the max blocks MMC INFO total 12byte 3 4 Macro Definitions This section presents the macro definitions Definitions of return value defin C OK int16 t 0 Successful operation defin C ERR PARAM int16 t 1 Parameter error defin C ERR HARD int16 t 2 Hardware error defin C_ERR_CRC int16_t 3 CRC error defin C ERR WP int16 t 4 Write protection error defin C ERR MBLKCMD intl6 t 5 Multi block command error defin C ERR IDLE intl6 t 6 Idle state error defin C ERR OTHER int16 t 7 Other error Definitions of log type defin C LOG ERR 1 Log type Error EJ Definitions of flag mur Fin C TRUE uint8_t 0x01 Flag ON RY defin C_FALSE uint8_t 0x00 Flag OFF By Definition of card type defin C CARD UNDETECT uint8 t 0x00 Card is not found kii defin C CARD MMC uint8_t 0x01 MMC ay defin C_CARD_OTHER uint8_t OxFF Other card aad Definitions of write protection status defin C NO PROTE
28. pletes when the card is removed e The program s execution progress and results are displayed in the LEDs The table below lists the display content LED3 P4 4 LED2 P4 3 Meaning ON OFF Execution in progress OFF ON No card inserted or error termination ON ON Normal completion RO1AN1026EJ0101 Rev 1 01 Page 26 of 31 Jul 23 2012 RENESAS V850E2 ML4 8 2 Processing Flow MultiMediaCard SPI Mode Device Driver Adoption Guide main Initialization CSIH and port settings LED output and set all LEDs off Initialize MMC driver Initialize card insertion removal detection memory Card detection Is a card inserted Turn LED 2 on Initialize MMC slot o Did initialization complete normally Turn LED 2 on Turn LED 2 off LED 3 on o Register file system work area Open file write mode Did file open complete normally Yes Write data 9 a data write complete normally Yes Yes Close file Open file read mode Did file open No complete normally e Yes Move file pointer Read data Did data read ii complete normally 2 Yes Compare read write data No Yes Is data identical 2 Yes Close file Set LEDs 2 and 3 on EN Normal completion infinite loop No 9 Turn LED 2 on LED 3 off n Error completion infinite loop No RO1AN1026EJ0101 Rev 1 01 Jul 23 2012 Page 27 of 31 34 NE SAS
29. product with a third party to notify such third party in advance of the contents and conditions set forth in this document Renesas Electronics assumes no responsibility for any losses incurred by you or third parties as a result of unauthorized use of Renesas Electronics products 11 This document may not be reproduced or duplicated in any form in whole or in part without prior written consent of Renesas Electronics 12 Please contact a Renesas Electronics sales office if you have any questions regarding the information contained in this document or Renesas Electronics products or if you have any other inquiries Note 1 Renesas Electronics as used in this document means Renesas Electronics Corporation and also includes its majority owned subsidiaries Note 2 Renesas Electronics product s means any product developed or manufactured by or for Renesas Electronics 434 N SAS SALES OFFICES Renesas Electronics Corporation http www renesas com Refer to http www renesas com for the latest and detailed information Renesas Electronics America Inc 2880 Scott Boulevard Santa Clara CA 95050 2554 U S A Tel 1 408 588 6000 Fax 1 408 588 6130 Renesas Electronics Canada Limited 1101 Nicholson Road Newmarket Ontario L3Y 9C3 Canada Tel 1 905 898 5441 Fax 1 905 898 3220 Renesas Electronics Europe Limited Dukes Meadow Millboard Road Bourne End Buckinghamshire SL8 5FH U K Tel 44 1628 651 700 Fa
30. ro from r_mtl_tim h that matches the system clock If a V850E2 series microcontroller is operated at 50 MHz define MTL TIM V850E2 50 OMHz When not using the loop timer put the following include as comments define MTL TIM V850E2 50 O0MHz include r mtl tim h 2 Endian type definition Specify either little endian or big endian if defined __LIT defined BIG define MTL MCU LITTLE Little Endian SET ndif 3 Definition of the type of the standard library used Define the type of the standard library used If the processing shown below is used with the standard library comment out the following macro definition In the example shown below the library provided with the compiler is not used Specify the type of user standard library f SET When using the compiler bundled library for the following f SET processes put the following define as comments SET memcmp memmove memcpy memset strcat stremp strcpy strlen SET define MTL USER LIB use optimized library SET RO1AN1026EJ0101 Rev 1 01 Page 11 of 31 Jul 23 2012 RENESAS V850E2 MLA MultiMediaCard SPI Mode Device Driver Adoption Guide 4 1 2 r mtl tim h If the loop timer is defined in r mtl com h it is included These values depend on the microcontroller used the
31. s function should be called when a card insertion is detected Return value Returns the initialization result MMC OK Normal completion MMC ERR PARAM Parameter error MMC ERR HARD Hardware error MMC ERR CRC CRC error MMC_ERR_IDLE Idle state error MMC ERR OTHER Other error 3 2 3 MMC slot stop processing R mmc Detach Item Description Prototype int t RH mmc Detach uint8 t SlotNo Arguments uint8 t SlotNo The slot number Description Performs the MMC removal processing for the specified slot Performs MMC control SFR initialization control port open and control RAM initialization This function should be called when a card removal is detected Return value Returns the result of removal processing MMC OK Normal completion MMC ERR PARAM Parameter error RO1AN1026EJ0101 Rev 1 01 Page 6 of 31 Jul 23 2012 RENESAS V850E2 MLA MultiMediaCard SPI Mode Device Driver Adoption Guide 3 2 4 MMC insertion check R mmc Chk Detect Item Description Prototype int t H mmc Chk Detect uint8 t SlotNo uint8 t pDetSts Arguments uint8 t SlotNo The slot number uint8 t pDetSts MMC insertion status storage buffer pointer Description Checks the MMC insertion state for the slot specified by the argument When the return value is MMC OK the MMC insertion detection pin state will be stored in the MMC insertion status storage buffer pDetSts e MMC TRUE The MMC insertion detection pin is active e
32. specify the buad rate f When operating card with SPI mode 7 specify the following two definitions of Identification mode and Data Transfer mode Specify the definition to meet tODLY of both Identification mode and Data Transfer mode In addition meet tOD 100kHz tOD 400kHz at Identification mode a and tPP 0 1MHz lt tPP lt 20MHz at Data Transfer mode R The maximum frequency depends on MCU type Ay ie KU BRR PCLK 2m B 2 K PCLK Operating frequency MHz B Bit rate bit s m Determined by the SMR settings shown in the following table x ee EEEE EE EE EEEE EE E EE EEE EEEE PCLK 50MHz n 0 define MMC UBRG IDENTIFICATION uint16_t 0x0050 BRR identification mode setting SET o4RBRR lt 400kHz SET define MMC UBRG D TRANSFER uintl6 t 0x0002 BRR data Transfer mode setting SET e lt 20MHz SET define MMC CLK D TRANSFER uint32 t 600000 Data Transfer mode clock frequency SET R01AN1026EJ0101 Rev 1 01 Page 16 of 31 Jul 23 2012 RENESAS V850E2 MLA MultiMediaCard SPI Mode Device Driver Adoption Guide 5 Microcontroller Connection and Used Microcontroller Resources 5 1 Used Microcontroller Resources This program performs the following control operations It controls data I O using a clock synchronous interface CSIH operated with the P bus clock When alloca
33. ssary to set the communication speed settings so that the tODLY values from the card specifications for both Identification mode and Data Transfer mode are met It is additionally necessary to set the parameters so that the conditions for tOD 100 kHz lt tOD lt 400 kHz in Identification mode and tPP 0 1 MHz x tPP lt 20 MHz in Data Transfer mode are met Note that in this system tOD and tPP indicate the clock frequency Since the SIO clock frequencies that can be supported differ with the microcontroller used refer to the microcontroller s data sheet for these values Set the MMC UBRG IDENTIFICATION macro to the clock setting in Identification mode Set the MMC UBRG D TRANSFER macro to the clock setting in Transfer mode Set the MMC CLK D TRANSFER macro to the clock frequency used in Transfer mode In this program these are set to 312 5 kHz for Identification mode and 12 5 MHz for Transfer mode Define the value of the bit rate register according to a communication baud rate y Set the frequency of CLK to 6MHz or less The possible maximum transfer frequency of CLK is depends on hardware circuit A and MCU conditions xf Refer to MCU hardware manual memory card specifications and
34. stop power supply to the card then set the card CS DataIn DataOut and CLK signals to the high impedance state and then remove the card e Although the card CS DataIn DataOut and CLK signals are allocated to microcontroller SIO and port pins it is assumed that those ports may also be allocated to other resources Therefore this driver does not set these lines to the high impedance state Accordingly these microcontroller pins must be set to the high impedance state for card insertion and removal at a higher level in the application software RO1AN1026EJ0101 Rev 1 01 Page 21 of 31 Jul 23 2012 RENESAS V850E2 MLA MultiMediaCard SPI Mode Device Driver Adoption Guide 7 TFATLibrary 7 1 TFAT Library Function Overview The table below lists the TFAT library API functions used in this program File Manipulation Functions Function Overview R_tfat_disk_initialize External media initialization function R_tfat_f_mount FAT file system working area register function R_tfat_f_open File open function R_tfat_f_read File data read function I R tfat f write File data write function R tfat f close File close function raat tet ES R_tfat_f_lseek File read write pointer move function RO1AN1026EJ0101 Rev 1 01 Page 22 of 31 Jul 23 2012 RENESAS V850E2 MLA MultiMediaCard SPI Mode Device Driver Adoption Guide 7 2 Function Descriptions 7 2 1 Media initialization R_tfat_disk_initialize
35. tes on Card Insertion Removal Detection The R mmc Chk Detect function can be used to detect card insertion removal using the card detection pin in the card connector Therefore we recommend using poling at a fixed period to verify card insertion for card detection Also if the reader goes to the card removed state during communication the state will be seen as an abnormal response to a command and as a result the driver will return an error Therefore one item that should be considered is the possibility that the card was removed during communication The driver may not return an error in the following cases e Ifthe driver is unable to detect a card insertion removal within the period and there is no response abnormality from the card normal operation will continue e fa brief hot swap is performed during a write operation the driver may incorrectly recognize a write completion This is because the specifications are that the write busy signal clear is detected when the DatalIn pin is high The DataIn pin is pulled up Problems should be resolved with a method appropriate to the system by for example hardware interrupt based control or adjusting the poling period 6 5 Notes on Port Allocation and Making Ports High Impedance for Card Swapping e For card insertion set the card CS DataIn DataOut and CLK signals to the high impedance state and then insert the card After that provide power to the card e For card removal first
36. the disk When this function completes normally the file object will be invalid and its memory can be released Return value Returns the result TFAT FR OK Normal completion 7 2 7 Move file read write pointer R tfat f Iseek Item Description Prototype FRESULT R tfat f Iseek FIL fp uint32 t ofs Arguments FIL fp Pointer to a structure object Uint32 t ofs Offset to pointer move target Description Moves the file read write pointer the offset to the byte to be read written next The offset origin is the start of file In write mode if a value larger than the file size is specified the file size is expanded to that size and the data in the expanded part of the file will be undefined When it is desirable to write data quickly with no delay we recommend using this function to increase the file size to the required size in advance Return value Returns the result TFAT FR OK Normal completion TFAT FR RW ERROR Read or write error RO1AN1026EJ0101 Rev 1 01 Page 25 of 31 Jul 23 2012 RENESAS V850E2 MLA MultiMediaCard SPI Mode Device Driver Adoption Guide 8 Sample Program This section describes the sample program 8 1 Processing e When an MMC is inserted this program creates a file on the MMC and writes 2 KB of text data To verify the written data it reads the whole contents of the file and compares it to the program s write buffer e After executing through the last block mentioned above operation com
37. ting the CSIH allocate pins that support CMOS output to enable high speed operation and set those pins to CMOS output For transmission control the transmission buffer empty state is detected and the transmission interrupt request bit is used without using interrupts Therefore the interrupt related setting must be set as shown below e Set the interrupt priority level to level 0 interrupts disabled e Connect the MMC CS pin to a microcontroller port and control it with microcontroller general purpose port output Used Resources CSIH module Ports for CS signals 1 signal per card Card detection ports 1 signal per card Power supply control ports 1 signal per card RO1AN1026EJ0101 Rev 1 01 Page 17 of 31 Jul 23 2012 RENESAS V850E2 MLA MultiMediaCard SPI Mode Device Driver Adoption Guide 5 2 Connection with the Microcontroller This section shows connection with the V850E2 ML4 microcontroller Similar connections are used with other microcontrollers Pulled up with external resistors V850E2 MMC ML4 MMC socket Vop CSIH1TSO P2_6 SO1F Data In CSIH1TSI P2 8 SMF i Data Out CSIH1TSCK CLK P2 7 SCKTF Pulled up with external resistors CSIH1TCSS P2 5 CSMF CS2 CS DETECT P7_0 Detect A power supply control circuit is required for hot swapping control This power supply control circuit is not shown in the figure After card detection due
38. x 44 1628 651 804 Renesas Electronics Europe GmbH Arcadiastrasse 10 40472 D sseldorf Germany Tel 49 211 65030 Fax 49 211 6503 1327 Renesas Electronics China Co Ltd 7th Floor Quantum Plaza No 27 ZhiChunLu Haidian District Beijing 100083 P R China Tel 86 10 8235 1155 Fax 86 10 8235 7679 Renesas Electronics Shanghai Co Ltd Unit 204 205 AZIA Center No 1233 Lujiazui Ring Rd Pudong District Shanghai 200120 China Tel 86 21 5877 1818 Fax 86 21 6887 7858 7898 Renesas Electronics Hong Kong Limited Unit 1601 1613 16 F Tower 2 Grand Century Place 193 Prince Edward Road West Mongkok Kowloon Hong Kong Tel 852 2886 9318 Fax 852 2886 9022 9044 Renesas Electronics Taiwan Co Ltd 13F No 363 Fu Shing North Road Taipei Taiwan Tel 886 2 8175 9600 Fax 886 2 8175 9670 Renesas Electronics Singapore Pte Ltd 80 Bendemeer Road Unit 06 02 Hyflux Innovation Centre Singapore 339949 Tel 65 6213 0200 Fax 65 6213 0300 Renesas Electronics Malaysia Sdn Bhd Unit 906 Block B Menara Amcorp Amcorp Trade Centre No 18 Jin Persiaran Barat 46050 Petaling Jaya Selangor Darul Ehsan Malaysia Tel 60 3 7955 9390 Fax 60 3 7955 9510 Renesas Electronics Korea Co Ltd 11F Samik Lavied or Bldg 720 2 Yeoksam Dong Kangnam Ku Seoul 135 080 Korea Tel 82 2 558 3737 Fax 82 2 558 5141 2012 Renesas Electronics Corporation All rights reserved Colophon 2 2
39. ype numbers may differ because of the differences in internal memory capacity and layout pattern When changing to products of different type numbers implement a system evaluation test for each of the products Notice 1 Descriptions of circuits software and other related information in this document are provided only to illustrate the operation of semiconductor products and application examples You are fully responsible for the incorporation of these circuits software and information in the design of your equipment Renesas Electronics assumes no responsibility for any losses incurred by you or third parties arising from the use of these circuits software or information 2 Renesas Electronics has used reasonable care in preparing the information included in this document but Renesas Electronics does not warrant that such information is error free Renesas Electronics assumes no liability whatsoever for any damages incurred by you resulting from errors in or omissions from the information included herein 3 Renesas Electronics does not assume any liability for infringement of patents copyrights or other intellectual property rights of third parties by or arising from the use of Renesas Electronics products or technical information described in this document No license express implied or otherwise is granted hereby under any patents copyrights or other intellectual property rights of Renesas Electronics or others 4 You should not alt
Download Pdf Manuals
Related Search
Related Contents
Vectorspace Manual 1.0 20 Compact MODE D-EMPLOI pour la COMPOSITION DES POULES Corner Computer Desk Instrucciones de operación Cortadora Láser I t ti I i i d d Rhi Ressources en prêt à la Médiathèque du CDDP de l`Aube 6, avenue Integral INSDX64G10-40/20U1 flash memory Copyright © All rights reserved.
Failed to retrieve file