{"action":"created","issue":{"url":"https://api.github.com/repos/cleanflight/cleanflight/issues/532","labels_url":"https://api.github.com/repos/cleanflight/cleanflight/issues/532/labels{/name}","comments_url":"https://api.github.com/repos/cleanflight/cleanflight/issues/532/comments","events_url":"https://api.github.com/repos/cleanflight/cleanflight/issues/532/events","html_url":"https://github.com/cleanflight/cleanflight/issues/532","id":58361572,"number":532,"title":"[Idea] Onboard SD card","user":{"login":"projectkk2glider","id":5950438,"avatar_url":"https://avatars.githubusercontent.com/u/5950438?v=3","gravatar_id":"","url":"https://api.github.com/users/projectkk2glider","html_url":"https://github.com/projectkk2glider","followers_url":"https://api.github.com/users/projectkk2glider/followers","following_url":"https://api.github.com/users/projectkk2glider/following{/other_user}","gists_url":"https://api.github.com/users/projectkk2glider/gists{/gist_id}","starred_url":"https://api.github.com/users/projectkk2glider/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/projectkk2glider/subscriptions","organizations_url":"https://api.github.com/users/projectkk2glider/orgs","repos_url":"https://api.github.com/users/projectkk2glider/repos","events_url":"https://api.github.com/users/projectkk2glider/events{/privacy}","received_events_url":"https://api.github.com/users/projectkk2glider/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-02-20T14:42:21Z","updated_at":"2015-02-20T23:29:48Z","closed_at":null,"body":"The Flip32 board could be easily modified to support direct connection to an SD card (this is probably also true for Naze32 and other clones). This would then give a possibility to implement black-box logging on-board without the need for external serial logging device. This should also support higher logging rates (more RAM for write buffer).\r\n\r\nThe hardware wiring on Flip32:\r\n* Use SPI1 peripheral\r\n* SCK pin PA5 (pin 15) is wired to pin 9 of MMA8452Q accelerometer (which is not fitted on board). This is the only **hard** pin to reach, ti will require precise soldering, but the pin is quite acessible.\r\n* MISO pin PA6 (pin16) which is wired on RC input 5\r\n* MOSI pin PA7 (pin17) which is wired on RC input 6.\r\n* 3.3V VCC \r\n* GND\r\n\r\nSince RC5 and RC6 are used by softserial 1, we loose that functionality, but gain SD card access. What do you think?"},"comment":{"url":"https://api.github.com/repos/cleanflight/cleanflight/issues/comments/75338709","html_url":"https://github.com/cleanflight/cleanflight/issues/532#issuecomment-75338709","issue_url":"https://api.github.com/repos/cleanflight/cleanflight/issues/532","id":75338709,"user":{"login":"thenickdude","id":1921411,"avatar_url":"https://avatars.githubusercontent.com/u/1921411?v=3","gravatar_id":"","url":"https://api.github.com/users/thenickdude","html_url":"https://github.com/thenickdude","followers_url":"https://api.github.com/users/thenickdude/followers","following_url":"https://api.github.com/users/thenickdude/following{/other_user}","gists_url":"https://api.github.com/users/thenickdude/gists{/gist_id}","starred_url":"https://api.github.com/users/thenickdude/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thenickdude/subscriptions","organizations_url":"https://api.github.com/users/thenickdude/orgs","repos_url":"https://api.github.com/users/thenickdude/repos","events_url":"https://api.github.com/users/thenickdude/events{/privacy}","received_events_url":"https://api.github.com/users/thenickdude/received_events","type":"User","site_admin":false},"created_at":"2015-02-20T23:29:48Z","updated_at":"2015-02-20T23:29:48Z","body":"@tommyleo achieved this with his port of Baseflight to the [μBrain's 168MHz STM32 CPU](https://vrbrain.wordpress.com/vr-microbrain/), called [speedyflight](https://github.com/tommyleo/speedyflight). He used [fatfs](http://elm-chan.org/fsw/ff/00index_e.html) as the FAT filesystem driver.\r\n\r\n[fatfs takes 4.6-7.1 kB of flash](http://elm-chan.org/fsw/ff/en/appnote.html) depending on selected features, if using ARM7 Thumb instructions.\r\n\r\nBUT as far I can tell, fatfs is completely based around blocking operations: Writing a single character to the SD card can cause a flush that [must wait](https://github.com/tommyleo/speedyflight/blob/master/lib/fatfs/fatfs_sd.c#L129) for the card to become ready. This can take 150ms on slow cards, and the flight control loop will be paused until that completes. By default it even uses a 500ms timeout, so I imagine if the SD card falls out during flight, terrible things will happen.\r\n\r\nBy contrast, my [flashfs](https://github.com/sherlockflight/cleanflight-dev/blob/blackbox-flash/src/main/io/flashfs.c) for writing to NOR flash never waits for the flash device to become ready, if it is busy then data is buffered instead, and if the buffer is overrun then data is dropped rather than freezing the flight controller for many milliseconds. \r\n\r\nA FAT filesystem driver which supports asynchronous writes like this would seem like a prerequisite, but I don't know of one. Alternatively we could adapt flashfs to write to an SD card with no filesystem pretty easily, but end users wouldn't be able to read the cards without a lot of pain on their part."}}