Compiling STM32F4-Discovery with SD-Card Interface

Posted on
  • Hi folks,
    I'm trying to add the SD-card functionality to the STM32F4-DISCOVERY image.
    I changed the File "STM32F4DISCOVERY.py" as follows:

    devices = {
      'OSC' : { 'pin_1' : 'H0',
                'pin_2' : 'H1' },
      'OSC_RTC' : { 'pin_1' : 'C14',
                    'pin_2' : 'C15' },
      'LED1' : { 'pin' : 'D13' },
      'LED2' : { 'pin' : 'D12' },
      'LED3' : { 'pin' : 'D14' },
      'LED4' : { 'pin' : 'D15' },
      'BTN1' : { 'pin' : 'A0' },
      'USB' : { 'pin_otg_pwr' : 'C0',
                'pin_dm' : 'A11',
                'pin_bp' : 'A12',
                'pin_vbus' : 'A9',
                'pin_id' : 'A10', },
      'SD' :  { 'pin_cmd' :  'D2',
                'pin_cd' :  'B15',
                'pin_d0' :  'C8',
                'pin_d1' :  'C9',
                'pin_d2' :  'C10',
                'pin_d3' :  'C11',
                'pin_clk' :  'C12' },
      'MEMS' :  {  'device' : 'LIS302DL',
                'pin_cs' :  'E3',
                'pin_int1' :  'E0',
                'pin_int2' :  'E1',
                'pin_mosi' :  'A7',
                'pin_miso' :  'A6',
                'pin_sck' :  'A5' },
      'MIC' :  { 'device' : 'MP45DT02',
                 'pin_clk' :  'C3',
                 'pin_dout' :  'B10', },
      'AUDIO' :  { 'device' : 'CS43L22',
                   'pin_sda' :  'B9',
                   'pin_scl' :  'B6',
                   'pin_mclk' :  'C7',
                   'pin_sclk' :  'C10',    
                   'pin_sdin' :  'C12',  
                   'pin_lrck' :  'A4',
                   'pin_nrst' :  'D4',    
                    },
    };
    

    And the "Makefile" :

    else ifdef STM32F4DISCOVERY
    PROJ_NAME=espruino_stm32f4discovery
    USB=1
    [#USE_CC3000](https://forum.espruino.com/search/?q=%23USE_CC3000)=1
    USE_GRAPHICS=1
    USE_FILESYSTEM=1
    USE_FILESYSTEM_SDIO=1
    DEFINES += -DUSE_USB_OTG_FS=1
    FAMILY=STM32F4
    CHIP=STM32F407
    BOARD=STM32F4DISCOVERY
    STLIB=STM32F4XX
    PRECOMPILED_OBJS+=$(ROOT)/targetlibs/stm32f4/lib/startup_stm32f4xx.o
    OPTIMIZEFLAGS+=-O3
    

    As Result I get the following errors:

    */home/kwittwer/arm-2013.05/bin/arm-none-eabi-gcc -Wall -Wextra -Wconversion -Werror=implicit-function-declaration -fdiagnostics-show-option  -O3 -fno-common -fno-exceptions -fdata-sections -ffunction-sections -c -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork -mfpu=fpv4-sp-d16 -mfloat-abi=softfp  -DNO_ASSERT -DUSE_USB_OTG_FS=1 -DUSE_FILESYSTEM -DUSE_FILESYSTEM_SDIO -DUSE_MATH -DUSE_GRAPHICS -DUSB -DSTM32F4 -DARM  -DFAKE_STDLIB -DSTM32 -DUSE_STDPERIPH_DRIVER=1 -DSTM32F407 -DSTM32F4DISCOVERY -DSTM32F4XX -I/home/kwittwer/Espruino/Espruino-master -I/home/kwittwer/Espruino/Espruino-master/targets -I/home/kwittwer/Espruino/Espruino-master/src -I/home/kwittwer/Espruino/Espruino-master/gen -I/home/kwittwer/Espruino/Espruino-master/libs/fat_sd -I/home/kwittwer/Espruino/Espruino-master/libs/math -I/home/kwittwer/Espruino/Espruino-master/libs/graphics -I/home/kwittwer/Espruino/Espruino-master/targetlibs/stm32f4 -I/home/kwittwer/Espruino/Espruino-master/targetlibs/stm32f4/lib -I/home/kwittwer/Espruino/Espruino-master/targetlibs/stm32f4/usblib -I/home/kwittwer/Espruino/Espruino-master/targetlibs/stm32f4/usb -I/home/kwittwer/Espruino/Espruino-master/targetlibs/arm -I/home/kwittwer/Espruino/Espruino-master/targets/stm32  -DNO_ASSERT -DUSE_USB_OTG_FS=1 -DUSE_FILESYSTEM -DUSE_FILESYSTEM_SDIO -DUSE_MATH -DUSE_GRAPHICS -DUSB -DSTM32F4 -DARM  -DFAKE_STDLIB -DSTM32 -DUSE_STDPERIPH_DRIVER=1 -DSTM32F407 -DSTM32F4DISCOVERY -DSTM32F4XX libs/fat_sd/sdio_sdcard.c -o libs/fat_sd/sdio_sdcard.o
    libs/fat_sd/sdio_sdcard.c: In function 'SD_Init':
    libs/fat_sd/sdio_sdcard.c:147:3: error: implicit declaration of function 'RCC_AHBPeriphClockCmd' [-Werror=implicit-function-declaration]
    libs/fat_sd/sdio_sdcard.c:147:25: error: 'RCC_AHBPeriph_SDIO' undeclared (first use in this function)
    libs/fat_sd/sdio_sdcard.c:147:25: note: each undeclared identifier is reported only once for each function it appears in
    libs/fat_sd/sdio_sdcard.c:150:25: error: 'RCC_AHBPeriph_DMA2' undeclared (first use in this function)
    libs/fat_sd/sdio_sdcard.c: In function 'SD_GetCardInfo':
    libs/fat_sd/sdio_sdcard.c:447:50: warning: conversion to 'uint8_t' from 'int' may alter its value [-Wconversion]
    libs/fat_sd/sdio_sdcard.c:464:42: warning: conversion to 'uint16_t' from 'int' may alter its value [-Wconversion]
    libs/fat_sd/sdio_sdcard.c:468:36: warning: conversion to 'uint16_t' from 'int' may alter its value [-Wconversion]
    libs/fat_sd/sdio_sdcard.c:474:51: warning: conversion to 'uint8_t' from 'int' may alter its value [-Wconversion]
    libs/fat_sd/sdio_sdcard.c:475:51: warning: conversion to 'uint8_t' from 'int' may alter its value [-Wconversion]
    libs/fat_sd/sdio_sdcard.c:476:43: warning: conversion to 'uint8_t' from 'int' may alter its value [-Wconversion]
    libs/fat_sd/sdio_sdcard.c:481:48: warning: conversion to 'uint32_t' from 'int' may change the sign of the result [-Wsign-conversion]
    libs/fat_sd/sdio_sdcard.c:485:42: warning: conversion to 'long unsigned int' from 'int' may change the sign of the result [-Wsign-conversion]
    libs/fat_sd/sdio_sdcard.c:489:49: warning: conversion to 'long unsigned int' from 'int' may change the sign of the result [-Wsign-conversion]
    libs/fat_sd/sdio_sdcard.c:491:56: warning: conversion to 'uint8_t' from 'int' may alter its value [-Wconversion]
    libs/fat_sd/sdio_sdcard.c:497:56: warning: conversion to 'uint8_t' from 'int' may alter its value [-Wconversion]
    libs/fat_sd/sdio_sdcard.c:498:51: warning: conversion to 'uint8_t' from 'int' may alter its value [-Wconversion]
    libs/fat_sd/sdio_sdcard.c:504:34: warning: conversion to 'long unsigned int' from 'int' may change the sign of the result [-Wsign-conversion]
    libs/fat_sd/sdio_sdcard.c:505:33: warning: conversion to 'uint32_t' from 'int' may change the sign of the result [-Wsign-conversion]
    libs/fat_sd/sdio_sdcard.c:512:48: warning: conversion to 'uint32_t' from 'int' may change the sign of the result [-Wsign-conversion]
    libs/fat_sd/sdio_sdcard.c:517:41: warning: conversion to 'long unsigned int' from 'int' may change the sign of the result [-Wsign-conversion]
    libs/fat_sd/sdio_sdcard.c:532:47: warning: conversion to 'uint8_t' from 'int' may alter its value [-Wconversion]
    libs/fat_sd/sdio_sdcard.c:533:46: warning: conversion to 'uint8_t' from 'int' may alter its value [-Wconversion]
    libs/fat_sd/sdio_sdcard.c:543:46: warning: conversion to 'uint8_t' from 'int' may alter its value [-Wconversion]
    libs/fat_sd/sdio_sdcard.c:544:47: warning: conversion to 'uint8_t' from 'int' may alter its value [-Wconversion]
    libs/fat_sd/sdio_sdcard.c:545:49: warning: conversion to 'uint8_t' from 'int' may alter its value [-Wconversion]
    libs/fat_sd/sdio_sdcard.c:550:55: warning: conversion to 'uint8_t' from 'int' may alter its value [-Wconversion]
    libs/fat_sd/sdio_sdcard.c:557:44: warning: conversion to 'uint8_t' from 'int' may alter its value [-Wconversion]
    libs/fat_sd/sdio_sdcard.c:558:49: warning: conversion to 'uint8_t' from 'int' may alter its value [-Wconversion]
    libs/fat_sd/sdio_sdcard.c:559:49: warning: conversion to 'uint8_t' from 'int' may alter its value [-Wconversion]
    libs/fat_sd/sdio_sdcard.c:560:46: warning: conversion to 'uint8_t' from 'int' may alter its value [-Wconversion]
    libs/fat_sd/sdio_sdcard.c:575:38: warning: conversion to 'uint16_t' from 'int' may alter its value [-Wconversion]
    libs/fat_sd/sdio_sdcard.c:579:32: warning: conversion to 'uint16_t' from 'int' may alter its value [-Wconversion]
    libs/fat_sd/sdio_sdcard.c:583:36: warning: conversion to 'uint32_t' from 'int' may change the sign of the result [-Wsign-conversion]
    libs/fat_sd/sdio_sdcard.c:587:37: warning: conversion to 'long unsigned int' from 'int' may change the sign of the result [-Wsign-conversion]
    libs/fat_sd/sdio_sdcard.c:591:37: warning: conversion to 'long unsigned int' from 'int' may change the sign of the result [-Wsign-conversion]
    libs/fat_sd/sdio_sdcard.c:607:33: warning: conversion to 'uint32_t' from 'int' may change the sign of the result [-Wsign-conversion]
    libs/fat_sd/sdio_sdcard.c:611:34: warning: conversion to 'long unsigned int' from 'int' may change the sign of the result [-Wsign-conversion]
    libs/fat_sd/sdio_sdcard.c:615:34: warning: conversion to 'long unsigned int' from 'int' may change the sign of the result [-Wsign-conversion]
    libs/fat_sd/sdio_sdcard.c:624:48: warning: conversion to 'uint16_t' from 'int' may alter its value [-Wconversion]
    libs/fat_sd/sdio_sdcard.c:628:33: warning: conversion to 'uint16_t' from 'int' may alter its value [-Wconversion]
    libs/fat_sd/sdio_sdcard.c: In function 'SD_ReadBlock':
    libs/fat_sd/sdio_sdcard.c:910:30: error: 'DMA2_FLAG_TC4' undeclared (first use in this function)
    libs/fat_sd/sdio_sdcard.c:910:5: error: too few arguments to function 'DMA_GetFlagStatus'
    In file included from /home/kwittwer/Espruino/Espruino-master/targetlibs/stm32f4/lib/stm32f4xx_conf.h:41:0,
                     from /home/kwittwer/Espruino/Espruino-master/targetlibs/stm32f4/lib/stm32f4xx.h:6965,
                     from /home/kwittwer/Espruino/Espruino-master/gen/platform_config.h:9,
                     from libs/fat_sd/sdio_sdcard.h:36,
                     from libs/fat_sd/sdio_sdcard.c:23:
    /home/kwittwer/Espruino/Espruino-master/targetlibs/stm32f4/lib/stm32f4xx_dma.h:582:12: note: declared here
    libs/fat_sd/sdio_sdcard.c: In function 'SD_ReadMultiBlocks':
    libs/fat_sd/sdio_sdcard.c:1108:32: error: 'DMA2_FLAG_TC4' undeclared (first use in this function)
    libs/fat_sd/sdio_sdcard.c:1108:7: error: too few arguments to function 'DMA_GetFlagStatus'
    In file included from /home/kwittwer/Espruino/Espruino-master/targetlibs/stm32f4/lib/stm32f4xx_conf.h:41:0,
                     from /home/kwittwer/Espruino/Espruino-master/targetlibs/stm32f4/lib/stm32f4xx.h:6965,
                     from /home/kwittwer/Espruino/Espruino-master/gen/platform_config.h:9,
                     from libs/fat_sd/sdio_sdcard.h:36,
                     from libs/fat_sd/sdio_sdcard.c:23:
    /home/kwittwer/Espruino/Espruino-master/targetlibs/stm32f4/lib/stm32f4xx_dma.h:582:12: note: declared here
    libs/fat_sd/sdio_sdcard.c: In function 'SD_WriteBlock':
    libs/fat_sd/sdio_sdcard.c:1331:30: error: 'DMA2_FLAG_TC4' undeclared (first use in this function)
    libs/fat_sd/sdio_sdcard.c:1331:5: error: too few arguments to function 'DMA_GetFlagStatus'
    In file included from /home/kwittwer/Espruino/Espruino-master/targetlibs/stm32f4/lib/stm32f4xx_conf.h:41:0,
                     from /home/kwittwer/Espruino/Espruino-master/targetlibs/stm32f4/lib/stm32f4xx.h:6965,
                     from /home/kwittwer/Espruino/Espruino-master/gen/platform_config.h:9,
                     from libs/fat_sd/sdio_sdcard.h:36,
                     from libs/fat_sd/sdio_sdcard.c:23:
    /home/kwittwer/Espruino/Espruino-master/targetlibs/stm32f4/lib/stm32f4xx_dma.h:582:12: note: declared here
    libs/fat_sd/sdio_sdcard.c: In function 'SD_WriteMultiBlocks':
    libs/fat_sd/sdio_sdcard.c:1603:32: error: 'DMA2_FLAG_TC4' undeclared (first use in this function)
    libs/fat_sd/sdio_sdcard.c:1603:7: error: too few arguments to function 'DMA_GetFlagStatus'
    In file included from /home/kwittwer/Espruino/Espruino-master/targetlibs/stm32f4/lib/stm32f4xx_conf.h:41:0,
                     from /home/kwittwer/Espruino/Espruino-master/targetlibs/stm32f4/lib/stm32f4xx.h:6965,
                     from /home/kwittwer/Espruino/Espruino-master/gen/platform_config.h:9,
                     from libs/fat_sd/sdio_sdcard.h:36,
                     from libs/fat_sd/sdio_sdcard.c:23:
    /home/kwittwer/Espruino/Espruino-master/targetlibs/stm32f4/lib/stm32f4xx_dma.h:582:12: note: declared here
    libs/fat_sd/sdio_sdcard.c: In function 'SDEnWideBus':
    libs/fat_sd/sdio_sdcard.c:2425:3: warning: conversion to 'uint16_t' from 'uint32_t' may alter its value [-Wconversion]
    libs/fat_sd/sdio_sdcard.c: In function 'FindSCR':
    libs/fat_sd/sdio_sdcard.c:2686:34: warning: unused parameter 'rca' [-Wunused-parameter]
    libs/fat_sd/sdio_sdcard.c: In function 'GPIO_Configuration':
    libs/fat_sd/sdio_sdcard.c:2818:26: error: 'RCC_APB2Periph_GPIOC' undeclared (first use in this function)
    libs/fat_sd/sdio_sdcard.c:2818:49: error: 'RCC_APB2Periph_GPIOD' undeclared (first use in this function)
    libs/fat_sd/sdio_sdcard.c:2823:34: error: 'GPIO_Mode_AF_PP' undeclared (first use in this function)
    libs/fat_sd/sdio_sdcard.c: In function 'DMA_TxConfiguration':
    libs/fat_sd/sdio_sdcard.c:2841:17: error: 'DMA2_FLAG_TC4' undeclared (first use in this function)
    libs/fat_sd/sdio_sdcard.c:2841:33: error: 'DMA2_FLAG_TE4' undeclared (first use in this function)
    libs/fat_sd/sdio_sdcard.c:2841:49: error: 'DMA2_FLAG_HT4' undeclared (first use in this function)
    libs/fat_sd/sdio_sdcard.c:2841:65: error: 'DMA2_FLAG_GL4' undeclared (first use in this function)
    libs/fat_sd/sdio_sdcard.c:2841:3: error: too few arguments to function 'DMA_ClearFlag'
    In file included from /home/kwittwer/Espruino/Espruino-master/targetlibs/stm32f4/lib/stm32f4xx_conf.h:41:0,
                     from /home/kwittwer/Espruino/Espruino-master/targetlibs/stm32f4/lib/stm32f4xx.h:6965,
                     from /home/kwittwer/Espruino/Espruino-master/gen/platform_config.h:9,
                     from libs/fat_sd/sdio_sdcard.h:36,
                     from libs/fat_sd/sdio_sdcard.c:23:
    /home/kwittwer/Espruino/Espruino-master/targetlibs/stm32f4/lib/stm32f4xx_dma.h:583:6: note: declared here
    libs/fat_sd/sdio_sdcard.c:2844:11: error: 'DMA2_Channel4' undeclared (first use in this function)
    libs/fat_sd/sdio_sdcard.c:2848:20: error: 'DMA_InitTypeDef' has no member named 'DMA_MemoryBaseAddr'
    libs/fat_sd/sdio_sdcard.c:2849:31: error: 'DMA_DIR_PeripheralDST' undeclared (first use in this function)
    libs/fat_sd/sdio_sdcard.c:2857:20: error: 'DMA_InitTypeDef' has no member named 'DMA_M2M'
    libs/fat_sd/sdio_sdcard.c:2857:31: error: 'DMA_M2M_Disable' undeclared (first use in this function)
    libs/fat_sd/sdio_sdcard.c: In function 'DMA_RxConfiguration':
    libs/fat_sd/sdio_sdcard.c:2874:17: error: 'DMA2_FLAG_TC4' undeclared (first use in this function)
    libs/fat_sd/sdio_sdcard.c:2874:33: error: 'DMA2_FLAG_TE4' undeclared (first use in this function)
    libs/fat_sd/sdio_sdcard.c:2874:49: error: 'DMA2_FLAG_HT4' undeclared (first use in this function)
    libs/fat_sd/sdio_sdcard.c:2874:65: error: 'DMA2_FLAG_GL4' undeclared (first use in this function)
    libs/fat_sd/sdio_sdcard.c:2874:3: error: too few arguments to function 'DMA_ClearFlag'
    In file included from /home/kwittwer/Espruino/Espruino-master/targetlibs/stm32f4/lib/stm32f4xx_conf.h:41:0,
                     from /home/kwittwer/Espruino/Espruino-master/targetlibs/stm32f4/lib/stm32f4xx.h:6965,
                     from /home/kwittwer/Espruino/Espruino-master/gen/platform_config.h:9,
                     from libs/fat_sd/sdio_sdcard.h:36,
                     from libs/fat_sd/sdio_sdcard.c:23:
    /home/kwittwer/Espruino/Espruino-master/targetlibs/stm32f4/lib/stm32f4xx_dma.h:583:6: note: declared here
    libs/fat_sd/sdio_sdcard.c:2877:11: error: 'DMA2_Channel4' undeclared (first use in this function)
    libs/fat_sd/sdio_sdcard.c:2881:20: error: 'DMA_InitTypeDef' has no member named 'DMA_MemoryBaseAddr'
    libs/fat_sd/sdio_sdcard.c:2882:31: error: 'DMA_DIR_PeripheralSRC' undeclared (first use in this function)
    libs/fat_sd/sdio_sdcard.c:2890:20: error: 'DMA_InitTypeDef' has no member named 'DMA_M2M'
    libs/fat_sd/sdio_sdcard.c:2890:31: error: 'DMA_M2M_Disable' undeclared (first use in this function)
    cc1: some warnings being treated as errors
    make: *** [libs/fat_sd/sdio_sdcard.o] Error 1
    *
    

    It seems like an include error ... someone an idea how the includsructure works?

  • I think it's because it's trying to include an stm32f1 header file. You'll have to edit libs/fat_sd/* and #ifdef STM32F4 all the includes. You'll also need to modify the header file to have the correct pin definitions. If you want to change that and modify build_patform_config.h to automatically set the pin definitions that'd be awesome though.

    Personally I wouldn't use SDIO as it's just ore complexity - just stick with normal SPI and follow the circuit from https://github.com/espruino/EspruinoBoard

  • In order to recompile the espruino code for the STM32F4 board, as Gordon suggests, you need to :
    1) change the python definition file.
    2) add the define USE_FILESYSTEM=1 in the Makefile
    3) modify the spi_diskio.c file and include the management of the SPI peripheral in order to manage the slightly different instructions for the STM32 processors, such alternate function. or OType and PuPd records in the GPIO init port structure.
    I succeded in doing the update, but at present time my code has bugs possibly in the C code, do I have to verify using gdb debugger why the code hangs up, as can be seen in the following screenshot. May be that the SPI clock is wrongly set.


    1 Attachment

    • 87f83fad5dfaeb65535cb714fec71c8b562a4be6.png
  • Yes, if it's not coming back your best bet is to use the debugger (or to add loads of jsiConsolePrint statements).

    If you're up for it, the ideal solution would be to use jshSPISetup and jshSPISend functions though - and then filesystem would work on any platform that normal SPI was supported on.

  • It's a long way to Tipperary, but I will succeed at the end.
    Thanks for your suggestions.


    1 Attachment

    • aacd6d2d99f412731aca5cb81eca3fdb376939f9.png
  • Hello user6350,
    did you ever succeed in getting the SDCard to work on STM32F4DISCOVERY?
    I have a few of these boards laying around and want to make them useful by using the Espruino firmware on them...

  • Yes, you can definitely use it. There's a post from a few days ago where someone used it just fine.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Compiling STM32F4-Discovery with SD-Card Interface

Posted by Avatar for kwittwer @kwittwer

Actions