硬汉嵌入式论坛

 找回密码
 立即注册
查看: 3981|回复: 3
收起左侧

[FatFs] 重新初始化  stm32的io以后然后恢复到之前的配置,  f_printf

[复制链接]

12

主题

46

回帖

82

积分

初级会员

积分
82
发表于 2015-11-4 11:56:25 | 显示全部楼层 |阅读模式
stm32初始化以后 往 sd卡里面的txt   写数据正常,
切换stm32io口配置  过一段时间 再配置回来,  写不进去  sd卡的txt数据了, 调试显示f_printf函数不调用disk_write ()了,
复位以后就可以正常工作
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106938
QQ
发表于 2015-11-4 14:54:31 | 显示全部楼层
以前我遇到过类似的情况,比如刚开始引脚是配置为USART功能,后来切换成SPI引脚就不干活了,不知道怎么回事。

做IO功能切换的时候,调用这个时钟复位函数试试看
  1. /**
  2.   * @brief  Forces or releases High Speed APB (APB2) peripheral reset.
  3.   * @param  RCC_APB2Periph: specifies the APB2 peripheral to reset.
  4.   *   This parameter can be any combination of the following values:
  5.   *     @arg RCC_APB2Periph_AFIO, RCC_APB2Periph_GPIOA, RCC_APB2Periph_GPIOB,
  6.   *          RCC_APB2Periph_GPIOC, RCC_APB2Periph_GPIOD, RCC_APB2Periph_GPIOE,
  7.   *          RCC_APB2Periph_GPIOF, RCC_APB2Periph_GPIOG, RCC_APB2Periph_ADC1,
  8.   *          RCC_APB2Periph_ADC2, RCC_APB2Periph_TIM1, RCC_APB2Periph_SPI1,
  9.   *          RCC_APB2Periph_TIM8, RCC_APB2Periph_USART1, RCC_APB2Periph_ADC3,
  10.   *          RCC_APB2Periph_TIM15, RCC_APB2Periph_TIM16, RCC_APB2Periph_TIM17,
  11.   *          RCC_APB2Periph_TIM9, RCC_APB2Periph_TIM10, RCC_APB2Periph_TIM11  
  12.   * @param  NewState: new state of the specified peripheral reset.
  13.   *   This parameter can be: ENABLE or DISABLE.
  14.   * @retval None
  15.   */
  16. void RCC_APB2PeriphResetCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)
  17. {
  18.   /* Check the parameters */
  19.   assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph));
  20.   assert_param(IS_FUNCTIONAL_STATE(NewState));
  21.   if (NewState != DISABLE)
  22.   {
  23.     RCC->APB2RSTR |= RCC_APB2Periph;
  24.   }
  25.   else
  26.   {
  27.     RCC->APB2RSTR &= ~RCC_APB2Periph;
  28.   }
  29. }
  30. /**
  31.   * @brief  Forces or releases Low Speed APB (APB1) peripheral reset.
  32.   * @param  RCC_APB1Periph: specifies the APB1 peripheral to reset.
  33.   *   This parameter can be any combination of the following values:
  34.   *     @arg RCC_APB1Periph_TIM2, RCC_APB1Periph_TIM3, RCC_APB1Periph_TIM4,
  35.   *          RCC_APB1Periph_TIM5, RCC_APB1Periph_TIM6, RCC_APB1Periph_TIM7,
  36.   *          RCC_APB1Periph_WWDG, RCC_APB1Periph_SPI2, RCC_APB1Periph_SPI3,
  37.   *          RCC_APB1Periph_USART2, RCC_APB1Periph_USART3, RCC_APB1Periph_USART4,
  38.   *          RCC_APB1Periph_USART5, RCC_APB1Periph_I2C1, RCC_APB1Periph_I2C2,
  39.   *          RCC_APB1Periph_USB, RCC_APB1Periph_CAN1, RCC_APB1Periph_BKP,
  40.   *          RCC_APB1Periph_PWR, RCC_APB1Periph_DAC, RCC_APB1Periph_CEC,
  41.   *          RCC_APB1Periph_TIM12, RCC_APB1Periph_TIM13, RCC_APB1Periph_TIM14  
  42.   * @param  NewState: new state of the specified peripheral clock.
  43.   *   This parameter can be: ENABLE or DISABLE.
  44.   * @retval None
  45.   */
  46. void RCC_APB1PeriphResetCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)
  47. {
  48.   /* Check the parameters */
  49.   assert_param(IS_RCC_APB1_PERIPH(RCC_APB1Periph));
  50.   assert_param(IS_FUNCTIONAL_STATE(NewState));
  51.   if (NewState != DISABLE)
  52.   {
  53.     RCC->APB1RSTR |= RCC_APB1Periph;
  54.   }
  55.   else
  56.   {
  57.     RCC->APB1RSTR &= ~RCC_APB1Periph;
  58.   }
  59. }
复制代码
比如串口的的复位:
  1. /**
  2.   * @brief  Deinitializes the USARTx peripheral registers to their default reset values.
  3.   * @param  USARTx: Select the USART or the UART peripheral.
  4.   *   This parameter can be one of the following values:
  5.   *      USART1, USART2, USART3, UART4 or UART5.
  6.   * @retval None
  7.   */
  8. void USART_DeInit(USART_TypeDef* USARTx)
  9. {
  10.   /* Check the parameters */
  11.   assert_param(IS_USART_ALL_PERIPH(USARTx));
  12.   if (USARTx == USART1)
  13.   {
  14.     RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE);
  15.     RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE);
  16.   }
  17.   else if (USARTx == USART2)
  18.   {
  19.     RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, ENABLE);
  20.     RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, DISABLE);
  21.   }
  22.   else if (USARTx == USART3)
  23.   {
  24.     RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, ENABLE);
  25.     RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, DISABLE);
  26.   }   
  27.   else if (USARTx == UART4)
  28.   {
  29.     RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4, ENABLE);
  30.     RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4, DISABLE);
  31.   }   
  32.   else
  33.   {
  34.     if (USARTx == UART5)
  35.     {
  36.       RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART5, ENABLE);
  37.       RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART5, DISABLE);
  38.     }
  39.   }
  40. }
复制代码
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106938
QQ
发表于 2015-11-4 14:55:25 | 显示全部楼层
调用这个函数就实现了串口复位:
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE);
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE);
回复

使用道具 举报

12

主题

46

回帖

82

积分

初级会员

积分
82
 楼主| 发表于 2015-11-5 10:08:55 | 显示全部楼层

回 eric2013 的帖子

eric2013:调用这个函数就实现了串口复位:
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE);
    RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE); (2015-11-04 14:55) 
问题解决了,调试了很多次,文件系统是正常的 ,控制sd卡的时候,先是stm32的spi驱动,后来将spi的几个io口配置成浮空模式,然后用三极管给SD卡断电通电复位一次,交给读卡器用sdio驱动。    再回来的时候要先关闭读卡器,先复位sd卡 再配置 stm32的spi   再初始化SD卡,Stm32 就能正常了的写文件了。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-11 03:37 , Processed in 0.181331 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表