USBMSD SD card Hello World for Mbed platforms
Dependencies: mbed USBMSD_SD USBDevice
USBDevice/USBMSD/AT45.h@2:27a7e7f8d399, 2011-11-11 (annotated)
- Committer:
- samux
- Date:
- Fri Nov 11 15:22:53 2011 +0000
- Revision:
- 2:27a7e7f8d399
we have 2MB with the sdcard!!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux |
2:27a7e7f8d399 | 1 | /* mbed Library - AT45 |
samux |
2:27a7e7f8d399 | 2 | * Copyright (c) 2008, cstyles |
samux |
2:27a7e7f8d399 | 3 | |
samux |
2:27a7e7f8d399 | 4 | |
samux |
2:27a7e7f8d399 | 5 | Class to make the AT45 SPI flash parts from ATMEL appear as SRAM or 512 byte block devices |
samux |
2:27a7e7f8d399 | 6 | |
samux |
2:27a7e7f8d399 | 7 | This class supports 011,021,041,081,161,321,641 variants of the AT45DBxxx family |
samux |
2:27a7e7f8d399 | 8 | |
samux |
2:27a7e7f8d399 | 9 | || Code || Density || Page size || Pages || Package || |
samux |
2:27a7e7f8d399 | 10 | || 011 || 1 || 256 || 512 || 8 SOIC || |
samux |
2:27a7e7f8d399 | 11 | || 021 || 2 || 256 || 1024 || 8 SOIC || |
samux |
2:27a7e7f8d399 | 12 | || 041 || 4 || 256 || 2048 || 8 SOIC || |
samux |
2:27a7e7f8d399 | 13 | || 081 || 8 || 256 || 4096 || 8 SOIC || |
samux |
2:27a7e7f8d399 | 14 | || 161 || 16 || 512 || 4096 || 8 SOIC || |
samux |
2:27a7e7f8d399 | 15 | || 321 || 32 || 512 || 8192 || 8 SOIC || |
samux |
2:27a7e7f8d399 | 16 | || 641 || 64 || 1024 || 8192 || 28 TSOP || |
samux |
2:27a7e7f8d399 | 17 | |
samux |
2:27a7e7f8d399 | 18 | To do : |
samux |
2:27a7e7f8d399 | 19 | |
samux |
2:27a7e7f8d399 | 20 | - Check for current status on Erase Chip command not working. |
samux |
2:27a7e7f8d399 | 21 | |
samux |
2:27a7e7f8d399 | 22 | */ |
samux |
2:27a7e7f8d399 | 23 | |
samux |
2:27a7e7f8d399 | 24 | #ifndef MBED_AT45_H |
samux |
2:27a7e7f8d399 | 25 | #define MBED_AT45_H |
samux |
2:27a7e7f8d399 | 26 | |
samux |
2:27a7e7f8d399 | 27 | #include "mbed.h" |
samux |
2:27a7e7f8d399 | 28 | |
samux |
2:27a7e7f8d399 | 29 | class AT45 { |
samux |
2:27a7e7f8d399 | 30 | |
samux |
2:27a7e7f8d399 | 31 | // Public functions |
samux |
2:27a7e7f8d399 | 32 | public: |
samux |
2:27a7e7f8d399 | 33 | |
samux |
2:27a7e7f8d399 | 34 | AT45(PinName mosi = p5, PinName miso = p6, PinName clk = p7, PinName ncs = p8); |
samux |
2:27a7e7f8d399 | 35 | |
samux |
2:27a7e7f8d399 | 36 | void erase (void); |
samux |
2:27a7e7f8d399 | 37 | |
samux |
2:27a7e7f8d399 | 38 | // Integer RAM access |
samux |
2:27a7e7f8d399 | 39 | char read (int address); // read int from address. Automatically word-aligns address |
samux |
2:27a7e7f8d399 | 40 | void write (int address, char data); // Write int to address. Automatically world-aligns address |
samux |
2:27a7e7f8d399 | 41 | |
samux |
2:27a7e7f8d399 | 42 | // Block device access |
samux |
2:27a7e7f8d399 | 43 | int blocks (void); // returns the number of 512 byte blocks |
samux |
2:27a7e7f8d399 | 44 | int blockread (char* data, int block); // read a block |
samux |
2:27a7e7f8d399 | 45 | int blockwrite (char* data, int block); // write a block |
samux |
2:27a7e7f8d399 | 46 | int blockerase (int block); // erase a block |
samux |
2:27a7e7f8d399 | 47 | |
samux |
2:27a7e7f8d399 | 48 | // Part interrogation |
samux |
2:27a7e7f8d399 | 49 | int size (void); // Device size in bytes |
samux |
2:27a7e7f8d399 | 50 | int pages (void); // Device size in bytes |
samux |
2:27a7e7f8d399 | 51 | int pagesize (void); // Device size in bytes |
samux |
2:27a7e7f8d399 | 52 | |
samux |
2:27a7e7f8d399 | 53 | int id (void); // ID of part |
samux |
2:27a7e7f8d399 | 54 | int status (void); // Status register |
samux |
2:27a7e7f8d399 | 55 | void pollbusy (void); // Wait until Flash is not busy |
samux |
2:27a7e7f8d399 | 56 | |
samux |
2:27a7e7f8d399 | 57 | // Private variables |
samux |
2:27a7e7f8d399 | 58 | private : |
samux |
2:27a7e7f8d399 | 59 | |
samux |
2:27a7e7f8d399 | 60 | SPI _spi; |
samux |
2:27a7e7f8d399 | 61 | DigitalOut _ncs; |
samux |
2:27a7e7f8d399 | 62 | |
samux |
2:27a7e7f8d399 | 63 | int _pages; // Integer number of pages |
samux |
2:27a7e7f8d399 | 64 | int _pagesize; // page size, in bytes |
samux |
2:27a7e7f8d399 | 65 | int _devicesize; // device size in bytes |
samux |
2:27a7e7f8d399 | 66 | int _blocks; // Number of 512 byte blocks |
samux |
2:27a7e7f8d399 | 67 | |
samux |
2:27a7e7f8d399 | 68 | // Some flags for buffering |
samux |
2:27a7e7f8d399 | 69 | int _buffer1address; |
samux |
2:27a7e7f8d399 | 70 | int _buffer2address; |
samux |
2:27a7e7f8d399 | 71 | int _lru; |
samux |
2:27a7e7f8d399 | 72 | |
samux |
2:27a7e7f8d399 | 73 | // Helper routunes |
samux |
2:27a7e7f8d399 | 74 | void _reset(); |
samux |
2:27a7e7f8d399 | 75 | void _select(); |
samux |
2:27a7e7f8d399 | 76 | void _deselect(); |
samux |
2:27a7e7f8d399 | 77 | void _pollbusy (void); |
samux |
2:27a7e7f8d399 | 78 | |
samux |
2:27a7e7f8d399 | 79 | // accessing SRAM buffers |
samux |
2:27a7e7f8d399 | 80 | void _sramwrite (int buffer, int address, int data); |
samux |
2:27a7e7f8d399 | 81 | int _sramread (int buffer, int address); |
samux |
2:27a7e7f8d399 | 82 | |
samux |
2:27a7e7f8d399 | 83 | // Transferring SRAM buffers to/from FLASH |
samux |
2:27a7e7f8d399 | 84 | void _flashwrite (int buffer, int paddr); |
samux |
2:27a7e7f8d399 | 85 | void _flashread (int buffer, int paddr); |
samux |
2:27a7e7f8d399 | 86 | |
samux |
2:27a7e7f8d399 | 87 | // Allocate buffer |
samux |
2:27a7e7f8d399 | 88 | int _allocatebuffer(int address); |
samux |
2:27a7e7f8d399 | 89 | void _flushbuffer(int buffer); |
samux |
2:27a7e7f8d399 | 90 | |
samux |
2:27a7e7f8d399 | 91 | // Reading FLASH directly |
samux |
2:27a7e7f8d399 | 92 | int _memread (int address); |
samux |
2:27a7e7f8d399 | 93 | |
samux |
2:27a7e7f8d399 | 94 | // Calculate page/subpage addresses |
samux |
2:27a7e7f8d399 | 95 | int _getpaddr (int); |
samux |
2:27a7e7f8d399 | 96 | int _getbaddr (int); |
samux |
2:27a7e7f8d399 | 97 | |
samux |
2:27a7e7f8d399 | 98 | // Send 3 byte address |
samux |
2:27a7e7f8d399 | 99 | void _sendaddr (int address); |
samux |
2:27a7e7f8d399 | 100 | |
samux |
2:27a7e7f8d399 | 101 | }; |
samux |
2:27a7e7f8d399 | 102 | |
samux |
2:27a7e7f8d399 | 103 | #endif |