你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

陈酿!四年陈的STM32F103外设测试代码!希望对你有帮助~~~ 精华  

[复制链接]
Dylan疾风闪电 发布时间:2016-1-7 14:26
阅读主题, 点击返回1楼
收藏 22 评论60 发布时间:2016-1-7 14:26
60个回答
Dylan疾风闪电 回答时间:2016-1-7 15:05:09
  1. /**
  2.   ******************************************************************************
  3.   * @file /CRC_Example.h
  4.   * @author    xd.wu
  5.   * @version   V1.0
  6.   * @date     2012-4-14
  7.   * @brief    CRC:以多项式(0x4C11DB7)进行CRC计算得到一个32位的值
  8.   use CRC  calculation unit to get a CRC code of a given buffer of data word,
  9.   based on a fixed generator polynomial(0x4C11DB7).
  10.   使用循环冗余校验(CRC) 以CRC-32(以太网)多项式(0x4C11DB7)为基础 得到一个32位的CRC计算结果
  11.   CRC技术主要应用于核实数据传输或者数据存储的正确性和完整性。
  12.   ******************************************************************************
  13.   *用途:校验一组数据
  14.   CRC->DR:写操作时,作为输入寄存器,可以输入要进行CRC计算的新数据。
  15.           读操作时,返回上一次CRC计算的结果。
  16.   每一次写入数据寄存器,其计算结果是前一次CRC计算结果和新计算结果的组合(对整个32位字进行CRC计算,而不是逐字节地计算)。
  17.   */
  18.   /*实例应用步骤:
  19.   //1."main.cpp"调用fmain()
  20.   
  21.   //2.Watch中观察
  22.   LED
  23.   */

  24. #ifndef __CRC_EXAMPLE_H
  25. #define __CRC_EXAMPLE_H
  26. /* Includes ------------------------------------------------------------------*/
  27. #include "std32periph.h"

  28. /* Private typedef -----------------------------------------------------------*/
  29. /* Private define ------------------------------------------------------------*/
  30. #define BUFFER_SIZE    114
  31. /* Private macro -------------------------------------------------------------*/
  32. /* Private variables ---------------------------------------------------------*/
  33. static uc32 DataBuffer[BUFFER_SIZE] =//const uint32_t
  34. {
  35.   0x00001021, 0x20423063, 0x408450a5, 0x60c670e7, 0x9129a14a, 0xb16bc18c,
  36.   0xd1ade1ce, 0xf1ef1231, 0x32732252, 0x52b54294, 0x72f762d6, 0x93398318,
  37.   0xa35ad3bd, 0xc39cf3ff, 0xe3de2462, 0x34430420, 0x64e674c7, 0x44a45485,
  38.   0xa56ab54b, 0x85289509, 0xf5cfc5ac, 0xd58d3653, 0x26721611, 0x063076d7,
  39.   0x569546b4, 0xb75ba77a, 0x97198738, 0xf7dfe7fe, 0xc7bc48c4, 0x58e56886,
  40.   0x78a70840, 0x18612802, 0xc9ccd9ed, 0xe98ef9af, 0x89489969, 0xa90ab92b,
  41.   0x4ad47ab7, 0x6a961a71, 0x0a503a33, 0x2a12dbfd, 0xfbbfeb9e, 0x9b798b58,
  42.   0xbb3bab1a, 0x6ca67c87, 0x5cc52c22, 0x3c030c60, 0x1c41edae, 0xfd8fcdec,
  43.   0xad2abd0b, 0x8d689d49, 0x7e976eb6, 0x5ed54ef4, 0x2e321e51, 0x0e70ff9f,
  44.   0xefbedfdd, 0xcffcbf1b, 0x9f598f78, 0x918881a9, 0xb1caa1eb, 0xd10cc12d,
  45.   0xe16f1080, 0x00a130c2, 0x20e35004, 0x40257046, 0x83b99398, 0xa3fbb3da,
  46.   0xc33dd31c, 0xe37ff35e, 0x129022f3, 0x32d24235, 0x52146277, 0x7256b5ea,
  47.   0x95a88589, 0xf56ee54f, 0xd52cc50d, 0x34e224c3, 0x04817466, 0x64475424,
  48.   0x4405a7db, 0xb7fa8799, 0xe75ff77e, 0xc71dd73c, 0x26d336f2, 0x069116b0,
  49.   0x76764615, 0x5634d94c, 0xc96df90e, 0xe92f99c8, 0xb98aa9ab, 0x58444865,
  50.   0x78066827, 0x18c008e1, 0x28a3cb7d, 0xdb5ceb3f, 0xfb1e8bf9, 0x9bd8abbb,
  51.   0x4a755a54, 0x6a377a16, 0x0af11ad0, 0x2ab33a92, 0xed0fdd6c, 0xcd4dbdaa,
  52.   0xad8b9de8, 0x8dc97c26, 0x5c644c45, 0x3ca22c83, 0x1ce00cc1, 0xef1fff3e,
  53.   0xdf7caf9b, 0xbfba8fd9, 0x9ff86e17, 0x7e364e55, 0x2e933eb2, 0x0ed11ef0
  54. };

  55. vu32 CRCValue = 0;
  56. /* Private functions ---------------------------------------------------------*/

  57. void fmain(void)
  58. {
  59.   RCC_HSEConf(9);//72M

  60.   /* Enable CRC clock */
  61.   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE);

  62.   /* Compute the CRC of "DataBuffer" */
  63.   //CRCValue = CRC_CalcBlockCRC((u32 *)DataBuffer, BUFFER_SIZE);//此行代码的实现如下
  64.   CRC->CR = 0x1;//复位CRC->DR:如不进行复位,可能残留DR值,导致计算过程不是预期的
  65.   for(u8 index = 0; index < BUFFER_SIZE; index++)
  66.   {
  67.     CRC->DR = DataBuffer[index];
  68.   }
  69.   CRCValue = CRC->DR;
  70. }

  71. #endif
  72. /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
复制代码
Dylan疾风闪电 回答时间:2016-1-7 15:05:25
  1. /**
  2.   ******************************************************************************
  3.   * @file /DAC_2ChTriangleWave.h
  4.   * @author    xd.wu
  5.   * @version   V1.0
  6.   * @date     2012-4-14
  7.   * @brief    DAC:使用不同三角波发生器的同时触发
  8.   ******************************************************************************
  9.   *
  10.   */
  11.   /*实例应用步骤:
  12.   //1."main.cpp"调用fmain()
  13.   
  14.   //4.Watch中观察
  15.   DAC_DOR1
  16.   DAC_DOR2
  17.   */

  18. #ifndef __DAC_2CHTRIANGLEWAVE_H
  19. #define __DAC_2CHTRIANGLEWAVE_H
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "std32periph.h"

  22. /* Private typedef -----------------------------------------------------------*/
  23. /* Private define ------------------------------------------------------------*/
  24. /* Private macro -------------------------------------------------------------*/
  25. /* Private variables ---------------------------------------------------------*/
  26. /* Private functions ---------------------------------------------------------*/

  27. void fmain(void)
  28. {
  29.   RCC_HSEConf(7);//56M

  30.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  31.   RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC | RCC_APB1Periph_TIM2, ENABLE);
  32.   //复位DAC
  33.   RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC, ENABLE);
  34.   RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC, DISABLE);


  35.   GPIO_InitTypeDef GPIO_InitStructure;
  36.   GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_4 | GPIO_Pin_5;
  37.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  38.   GPIO_Init(GPIOA, &GPIO_InitStructure);


  39.   /* TIM2 Configuration */
  40.   TIM_TimeBaseInitTypeDef    TIM_TimeBaseStructure;
  41.   TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
  42.   TIM_TimeBaseStructure.TIM_Period = 0xF;         
  43.   TIM_TimeBaseStructure.TIM_Prescaler = 0xF;      
  44.   TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;   
  45.   TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  
  46.   TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

  47.   /* TIM2 TRGO selection */
  48.   TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update);

  49.   /* DAC channel1 Configuration */
  50.   DAC_InitTypeDef            DAC_InitStructure;
  51.   DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO;
  52.   DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_Triangle;
  53.   DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_2047;
  54.   DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
  55.   DAC_Init(DAC_Channel_1, &DAC_InitStructure);
  56.   /* DAC channel2 Configuration */
  57.   DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_1023;
  58.   DAC_Init(DAC_Channel_2, &DAC_InitStructure);

  59.   DAC_Cmd(DAC_Channel_1, ENABLE);
  60.   DAC_Cmd(DAC_Channel_2, ENABLE);

  61.   DAC_SetDualChannelData(DAC_Align_12b_R, 0x100, 0x100);/* Set DAC dual channel DHR12RD register */

  62.   TIM_Cmd(TIM2, ENABLE);
  63. }

  64. #endif
  65. /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
复制代码
Dylan疾风闪电 回答时间:2016-1-7 15:05:40
  1. /**
  2.   ******************************************************************************
  3.   * @file /DAC_DMAEscalator.h
  4.   * @author    xd.wu
  5.   * @version   V1.0
  6.   * @date     2012-4-14
  7.   * @brief    DAC:DMA输出梯形波
  8.   ******************************************************************************
  9.   *
  10.   */
  11.   /*实例应用步骤:
  12.   //1."main.cpp"调用fmain()
  13.   
  14.   //4.Watch中观察
  15.   DAC_DHR12RD
  16.   */

  17. #ifndef __DAC_DMAESCALATOR_H
  18. #define __DAC_DMAESCALATOR_H
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "std32periph.h"

  21. /* Private typedef -----------------------------------------------------------*/
  22. /* Private define ------------------------------------------------------------*/
  23. /* Private macro -------------------------------------------------------------*/
  24. /* Private variables ---------------------------------------------------------*/
  25. uc8 Escalator8bit[6] = {0x0, 0x33, 0x66, 0x99, 0xCC, 0xFF};
  26. /* Private functions ---------------------------------------------------------*/

  27. void fmain(void)
  28. {
  29.   RCC_HSEConf(7);//56M

  30.   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);
  31.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  32.   RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC | RCC_APB1Periph_TIM6, ENABLE);
  33.   //复位DAC
  34.   RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC, ENABLE);
  35.   RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC, DISABLE);


  36.   GPIO_InitTypeDef GPIO_InitStructure;
  37.   GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_4;
  38.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  39.   GPIO_Init(GPIOA, &GPIO_InitStructure);


  40.   /* TIM6 Configuration */
  41.   TIM_PrescalerConfig(TIM6, 0xF, TIM_PSCReloadMode_Update);
  42.   TIM_SetAutoreload(TIM6, 0xFF);
  43.   /* TIM6 TRGO selection */
  44.   TIM_SelectOutputTrigger(TIM6, TIM_TRGOSource_Update);


  45.   // DAC channel1 Configuration:MAMP1[]=0111、WAVE1[]=10、TSEL1[]=000、TEN1=1、BOFF1=1
  46.   DAC->CR &= 0xFFFFF000;
  47.   DAC->CR |= 0x00000786;

  48.   /* DMA2 channel3 configuration */
  49.   DMA_InitTypeDef            DMA_InitStructure;
  50.   DMA_InitStructure.DMA_PeripheralBaseAddr = 0x40007410;//DAC_DHR8R1_Address;
  51.   DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&Escalator8bit;
  52.   DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
  53.   DMA_InitStructure.DMA_BufferSize = 6;
  54.   DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  55.   DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
  56.   DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
  57.   DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
  58.   DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
  59.   DMA_InitStructure.DMA_Priority = DMA_Priority_High;
  60.   DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
  61.   DMA_Init(DMA2_Channel3, &DMA_InitStructure);
  62.   DMA_Cmd(DMA2_Channel3, ENABLE);

  63.   DAC_Cmd(DAC_Channel_1, ENABLE);

  64.   DAC_DMACmd(DAC_Channel_1, ENABLE);

  65.   TIM_Cmd(TIM6, ENABLE);
  66. }

  67. #endif
  68. /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
复制代码
Dylan疾风闪电 回答时间:2016-1-7 15:05:55
  1. /**
  2.   ******************************************************************************
  3.   * @file /DAC_DualModeDMASineWave.h
  4.   * @author    xd.wu
  5.   * @version   V1.0
  6.   * @date     2012-4-14
  7.   * @brief    DAC:双DAC通道转换
  8.   DAC集成了3个供双DAC模式使用的寄存器:DHR8RD、DHR12RD和DHR12LD,
  9.   只需要访问一个寄存器即可完成同时驱动2个DAC通道的操作。
  10.   ******************************************************************************
  11.   *用途:双路波形输出,可做简易示波器
  12.   */
  13.   /*实例应用步骤:
  14.   //1."main.cpp"调用fmain()
  15.   
  16.   //4.Watch中观察
  17.   DAC_DHR12RD
  18.   */

  19. #ifndef __DAC_DUALMODEDMASINEWAVE_H
  20. #define __DAC_DUALMODEDMASINEWAVE_H
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "std32periph.h"

  23. /* Private typedef -----------------------------------------------------------*/
  24. /* Private define ------------------------------------------------------------*/
  25. /* Private macro -------------------------------------------------------------*/
  26. /* Private variables ---------------------------------------------------------*/
  27. uc16 Sine12bit[32] =
  28. {
  29.   0x0026, 0x009B, 0x0158, 0x0257, 0x038D, 0x04EF, 0x066F, 0x07FF, 0x098F, 0x0B0F, 0x0C71, 0x0DAA, 0x0EA6, 0x0F63, 0x0FD8, 0x0FFF,
  30.   0x0FD8, 0x0F63, 0x0EA6, 0x0DAA, 0x0C71, 0x0B0F, 0x098F, 0x07FF, 0x066F, 0x04EF, 0x038D, 0x0257, 0x0158, 0x009B, 0x0026, 0x0000
  31. };

  32. u32 DualSine12bit[32];
  33. /* Private functions ---------------------------------------------------------*/

  34. void fmain(void)
  35. {
  36.   RCC_HSEConf(7);//56M

  37.   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);
  38.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_TIM8, ENABLE);
  39.   RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
  40.   //复位DAC
  41.   RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC, ENABLE);
  42.   RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC, DISABLE);


  43.   GPIO_InitTypeDef GPIO_InitStructure;
  44.   GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_4 | GPIO_Pin_5;
  45.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  46.   GPIO_Init(GPIOA, &GPIO_InitStructure);


  47.   /* TIM8 Configuration */
  48.   TIM_TimeBaseInitTypeDef    TIM_TimeBaseStructure;
  49.   TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
  50.   TIM_TimeBaseStructure.TIM_Period = 0x19;         
  51.   TIM_TimeBaseStructure.TIM_Prescaler = 0x0;      
  52.   TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;   
  53.   TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  
  54.   TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);
  55.   /* TIM8 TRGO selection */
  56.   TIM_SelectOutputTrigger(TIM8, TIM_TRGOSource_Update);

  57.   // DAC channel1,2 Configuration:WAVE1/2[]=00、TSEL1/2[]=001、TEN1/2=1、BOFF1/2=1
  58.   DAC->CR &= 0xFF00FF00;
  59.   DAC->CR |= 0x000E000E;

  60.   /* Fill Sine32bit table */
  61.   for (u8 Idx= 0; Idx<32; Idx++)
  62.   {
  63.     DualSine12bit[Idx] = (Sine12bit[Idx] << 16) + (Sine12bit[Idx]);
  64.   }

  65.   /* DMA2 channel4 configuration */
  66.   DMA_InitTypeDef            DMA_InitStructure;
  67.   DMA_InitStructure.DMA_PeripheralBaseAddr = 0x40007420;//DAC_DHR12RD_Address;
  68.   DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&DualSine12bit;
  69.   DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
  70.   DMA_InitStructure.DMA_BufferSize = 32;
  71.   DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  72.   DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
  73.   DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
  74.   DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
  75.   DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
  76.   DMA_InitStructure.DMA_Priority = DMA_Priority_High;
  77.   DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
  78.   DMA_Init(DMA2_Channel4, &DMA_InitStructure);
  79.   DMA_Cmd(DMA2_Channel4, ENABLE);

  80.   DAC_Cmd(DAC_Channel_1, ENABLE);
  81.   DAC_Cmd(DAC_Channel_2, ENABLE);

  82.   /* Enable DMA for DAC Channel2 */
  83.   DAC_DMACmd(DAC_Channel_2, ENABLE);//最终DAC->CR = 0x100F000F;

  84.   TIM_Cmd(TIM8, ENABLE);
  85. }

  86. #endif
  87. /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
复制代码
Dylan疾风闪电 回答时间:2016-1-7 15:06:13
  1. /**
  2.   ******************************************************************************
  3.   * @file /DAC_NoiseWave.h
  4.   * @author    xd.wu
  5.   * @version   V1.0
  6.   * @date     2012-4-14
  7.   * @brief    DAC:噪声生成
  8.   可以利用线性反馈移位寄存器(Linear Feedback Shift Register LFSR)产生幅度变化的伪噪声。
  9.   设置WAVE[1:0]位为’01’选择DAC噪声生成功能。
  10.   寄存器LFSR的预装入值为0xAAA。
  11.   按照特定算法,在每次触发事件后3个APB1时钟周期之后更新该寄存器的值。
  12.   ******************************************************************************
  13.   *用途:伪噪声生成器
  14.   */
  15.   /*实例应用步骤:
  16.   //1."main.cpp"调用fmain()
  17.   
  18.   //4.Watch中观察
  19.   DAC_DHR12LD
  20.   */

  21. #ifndef __DAC_NOISEWAVE_H
  22. #define __DAC_NOISEWAVE_H
  23. /* Includes ------------------------------------------------------------------*/
  24. #include "std32periph.h"

  25. /* Private typedef -----------------------------------------------------------*/
  26. /* Private define ------------------------------------------------------------*/
  27. /* Private macro -------------------------------------------------------------*/
  28. /* Private variables ---------------------------------------------------------*/
  29. /* Private functions ---------------------------------------------------------*/

  30. void fmain(void)
  31. {
  32.   RCC_HSEConf(7);//56M

  33.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  34.   RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
  35.   //复位DAC
  36.   RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC, ENABLE);
  37.   RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC, DISABLE);


  38.   GPIO_InitTypeDef GPIO_InitStructure;
  39.   GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_4;
  40.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  41.   GPIO_Init(GPIOA, &GPIO_InitStructure);


  42.   // DAC channel1 Configuration:MAMP1[]=1000、WAVE1[]=01、TSEL1[]=111、TEN1=1、BOFF1=0、EN1=0
  43.   DAC->CR &= 0xFFFFF000;
  44.   DAC->CR |= 0x0000087C;  //设置WAVE[1:0]位为’01’选择DAC噪声生成功能。
  45.   DAC_Cmd(DAC_Channel_1, ENABLE);

  46.   DAC_SetChannel1Data(DAC_Align_12b_L, 0x7FF0);/* Set DAC Channel1 DHR12L register */
  47.   
  48.   while(1)
  49.   {
  50.     DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);/* Start DAC Channel1 conversion by software */
  51.   }
  52. }

  53. #endif
  54. /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
复制代码
Dylan疾风闪电 回答时间:2016-1-7 15:06:27
  1. /**
  2.   ******************************************************************************
  3.   * @file /DEBUG.h
  4.   * @author    xd.wu
  5.   * @version   V1.0
  6.   * @date     2012-4-19
  7.   * @brief    DEBUG:
  8.   ******************************************************************************
  9.   *用途:方便差错
  10.   */
  11.   /*实例应用步骤:
  12.   //1."main.cpp"调用fmain()修改以下函数
  13.   
  14.   #define __DEBUG_Example
  15.   void assert_failed(uint8_t* file, uint32_t line)
  16.   {
  17.       // User can add his own implementation to report the file name and line number,
  18.          ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line)
  19.     #ifdef __DEBUG_Example
  20.       printf("Wrong parameters value: file %s on line %d\r\n", file, line);
  21.     #else
  22.       // Infinite loop
  23.       while (1)
  24.       {
  25.       }
  26.     #endif
  27.   }

  28.   //2.PC端USART配置
  29.    - Connect a null-modem female/female RS232 cable between the DB9 connector
  30.         CN2(USART1) and PC serial port.
  31.    
  32.   
  33.    - Hyperterminal configuration:
  34.       - Word Length = 8 Bits
  35.       - One Stop Bit
  36.       - No parity
  37.       - BaudRate = 115200 baud
  38.       - flow control: None

  39.   //3.Terminal I/O中观察
  40.   显示printf的字符串和错误信息
  41.   STM32F10x Firmware Library compiled in DEBUG mode...
  42.   ...Run-time checking enabled

  43.   Wrong parameters value: file D:\xd_ST_ARM\(中文名乱码)\STM32F10x_StdPeriph_Driver\src\stm32f10x_rcc.cpp on line 1136
  44.   */

  45. #ifndef __DEBUG_H
  46. #define __DEBUG_H
  47. /* Includes ------------------------------------------------------------------*/
  48. #include "std32periph.h"
  49. #include <stdio.h>

  50. /* Private typedef -----------------------------------------------------------*/
  51. /* Private define ------------------------------------------------------------*/
  52. #ifdef __GNUC__
  53.   /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
  54.      set to 'Yes') calls __io_putchar() */
  55.   #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
  56. #else
  57.   #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
  58. #endif /* __GNUC__ */
  59. /* Private macro -------------------------------------------------------------*/
  60. /* Private variables ---------------------------------------------------------*/
  61. /* Private functions ---------------------------------------------------------*/

  62. void fmain(void)
  63. {
  64.   RCC_HSEConf(9);//72M
  65.   
  66.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
  67.   
  68.   
  69.   GPIO_InitTypeDef GPIO_InitStructure;
  70.   /* Configure USART1 Tx (PA.09) as alternate function push-pull */
  71.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  72.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  73.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  74.   GPIO_Init(GPIOA, &GPIO_InitStructure);
  75.   /* Configure USART1 Rx (PA.10) as input floating */
  76.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  77.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  78.   GPIO_Init(GPIOA, &GPIO_InitStructure);
  79.   

  80. /* USART1 configuration ------------------------------------------------------*/
  81.   /* USART1 configured as follow:
  82.         - BaudRate = 115200 baud  
  83.         - Word Length = 8 Bits
  84.         - One Stop Bit
  85.         - No parity
  86.         - Hardware flow control disabled (RTS and CTS signals)
  87.         - Receive and transmit enabled
  88.   */
  89.   USART_InitTypeDef USART_InitStructure;
  90.   USART_InitStructure.USART_BaudRate = 115200;
  91.   USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  92.   USART_InitStructure.USART_StopBits = USART_StopBits_1;
  93.   USART_InitStructure.USART_Parity = USART_Parity_No;
  94.   USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  95.   USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  96.   USART_Init(USART1, &USART_InitStructure);
  97.   USART_Cmd(USART1, ENABLE);
  98.   
  99.   //在PC端串口助手显示
  100.   u8 buff[] = "\r\n STM32F10x Firmware Library compiled in DEBUG mode... \n\r...Run-time checking enabled  \n\r";
  101.   u8 *p = buff;
  102.   u16 SR = USART1->SR;
  103.   #define ARR_SIZE(a) (sizeof(a)/sizeof(a[0]))//返回数组元素的个数
  104.   u8 len = ARR_SIZE(buff);
  105.   for(u8 i=0; i<len; i++)
  106.   {
  107.     USART1->DR = *p++;
  108.     while ((USART1->SR & 0x0040) == 0);
  109.   }
  110.   
  111.   //在IAR软件的输出窗口显示
  112.   printf("\r\n STM32F10x Firmware Library compiled in DEBUG mode... \n\r");
  113.   printf("...Run-time checking enabled  \n\r");
  114.   
  115.   //产生错误信息:错误的SPI时钟使能
  116.   /* Simulate wrong parameter passed to library function ---------------------*/
  117.   /* To enable SPI1 clock, RCC_APB2PeriphClockCmd function must be used and
  118.      not RCC_APB1PeriphClockCmd*/
  119.   RCC_APB1PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
  120.   
  121.   /* Some member of GPIOA_InitStructure structure are not initialized */
  122.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
  123.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  124.   /* GPIOA_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; */
  125.   GPIO_Init(GPIOA, &GPIO_InitStructure);
  126. }

  127. #endif
  128. /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
复制代码
Dylan疾风闪电 回答时间:2016-1-7 15:06:46
  1. /**
  2.   ******************************************************************************
  3.   * @file /DMA_ADC_TIM1.h
  4.   * @author    xd.wu
  5.   * @version   V1.0
  6.   * @date     2012-4-14
  7.   * @brief    DMA:通过DMA将ADC采样 反映为TIM1_CH1的脉冲频率(CCR1)
  8.   use a DMA channel to transfer continuously a data from a peripheral (ADC1)
  9.   to another peripheral (TIM1) supporting DMA transfer.
  10.   ******************************************************************************
  11.   *用途:可改为ADC->DR 直接通过 USART->DR等
  12.   */
  13.   /*实例应用步骤:
  14.   //1."main.cpp"调用fmain()
  15.   
  16.   //2.Watch中观察
  17.   TIM1_CCR1
  18.   ADC1_DR
  19.   */

  20. #ifndef __DMA_ADC_TIM1_H
  21. #define __DMA_ADC_TIM1_H
  22. /* Includes ------------------------------------------------------------------*/
  23. #include "std32periph.h"

  24. /* Private typedef -----------------------------------------------------------*/
  25. /* Private define ------------------------------------------------------------*/
  26. #define ADC1_DR_Address     0x4001244C
  27. #define TIM1_CCR1_Address   0x40012C34
  28. /* Private macro -------------------------------------------------------------*/
  29. /* Private variables ---------------------------------------------------------*/
  30. /* Private functions ---------------------------------------------------------*/

  31. void fmain(void)
  32. {
  33.   RCC_HSEConf(7);//56M

  34.   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
  35.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC |
  36.                          RCC_APB2Periph_ADC1 | RCC_APB2Periph_TIM1, ENABLE);
  37.   //复位ADC
  38.   RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1, ENABLE);
  39.   RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1, DISABLE);


  40.   GPIO_InitTypeDef GPIO_InitStructure;
  41.   /* Configure TIM1 Channel1 output */
  42.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
  43.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  44.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  45.   GPIO_Init(GPIOA, &GPIO_InitStructure);
  46.   /* Configure ADC Channel14 as analog input */
  47.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4  ;
  48.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  49.   GPIO_Init(GPIOC, &GPIO_InitStructure);


  50.   /* DMA1 Channel5 configuration ----------------------------------------------*/
  51.   DMA_InitTypeDef           DMA_InitStructure;
  52.   DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)TIM1_CCR1_Address;
  53.   DMA_InitStructure.DMA_MemoryBaseAddr = (u32)ADC1_DR_Address;
  54.   DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
  55.   DMA_InitStructure.DMA_BufferSize = 1;
  56.   DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  57.   DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
  58.   DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
  59.   DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
  60.   DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
  61.   DMA_InitStructure.DMA_Priority = DMA_Priority_High;
  62.   DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
  63.   DMA_Init(DMA1_Channel5, &DMA_InitStructure);
  64.   /* Enable DMA1 Channel5 */
  65.   DMA_Cmd(DMA1_Channel5, ENABLE);

  66.   /* ADC1 configuration ------------------------------------------------------*/
  67.   ADC_InitTypeDef           ADC_InitStructure;
  68.   ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
  69.   ADC_InitStructure.ADC_ScanConvMode = DISABLE;
  70.   ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
  71.   ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
  72.   ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
  73.   ADC_InitStructure.ADC_NbrOfChannel = 1;
  74.   ADC_Init(ADC1, &ADC_InitStructure);
  75.   ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_55Cycles5);

  76.   // TIM1_channel1:PWM mode、 TIM输出比较极性低、0x7F
  77.   // F = TIMxCLK/(PSC+1)/(ARR+1)  (56/2*2)/4=14M *0x7F
  78.   TIM1->PSC = 3;
  79.   TIM1->ARR = 0xFF0;
  80.   TIM1->CR1 = 0x0000;
  81.   TIM1->CCMR1 &= 0xFF00;
  82.   TIM1->CCMR1 |= 0x0060;
  83.   TIM1->CCER &= 0xFFF0;
  84.   TIM1->CCER |= 0x0001;

  85.   TIM_Cmd(TIM1, ENABLE);
  86.   TIM_CtrlPWMOutputs(TIM1, ENABLE);

  87.   TIM_DMACmd(TIM1, TIM_DMA_Update, ENABLE);

  88.   ADC_Cmd(ADC1, ENABLE);
  89.   ADC_ResetCalibration(ADC1);
  90.   while(ADC_GetResetCalibrationStatus(ADC1));
  91.   ADC_StartCalibration(ADC1);
  92.   while(ADC_GetCalibrationStatus(ADC1));

  93.   ADC_SoftwareStartConvCmd(ADC1, ENABLE);
  94. }

  95. #endif
  96. /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
复制代码
Dylan疾风闪电 回答时间:2016-1-7 15:12:13
  1. /**
  2.   ******************************************************************************
  3.   * @file /DMA_FlashRAM.h
  4.   * @author    xd.wu
  5.   * @version   V1.0
  6.   * @date     2012-4-15
  7.   * @brief    DMA:从ROM中拷贝数组常量到RAM中 (存在弊端,不复位的情况下可能 FAILED)
  8.   ******************************************************************************
  9.   *用途:快速读取ROM
  10.   */
  11.   /*实例应用步骤:
  12.   //1."main.cpp"调用fmain()
  13.   
  14.   //2."stm32f10x_it.cpp"拷贝
  15.   extern vu16 CurrDataCounterEnd;
  16.   void DMA1_Channel6_IRQHandler(void)
  17.   {
  18.     if(DMA_GetITStatus(DMA1_IT_TC6))
  19.     {
  20.       CurrDataCounterEnd = DMA_GetCurrDataCounter(DMA1_Channel6);
  21.       DMA_ClearITPendingBit(DMA1_IT_GL6);
  22.     }
  23.   }

  24.   //3."stm32f10x_it.h"声明
  25.   void DMA1_Channel6_IRQHandler(void);

  26.   //4.Watch中观察
  27.   SRC_Const_Buffer[]
  28.   DST_Buffer[]
  29.   */

  30. #ifndef __DMA_FLASHRAM_H
  31. #define __DMA_FLASHRAM_H
  32. /* Includes ------------------------------------------------------------------*/
  33. #include "std32periph.h"

  34. /* Private typedef -----------------------------------------------------------*/
  35. typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus;
  36. /* Private define ------------------------------------------------------------*/
  37. #define BufferSize  32
  38. /* Private macro -------------------------------------------------------------*/
  39. /* Private variables ---------------------------------------------------------*/
  40. vu16 CurrDataCounterBegin = 0, CurrDataCounterEnd = 0;
  41. volatile TestStatus TransferStatus = FAILED;
  42. uc32 SRC_Const_Buffer[BufferSize]= {0x01020304,0x05060708,0x090A0B0C,0x0D0E0F10,
  43.                                     0x11121314,0x15161718,0x191A1B1C,0x1D1E1F20,
  44.                                     0x21222324,0x25262728,0x292A2B2C,0x2D2E2F30,
  45.                                     0x31323334,0x35363738,0x393A3B3C,0x3D3E3F40,
  46.                                     0x41424344,0x45464748,0x494A4B4C,0x4D4E4F50,
  47.                                     0x51525354,0x55565758,0x595A5B5C,0x5D5E5F60,
  48.                                     0x61626364,0x65666768,0x696A6B6C,0x6D6E6F70,
  49.                                     0x71727374,0x75767778,0x797A7B7C,0x7D7E7F80};
  50. u32 DST_Buffer[BufferSize];
  51. /* Private functions ---------------------------------------------------------*/

  52. TestStatus Buffercmp(uc32* pBuffer, u32* pBuffer1, u16 BufferLength)
  53. {
  54.   while(BufferLength--)
  55.   {
  56.     if(*pBuffer != *pBuffer1)
  57.     {
  58.       return FAILED;
  59.     }
  60.    
  61.     pBuffer++;
  62.     pBuffer1++;
  63.   }

  64.   return PASSED;  
  65. }

  66. void fmain(void)
  67. {
  68.   RCC_HSEConf(9);//72M

  69.   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);

  70.   NVIC_GroupSet(NVIC_PriorityGroup_0, DMA1_Channel6_IRQn, 0);

  71.   /* DMA1 channel6 configuration */
  72.   DMA_InitTypeDef  DMA_InitStructure;
  73.   DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)SRC_Const_Buffer;
  74.   DMA_InitStructure.DMA_MemoryBaseAddr = (u32)DST_Buffer;
  75.   DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
  76.   DMA_InitStructure.DMA_BufferSize = BufferSize;
  77.   DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable;
  78.   DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
  79.   DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
  80.   DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
  81.   DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
  82.   DMA_InitStructure.DMA_Priority = DMA_Priority_High;
  83.   DMA_InitStructure.DMA_M2M = DMA_M2M_Enable;
  84.   DMA_Init(DMA1_Channel6, &DMA_InitStructure);

  85.   /* Enable DMA1 Channel6 Transfer Complete interrupt */
  86.   DMA_ITConfig(DMA1_Channel6, DMA_IT_TC, ENABLE);

  87.   /* Get Current Data Counter value before transfer begins */
  88.   CurrDataCounterBegin = DMA_GetCurrDataCounter(DMA1_Channel6);

  89.   /* Enable DMA1 Channel6 transfer */
  90.   DMA_Cmd(DMA1_Channel6, ENABLE);

  91.   /* Wait the end of transmission */
  92.   while (CurrDataCounterEnd != 0)
  93.   {
  94.   }
  95.   
  96.   /* Check if the transmitted and received data are equal */
  97.   TransferStatus = Buffercmp(SRC_Const_Buffer, DST_Buffer, BufferSize);
  98.   /* TransferStatus = PASSED, if the transmitted and received data
  99.      are the same */
  100.   /* TransferStatus = FAILED, if the transmitted and received data
  101.      are different */
  102. }

  103. #endif
  104. /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
复制代码
Dylan疾风闪电 回答时间:2016-1-7 15:12:29
  1. /**
  2.   ******************************************************************************
  3.   * @file /DMA_FSMC.h
  4.   * @author    xd.wu
  5.   * @version   V1.0
  6.   * @date     2012-4-15
  7.   * @brief    DMA:通过2个DMA通道,
  8.   将32位数据SRC_Const_Buffer[]从FLASH_ROM写入外设FSMC的SRAM,
  9.   然后从外设FSMC的SRAM以8位DST_Buffer[]逐个读取数据存入 (存在弊端,不复位的情况下可能 卡while)
  10.   use two DMA channels to transfer a word data buffer from Flash memory to external SRAM memory
  11.   and to recuperate the written data from external SRAM to be stored in internal SRAM.
  12.   ******************************************************************************
  13.   *用途:快速的将32位数据转换成8位数据
  14.   */
  15.   /*实例应用步骤:
  16.   //1."main.cpp"调用fmain()

  17.   //2.Watch中观察
  18.   SRC_Const_Buffer[]
  19.   DST_Buffer[]
  20.   */

  21. #ifndef __DMA_FSMC_H
  22. #define __DMA_FSMC_H
  23. /* Includes ------------------------------------------------------------------*/
  24. #include "std32periph.h"

  25. /* Private typedef -----------------------------------------------------------*/
  26. typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus;
  27. /* Private define ------------------------------------------------------------*/
  28. #define BufferSize  32
  29. #define Bank1_SRAM3_ADDR    ((u32)0x68000000)
  30. /* Private macro -------------------------------------------------------------*/
  31. /* Private variables ---------------------------------------------------------*/
  32. volatile TestStatus TransferStatus;
  33. uc32 SRC_Const_Buffer[BufferSize]= {0x01020304,0x05060708,0x090A0B0C,0x0D0E0F10,
  34.                             0x11121314,0x15161718,0x191A1B1C,0x1D1E1F20,
  35.                             0x21222324,0x25262728,0x292A2B2C,0x2D2E2F30,
  36.                             0x31323334,0x35363738,0x393A3B3C,0x3D3E3F40,
  37.                             0x41424344,0x45464748,0x494A4B4C,0x4D4E4F50,
  38.                             0x51525354,0x55565758,0x595A5B5C,0x5D5E5F60,
  39.                             0x61626364,0x65666768,0x696A6B6C,0x6D6E6F70,
  40.                             0x71727374,0x75767778,0x797A7B7C,0x7D7E7F80};
  41. u8 DST_Buffer[4*BufferSize], Idx = 0;
  42. /* Private functions ---------------------------------------------------------*/

  43. void FSMC_SRAM_Init(void)
  44. {
  45.   FSMC_NORSRAMInitTypeDef  FSMC_NORSRAMInitStructure;
  46.   FSMC_NORSRAMTimingInitTypeDef  p;
  47.   GPIO_InitTypeDef GPIO_InitStructure;
  48.   
  49.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOG | RCC_APB2Periph_GPIOE |
  50.                          RCC_APB2Periph_GPIOF, ENABLE);
  51.   
  52. /*-- GPIO Configuration ------------------------------------------------------*/
  53.   /* SRAM Data lines configuration */
  54.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 |
  55.                                 GPIO_Pin_10 | GPIO_Pin_14 | GPIO_Pin_15;
  56.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  57.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  58.   GPIO_Init(GPIOD, &GPIO_InitStructure);
  59.   
  60.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
  61.                                 GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 |
  62.                                 GPIO_Pin_15;
  63.   GPIO_Init(GPIOE, &GPIO_InitStructure);
  64.   
  65.   /* SRAM Address lines configuration */
  66.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
  67.                                 GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12 | GPIO_Pin_13 |
  68.                                 GPIO_Pin_14 | GPIO_Pin_15;
  69.   GPIO_Init(GPIOF, &GPIO_InitStructure);
  70.   
  71.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
  72.                                 GPIO_Pin_4 | GPIO_Pin_5;
  73.   GPIO_Init(GPIOG, &GPIO_InitStructure);
  74.   
  75.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13;
  76.   GPIO_Init(GPIOD, &GPIO_InitStructure);
  77.    
  78.   /* NOE and NWE configuration */  
  79.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5;
  80.   GPIO_Init(GPIOD, &GPIO_InitStructure);
  81.   
  82.   /* NE3 configuration */
  83.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  84.   GPIO_Init(GPIOG, &GPIO_InitStructure);
  85.   
  86.   /* NBL0, NBL1 configuration */
  87.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
  88.   GPIO_Init(GPIOE, &GPIO_InitStructure);
  89.   
  90. /*-- FSMC Configuration ------------------------------------------------------*/
  91.   p.FSMC_AddressSetupTime = 0;
  92.   p.FSMC_AddressHoldTime = 0;
  93.   p.FSMC_DataSetupTime = 2;
  94.   p.FSMC_BusTurnAroundDuration = 0;
  95.   p.FSMC_CLKDivision = 0;
  96.   p.FSMC_DataLatency = 0;
  97.   p.FSMC_AccessMode = FSMC_AccessMode_A;

  98.   FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM3;
  99.   FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
  100.   FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
  101.   FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
  102.   FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
  103.   FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
  104.   FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
  105.   FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
  106.   FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
  107.   FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
  108.   FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
  109.   FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
  110.   FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
  111.   FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;

  112.   FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);

  113.   /* Enable FSMC Bank1_SRAM Bank */
  114.   FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE);  
  115. }

  116. TestStatus Buffercmp(uc32* pBuffer, u32* pBuffer1, u16 BufferLength)
  117. {
  118.   while(BufferLength--)
  119.   {
  120.     if(*pBuffer != *pBuffer1)
  121.     {
  122.       return FAILED;
  123.     }
  124.    
  125.     pBuffer++;
  126.     pBuffer1++;
  127.   }

  128.   return PASSED;  
  129. }

  130. void fmain(void)
  131. {
  132.   RCC_HSEConf(9);//72M

  133.   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 | RCC_AHBPeriph_DMA2 | RCC_AHBPeriph_FSMC, ENABLE);

  134.   
  135.   /* FSMC for SRAM and SRAM pins configuration */
  136.   FSMC_SRAM_Init();

  137.   DMA_InitTypeDef    DMA_InitStructure;
  138.   /* Write to FSMC -----------------------------------------------------------*/
  139.   /* DMA2 channel5 configuration */
  140.   DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)SRC_Const_Buffer;
  141.   DMA_InitStructure.DMA_MemoryBaseAddr = (u32)Bank1_SRAM3_ADDR;   
  142.   DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
  143.   DMA_InitStructure.DMA_BufferSize = 32;
  144.   DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable;
  145.   DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
  146.   DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
  147.   DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
  148.   DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
  149.   DMA_InitStructure.DMA_Priority = DMA_Priority_High;
  150.   DMA_InitStructure.DMA_M2M = DMA_M2M_Enable;
  151.   DMA_Init(DMA2_Channel5, &DMA_InitStructure);
  152.   DMA_Cmd(DMA2_Channel5, ENABLE);
  153.   while(!DMA_GetFlagStatus(DMA2_FLAG_TC5));
  154.   DMA_ClearFlag(DMA2_FLAG_TC5);

  155.   /* Read from FSMC ----------------------------------------------------------*/
  156.   /* Destination buffer initialization */
  157.   for(Idx=0; Idx<128; Idx++)
  158.     DST_Buffer[Idx]=0;
  159.   /* DMA1 channel3 configuration */
  160.   DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)Bank1_SRAM3_ADDR;  
  161.   DMA_InitStructure.DMA_MemoryBaseAddr = (u32)DST_Buffer;
  162.   DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
  163.   DMA_InitStructure.DMA_BufferSize = 128;
  164.   DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable;
  165.   DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
  166.   DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
  167.   DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
  168.   DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
  169.   DMA_InitStructure.DMA_Priority = DMA_Priority_High;
  170.   DMA_InitStructure.DMA_M2M = DMA_M2M_Enable;
  171.   DMA_Init(DMA1_Channel3, &DMA_InitStructure);
  172.   DMA_Cmd(DMA1_Channel3, ENABLE);
  173.   while(!DMA_GetFlagStatus(DMA1_FLAG_TC3));
  174.   DMA_ClearFlag(DMA1_FLAG_TC3);

  175.   /* Check if the transmitted and received data are equal */
  176.   TransferStatus = Buffercmp(SRC_Const_Buffer, (u32*)DST_Buffer, BufferSize);
  177.   /* TransferStatus = PASSED, if the transmitted and received data
  178.      are the same */
  179.   /* TransferStatus = FAILED, if the transmitted and received data
  180.      are different */
  181. }

  182. #endif
  183. /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
复制代码
Dylan疾风闪电 回答时间:2016-1-7 15:12:56
  1. /**
  2.   ******************************************************************************
  3.   * @file /EXTI_Example.h
  4.   * @author    xd.wu
  5.   * @version   V1.0
  6.   * @date     2012-4-17
  7.   * @brief    EXTI:按下PB10(Key4) 翻转绿灯(PF6)上的电平
  8.   ******************************************************************************
  9.   *用途:执行外部中断,来切换某些功能
  10.   */
  11.   /*实例应用步骤:
  12.   //1."main.cpp"调用fmain()
  13.   
  14.   //2."stm32f10x_it.cpp"拷贝
  15.   #define GPIO_LED  GPIOF
  16.   void EXTI15_10_IRQHandler(void)
  17.   {
  18.       if(EXTI_GetITStatus(EXTI_Line10) != RESET)
  19.     {
  20.       GPIO_WriteBit(GPIO_LED, GPIO_Pin_6, (BitAction)((1-GPIO_ReadOutputDataBit(GPIO_LED, GPIO_Pin_6))));
  21.   
  22.       EXTI_ClearITPendingBit(EXTI_Line10);
  23.     }
  24.   }
  25.   
  26.   //3."stm32f10x_it.h"声明
  27.   void EXTI15_10_IRQHandler(void);

  28.   //4.Watch中观察
  29.   LED
  30.   */

  31. #ifndef __EXTI_EXAMPLE_H
  32. #define __EXTI_EXAMPLE_H
  33. /* Includes ------------------------------------------------------------------*/
  34. #include "std32periph.h"

  35. /* Private typedef -----------------------------------------------------------*/
  36. /* Private define ------------------------------------------------------------*/
  37.   #define GPIO_LED        GPIOF   
  38.   #define RCC_LED         RCC_APB2Periph_GPIOF
  39.   #define GPIO_EXTI       GPIOB
  40.   #define RCC_EXTI        RCC_APB2Periph_GPIOB
  41. /* Private macro -------------------------------------------------------------*/
  42. /* Private variables ---------------------------------------------------------*/
  43. /* Private functions ---------------------------------------------------------*/

  44. void fmain(void)
  45. {
  46.   RCC_HSEConf(9);//72M

  47.   RCC_APB2PeriphClockCmd(RCC_EXTI | RCC_LED | RCC_APB2Periph_AFIO, ENABLE);
  48.   
  49.   GPIO_InitTypeDef GPIO_InitStructure;
  50.   /* Configure GPIO Led pin 6 as Output push-pull */
  51.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
  52.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  53.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  54.   GPIO_Init(GPIO_LED, &GPIO_InitStructure);
  55.   /* Configure Key Button GPIO Pin as input pull-up (Key Button EXTI Line) */
  56.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  57.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  58.   GPIO_Init(GPIO_EXTI, &GPIO_InitStructure);
  59.   

  60.   //NVIC for EXTI
  61.   NVIC_GroupSet(NVIC_PriorityGroup_0, EXTI15_10_IRQn, 0);

  62.   
  63.   /* Connect Key Button EXTI Line to Key Button GPIO Pin */
  64.   GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource10);
  65.   /* Configure Key Button EXTI Line to generate an interrupt on falling edge */  
  66.   EXTI_InitTypeDef EXTI_InitStructure;
  67.   EXTI_InitStructure.EXTI_Line = EXTI_Line10;
  68.   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  69.   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  70.   EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  71.   EXTI_Init(&EXTI_InitStructure);

  72.   /* Generate software interrupt: simulate a falling edge applied on Key Button EXTI line */
  73.   EXTI_GenerateSWInterrupt(EXTI_Line10);
  74. }

  75. #endif
  76. /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
复制代码

所属标签

STM32团队

意法半导体微控制器和微处理器拥有广泛的产品线,包含低成本的8位单片机和基于ARM® Cortex®-M0、M0+、M3、M4、M33、M7及A7内核并具备丰富外设选择的32位微控制器及微处理器


最新内容

相似技术帖

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
微信公众号二维码 微信公众号
手机版二维码 手机版