(求助)STM32F100C8T6不能下载程序

2019-12-19 18:09发布

如题:
STM32F100C8T6不能下载程序,总是提示:Flash down load failed。
网上找了很多教程,没有作用。
请各位大神指点一下。
1. 我应该考虑哪些地方?
2. 有没有例程?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
8条回答
tomzbj
2019-12-19 18:37
ly830102624 发表于 2018-4-22 00:18
统一回复:下载不进去是硬件问题。现在外部时钟8M,LED灯都点不亮。难道时钟配置错误?有大神贴出时钟配置 ...

gcc的, 不过估计和其他编译器的也差不多少
需要在Makefile里指定-DSTM32F10X_MD_VL, 这样它会执行SetSysclkTo24()
跟f103的时钟树还是稍微有一点点不一样的, f103的hse在进PLL之前的预分频器只能/1或/2, 其他大部分stm32都可以从/1一直到/16

  1. #include "stm32f10x.h"

  2. #if defined (STM32F10X_LD_VL) || (defined STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)
  3. #define SYSCLK_FREQ_24MHz  24000000
  4. #else
  5. #define SYSCLK_FREQ_72MHz  72000000
  6. #endif

  7. #define VECT_TAB_OFFSET  0x0   

  8. #ifdef SYSCLK_FREQ_HSE
  9. uint32_t SystemCoreClock = SYSCLK_FREQ_HSE;
  10. #elif defined SYSCLK_FREQ_24MHz
  11. uint32_t SystemCoreClock = SYSCLK_FREQ_24MHz;
  12. #elif defined SYSCLK_FREQ_72MHz
  13. uint32_t SystemCoreClock = SYSCLK_FREQ_72MHz;
  14. #else
  15. uint32_t SystemCoreClock = HSI_VALUE;
  16. #endif

  17. static void SetSysClock(void);

  18. #ifdef SYSCLK_FREQ_HSE
  19. static void SetSysClockToHSE(void);
  20. #elif defined SYSCLK_FREQ_24MHz
  21. static void SetSysClockTo24(void);
  22. #elif defined SYSCLK_FREQ_72MHz
  23. static void SetSysClockTo72(void);
  24. #endif

  25. void SystemInit(void)
  26. {
  27.     RCC_DeInit();
  28.     /* Configure the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers */
  29.     /* Configure the Flash Latency cycles and enable prefetch buffer */
  30.     SetSysClock();
  31.     NVIC_SetVectorTable(NVIC_VectTab_FLASH, VECT_TAB_OFFSET);
  32. }

  33. void SystemCoreClockUpdate(void)
  34. {
  35.     RCC_ClocksTypeDef clocks;
  36.     RCC_GetClocksFreq(&clocks);
  37.     SystemCoreClock = clocks.SYSCLK_Frequency;
  38. }

  39. static void SetSysClock(void)
  40. {
  41. #ifdef SYSCLK_FREQ_HSE
  42.     SetSysClockToHSE();
  43. #elif defined SYSCLK_FREQ_24MHz
  44.     SetSysClockTo24();
  45. #elif defined SYSCLK_FREQ_72MHz
  46.     SetSysClockTo72();
  47. #endif
  48. } // If none of the define above is enabled, the HSI is used as System clock source (default after reset)

  49. #ifdef SYSCLK_FREQ_HSE
  50. static void SetSysClockToHSE(void)
  51. {
  52.     volatile unsigned long HSEStatus = 0;

  53.     RCC_HSEConfig(RCC_HSE_ON);
  54.     HSEStatus = RCC_WaitForHSEStartUp();

  55.     if(HSEStatus == 0x01) {

  56. #if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL && !defined STM32F10X_HD_VL
  57.         FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
  58.         FLASH_SetLatency(FLASH_Latency_0);
  59. #endif
  60.         RCC_HCLKConfig(RCC_SYSCLK_Div1);    // AHB CLK = SYSCLK
  61.         RCC_PCLK2Config(RCC_HCLK_Div1);// APB2 CLK = SYSCLK
  62.         RCC_PCLK1Config(RCC_HCLK_Div1);// APB1 CLK = SYSCLK
  63.         RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);

  64.         while(RCC_GetSYSCLKSource() != 0x04);  /* Wait till HSE is used as system clock source */
  65.     }
  66.     else {
  67.         // If HSE start-up failed, do something here.
  68.     }
  69. }
  70. #elif defined SYSCLK_FREQ_24MHz

  71. static void SetSysClockTo24(void)
  72. {
  73.     volatile unsigned long HSEStatus = 0;

  74.     RCC_HSEConfig(RCC_HSE_ON);
  75.     HSEStatus = RCC_WaitForHSEStartUp();

  76.     if(HSEStatus == 0x01) {

  77. #if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL && !defined STM32F10X_HD_VL
  78.         FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
  79.         FLASH_SetLatency(FLASH_Latency_0);
  80. #endif
  81.         RCC_HCLKConfig(RCC_SYSCLK_Div1);    // AHB CLK = SYSCLK
  82.         RCC_PCLK2Config(RCC_HCLK_Div1);     // APB2 CLK = SYSCLK
  83.         RCC_PCLK1Config(RCC_HCLK_Div1);     // APB1 CLK = SYSCLK

  84. #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
  85.         RCC_PREDIV1Config(RCC_PREDIV1_Source_HSE, RCC_PREDIV1_Div2);
  86.         RCC_PLLConfig(RCC_PLLSource_PREDIV1, RCC_PLLMul_6);
  87. #else
  88.         RCC_PLLConfig(RCC_PLLSource_HSE_Div2, RCC_PLLMul_6);
  89. #endif
  90.         RCC_PLLCmd(ENABLE);

  91.         while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); /* Wait till PLL is ready */
  92.         RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
  93.         while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); /* Wait till PLL is ready */
  94.         while(RCC_GetSYSCLKSource() != 0x08);  /* Wait till PLL is used as system clock source */
  95.     }
  96.     else {
  97.     }
  98. }

  99. #elif defined SYSCLK_FREQ_72MHz
  100. static void SetSysClockTo72(void)
  101. {
  102.     volatile unsigned long HSEStatus = 0;

  103.     RCC_HSEConfig(RCC_HSE_ON);
  104.     HSEStatus = RCC_WaitForHSEStartUp();

  105.     if(HSEStatus == 0x01) {

  106. #if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL && !defined STM32F10X_HD_VL
  107.         FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
  108.         FLASH_SetLatency(FLASH_Latency_2);
  109. #endif
  110.         RCC_HCLKConfig(RCC_SYSCLK_Div1);    // AHB CLK = SYSCLK
  111.         RCC_PCLK2Config(RCC_HCLK_Div1);     // APB2 CLK = SYSCLK
  112.         RCC_PCLK1Config(RCC_HCLK_Div2);     // APB1 CLK = SYSCLK

  113. #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
  114.         RCC_PREDIV1Config(RCC_PREDIV1_Source_HSE, RCC_PREDIV1_Div1);
  115.         RCC_PLLConfig(RCC_PLLSource_PREDIV1, RCC_PLLMul_9);
  116. #else
  117.         RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
  118. #endif
  119.         RCC_PLLCmd(ENABLE);

  120.         while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); /* Wait till PLL is ready */
  121.         RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
  122.         while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); /* Wait till PLL is ready */
  123.         while(RCC_GetSYSCLKSource() != 0x08);  /* Wait till PLL is used as system clock source */
  124.     }
  125.     else {
  126.     }
  127. }
  128. #endif
复制代码

一周热门 更多>