<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>SPI3 and SD Card</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/41521/spi3-and-sd-card</link><description> 
Hi Does anybody have a working example of an STM32F407VG reading
and or writing an SD card using SPI3. 

 
I have tried everything but always fails on mount with
fsMediaError am at my wits end, i have even tried to follow example
 http://www.keil.com</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: SPI3 and SD Card</title><link>https://community.arm.com/thread/148531?ContentTypeID=1</link><pubDate>Wed, 08 Mar 2017 13:19:11 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:26a85730-6727-496c-914f-5a84eb480f50</guid><dc:creator>Derek Hodge</dc:creator><description>&lt;p&gt;&lt;p&gt;
OK, I tried moving the __SPI3_CLK_ENABLE();&lt;br /&gt;
Still no luck, could cry at this point :(&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI3 and SD Card</title><link>https://community.arm.com/thread/148340?ContentTypeID=1</link><pubDate>Wed, 08 Mar 2017 05:51:58 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:443985f4-1d18-42ca-b560-569ff8fa8a26</guid><dc:creator>Clive Unspecified</dc:creator><description>&lt;p&gt;&lt;p&gt;
Enable the clock before you initialize the interface, the part is
synchronous&lt;/p&gt;

&lt;p&gt;
__SPI3_CLK_ENABLE(); // DO IT BEFORE&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI3 and SD Card</title><link>https://community.arm.com/thread/147957?ContentTypeID=1</link><pubDate>Wed, 08 Mar 2017 04:37:09 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:59595f08-8364-4924-9fe7-769c8a1b5c53</guid><dc:creator>Derek Hodge</dc:creator><description>&lt;p&gt;&lt;p&gt;
Blink Thread - This Flashes every Second&lt;/p&gt;

&lt;pre&gt;
/* USER CODE BEGIN 4 */
void Blink(void const *arg){

        while (1){
                osDelay(1000);
                HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_0);
                WriteFile();
        }
}
&lt;/pre&gt;

&lt;p&gt;
It calls the writefile routine which should mount the card but
fails.&lt;/p&gt;

&lt;pre&gt;
int32_t fs_mc_spi_control_ss (uint32_t drive_num, uint32_t ss){
        if (ss==0) {
                HAL_GPIO_WritePin(GPIOD,GPIO_PIN_3,GPIO_PIN_SET);
                return 1;
        }
          else {
                        HAL_GPIO_WritePin(GPIOD,GPIO_PIN_3,GPIO_PIN_RESET);
            return 0;
                }
}

void WriteFile()
{
        fsStatus st;
        if (finit(&amp;quot;&amp;quot;) == fsOK) {
        st=fmount(&amp;quot;&amp;quot;);
        if (st == fsOK) HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_1); ;
        }
        FILE *f=fopen(&amp;quot;try.txt&amp;quot;,&amp;quot;a&amp;quot;);
                if (f!=NULL) {
                        HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_2);
                        fprintf(f,&amp;quot;Test\n&amp;quot;);
                        fclose(f);
                }
}

&lt;/pre&gt;

&lt;p&gt;
The fs_mc_spi_control_ss function is setting the CS pin, I have
tried reversing polarity.&lt;br /&gt;
Also tried to lengthen the delay on the thread.&lt;/p&gt;

&lt;p&gt;
Thanks so much for your time.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI3 and SD Card</title><link>https://community.arm.com/thread/147157?ContentTypeID=1</link><pubDate>Wed, 08 Mar 2017 04:24:20 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:508203bc-3a77-41e1-89bd-80a8728122b4</guid><dc:creator>Derek Hodge</dc:creator><description>&lt;p&gt;&lt;p&gt;
SPI Config&lt;/p&gt;

&lt;pre&gt;
/* SPI3 init function */
static void MX_SPI3_Init(void)
{

  hspi3.Instance = SPI3;
  hspi3.Init.Mode = SPI_MODE_MASTER;
  hspi3.Init.Direction = SPI_DIRECTION_2LINES;
  hspi3.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi3.Init.CLKPolarity = SPI_POLARITY_LOW;
  hspi3.Init.CLKPhase = SPI_PHASE_1EDGE;
  hspi3.Init.NSS = SPI_NSS_SOFT;
  hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
  hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi3.Init.TIMode = SPI_TIMODE_DISABLE;
  hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  hspi3.Init.CRCPolynomial = 10;
  if (HAL_SPI_Init(&amp;amp;hspi3) != HAL_OK)
  {
    Error_Handler();
  }
  __SPI3_CLK_ENABLE();

}

&lt;/pre&gt;

&lt;p&gt;
GPIO Config&lt;/p&gt;

&lt;pre&gt;
static void MX_GPIO_Init(void)
{

  GPIO_InitTypeDef GPIO_InitStruct;

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOH_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();
  __HAL_RCC_GPIOD_CLK_ENABLE();


  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOD, GPIO_PIN_3, GPIO_PIN_RESET);

  /*Configure GPIO pins : PB0 PB1 PB2 */
  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOB, &amp;amp;GPIO_InitStruct);

  /*Configure GPIO pin : PD3 */
  GPIO_InitStruct.Pin = GPIO_PIN_3;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOD, &amp;amp;GPIO_InitStruct);

        GPIO_InitStruct.Pin = GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12;
        GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
        GPIO_InitStruct.Pull = GPIO_PULLUP;
        GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
        GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
  HAL_GPIO_Init(GPIOC, &amp;amp;GPIO_InitStruct);
}
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI3 and SD Card</title><link>https://community.arm.com/thread/145734?ContentTypeID=1</link><pubDate>Wed, 08 Mar 2017 04:22:24 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:8a6782c3-c2bb-42db-8dca-ea0b331995b5</guid><dc:creator>Derek Hodge</dc:creator><description>&lt;p&gt;&lt;p&gt;
Clock Config&lt;/p&gt;

&lt;pre&gt;
void SystemClock_Config(void)
{

  RCC_OscInitTypeDef RCC_OscInitStruct;
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
  RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;

    /**Configure the main internal regulator output voltage
    */
  __HAL_RCC_PWR_CLK_ENABLE();

  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

    /**Initializes the CPU, AHB and APB busses clocks
    */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.LSEState = RCC_LSE_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 25;
  RCC_OscInitStruct.PLL.PLLN = 336;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = 7;
  if (HAL_RCC_OscConfig(&amp;amp;RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

    /**Initializes the CPU, AHB and APB busses clocks
    */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

  if (HAL_RCC_ClockConfig(&amp;amp;RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
  {
    Error_Handler();
  }

  PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
  PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
  if (HAL_RCCEx_PeriphCLKConfig(&amp;amp;PeriphClkInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

    /**Configure the Systick interrupt time
    */
  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

    /**Configure the Systick
    */
  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  /* SysTick_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(SysTick_IRQn, 15, 15);
}
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI3 and SD Card</title><link>https://community.arm.com/thread/143719?ContentTypeID=1</link><pubDate>Tue, 07 Mar 2017 20:26:43 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:acddd49c-19f6-498d-a257-94fc9712b776</guid><dc:creator>Clive Unspecified</dc:creator><description>&lt;p&gt;&lt;p&gt;
Ok, so if I understood correctly the same hardware configuration
worked with another compiler, and using Keil and its libraries you
don&amp;#39;t see signals at the pins, and you don&amp;#39;t have a working card.
There&amp;#39;s an interference that it works on a different SPI bus.&lt;/p&gt;

&lt;p&gt;
I&amp;#39;m not yet convinced that the clocks, peripherals and pins are
correctly configured, you&amp;#39;ve made declarative statements that they
are correct, but you&amp;#39;re also man-weeks into &amp;quot;not working&amp;quot;. Beyond
that you&amp;#39;d need to dig into the middleware code itself. I&amp;#39;m not
looking to wade into this with my own resources, or build equivalent
hardware, if you have code to present I&amp;#39;ll look at that, guessing
isn&amp;#39;t my game.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI3 and SD Card</title><link>https://community.arm.com/thread/141023?ContentTypeID=1</link><pubDate>Tue, 07 Mar 2017 15:54:42 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:a03e8cbb-e2b0-44c7-b57a-a91597499293</guid><dc:creator>Derek Hodge</dc:creator><description>&lt;p&gt;&lt;p&gt;
That&amp;#39;s what I was thinking, so I still am stuck on why I can&amp;#39;t get
the SD card to mount.&lt;/p&gt;

&lt;p&gt;
Do we have any other ideas?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI3 and SD Card</title><link>https://community.arm.com/thread/137403?ContentTypeID=1</link><pubDate>Tue, 07 Mar 2017 15:40:39 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:b1f1e9ac-38e3-4643-8a66-a6408d86987d</guid><dc:creator>Clive Unspecified</dc:creator><description>&lt;p&gt;&lt;p&gt;
Ok, let&amp;#39;s not get distracted by pins John selected. The PB3 pin is
problematic, as are the pins I mentioned on the STM32F1.&lt;/p&gt;

&lt;p&gt;
The pin muxing on the F2/F4 is far more flexible, the pins you
mentioned should not conflict with JTAG.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI3 and SD Card</title><link>https://community.arm.com/thread/129369?ContentTypeID=1</link><pubDate>Tue, 07 Mar 2017 13:58:05 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:aae689a0-87ed-4651-9a9f-6898adbb2861</guid><dc:creator>Derek Hodge</dc:creator><description>&lt;p&gt;&lt;p&gt;
Thanks,&lt;br /&gt;
looking at data sheet it says jtag is not for PC10,11,12 but pb3 and
4.&lt;br /&gt;
Does jtag effect spi3 or the specific pins?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI3 and SD Card</title><link>https://community.arm.com/thread/121024?ContentTypeID=1</link><pubDate>Tue, 07 Mar 2017 11:37:07 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:04b4e74c-ae8d-401d-839c-69d92f7d1188</guid><dc:creator>Clive Unspecified</dc:creator><description>&lt;p&gt;&lt;p&gt;
On the F1, I used this to free SPI2 on PB13,14 and 15 while
keeping SWD/SWV viable, not salient on F4&lt;/p&gt;

&lt;pre&gt;
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
  /* JTAG-DP Disabled and SW-DP Enabled */
  GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
&lt;/pre&gt;

&lt;p&gt;
On the F2/F4 GPIO_AF_SWJ and GPIO_AF_TRACE is zero, so should be
able to mux off functionality&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI3 and SD Card</title><link>https://community.arm.com/thread/109110?ContentTypeID=1</link><pubDate>Tue, 07 Mar 2017 11:20:51 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:a090e040-95bf-4177-9a12-7267930e8860</guid><dc:creator>Derek Hodge</dc:creator><description>&lt;p&gt;&lt;p&gt;
Probably a silly question but how do I do this?&lt;br /&gt;
I was looking for the JTAG disable about 3 weeks ago. Could not find
it in data sheet so assumed I was wrong.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI3 and SD Card</title><link>https://community.arm.com/thread/93938?ContentTypeID=1</link><pubDate>Tue, 07 Mar 2017 11:10:38 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:dacb30f2-8439-42fe-b127-e313ddb96e47</guid><dc:creator>Clive Unspecified</dc:creator><description>&lt;p&gt;&lt;p&gt;
The OP isn&amp;#39;t using the JTAG pins, got F1 board that does and you
need to disable Full JTAG&lt;/p&gt;

&lt;p&gt;
LED = PB1&lt;br /&gt;
LED = PB2&lt;br /&gt;
CS = PD3&lt;br /&gt;
SCK = PC10&lt;br /&gt;
MISO = PC11&lt;br /&gt;
MOSI = PC12&lt;/p&gt;

&lt;p&gt;
HSE = 25 MHZ&lt;br /&gt;
SYSCLK = 150 MHZ&lt;/p&gt;

&lt;p&gt;
SPI3 = APB1 = 37.5 MHZ?&lt;/p&gt;

&lt;p&gt;
I don&amp;#39;t know what board this is, and don&amp;#39;t have resources to fool
with. Would suggest dissecting clocks and peripheral register
settings in viewer.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI3 and SD Card</title><link>https://community.arm.com/thread/85548?ContentTypeID=1</link><pubDate>Mon, 06 Mar 2017 19:24:23 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:263e6dd5-e53b-46ed-ac22-a015123b2886</guid><dc:creator>John Linq</dc:creator><description>&lt;p&gt;&lt;pre&gt;
GPIO_PinAFConfig(GPIOB, GPIO_PinSource3, GPIO_AF_SPI3);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_AF_SPI3);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_SPI3);
&lt;/pre&gt;

&lt;p&gt;
Pins for SPI3 are also for JTAG.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>