ris8_allo_zen0 Posted June 4, 2008 Report Share Posted June 4, 2008 Hello,my 2cents: can a PIC emulate an I2C eeprom? If so, it could be visible to the Core as a common (huge) BankStick and no modification to MIOS would be required. On the other hand, the emulator can implement all the SD/FAT stuff, or even gather data from anything else than an SD. Quote Link to comment Share on other sites More sharing options...
TK. Posted June 4, 2008 Report Share Posted June 4, 2008 I had the idea to use a PIC18F4550 to bridge the SD card to USB and IIC, but I skipped it because of the reduced flexibility, and the slow IIC transfer speed.I also think, that getting such a system stable and foolproven would cost me even more effort.Best Regards, Thorsten. Quote Link to comment Share on other sites More sharing options...
TheAncientOne Posted June 5, 2008 Report Share Posted June 5, 2008 I'd been thinking more SPI than I2C, and using a second processor to off load the file system from the main processor, though the filing I/O and display etc wouldn't mean that much of an off-load.I still like the idea of a local processor to do the filing system 'primitives', given the cost of the hardware, but I'm not competent enough in PIC design to analyse the hardware/software trade off.My thinking was coloured by my work with CF. IDE already does quite a lot of the filing primitive worK, SCSI does a bit more. It might be possible to have a similar thing for SD.A point I'd forgotten: where are the life extending algorithms for the SD?, (the software that prevents spurious erase and write cycles, to optimise the cards working life) are they in the card, or do they need to be implemented outside?Card would still be a very good idea though.Best wishesMike Quote Link to comment Share on other sites More sharing options...
ilmenator Posted June 5, 2008 Report Share Posted June 5, 2008 A point I'd forgotten: where are the life extending algorithms for the SD?, (the software that prevents spurious erase and write cycles, to optimise the cards working life) are they in the card, or do they need to be implemented outside?They are in the card itself.Best regards, ilmenator Quote Link to comment Share on other sites More sharing options...
TK. Posted June 5, 2008 Report Share Posted June 5, 2008 In distance to IIC, SPI doesn't allow to stretch a data transfer request, accordingly the SPI slave has to handle the request immediately during a block transfer to avoid data loss. An handshaking to sync the master with the slave can only take place at the beginning of a block transfer. Since SD is interfaced via SPI as well, the resulting overall bandwidth will be (much) lower than the speed which could be achieved on a direct connection. And it would probably be lower than using the more reliable IIC protocol.Only elegant solution I see for a multi-processor setup: searching for a ready-made open source solution which is running on a faster microcontroller. The microcontroller should be faster than the PIC to avoid performance loss. Once such a project has been found, let's compare the costs ;)Best Regards, Thorsten. Quote Link to comment Share on other sites More sharing options...
stryd_one Posted June 21, 2008 Report Share Posted June 21, 2008 http://www.dosonchip.com/ Interesting? Quote Link to comment Share on other sites More sharing options...
ilmenator Posted June 21, 2008 Report Share Posted June 21, 2008 I2C/SMBus (not enabled in current firmware)(see here)Which probably means that they did not even start with implementing this...? Nice find, though!Best regards, ilmenator Quote Link to comment Share on other sites More sharing options...
stryd_one Posted June 21, 2008 Report Share Posted June 21, 2008 Well, they've got a new firmware in progress at the moment, which increases speed, and introduces some new features, I suspect that IIC may be one of them... But it still works with SPI in the meantime.While they're focussing on the new firmware, they aren't shipping to distributors, but sparkfun had these for $12, and I read a fairly recent forum post saying something about a $5 price (probably in large quantities).... They also have a note there saying that they will take inquiries about stock in the meantime. I suspect that a community like ours could arrange a decent size bulk buy of these, and maybe we could provide some useful assistance to them with testing the IIC interface? Could be a win-win situation.... Quote Link to comment Share on other sites More sharing options...
ilmenator Posted June 21, 2008 Report Share Posted June 21, 2008 Yes, I saw that Sparkfun had the chips for US 13$ (and the complete module for US 45$ - a little steep for my taste). A community bulk buy might actually be a good idea. Assuming that the bankstick memory was replaced in all applications with this module (or the SD would be available as an alternative to the bankstick memory), this could actually create the necessary demand. Let's see how the USB MIDI interface thingy develops and what experiences can be gained from that. The documentation looks as if the necessary hardware was rather easy to implement, and the ridiculous prices for (proper) card connectors should come down considerably for larger quantities.Best regards, ilmenator Quote Link to comment Share on other sites More sharing options...
stryd_one Posted June 21, 2008 Report Share Posted June 21, 2008 I dunno, I got the best connector around for $5... They aren't that bad. I even offered freebies to everyone I saw at the time I was ordering, and noone wanted one!Speaking of which... $5-13 for the chip... $5 for the socket... so, that sparkfunPCB is worth like 30 bucks. ouch! Good if you want it ready to go, but in our case, I'm sure we could make it as a small kit for a lot cheaper.It's an interesting idea as to whether they could be used as a generic replacement for banksticks. Given that these are file-based, and BS are address-based, I don't know how it'll work. The datasheets will say a lot :) Quote Link to comment Share on other sites More sharing options...
ilmenator Posted June 22, 2008 Report Share Posted June 22, 2008 I dunno, I got the best connector around for $5... Now, that sounds more reasonable than what even Reichelt have in their shop - usually they have rather good prices, so I might got confused.And yes, the PCB should be cheaper than what Sparkfun has to offer. As for file-based vs. address-based: a simple conversion/naming scheme might already do the trick.Best regards, ilmenator Quote Link to comment Share on other sites More sharing options...
SLP Posted June 22, 2008 Report Share Posted June 22, 2008 Now, that sounds more reasonable than what even Reichelt have in their shop - usually they have rather good prices, so I might got confused.ouch... but perhaps we could misuse one of those cheap USB-SD-card-readers which you can buy everywhere. Quote Link to comment Share on other sites More sharing options...
stryd_one Posted June 22, 2008 Report Share Posted June 22, 2008 http://australia.rs-online.com/web/search/searchBrowseAction.html?method=getProduct&R=5025010That's the Hirose DMB1 series, it's a springloaded push-in/push-out with a detector switch and all that, AUD$4.81 (about USD$5). This seems to be the standard 'nice' connector :) This is the DMB1-B* where the card goes into the slot pin-side-up, There is one that costs ~10c more, where the card is not upside-down, the DMB1-A*. Or, you can go with a slightly less-nice older model like this one for about $3 :) Quote Link to comment Share on other sites More sharing options...
DrBunsen Posted June 24, 2008 Report Share Posted June 24, 2008 http://www.dosonchip.com/ Interesting?You're freakin me out stryd, I was just looking at that site yesterday in relation to a completely different project (IDE support on 68k Macs)A very geeky SD socket replacement by Rob Wentworth: http://uanr.com/sdfloppy/See, this is why I never throw out connectors, ever. Quote Link to comment Share on other sites More sharing options...
ilmenator Posted June 25, 2008 Report Share Posted June 25, 2008 That kind of connector is ok if you never ever want to change the SD card, e.g. if it goes inside the box as a fixed memory extension. It is not so nice anymore (and probably rather error-prone) if you want to exchange the SD card on a regular basis. Though at the moment, I cannot think of any application scenario that would make replacing an SD card necessary - except for backups maybe, but then a file system is a must. dosonchip again...Best regards, ilmenator Quote Link to comment Share on other sites More sharing options...
stryd_one Posted June 25, 2008 Report Share Posted June 25, 2008 Bunsen I've ordered extras, next time we're in the same part of the city you can steal one of mine :) Quote Link to comment Share on other sites More sharing options...
TK. Posted June 29, 2008 Report Share Posted June 29, 2008 This spaghetti code is mainly a "proof of concept" - it searches for a specific file (here: MBSID_P.V2) in the root directory, and returns the starting sector. It has a lot of room for improvements (e.g. I splitted the 512 byte sector into two pages, so that array accesses are faster in C) - but the code will be thrown away anyhow, since the final version will be in assembler.So, next step is to write the algorithm in assembler, and the last step is a "file seek" function, which goes through the FAT to search for a specific file offset (easy!)unsigned long partition_sector0;unsigned char partition_cluster_size;unsigned int partition_res_sectors;unsigned int partition_fat_sectors;unsigned int partition_root_entries;unsigned long partition_sector_fat;unsigned long partition_sector_root;unsigned char partition_root_sectors;unsigned long partition_sector_cl2;unsigned long partition_sector_file;unsigned int partition_file_cluster;const unsigned char filename[8+3+1] = "MBSID_P V2 ";#define EXPECTED_FILESIZE_B0 0x00#define EXPECTED_FILESIZE_B1 0x00#define EXPECTED_FILESIZE_B2 0x08#define EXPECTED_FILESIZE_B3 0x00#define SDCARD_ERROR_NONE 0x00#define SDCARD_ERROR_MBR_MISSING_MARKER 0x01#define SDCARD_ERROR_MBR_WRONG_PARTI_TYPE 0x02#define SDCARD_ERROR_BR_MISSING_MARKER 0x08#define SDCARD_ERROR_BR_UNSUPP_SEC_SIZE 0x09#define SDCARD_ERROR_FILE_NOT_FOUND 0x10#define SDCARD_ERROR_FILE_WRONG_SIZE 0x11// returns != 0 on errorsunsigned char ReadFile(void){ unsigned char entry, dir_sec, offset, i; // read MBR SDCARD_SectorRead(0x00000000); // references for MBR structure: // http://mirror.href.com/thestarman/asm/mbr/PartTables.htm // http://home.teleport.com/~brainy/fat16.htm // check for boot marker if( sdcard_buffer_p1[0xfe] != 0x55 || sdcard_buffer_p1[0xff] != 0xaa ) return SDCARD_ERROR_MBR_MISSING_MARKER; // check for type of partition (expecting FAT16 larger than 32MB) if( sdcard_buffer_p1[0xbe + 0x04] != 0x06 ) return SDCARD_ERROR_MBR_WRONG_PARTI_TYPE; // get first sector of partition partition_sector0 = (sdcard_buffer_p1[0xbe + 0x09] << 8) | sdcard_buffer_p1[0xbe + 0x08]; // read FAT16 boot record at sector 0 of partition SDCARD_SectorRead(partition_sector0); // check for boot marker if( sdcard_buffer_p1[0xfe] != 0x55 || sdcard_buffer_p1[0xff] != 0xaa ) return SDCARD_ERROR_BR_MISSING_MARKER; // check that bytes per sectors is 512 if( sdcard_buffer_p0[0x0b] != 0x00 || sdcard_buffer_p0[0x0c] != 0x02 ) return SDCARD_ERROR_BR_UNSUPP_SEC_SIZE; // bytes per clusters partition_cluster_size = sdcard_buffer_p0[0x0d]; // number of reserved sectors partition_res_sectors = (sdcard_buffer_p0[0x0f] << 8) | sdcard_buffer_p0[0x0e]; // number of FAT sectors partition_fat_sectors = (sdcard_buffer_p0[0x17] << 8) | sdcard_buffer_p0[0x16]; // calculate address to FAT partition_sector_fat = partition_sector0 + partition_res_sectors; // calculate address to root directory partition_sector_root = partition_sector_fat + 2*partition_fat_sectors; // max. number of root entries partition_root_entries = (sdcard_buffer_p0[0x12] << 8) | sdcard_buffer_p0[0x11]; // number of directory sectors partition_root_sectors = (partition_root_entries >> 4); // calculate address to cluster 2 (start of data) partition_sector_cl2 = partition_sector_root + partition_root_sectors; // read root directory and search for filename // reference: http://home.teleport.com/~brainy/lfn.htm partition_file_cluster=0; for(dir_sec=0; (dir_sec<partition_root_sectors) && !partition_file_cluster; ++dir_sec) { SDCARD_SectorRead(partition_sector_root + dir_sec); // searching for file in lower and upper page for(entry=0, offset=0x00; (entry<8) && !partition_file_cluster; ++entry) { // lower page for(offset=entry<<5, i=0; i<8+3; ++i, ++offset) { MIOS_MIDI_TxBufferPut(0xc0); MIOS_MIDI_TxBufferPut(offset & 0x7f); if( sdcard_buffer_p0[offset] != filename[i] ) break; } if( i == 8+3 ) { if( sdcard_buffer_p0[offset-8-3+28] != EXPECTED_FILESIZE_B0 || sdcard_buffer_p0[offset-8-3+29] != EXPECTED_FILESIZE_B1 || sdcard_buffer_p0[offset-8-3+30] != EXPECTED_FILESIZE_B2 || sdcard_buffer_p0[offset-8-3+31] != EXPECTED_FILESIZE_B3 ) { return SDCARD_ERROR_FILE_WRONG_SIZE; } partition_file_cluster = (sdcard_buffer_p0[offset+-8-3+27] << 8) | sdcard_buffer_p0[offset+-8-3+26]; } else { // upper page for(offset=entry<<5, i=0; i<8+3; ++i, ++offset) { if( sdcard_buffer_p1[offset] != filename[i] ) break; } if( i == 8+3 ) { if( sdcard_buffer_p1[offset-8-3+28] != EXPECTED_FILESIZE_B0 || sdcard_buffer_p1[offset-8-3+29] != EXPECTED_FILESIZE_B1 || sdcard_buffer_p1[offset-8-3+30] != EXPECTED_FILESIZE_B2 || sdcard_buffer_p1[offset-8-3+31] != EXPECTED_FILESIZE_B3 ) { return SDCARD_ERROR_FILE_WRONG_SIZE; } partition_file_cluster = (sdcard_buffer_p1[offset+-8-3+27] << 8) | sdcard_buffer_p1[offset+-8-3+26]; } } } } // exit if file hasn't been found in root directory if( !partition_file_cluster ) return SDCARD_ERROR_FILE_NOT_FOUND; // read first sector of file partition_sector_file = partition_sector_cl2 + (partition_file_cluster-2) * partition_cluster_size; SDCARD_SectorRead(partition_sector_file); return SDCARD_ERROR_NONE;}[/code]Best Regards, Thorsten. Quote Link to comment Share on other sites More sharing options...
stryd_one Posted July 1, 2008 Report Share Posted July 1, 2008 Mmmmmm, spaghetti :) Quote Link to comment Share on other sites More sharing options...
TK. Posted July 6, 2008 Report Share Posted July 6, 2008 Ok, drivers are up and running. There are also two demo applications, one allows to browse through a directory, and another can be used to send .syx files stored in a SD cardSD Card DriverDemo ApplicationsMore infos (e.g. schematic of the adapter) soonBest Regards, Thorsten. Quote Link to comment Share on other sites More sharing options...
ilmenator Posted July 6, 2008 Report Share Posted July 6, 2008 That sounds GREAT! THANKS!Best regards, ilmenator Quote Link to comment Share on other sites More sharing options...
stryd_one Posted July 6, 2008 Report Share Posted July 6, 2008 Sweet!! 8)"Oops, TK did it again" ;DLast call for SD connectors, if you want one, PM me NOW! They'll be USD$5 plus postage from Australia to wherever you are.Here's the link with datasheet:http://australia.rs-online.com/web/search/searchBrowseAction.html?method=getProduct&R=5025010For 30c more you can get the top-side-up version:http://australia.rs-online.com/web/search/searchBrowseAction.html?method=getProduct&R=5025004If you're stateside then you might like to look to sparkfun, but it seems that you euro guys have no cheap source, so here it is :) Last chance from me for a while! Quote Link to comment Share on other sites More sharing options...
ilmenator Posted August 5, 2008 Report Share Posted August 5, 2008 Thorsten,I checked the repository but could not find any reference to the schematic / hardware you used to interface the SD card. Can you provide us with that, so I can really try the SD card module?Best regards, ilmenator Quote Link to comment Share on other sites More sharing options...
stryd_one Posted August 5, 2008 Report Share Posted August 5, 2008 Ooh yes please :) Quote Link to comment Share on other sites More sharing options...
ilmenator Posted August 7, 2008 Report Share Posted August 7, 2008 Okay, I think I know how the schematic TK uses looks like. Apparently, judging from the photos he posted, it is very similar to this, which is basically the same as published by U. Radig here. All the sources I found on the net are extremely similar :).I'll see if I can find these components in my spare parts box :D. Quote Link to comment Share on other sites More sharing options...
stryd_one Posted August 7, 2008 Report Share Posted August 7, 2008 Nice 1 illy! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.