{"id":523,"date":"2017-11-25T15:04:51","date_gmt":"2017-11-25T14:04:51","guid":{"rendered":"http:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=523"},"modified":"2017-12-30T19:40:56","modified_gmt":"2017-12-30T18:40:56","slug":"89-fatfs_spi-library-stm32f4","status":"publish","type":"page","link":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=523","title":{"rendered":"89-FATFS_SPI-Library (STM32F4)"},"content":{"rendered":"<p><div id=\"nav-below\" class=\"navigation\"><div class=\"nav-previous\"><a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=521\" title=\"88-WS2812_8CH-Library (STM32F4)\"><span class=\"meta-nav\">\u2190<\/span> 88-WS2812_8CH-Library (STM32F4)<\/a><\/div><\/div><!-- #nav-below --><div id=\"nav-below\" class=\"navigation\"><div class=\"nav-next\"><a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=525\" title=\"90-I2C_GY271-Library (STM32F4)\">90-I2C_GY271-Library (STM32F4) <span class=\"meta-nav\">&rarr;<\/span><\/a><\/div><\/div><!-- #nav-below --><\/p>\n<p>mit dieser Library k\u00f6nnen SD-Karten mit einem FAT-Dateisystem per SPI-Schnittstelle vom STM32F4 verwaltet werden.<br \/>\nHinweis : es gibt noch eine Library f\u00fcr den SDIO-Bus (<a href=\"http:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=225\">Nr. 13<\/a>) f\u00fcr USB-Sticks per FATFS (<a href=\"http:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=383\">Nr. 32<\/a>) und eine kombinierte Library SD+USB (<a href=\"http:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=519\">Nr. 87<\/a>)<\/p>\n<p>F\u00fcr eine genauere Beschreibung siehe Library Nr. 13 (die ist softwareseitig identisch)<\/p>\n<p>FATFS von ChaN ist in der Version 0.10c und die SPI-Funktionen sind auch von ChaN.<br \/>\n(siehe beiliegende Doku)<\/p>\n<p>Hinweis : der MISO-Pin braucht einen PullUp Widerstand<br \/>\n(ich habe den internen der CPU per Software aktiviert)<\/p>\n<p>Den CardDetect Pin habe ich im H-File deaktiviert.<br \/>\n(mein SD-Kartenhalter hat keinen Detect-Schalter)<br \/>\nDer \u201cMount-Befehl\u201d wirft einen Fehler, wenn keine Karte eingesteckt ist.<\/p>\n<p><strong>Benutzte Pins :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">PB12 -&gt; ChipSelect = SD-Karte CS   (CD)\r\nPB13 -&gt; SPI-SCK    = SD-Karte SCLK (CLK)\r\nPB14 -&gt; SPI-MISO   = SD-Karte DO   (DAT0) (*)\r\nPB15 -&gt; SPI-MOSI   = SD-Karte DI   (CMD)\r\n  (*) MISO needs PullUp (internal or external)\r\n\r\nmit Detect-Pin :\r\nPC0  -&gt; SD_Detect-Pin (Hi=ohne SD-Karte)<\/pre>\n<p><strong><strong>Voraussetzungen :<\/strong><\/strong><\/p>\n<pre lang=\"c\" line=\"1\">Benutzte Module der CooCox-IDE : GPIO, RCC, TIM, MISC, SPI\r\nBenutzte Librarys : FATFS (mehrere Files), STM32_UB_SPI<\/pre>\n<p><strong>Beispiel :<\/strong><\/p>\n<pre lang=\"c\" line=\"1\">\/\/--------------------------------------------------------------\r\n\/\/ File     : main.c\r\n\/\/ Datum    : 01.01.2014\r\n\/\/ Version  : 1.0\r\n\/\/ Autor    : UB\r\n\/\/ EMail    : mc-4u(@)t-online.de\r\n\/\/ Web      : www.mikrocontroller-4u.de\r\n\/\/ CPU      : STM32F4\r\n\/\/ IDE      : CooCox CoIDE 1.7.4\r\n\/\/ GCC      : 4.7 2012q4\r\n\/\/ Module   : CMSIS_BOOT, M4_CMSIS_CORE\r\n\/\/ Funktion : Hauptprogramm\r\n\/\/ Hinweis  : Diese zwei Files muessen auf 8MHz stehen\r\n\/\/              \"cmsis_boot\/stm32f4xx.h\"\r\n\/\/              \"cmsis_boot\/system_stm32f4xx.c\"\r\n\/\/--------------------------------------------------------------\r\n\r\n#include \"main.h\"\r\n#include \"stm32_ub_led.h\"\r\n#include \"stm32_ub_fatfs.h\"\r\n\r\nint main(void)\r\n{\r\n  FIL myFile;\r\n\r\n  SystemInit(); \/\/ Quarz Einstellungen aktivieren\r\n\r\n  \/\/ init der LEDs\r\n  UB_Led_Init();\r\n\r\n  \/\/ Init vom FATFS-System\r\n  UB_Fatfs_Init();\r\n\r\n  \/\/ Check ob Medium eingelegt ist\r\n  if(UB_Fatfs_CheckMedia(MMC_0)==FATFS_OK) {\r\n    \/\/ Media mounten\r\n    if(UB_Fatfs_Mount(MMC_0)==FATFS_OK) {\r\n      UB_Led_On(LED_BLUE);\r\n      \/\/ File zum schreiben im root neu anlegen\r\n      if(UB_Fatfs_OpenFile(&amp;myFile, \"0:\/UB_File.txt\", F_WR_CLEAR)==FATFS_OK) {\r\n        UB_Led_On(LED_GREEN);\r\n        \/\/ ein paar Textzeilen in das File schreiben\r\n        UB_Fatfs_WriteString(&amp;myFile,\"FATFS im SPI-Mode\");\r\n        UB_Fatfs_WriteString(&amp;myFile,\"hier Zeile zwei\");\r\n        UB_Fatfs_WriteString(&amp;myFile,\"ENDE\");\r\n        \/\/ File schliessen\r\n        UB_Fatfs_CloseFile(&amp;myFile);\r\n      }\r\n      \/\/ Media unmounten\r\n      UB_Fatfs_UnMount(MMC_0);\r\n    }\r\n    else {\r\n      UB_Led_On(LED_RED);\r\n    }\r\n  }\r\n\r\n  while(1)\r\n  {\r\n\r\n  }\r\n}\r\n<\/pre>\n<p>Hier die Library zum\u00a0<strong>Download :<\/strong><\/p>\n<p><a href=\"http:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-content\/uploads\/2014\/11\/ub_stm32f4_fatfs_spi_v100.zip\">ub_stm32f4_fatfs_spi_v100<\/a><\/p>\n<p>Hier der komplette CooCox-Projektordner zum\u00a0<strong>Download :<\/strong><\/p>\n<p><a href=\"http:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-content\/uploads\/2014\/11\/Demo_89_FAFTS_SPI.zip\">Demo_89_FAFTS_SPI<\/a><\/p>\n<hr \/>\n<h3 id=\"comments-title\">3 Antworten auf <em>89-FATFS_SPI-Library (STM32F4)<\/em><\/h3>\n<ol class=\"commentlist\">\n<li id=\"li-comment-2607\" class=\"comment even thread-even depth-1\">\n<div id=\"comment-2607\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/1.gravatar.com\/avatar\/9ce83dfdef303a8a072f750a3cdcc443?s=40&amp;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D40&amp;r=G\" alt=\"\" width=\"40\" height=\"40\" \/><cite class=\"fn\">Tamer SAFAK<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">2. Dezember 2014 um 14:08<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>Thanks a lotttt.<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/li>\n<li id=\"li-comment-2965\" class=\"comment odd alt thread-odd thread-alt depth-1\">\n<div id=\"comment-2965\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/0.gravatar.com\/avatar\/0fd70b660721ae228a03787eb3bf459d?s=40&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D40&amp;r=G\" alt=\"\" width=\"40\" height=\"40\" \/><cite class=\"fn\">UgraNarasimha<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">12. M\u00e4rz 2015 um 14:35<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>Hi Uwe,<\/p>\n<p>Ich kann deutsch aber besser in englisch zu erkl\u00e4ren. I want to use STMf4 29i Discovery Board instead of STM32F4 for my project, in this case, I checked the SPI Pins can remain the same, and I managed to change the LEDs (PG13, PG14). But the SD mount doesn\u2019t work. And I can\u2019t seem to find the reason. It fails here-<br \/>\n\/\/ Media mounten<br \/>\nif(UB_Fatfs_Mount(MMC_0)==FATFS_OK)<br \/>\nEs fehlt irgendwie hier f\u00fcr 29i Discovery, hast du etwas Idee?<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/p>\n<ul class=\"children\">\n<li id=\"li-comment-2975\" class=\"comment byuser comment-author-admin_ub bypostauthor even depth-2\">\n<div id=\"comment-2975\">\n<div class=\"comment-author vcard\"><img loading=\"lazy\" decoding=\"async\" class=\"avatar avatar-40 photo\" src=\"http:\/\/0.gravatar.com\/avatar\/67426419ead44d5afa132e92685bb460?s=40&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D40&amp;r=G\" alt=\"\" width=\"40\" height=\"40\" \/><cite class=\"fn\">admin_ub<\/cite> <span class=\"says\">sagt:<\/span><\/div>\n<p><!-- .comment-author .vcard --><\/p>\n<div class=\"comment-meta commentmetadata\">14. M\u00e4rz 2015 um 11:53<\/div>\n<p><!-- .comment-meta .commentmetadata --><\/p>\n<div class=\"comment-body\">\n<p>have you tested the example from this site ? (without modification first)<br \/>\nit\u2019s written for a stm32f429 and works out of the box<br \/>\ndo you use a detect-pin ?<br \/>\nhave you tested another sd-card ?<br \/>\ndouble check all 6 wires (no external pullups and short as possible)<\/p>\n<\/div>\n<\/div>\n<p><!-- #comment-## --><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>mit dieser Library k\u00f6nnen SD-Karten mit einem FAT-Dateisystem per SPI-Schnittstelle vom STM32F4 verwaltet werden. Hinweis : es gibt noch eine Library f\u00fcr den SDIO-Bus (Nr. 13) f\u00fcr USB-Sticks per FATFS (Nr. 32) und eine kombinierte Library SD+USB (Nr. 87) F\u00fcr &hellip; <a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=523\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":144,"menu_order":89,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[128],"tags":[152,9,49,7],"class_list":["post-523","page","type-page","status-publish","hentry","category-stm32f4","tag-fatfs","tag-library","tag-spi","tag-stm32f4"],"_links":{"self":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/523","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=523"}],"version-history":[{"count":4,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/523\/revisions"}],"predecessor-version":[{"id":1629,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/523\/revisions\/1629"}],"up":[{"embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/144"}],"wp:attachment":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}