[STM32F0] STM32F030XX烧录不了啊,求救!!!

[复制链接]
7630|14
 楼主| lizhenming 发表于 2016-5-30 22:40 | 显示全部楼层 |阅读模式

  1. void MemoryRemapConfig(void)
  2. {
  3.         uint32_t i = 0;
  4.         uint32_t Data,Address;

  5. //        VectorTable = (unsigned int *)0x20000000;  //RAM
  6.   for(i = 0; i < 48; i++)
  7.   {
  8.     Data=*(__IO unsigned int*)(0x08000000+i*4);
  9.                 Address=0x20000000+(i*4);
  10.                 *(__IO unsigned int*)Address=(uint32_t)Data;
  11.   }
  12.   /* Enable the SYSCFG peripheral clock*/
  13. //  RCC_APB2PeriphResetCmd(RCC_APB2Periph_SYSCFG, ENABLE);
  14.   /* Remap SRAM at 0x00000000 */
  15.         SYSCFG_MemoryRemapConfig(SYSCFG_MemoryRemap_SRAM);//RAM映射到0x0000 0000

  16. }

  17. void I2C_Configuration(void)
  18. {
  19.   I2C_InitTypeDef  I2C_InitStruct;

  20.   GPIO_InitTypeDef  GPIO_InitStruct;
  21.         NVIC_InitTypeDef NVIC_InitStructure;
  22.        
  23.         /* Enable  GPIOA clock */
  24.           RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);       
  25. //         /* Configure the I2C clock source. The clock is derived from the HSI */
  26. //   RCC_I2CCLKConfig(RCC_I2C1CLK_HSI);      
  27.   /*!< sEE_I2C Periph clock enable */
  28.   RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2 , ENABLE);

  29. /* Connect PXx to I2C_SCL*/
  30.   GPIO_PinAFConfig( GPIOB , GPIO_PinSource10, GPIO_AF_1);
  31.   /* Connect PXx to I2C_SDA*/
  32.    GPIO_PinAFConfig( GPIOB ,GPIO_PinSource11, GPIO_AF_1);
  33.   /*!< GPIO configuration */  
  34.   /*!< Configure sEE_I2C pins: SCL */
  35.   GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10;
  36.   GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
  37.                 GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
  38.                 GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
  39.   GPIO_InitStruct.GPIO_Speed = GPIO_Speed_Level_3;
  40.   GPIO_Init(GPIOB , &GPIO_InitStruct);
  41.   
  42.   /*!< Configure sEE_I2C pins: SDA */
  43.   GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11;
  44.   GPIO_Init(GPIOB , &GPIO_InitStruct);
  45.        
  46.          
  47.         NVIC_InitStructure.NVIC_IRQChannel = I2C2_IRQn;
  48.         NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
  49. //        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  50.         NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  51.         NVIC_Init(&NVIC_InitStructure);               
  52.          
  53.   /* I2C configuration */
  54.         I2C_InitStruct.I2C_Mode = I2C_Mode_I2C;
  55.   I2C_InitStruct.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
  56.   I2C_InitStruct.I2C_DigitalFilter = 0x00;
  57.   I2C_InitStruct.I2C_OwnAddress1 =0x00;
  58.   I2C_InitStruct.I2C_Ack = I2C_Ack_Enable;
  59.   I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;       
  60.   I2C_InitStruct.I2C_Timing = 0x60801B30;//0x10D05D84;100KHz
  61.   /* Apply I2C configuration after enabling it */
  62.   I2C_Init(I2C2, &I2C_InitStruct);
  63.   /* I2C Peripheral Enable */
  64.   I2C_Cmd(I2C2, ENABLE);

  65. }

  66. void Dmx_Config(void)
  67. {
  68.                 GPIO_InitTypeDef  GPIO_InitStructure;
  69.                 USART_InitTypeDef USART_InitStructure;
  70.         NVIC_InitTypeDef NVIC_InitStructure;
  71.                                                
  72.                 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOB, ENABLE);
  73.                 RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE );
  74.        
  75.                 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;//control
  76.                 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  77.                 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  78.                 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  79.                 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  80.                 GPIO_Init(GPIOC, &GPIO_InitStructure);
  81.                                                
  82.                 GPIO_PinAFConfig(GPIOB,GPIO_PinSource6,GPIO_AF_0);
  83.                 GPIO_PinAFConfig(GPIOB,GPIO_PinSource7,GPIO_AF_0);        
  84. /*               
  85.                 *  USART1_TX -> PB6, USART1_RX ->        PB7
  86.                 */
  87.                 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; //发送引脚              
  88.                 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  89.                 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  90.                 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  91.                 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  92.                 GPIO_Init(GPIOB, &GPIO_InitStructure);   

  93.                 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;                 
  94.                 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  95.                 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  96.                 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  97.                 GPIO_Init(GPIOB, &GPIO_InitStructure);  
  98.                
  99.                 NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
  100.                 NVIC_InitStructure.NVIC_IRQChannelPriority = 1;
  101.         //        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  102.                 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  103.                 NVIC_Init(&NVIC_InitStructure);               
  104.                        
  105.                 USART_InitStructure.USART_BaudRate = 250000;//设置串口波特率
  106.                 USART_InitStructure.USART_WordLength = USART_WordLength_9b;//设置数据位
  107.                 USART_InitStructure.USART_StopBits = USART_StopBits_1;//设置停止位
  108.                 USART_InitStructure.USART_Parity = USART_Parity_No;//设置效验位
  109.                 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//设置流控制
  110.                 USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//设置工作模式
  111.                 USART_Init(USART1, &USART_InitStructure); //配置入结构体

  112.                 USART_Cmd(USART1, ENABLE);//使能串口1
  113.                 USART_ClearITPendingBit(USART1, USART_IT_TC);
  114.                 USART_ITConfig(USART1, USART_IT_TC, ENABLE);
  115.                 USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
  116. }

  117. void Panel16v8_Config(void)
  118. {
  119.   GPIO_InitTypeDef GPIO_InitStructure;
  120.   /* Enable the GPIO Clock */
  121.   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
  122.        
  123.   /* Configure the GPIO pin 输出*/
  124.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  125.   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  126. // GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  127.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  128.        
  129.         GPIO_InitStructure.GPIO_Pin = (1 << DD_SCK);
  130.         GPIO_Init(GPIOpinCM006SCK, &GPIO_InitStructure);

  131.         GPIO_InitStructure.GPIO_Pin = (1 << DD_MOSI);
  132.         GPIO_Init(GPIOpinCM006MOSI, &GPIO_InitStructure);
  133.        
  134.         GPIO_InitStructure.GPIO_Pin = (1 << PinCM006Hold0);
  135.         GPIO_Init(GPIOpinCM006Hold0, &GPIO_InitStructure);
  136.         GPIO_InitStructure.GPIO_Pin = (1 << PinCM006Hold1);
  137.         GPIO_Init(GPIOpinCM006Hold1, &GPIO_InitStructure);
  138.         GPIO_InitStructure.GPIO_Pin = (1 << PinCM006Hold2);
  139.         GPIO_Init(GPIOpinCM006Hold2, &GPIO_InitStructure);
  140.         GPIO_InitStructure.GPIO_Pin = (1 << PinCM006Hold3);
  141.         GPIO_Init(GPIOpinCM006Hold3, &GPIO_InitStructure);
  142.        
  143. //输入
  144.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  145. //  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  146.   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//GPIO_PuPd_NOPULL;
  147. // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  148.         GPIO_InitStructure.GPIO_Pin = 1 << PinCM006KeyMenu;
  149.         GPIO_Init(GPIOpinCM006KeyMenu, &GPIO_InitStructure);
  150.        
  151.         GPIO_InitStructure.GPIO_Pin = 1 << PinCM006KeyIncrease;
  152.         GPIO_Init(GPIOpinCM006KeyIncrease, &GPIO_InitStructure);
  153.        
  154.         GPIO_InitStructure.GPIO_Pin = 1 << PinCM006KeyDecrease;
  155.         GPIO_Init(GPIOpinCM006KeyDecrease, &GPIO_InitStructure);
  156.        
  157.         GPIO_InitStructure.GPIO_Pin = 1 << PinCM006KeyEnter;
  158.         GPIO_Init(GPIOpinCM006KeyEnter, &GPIO_InitStructure);
  159.        


  160.        
  161. }



  162. void PFIO_Config(void)
  163. {
  164.   GPIO_InitTypeDef GPIO_InitStructure;
  165.   /* Enable the GPIO Clock */
  166.         RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA|RCC_AHBPeriph_GPIOB|RCC_AHBPeriph_GPIOC, ENABLE);

  167.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  168.   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  169.   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  170.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  171. // 电机驱动
  172.        
  173.         GPIO_InitStructure.GPIO_Pin  = (1 << PinMotorDriveEnable);
  174.         GPIO_Init(GPIOpinMotorDriveEnable, &GPIO_InitStructure);
  175.         MotorDriveDisable();

  176. //输入
  177.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  178.   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  179.        
  180.         GPIO_InitStructure.GPIO_Pin = (1 << PinPanHomeSense);          // Pan
  181.         GPIO_Init(GPIO_PanHomeSense, &GPIO_InitStructure);

  182.         GPIO_InitStructure.GPIO_Pin = (1 << PinTiltHomeSense);    // Tilt
  183.         GPIO_Init(GPIO_TiltHomeSense, &GPIO_InitStructure);       

  184. // MIC AD
  185.        

  186.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN ;
  187.         GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  188.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  189.         GPIO_InitStructure.GPIO_Pin = (1 << PinAD);
  190.         GPIO_Init(GPIOpinAD, &GPIO_InitStructure);       
  191.        
  192. }



  193. void IoInitial(void)
  194. {
  195.        
  196.                 /*--------系统时钟设置 20000 == 50us*/
  197.         if (SysTick_Config(SystemCoreClock / 20000))
  198.   {
  199.    while (1);
  200.   }
  201.         MemoryRemapConfig();//升级用的?
  202.        
  203.         I2C_Configuration();
  204.         Dmx_Config();
  205.        
  206.         AdcInitial();
  207.         PFIO_Config();
  208.         Panel16v8_Config();
  209. }
我程序的初始化时这样的,一开始板子是刚焊好,没程序的,烧录进去之后,重新烧写就不行了。是不是我增加了MemoryRemapConfig();//升级用的?这里导致后面用STlink连接都连接不上
1.png
有谁知道吗,搞不明白了
戈卫东 发表于 2016-5-30 23:06 | 显示全部楼层
应该不是吧?没有仔细看。
可能是JTAG/SWD管脚被占了?
泰山特曲123 发表于 2016-5-31 12:42 来自手机 | 显示全部楼层
用镊子将芯片的复位脚短接到地,让他保持复位,然后再用st link擦除
wahe2008 发表于 2016-5-31 16:10 | 显示全部楼层
可能是软件复位失灵了,手动复位一下看看
xmshao 发表于 2016-5-31 16:12 | 显示全部楼层
可能你的代码起作用了。
你代码里到底做了些什么知道否?

你长按住复位键,没键用镊子也行,然后点击TARGET/connect ,同时松开复位,应该可以连上的。
mohanwei 发表于 2016-5-31 18:34 | 显示全部楼层
不用看了,肯定是你没接nReset这个引脚
其它系列接SWCLK,SWDIO,GND这3个针就行。F0要加上nReset
 楼主| lizhenming 发表于 2016-5-31 19:07 | 显示全部楼层
xmshao 发表于 2016-5-31 16:12
可能你的代码起作用了。
你代码里到底做了些什么知道否?

如果跑程序的时候那两个引脚需要作为IO口使用,程序怎么设置SWD
 楼主| lizhenming 发表于 2016-5-31 19:07 | 显示全部楼层
mohanwei 发表于 2016-5-31 18:34
不用看了,肯定是你没接nReset这个引脚
其它系列接SWCLK,SWDIO,GND这3个针就行。F0要加上nReset ...

不关reset的事呢
desertsailor 发表于 2016-6-1 22:22 | 显示全部楼层
lizhenming 发表于 2016-5-31 19:07
如果跑程序的时候那两个引脚需要作为IO口使用,程序怎么设置SWD

如果下载口的IO在应用程序中配置为输出的模式可能导致这种情况,但此时仍可用串口下载程序,如果非得使用这些IO,建议在系统初始化之前加一定时间的延时,确保芯片上电后有一段时间下载口IO是没有配置为输出模式的,这样下载程序时只要按压板子上的复位按钮,然后再迅速使用仿真器连接就可以下载了。
xmshao 发表于 2016-6-2 15:07 | 显示全部楼层
lizhenming 发表于 2016-5-31 19:07
如果跑程序的时候那两个引脚需要作为IO口使用,程序怎么设置SWD

你如果想把SWD的那两个脚做IO是也可以的,通过GPIOX_MODER配置就好

对于空片的话,第一次用SWD口烧录的话没啥不方便。 当第二次烧录SWD口被当io用的程序时可能有点不方便。但也能烧,摁住复位键,连接的同时释放复位键也可以。

当然,你也可以通过其它串口ISP的方式进行程序烧录。
flydream0 发表于 2016-6-2 17:40 | 显示全部楼层
3种方法任你选择:
1: 确保烧录器有连接reset线,在STM32 ST-Link Utility工具下
Targett->Settings->Mode 下拉列表选择 Connect Under Reset
这样在烧录试试。

2 手动按住reset不放,在点击烧录的瞬间放开,没试个20次不要说已经试过了。

3 使用串口bootloader ISP 工具将芯片擦除后再烧录。
 楼主| lizhenming 发表于 2016-6-15 11:53 | 显示全部楼层
desertsailor 发表于 2016-6-1 22:22
如果下载口的IO在应用程序中配置为输出的模式可能导致这种情况,但此时仍可用串口下载程序,如果非得使用 ...

按住RESET,迅速放开是可以的,但是这样太麻烦了,我不想在板子上搞个复位按钮,因为这样太麻烦了,延时一段时间应该是可以的
flydream0 发表于 2016-6-15 12:08 | 显示全部楼层
Connect Under Reset,界面提示这个,你有没有试下?记得要连上复位线。
E-Kaia 发表于 2016-6-15 22:24 | 显示全部楼层
你用的是什么样的下载硬件了?
capturesthe 发表于 2016-6-16 08:35 | 显示全部楼层
和程序没关系,开始我用stlink也下载不了,后来用cmsis-dap就可以了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

22

主题

129

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部