(五)灵动Mini-F5375-OB开发板CAN输出Hello World

1.打开“LibSamples_MM32F5370_V0.10.3\Samples\LibSamples\FlexCAN\FlexCAN_Interrupt\MDK-ARM\”文件夹下“FlexCAN_Interrupt.uvprojx”文件。

2.根据“Mini-F5375-OB (LQFP64) 原理图”文件(官方下载地址:https://www.mindmotion.com.cn...),修改flexcan_interrupt.c中内容如下:


/***********************************************************************************************************************
@file flexcan_interrupt.c
@author FAE Team
@date 23-Aug-2023
@brief THIS FILE PROVIDES ALL THE SYSTEM FUNCTIONS.
**********************************************************************************************************************
@attention
<h2><center>© Copyright(c) <2023> <MindMotion></center></h2>
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or
promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*********************************************************************************************************************/
/* Define to prevent recursive inclusion */
#define _FLEXCAN_INTERRUPT_C_
/* Files include */
#include <stdio.h>
#include "platform.h"
#include "flexcan_interrupt.h"
/**
* @addtogroup MM32F5370_LibSamples
* @{
*/
/**
* @addtogroup FlexCAN
* @{
*/
/**
* @addtogroup FlexCAN_Interrupt
* @{
*/
/* Private typedef ****************************************************************************************************/
/* Private define *****************************************************************************************************/
/* Private macro ******************************************************************************************************/
/* Private variables **************************************************************************************************/
flexcan_frame_t FlexCAN_MB10_FrameStruct;
flexcan_mb_transfer_t FlexCAN_MB10_TransferStruct;
uint8_t FlexCAN_MB10_RxCompleteFlag = 0;
flexcan_frame_t FlexCAN_MB11_FrameStruct;
flexcan_mb_transfer_t FlexCAN_MB11_TransferStruct;
uint8_t FlexCAN_MB11_RxCompleteFlag = 0;
flexcan_frame_t FlexCAN_MB12_FrameStruct;
flexcan_mb_transfer_t FlexCAN_MB12_TransferStruct;
uint8_t FlexCAN_MB12_RxCompleteFlag = 0;
flexcan_frame_t FlexCAN_MB13_FrameStruct;
flexcan_mb_transfer_t FlexCAN_MB13_TransferStruct;
uint8_t FlexCAN_MB13_RxCompleteFlag = 0;
/* Private functions **************************************************************************************************/
/***********************************************************************************************************************
* @brief
* @note none
* @param none
* @retval none
*********************************************************************************************************************/
void FlexCAN_RxMB_Handler(void)
{
uint32_t ID = 0;
uint8_t Buffer[11], Length = 0;
if (FlexCAN_MB10_RxCompleteFlag == 1)
{
FlexCAN_MB10_RxCompleteFlag = 0;
ID = FlexCAN_MB10_FrameStruct.id;
Length = FlexCAN_MB10_FrameStruct.length;
Buffer[0] = FlexCAN_MB10_FrameStruct.dataByte0;
Buffer[1] = FlexCAN_MB10_FrameStruct.dataByte1;
Buffer[2] = FlexCAN_MB10_FrameStruct.dataByte2;
Buffer[3] = FlexCAN_MB10_FrameStruct.dataByte3;
Buffer[4] = FlexCAN_MB10_FrameStruct.dataByte4;
Buffer[5] = FlexCAN_MB10_FrameStruct.dataByte5;
Buffer[6] = FlexCAN_MB10_FrameStruct.dataByte6;
Buffer[7] = FlexCAN_MB10_FrameStruct.dataByte7;
if (FlexCAN_MB10_FrameStruct.format == (uint8_t)Enum_Flexcan_FrameFormatStandard)
{
if (FlexCAN_MB10_FrameStruct.type == (uint8_t)Enum_Flexcan_FrameTypeData)
{
FlexCAN_SendStandardFrameMessage((ID >> FLEXCAN_ID_STD_Pos), Buffer, Length);
}
else
{
FlexCAN_SendRemoteFrameMessage((ID >> FLEXCAN_ID_STD_Pos), Buffer, Length);
}
}
else if (FlexCAN_MB10_FrameStruct.format == (uint8_t)Enum_Flexcan_FrameFormatExtend)
{
FlexCAN_SendExtendFrameMessage((ID >> FLEXCAN_ID_EXT_Pos), Buffer, Length);
}
FLEXCAN_TransferReceiveNonBlocking(FLEXCAN1, &FlexCAN_Handle, &FlexCAN_MB10_TransferStruct);
}
if (FlexCAN_MB11_RxCompleteFlag == 1)
{
FlexCAN_MB11_RxCompleteFlag = 0;
ID = FlexCAN_MB11_FrameStruct.id;
Length = FlexCAN_MB11_FrameStruct.length;
Buffer[0] = FlexCAN_MB11_FrameStruct.dataByte0;
Buffer[1] = FlexCAN_MB11_FrameStruct.dataByte1;
Buffer[2] = FlexCAN_MB11_FrameStruct.dataByte2;
Buffer[3] = FlexCAN_MB11_FrameStruct.dataByte3;
Buffer[4] = FlexCAN_MB11_FrameStruct.dataByte4;
Buffer[5] = FlexCAN_MB11_FrameStruct.dataByte5;
Buffer[6] = FlexCAN_MB11_FrameStruct.dataByte6;
Buffer[7] = FlexCAN_MB11_FrameStruct.dataByte7;
if (FlexCAN_MB11_FrameStruct.format == (uint8_t)Enum_Flexcan_FrameFormatStandard)
{
if (FlexCAN_MB11_FrameStruct.type == (uint8_t)Enum_Flexcan_FrameTypeData)
{
FlexCAN_SendStandardFrameMessage((ID >> FLEXCAN_ID_STD_Pos), Buffer, Length);
}
else
{
FlexCAN_SendRemoteFrameMessage((ID >> FLEXCAN_ID_STD_Pos), Buffer, Length);
}
}
else if (FlexCAN_MB11_FrameStruct.format == (uint8_t)Enum_Flexcan_FrameFormatExtend)
{
FlexCAN_SendExtendFrameMessage((ID >> FLEXCAN_ID_EXT_Pos), Buffer, Length);
}
FLEXCAN_TransferReceiveNonBlocking(FLEXCAN1, &FlexCAN_Handle, &FlexCAN_MB11_TransferStruct);
}
if (FlexCAN_MB12_RxCompleteFlag == 1)
{
FlexCAN_MB12_RxCompleteFlag = 0;
ID = FlexCAN_MB12_FrameStruct.id;
Length = FlexCAN_MB12_FrameStruct.length;
Buffer[0] = FlexCAN_MB12_FrameStruct.dataByte0;
Buffer[1] = FlexCAN_MB12_FrameStruct.dataByte1;
Buffer[2] = FlexCAN_MB12_FrameStruct.dataByte2;
Buffer[3] = FlexCAN_MB12_FrameStruct.dataByte3;
Buffer[4] = FlexCAN_MB12_FrameStruct.dataByte4;
Buffer[5] = FlexCAN_MB12_FrameStruct.dataByte5;
Buffer[6] = FlexCAN_MB12_FrameStruct.dataByte6;
Buffer[7] = FlexCAN_MB12_FrameStruct.dataByte7;
if (FlexCAN_MB12_FrameStruct.format == (uint8_t)Enum_Flexcan_FrameFormatStandard)
{
if (FlexCAN_MB12_FrameStruct.type == (uint8_t)Enum_Flexcan_FrameTypeData)
{
FlexCAN_SendStandardFrameMessage((ID >> FLEXCAN_ID_STD_Pos), Buffer, Length);
}
else
{
FlexCAN_SendRemoteFrameMessage((ID >> FLEXCAN_ID_STD_Pos), Buffer, Length);
}
}
else if (FlexCAN_MB12_FrameStruct.format == (uint8_t)Enum_Flexcan_FrameFormatExtend)
{
FlexCAN_SendExtendFrameMessage((ID >> FLEXCAN_ID_EXT_Pos), Buffer, Length);
}
FLEXCAN_TransferReceiveNonBlocking(FLEXCAN1, &FlexCAN_Handle, &FlexCAN_MB12_TransferStruct);
}
if (FlexCAN_MB13_RxCompleteFlag == 1)
{
FlexCAN_MB13_RxCompleteFlag = 0;
ID = FlexCAN_MB13_FrameStruct.id;
Length = FlexCAN_MB13_FrameStruct.length;
Buffer[0] = FlexCAN_MB13_FrameStruct.dataByte0;
Buffer[1] = FlexCAN_MB13_FrameStruct.dataByte1;
Buffer[2] = FlexCAN_MB13_FrameStruct.dataByte2;
Buffer[3] = FlexCAN_MB13_FrameStruct.dataByte3;
Buffer[4] = FlexCAN_MB13_FrameStruct.dataByte4;
Buffer[5] = FlexCAN_MB13_FrameStruct.dataByte5;
Buffer[6] = FlexCAN_MB13_FrameStruct.dataByte6;
Buffer[7] = FlexCAN_MB13_FrameStruct.dataByte7;
if (FlexCAN_MB13_FrameStruct.format == (uint8_t)Enum_Flexcan_FrameFormatStandard)
{
if (FlexCAN_MB13_FrameStruct.type == (uint8_t)Enum_Flexcan_FrameTypeData)
{
FlexCAN_SendStandardFrameMessage((ID >> FLEXCAN_ID_STD_Pos), Buffer, Length);
}
else
{
FlexCAN_SendRemoteFrameMessage((ID >> FLEXCAN_ID_STD_Pos), Buffer, Length);
}
}
else if (FlexCAN_MB13_FrameStruct.format == (uint8_t)Enum_Flexcan_FrameFormatExtend)
{
FlexCAN_SendExtendFrameMessage((ID >> FLEXCAN_ID_EXT_Pos), Buffer, Length);
}
FLEXCAN_TransferReceiveNonBlocking(FLEXCAN1, &FlexCAN_Handle, &FlexCAN_MB13_TransferStruct);
}
int i;
for(i=0;i<11;i++)
{
printf(" 0X%x",Buffer[i]);
}
}
/***********************************************************************************************************************
* @brief
* @note none
* @param none
* @retval none
*********************************************************************************************************************/
void FlexCAN_Transfer_Callback(FLEXCAN_TypeDef *flex_can, flexcan_handle_t *handle, uint32_t status, uint32_t result, void *userData)
{
switch (status)
{
case Status_Flexcan_RxIdle:
if (10 == result)
{
FlexCAN_MB10_RxCompleteFlag = 1;
printf("\r\nStandard Frame, MB 10 Rx Complete");
}
else if (11 == result)
{
FlexCAN_MB11_RxCompleteFlag = 1;
printf("\r\nStandard Frame, MB 11 Rx Complete");
}
else if (12 == result)
{
FlexCAN_MB12_RxCompleteFlag = 1;
printf("\r\nExtend Frame, MB 12 Rx Complete");
}
else if (13 == result)
{
FlexCAN_MB13_RxCompleteFlag = 1;
printf("\r\nExtend Frame, MB 13 Rx Complete");
}
FlexCAN_RxMB_Handler();
break;
case Status_Flexcan_TxIdle:
if (7 == result)
{
printf("\r\nStandard Frame, MB 7 Tx Complete");
}
else if (8 == result)
{
printf("\r\nExtend Frame, MB 8 Tx Complete");
}
break;
case Status_Flexcan_TxSwitchToRx:
if (9 == result)
{
printf("\r\nRemote Frame, MB 9 Tx Complete");
}
break;
default:
break;
}
}
/***********************************************************************************************************************
* @brief
* @note none
* @param none
* @retval none
*********************************************************************************************************************/
void FlexCAN_Configure(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
NVIC_InitTypeDef NVIC_InitStruct;
RCC_ClocksTypeDef RCC_Clocks;
flexcan_config_t FlexCAN_ConfigStruct;
flexcan_rx_mb_config_t FlexCAN_RxMB_ConfigStruct;
RCC_GetClocksFreq(&RCC_Clocks);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_FLEXCAN1, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOI, ENABLE);
GPIO_PinAFConfig(GPIOI, GPIO_PinSource0, GPIO_AF_9);
GPIO_PinAFConfig(GPIOI, GPIO_PinSource1, GPIO_AF_9);
GPIO_StructInit(&GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_High;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_FLOATING;
GPIO_Init(GPIOI, &GPIO_InitStruct);
GPIO_StructInit(&GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_High;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOI, &GPIO_InitStruct);
NVIC_InitStruct.NVIC_IRQChannel = FLEXCAN1_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
FLEXCAN_GetDefaultConfig(&FlexCAN_ConfigStruct);
FlexCAN_ConfigStruct.baudRate = 250000; /* 250kbps */
FlexCAN_ConfigStruct.clkSrc = Enum_Flexcan_ClkSrc1;
FlexCAN_ConfigStruct.enableLoopBack = true;
FlexCAN_ConfigStruct.disableSelfReception = false;
FlexCAN_ConfigStruct.enableIndividMask = false;
#if 1 /* Baudrate calculate by automatically */
FLEXCAN_CalculateImprovedTimingValues(FlexCAN_ConfigStruct.baudRate, RCC_Clocks.PCLK1_Frequency, &FlexCAN_ConfigStruct.timingConfig);
#else /* You can modify the parameters yourself */
FlexCAN_ConfigStruct.timingConfig.preDivider = 23;
FlexCAN_ConfigStruct.timingConfig.propSeg = 6;
FlexCAN_ConfigStruct.timingConfig.phaseSeg1 = 3;
FlexCAN_ConfigStruct.timingConfig.phaseSeg2 = 3;
FlexCAN_ConfigStruct.timingConfig.rJumpwidth = 3;
#endif
FLEXCAN_Init(FLEXCAN1, &FlexCAN_ConfigStruct);
FLEXCAN_TxMbConfig(FLEXCAN1, 7, ENABLE);
FLEXCAN_TxMbConfig(FLEXCAN1, 8, ENABLE);
FLEXCAN_TxMbConfig(FLEXCAN1, 9, ENABLE);
FLEXCAN_TransferCreateHandle(FLEXCAN1, &FlexCAN_Handle, FlexCAN_Transfer_Callback, NULL);
/* STD */
FlexCAN_RxMB_ConfigStruct.id = FLEXCAN_ID_STD(0x111);
FlexCAN_RxMB_ConfigStruct.format = Enum_Flexcan_FrameFormatStandard;
FlexCAN_RxMB_ConfigStruct.type = Enum_Flexcan_FrameTypeData;
FLEXCAN_RxMbConfig(FLEXCAN1, 10, &FlexCAN_RxMB_ConfigStruct, ENABLE);
FLEXCAN_SetRxIndividualMask(FLEXCAN1, 10, FLEXCAN_RX_MB_STD_MASK(0xFFF, 0, 0));
FlexCAN_MB10_FrameStruct.length = (uint8_t)(8);
FlexCAN_MB10_FrameStruct.type = (uint8_t)Enum_Flexcan_FrameTypeData;
FlexCAN_MB10_FrameStruct.format = (uint8_t)Enum_Flexcan_FrameFormatStandard;
FlexCAN_MB10_FrameStruct.id = FLEXCAN_ID_STD(0x111);
FlexCAN_MB10_TransferStruct.mbIdx = 10;
FlexCAN_MB10_TransferStruct.frame = &FlexCAN_MB10_FrameStruct;
FLEXCAN_TransferReceiveNonBlocking(FLEXCAN1, &FlexCAN_Handle, &FlexCAN_MB10_TransferStruct);
/* STD */
FlexCAN_RxMB_ConfigStruct.id = FLEXCAN_ID_STD(0x222);
FlexCAN_RxMB_ConfigStruct.format = Enum_Flexcan_FrameFormatStandard;
FlexCAN_RxMB_ConfigStruct.type = Enum_Flexcan_FrameTypeData;
FLEXCAN_RxMbConfig(FLEXCAN1, 11, &FlexCAN_RxMB_ConfigStruct, ENABLE);
FLEXCAN_SetRxIndividualMask(FLEXCAN1, 11, FLEXCAN_RX_MB_STD_MASK(0xFFF, 0, 0));
FlexCAN_MB11_FrameStruct.length = (uint8_t)(8);
FlexCAN_MB11_FrameStruct.type = (uint8_t)Enum_Flexcan_FrameTypeData;
FlexCAN_MB11_FrameStruct.format = (uint8_t)Enum_Flexcan_FrameFormatStandard;
FlexCAN_MB11_FrameStruct.id = FLEXCAN_ID_STD(0x222);
FlexCAN_MB11_TransferStruct.mbIdx = 11;
FlexCAN_MB11_TransferStruct.frame = &FlexCAN_MB11_FrameStruct;
FLEXCAN_TransferReceiveNonBlocking(FLEXCAN1, &FlexCAN_Handle, &FlexCAN_MB11_TransferStruct);
/* EXT */
FlexCAN_RxMB_ConfigStruct.id = FLEXCAN_ID_EXT(0x333);
FlexCAN_RxMB_ConfigStruct.format = Enum_Flexcan_FrameFormatExtend;
FlexCAN_RxMB_ConfigStruct.type = Enum_Flexcan_FrameTypeData;
FLEXCAN_RxMbConfig(FLEXCAN1, 12, &FlexCAN_RxMB_ConfigStruct, ENABLE);
FLEXCAN_SetRxIndividualMask(FLEXCAN1, 12, FLEXCAN_RX_MB_EXT_MASK(0xFFF, 0, 1));
FlexCAN_MB12_FrameStruct.length = (uint8_t)(8);
FlexCAN_MB12_FrameStruct.type = (uint8_t)Enum_Flexcan_FrameTypeData;
FlexCAN_MB12_FrameStruct.format = (uint8_t)Enum_Flexcan_FrameFormatExtend;
FlexCAN_MB12_FrameStruct.id = FLEXCAN_ID_EXT(0x333);
FlexCAN_MB12_TransferStruct.mbIdx = 12;
FlexCAN_MB12_TransferStruct.frame = &FlexCAN_MB12_FrameStruct;
FLEXCAN_TransferReceiveNonBlocking(FLEXCAN1, &FlexCAN_Handle, &FlexCAN_MB12_TransferStruct);
/* RTR */
FlexCAN_RxMB_ConfigStruct.id = FLEXCAN_ID_STD(0x555);
FlexCAN_RxMB_ConfigStruct.format = Enum_Flexcan_FrameFormatStandard;
FlexCAN_RxMB_ConfigStruct.type = Enum_Flexcan_FrameTypeRemote;
FLEXCAN_RxMbConfig(FLEXCAN1, 13, &FlexCAN_RxMB_ConfigStruct, ENABLE);
FLEXCAN_SetRxIndividualMask(FLEXCAN1, 13, FLEXCAN_RX_MB_EXT_MASK(0xFFF, 1, 0));
FlexCAN_MB13_FrameStruct.length = (uint8_t)(8);
FlexCAN_MB13_FrameStruct.type = (uint8_t)Enum_Flexcan_FrameTypeRemote;
FlexCAN_MB13_FrameStruct.format = (uint8_t)Enum_Flexcan_FrameFormatStandard;
FlexCAN_MB13_FrameStruct.id = FLEXCAN_ID_STD(0x555);
FlexCAN_MB13_TransferStruct.mbIdx = 13;
FlexCAN_MB13_TransferStruct.frame = &FlexCAN_MB13_FrameStruct;
FLEXCAN_TransferReceiveNonBlocking(FLEXCAN1, &FlexCAN_Handle, &FlexCAN_MB13_TransferStruct);
}
/***********************************************************************************************************************
* @brief
* @note none
* @param none
* @retval none
*********************************************************************************************************************/
void FlexCAN_SendStandardFrameMessage(uint32_t ID, uint8_t *Buffer, uint8_t Length)
{
flexcan_frame_t FlexCAN_FrameStruct;
flexcan_mb_transfer_t FlexCAN_MB_TransferStruct;
FlexCAN_FrameStruct.length = (uint8_t)Length;
FlexCAN_FrameStruct.type = (uint8_t)Enum_Flexcan_FrameTypeData;
FlexCAN_FrameStruct.format = (uint8_t)Enum_Flexcan_FrameFormatStandard;
FlexCAN_FrameStruct.id = FLEXCAN_ID_STD(ID);
FlexCAN_FrameStruct.dataByte0 = Buffer[0];
FlexCAN_FrameStruct.dataByte1 = Buffer[1];
FlexCAN_FrameStruct.dataByte2 = Buffer[2];
FlexCAN_FrameStruct.dataByte3 = Buffer[3];
FlexCAN_FrameStruct.dataByte4 = Buffer[4];
FlexCAN_FrameStruct.dataByte5 = Buffer[5];
FlexCAN_FrameStruct.dataByte6 = Buffer[6];
FlexCAN_FrameStruct.dataByte7 = Buffer[7];
FlexCAN_MB_TransferStruct.mbIdx = 7;
FlexCAN_MB_TransferStruct.frame = &FlexCAN_FrameStruct;
FLEXCAN_TransferSendNonBlocking(FLEXCAN1, &FlexCAN_Handle, &FlexCAN_MB_TransferStruct);
}
/***********************************************************************************************************************
* @brief
* @note none
* @param none
* @retval none
*********************************************************************************************************************/
void FlexCAN_SendExtendFrameMessage(uint32_t ID, uint8_t *Buffer, uint8_t Length)
{
flexcan_frame_t FlexCAN_FrameStruct;
flexcan_mb_transfer_t FlexCAN_MB_TransferStruct;
FlexCAN_FrameStruct.length = (uint8_t)Length;
FlexCAN_FrameStruct.type = (uint8_t)Enum_Flexcan_FrameTypeData;
FlexCAN_FrameStruct.format = (uint8_t)Enum_Flexcan_FrameFormatExtend;
FlexCAN_FrameStruct.id = FLEXCAN_ID_EXT(ID);
FlexCAN_FrameStruct.dataByte0 = Buffer[0];
FlexCAN_FrameStruct.dataByte1 = Buffer[1];
FlexCAN_FrameStruct.dataByte2 = Buffer[2];
FlexCAN_FrameStruct.dataByte3 = Buffer[3];
FlexCAN_FrameStruct.dataByte4 = Buffer[4];
FlexCAN_FrameStruct.dataByte5 = Buffer[5];
FlexCAN_FrameStruct.dataByte6 = Buffer[6];
FlexCAN_FrameStruct.dataByte7 = Buffer[7];
FlexCAN_MB_TransferStruct.mbIdx = 8;
FlexCAN_MB_TransferStruct.frame = &FlexCAN_FrameStruct;
FLEXCAN_TransferSendNonBlocking(FLEXCAN1, &FlexCAN_Handle, &FlexCAN_MB_TransferStruct);
}
/***********************************************************************************************************************
* @brief
* @note none
* @param none
* @retval none
*********************************************************************************************************************/
void FlexCAN_SendRemoteFrameMessage(uint32_t ID, uint8_t *Buffer, uint8_t Length)
{
flexcan_frame_t FlexCAN_FrameStruct;
flexcan_mb_transfer_t FlexCAN_MB_TransferStruct;
FlexCAN_FrameStruct.length = (uint8_t)Length;
FlexCAN_FrameStruct.type = (uint8_t)Enum_Flexcan_FrameTypeRemote;
FlexCAN_FrameStruct.format = (uint8_t)Enum_Flexcan_FrameFormatStandard;
FlexCAN_FrameStruct.id = FLEXCAN_ID_STD(ID);
FlexCAN_FrameStruct.dataByte0 = Buffer[0];
FlexCAN_FrameStruct.dataByte1 = Buffer[1];
FlexCAN_FrameStruct.dataByte2 = Buffer[2];
FlexCAN_FrameStruct.dataByte3 = Buffer[3];
FlexCAN_FrameStruct.dataByte4 = Buffer[4];
FlexCAN_FrameStruct.dataByte5 = Buffer[5];
FlexCAN_FrameStruct.dataByte6 = Buffer[6];
FlexCAN_FrameStruct.dataByte7 = Buffer[7];
FlexCAN_MB_TransferStruct.mbIdx = 9;
FlexCAN_MB_TransferStruct.frame = &FlexCAN_FrameStruct;
FLEXCAN_TransferSendNonBlocking(FLEXCAN1, &FlexCAN_Handle, &FlexCAN_MB_TransferStruct);
}
/***********************************************************************************************************************
* @brief
* @note none
* @param none
* @retval none
*********************************************************************************************************************/
void FlexCAN_Interrupt_Sample(void)
{
uint8_t Buffer[8] = "Hello WD";
printf("\r\nTest %s", __FUNCTION__);
FlexCAN_Configure();
while (1)
{
FlexCAN_SendStandardFrameMessage(0x555, Buffer, sizeof(Buffer));
PLATFORM_DelayMS(5000);
}
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/********************************************** (C) Copyright MindMotion **********************************************/

3.重新对代码进行编译。

4.接入灵动Mini-F5375-OB开发板USB-DBG的USBType-C接口,终端出现新增盘符,即为连接成功。
5.下载代码至灵动Mini-F5375-OB开发板。

6.打开串口调试工具,看到循环输出Hello WD即为成功。

(六)灵动Mini-F5375-OB开发板控制GPIO小灯闪烁
1.打开“\LibSamples_MM32F5370_V0.10.3\Samples\LibSamples\GPIO\GPIO_LED_Toggle\MDK-ARM\”文件夹下“GPIO_LED_Toggle.uvprojx”文件。


/***********************************************************************************************************************
@file main.c
@author FAE Team
@date 31-Jul-2024
@brief THIS FILE PROVIDES ALL THE SYSTEM FUNCTIONS.
**********************************************************************************************************************
@attention
<h2><center>© Copyright(c) <2023> <MindMotion></center></h2>
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or
promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*********************************************************************************************************************/
/* Define to prevent recursive inclusion */
#define _MAIN_C_
/* Files include */
#include "platform.h"
#include "main.h"
/**
* @addtogroup MM32F5370_LibSamples
* @{
*/
/**
* @addtogroup GPIO
* @{
*/
/**
* @addtogroup GPIO_LED_Toggle
* @{
*/
/* Private typedef ****************************************************************************************************/
/* Private define *****************************************************************************************************/
/* Private macro ******************************************************************************************************/
/* Private variables **************************************************************************************************/
/* Private functions **************************************************************************************************/
/***********************************************************************************************************************
* @brief This function is main entrance
* @note main
* @param none
* @retval none
*********************************************************************************************************************/
void GPIO_Configure(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
GPIO_StructInit(&GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_High;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_WriteBit(GPIOB, GPIO_Pin_14 | GPIO_Pin_15, Bit_SET);
}
void GPIO_IO_Toggle(GPIO_TypeDef *GPIOn, uint16_t PINn)
{
if (Bit_RESET == GPIO_ReadOutputDataBit(GPIOn, PINn))
{
GPIO_SetBits(GPIOn, PINn);
}
else
{
GPIO_ResetBits(GPIOn, PINn);
}
}
int main(void)
{
PLATFORM_Init();
GPIO_Configure();
while (1)
{
GPIO_IO_Toggle(GPIOB, GPIO_Pin_14);
PLATFORM_DelayMS(500);
GPIO_IO_Toggle(GPIOB, GPIO_Pin_15);
PLATFORM_DelayMS(500);
}
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/********************************************** (C) Copyright MindMotion **********************************************/

3.重新对代码进行编译。

4.接入灵动Mini-F5375-OB开发板USB-DBG的USBType-C接口,终端出现新增盘符,即为连接成功。
5.下载代码至灵动Mini-F5375-OB开发板。

6.看到灵动Mini-F5375-OB开发板板载两个LED小灯交替闪烁即为成功。
