|
|
hai 5 meses | |
|---|---|---|
| .. | ||
| .settings | hai 6 meses | |
| board | hai 6 meses | |
| figures | hai 1 ano | |
| packages | hai 6 meses | |
| rzn | hai 6 meses | |
| rzn_cfg | hai 6 meses | |
| rzn_gen | hai 6 meses | |
| script | hai 6 meses | |
| src | hai 1 ano | |
| .api_xml | hai 1 ano | |
| .config | hai 6 meses | |
| .cproject | hai 6 meses | |
| .gitignore | hai 1 ano | |
| .project | hai 1 ano | |
| .secure_azone | hai 1 ano | |
| .secure_rzone | hai 6 meses | |
| .secure_xml | hai 6 meses | |
| Kconfig | hai 6 meses | |
| README.md | hai 5 meses | |
| README_zh.md | hai 5 meses | |
| SConscript | hai 6 meses | |
| SConstruct | hai 1 ano | |
| buildinfo.ipcf | hai 6 meses | |
| buildinfo.json | hai 6 meses | |
| configuration.xml | hai 6 meses | |
| envsetup.sh | hai 1 ano | |
| mklinks.bat | hai 1 ano | |
| mklinks.sh | hai 1 ano | |
| ozone_scons.jdebug | hai 1 ano | |
| project.ewd | hai 6 meses | |
| project.ewp | hai 6 meses | |
| project.ewt | hai 6 meses | |
| project.eww | hai 1 ano | |
| rtconfig.h | hai 6 meses | |
| rtconfig.py | hai 1 ano | |
| rzn_cfg.txt | hai 6 meses | |
| template.ewd | hai 6 meses | |
| template.ewp | hai 6 meses | |
| template.eww | hai 1 ano | |
English | Chinese
This tutorial mainly introduces how to use the CANFD device on the EtherKit.
Select the configuration.xml file under the newly created project and open it in rzn-fsp.
Click to add a new stack, search for canfd, and add r_canfd. Here, we need to add two canfd_stack.
In the basic configuration, enable the reception FIFO interrupt for canfd0 and canfd1 by selecting Common -> Reception -> FIFOs -> FIFO 0 / FIFO 1 -> Enable. For canfd0, enable FIFO 0 interrupt, and for canfd1, enable FIFO 1 interrupt:
Next, we need to configure the channel, interrupt callback functions, and filter array for CANFD.
Configure and enable the CANFD pins.
Next, enable the interrupt configuration for the message buffer, which determines which message buffer will trigger the interrupt when transmission is complete.
Open RT-Thread Settings and enable the CANFD configuration.
The project sends a message using canfd0 and receives it using canfd1, printing the result via serial port.
Example send code:
int can0_sample_send(int argc, char *argv[])
{
rt_err_t res;
rt_thread_t thread;
char can_name[RT_NAME_MAX];
if (argc == 2)
{
rt_strncpy(can_name, argv[1], RT_NAME_MAX);
}
else
{
rt_strncpy(can_name, CAN0_DEV_NAME, RT_NAME_MAX);
}
/* Find the CAN device */
can0_dev = rt_device_find(can_name);
if (!can0_dev)
{
rt_kprintf("find %s failed!\n", can_name);
return RT_ERROR;
}
/* Open the CAN device for interrupt-based receive and send */
res = rt_device_open(can0_dev, RT_DEVICE_FLAG_INT_TX | RT_DEVICE_FLAG_INT_RX);
RT_ASSERT(res == RT_EOK);
/* Create data reception thread */
thread = rt_thread_create("can0_tx", can0_tx_thread, RT_NULL, 1024, 25, 10);
if (thread != RT_NULL)
{
rt_thread_startup(thread);
}
else
{
rt_kprintf("create can_rx thread failed!\n");
}
return res;
}
/* Export to msh command list */
MSH_CMD_EXPORT(can0_sample_send, can device sample);
int can1_sample_receive(int argc, char *argv[])
{
rt_err_t res;
rt_thread_t thread;
char can_name[RT_NAME_MAX];
if (argc == 2)
{
rt_strncpy(can_name, argv[1], RT_NAME_MAX);
}
else
{
rt_strncpy(can_name, CAN1_DEV_NAME, RT_NAME_MAX);
}
/* Find the CAN device */
can1_dev = rt_device_find(can_name);
if (!can1_dev)
{
rt_kprintf("find %s failed!\n", can_name);
return RT_ERROR;
}
/* Initialize CAN reception semaphore */
rt_sem_init(&rx_sem, "rx_sem", 0, RT_IPC_FLAG_FIFO);
/* Open the CAN device for interrupt-based receive and send */
res = rt_device_open(can1_dev, RT_DEVICE_FLAG_INT_TX | RT_DEVICE_FLAG_INT_RX);
RT_ASSERT(res == RT_EOK);
/* Create data reception thread */
thread = rt_thread_create("can1_rx", can1_rx_thread, RT_NULL, 1024, 25, 10);
if (thread != RT_NULL)
{
rt_thread_startup(thread);
}
else
{
rt_kprintf("create can_rx thread failed!\n");
}
return res;
}
mklinks.bat to generate links to the rt-thread and libraries folders. Then use Env to generate the IAR project. Finally, double-click project.eww to open the IAR project and compile.After compiling, connect the Jlink interface of the development board to the PC and download the firmware to the development board.
Connect CAN0_L to CAN1_L, and CAN0_H to CAN1_H, as shown in the image below:
Use the serial port to send the can0_sample_send and can1_sample_receive commands for loopback testing: