STM32F407ZGT6 +AX58100 ETHERCAT芯片软件,需要查看SSC 协议栈运行情况,UART输出状态信息。
STM32F407ZGT6 驱动库使用标准库,虽然老,但是够用。
1.STM32F407ZGT6 芯片情况
STM32F407ZGT6 作为AX58100 的主控
2.板子硬件
STM32F407ZGT6 +AX58100 ETHERCAT 从站开发板
2.0 硬件连接图
AX58100 核心板的UART 采用UART1 PB6 PB7 PIN
2.1 UART1配置
/*
*********************************************************************************************************
* º¯ Êý Ãû: uart1_Init
* ¹¦ÄÜ˵Ã÷: ´®¿Ú1³õʼ»¯º¯Êý
* ÐÎ ²Î: 1.bound£¨´®¿Ú²¨ÌØÂÊ£©
* ·µ »Ø Öµ: ÎÞ
*********************************************************************************************************
*/
void uart1_Init(u32 bound)
{
//GPIO¶Ë¿ÚÉèÖÃ
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE); //ʹÄÜGPIOAʱÖÓ
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);//ʹÄÜUSART1ʱÖÓ
// GPIO_PinAFConfig(GPIOB,GPIO_PinSource6,GPIO_AF_USART1);
// void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF)
// GPIO_PinRemapConfig(GPIO_Remap_USART1, ENABLE);
//´®¿Ú1¶ÔÓ¦Òý½Å¸´ÓÃÓ³Éä
GPIO_PinAFConfig(GPIOB,GPIO_PinSource6,GPIO_AF_USART1); //GPIOA9¸´ÓÃΪUSART1
GPIO_PinAFConfig(GPIOB,GPIO_PinSource7,GPIO_AF_USART1); //GPIOA10¸´ÓÃΪUSART1
//USART1¶Ë¿ÚÅäÖÃ
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; //GPIOA9ÓëGPIOA10
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//¸´Óù¦ÄÜ
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //ËÙ¶È50MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //ÍÆÍ츴ÓÃÊä³ö
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //ÉÏÀ
GPIO_Init(GPIOB,&GPIO_InitStructure); //³õʼ»¯PA9£¬PA10
//USART1 ³õʼ»¯ÉèÖÃ
USART_InitStructure.USART_BaudRate = bound;//²¨ÌØÂÊÉèÖÃ
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//×Ö³¤Îª8λÊý¾Ý¸ñʽ
USART_InitStructure.USART_StopBits = USART_StopBits_1;//Ò»¸öֹͣλ
USART_InitStructure.USART_Parity = USART_Parity_No;//ÎÞÆæżУÑéλ
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//ÎÞÓ²¼þÊý¾ÝÁ÷¿ØÖÆ
USART_InitStructure.USART_Mode = USART_Mode_Tx; //ÊÕ·¢Ä£Ê½
USART_Init(USART1, &USART_InitStructure); //³õʼ»¯´®¿Ú1
USART_Cmd(USART1, ENABLE); //ʹÄÜ´®¿Ú1
//USART_ClearFlag(USART1, USART_FLAG_TC); //½â¾öµÚÒ»¸ö×Ö½Ú¶ªÊ§ÎÊÌâ,Èç¹ûµÚÒ»¸ö×Ö½Ú¶ªÊ§¿ÉÒÔ¼ÓÉÏÕâÐÐ
}
2.1.1 UART1调用代码
#include "Dbg.h"
int main(void)
{
SysTick_Init(); //ʱÖÓ³õʼ»¯
uart1_Init(115200);
// LED_Init(); //LED³õʼ»¯
// KEY_Init(); //°´¼ü³õʼ»¯
Println("³õʼ»¯Íê³É,´òÓ¡¿ª¹ØΪ%d\r\n",Print_Switch);
printf("build time is %s %s\n\r",__DATE__,__TIME__);
/*
ÅäÖÃϵͳʱÖÓµ½168MHz
- Çл»Ê¹ÓÃHSE¡£
- ´Ëº¯Êý»á¸üÐÂÈ«¾Ö±äÁ¿SystemCoreClock£¬²¢ÖØÐÂÅäÖÃHAL_InitTick¡£
*/
// SystemClock_Config();
// bsp_InitUart(); /* ³õʼ»¯´®¿Ú */
GPIO_Config();
/* initialize the Hardware and the EtherCAT Slave Controller */
HW_Init();
MainInit();
bRunApplication = TRUE;
do
{
MainLoop();
extern u32 SysTick_1ms ;
printf("SysTick_1ms=%d\r\n",SysTick_1ms);
} while (bRunApplication == TRUE);
HW_Release();
return 0;
}
2.2 UART1执行结果
3.参考
1.本地电脑工程路径:
D:\ethercat_stm32_ec01_master\AX58100从站开发板\04.软件开发指南\2.代码例程\EtherCAT例程\IO-FSMC-58100\IO-FMSC-58100\FMSC Ethercat AX58100\STM32F407 Ethercat\MDK-ARM
https://gitee.com/Notmi/stm32-standard-peripheral-libraries/tree/master/stm32%E6%A0%87%E5%87%86%E5%BA%93_03%E4%B8%B2%E5%8F%A3printf%E6%89%93%E5%8D%B0