[APM32F4] APM32F407替换XXX32F407

[复制链接]
 楼主| kkzz 发表于 2022-11-16 11:00 | 显示全部楼层 |阅读模式
2 底层驱动替换
    更改代码,将STM32的驱动函数替换为APM32的驱动函数,这部分比较繁琐,需要慢慢替换。可根据工程所需外设的驱动进行对照替换。如我们现在的工程主要涉及到的外设有:misc/gpio/spi/fsmc/usart/rcm。可以通过查看两者的参考手册,查看那些寄存器功能基本一致的对应的库函数的功能也基本一致。
2.1 驱动替换方式
     由于前文我们已经将“APM32F407”工程的声明设置为“APM32F40X”,这里我们仅需将涉及外部功能模块的源码文件内的驱动进行替换。通过宏定义的方式以支持不同平台的文件。
如包含头文件时:
  1. #ifdef STM32F40_41xxx



  2.         /** 原 stm32 接口或外设驱动 */



  3.     #include "stm32f4xx.h"



  4. #endif





  5. #ifdef APM32F40X



  6.         /** 替换为 apm32 接口或外设驱动 */



  7.     #include "apm32f4xx.h"



  8.     #include "apm32f4xx_misc.h"



  9.     #include "apm32f4xx_spi.h"



  10.     #include "apm32f4xx_rcm.h"



  11.     #include "apm32f4xx_smc.h"



  12.     #include "apm32f4xx_gpio.h"



  13.     #include "apm32f4xx_usart.h"



  14. #endif
如替换GPIO外设驱动时:
  1. #ifdef STM32F40_41xxx



  2.     /** 原 stm32 接口或外设驱动 */



  3.     GPIO_InitTypeDef  GPIO_InitStructure;



  4.     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);    //使能GPIOF时钟





  5.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9; //KEY0 KEY1 KEY2 KEY3对应引脚



  6.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;             //普通输入模式



  7.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;       //100M



  8.     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;             //上拉



  9.     GPIO_Init(GPIOF, &GPIO_InitStructure);                   //初始化GPIOF6,7,8,9



  10. #endif





  11. #ifdef APM32F40X



  12.         /** 替换为 apm32 接口或外设驱动 */



  13.     GPIO_Config_T  GPIO_InitStructure;



  14.     RCM_EnableAHB1PeriphClock(RCM_AHB1_PERIPH_GPIOF);



  15.     GPIO_InitStructure.pin = GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9;



  16.     GPIO_InitStructure.mode = GPIO_MODE_IN;



  17.     GPIO_InitStructure.speed = GPIO_SPEED_100MHz;



  18.     GPIO_InitStructure.otype = GPIO_OTYPE_PP;



  19.     GPIO_InitStructure.pupd = GPIO_PUPD_UP;



  20.     GPIO_Config(GPIOF, &GPIO_InitStructure);



  21. #endif


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

本版积分规则

332

主题

11219

帖子

13

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