diff --git a/docs/EtherKit_User_Manual.pdf b/docs/EtherKit_User_Manual.pdf index 123069b..275a253 100644 Binary files a/docs/EtherKit_User_Manual.pdf and b/docs/EtherKit_User_Manual.pdf differ diff --git a/projects/etherkit_ethercat_eoe/README.md b/projects/etherkit_ethercat_eoe/README.md index 2a14be0..d224f10 100644 --- a/projects/etherkit_ethercat_eoe/README.md +++ b/projects/etherkit_ethercat_eoe/README.md @@ -122,12 +122,86 @@ Set the Ethernet interrupt callback to: `user_ether0_callback` Finally, click Generate Project Content to generate the underlying driver source code. +## Build Configuration + +1. **Modify SConscript**: Navigate to the project and locate the file at the specified path: `.\rzn\SConscript`. Replace the file content with the following: + +```python +Import('RTT_ROOT') +Import('rtconfig') +from building import * +from gcc import * + +cwd = GetCurrentDir() +src = [] +group = [] +CPPPATH = [] + +if rtconfig.PLATFORM in ['iccarm']: + Return('group') +elif rtconfig.PLATFORM in GetGCCLikePLATFORM(): + if GetOption('target') != 'mdk5': + src += Glob('./fsp/src/bsp/mcu/all/*.c') + src += Glob('./fsp/src/bsp/mcu/all/cr/*.c') + src += Glob('./fsp/src/bsp/mcu/r*/*.c') + src += Glob('./fsp/src/bsp/cmsis/Device/RENESAS/Source/*.c') + src += Glob('./fsp/src/bsp/cmsis/Device/RENESAS/Source/cr/*.c') + src += Glob('./fsp/src/r_*/*.c') + CPPPATH = [ cwd + '/arm/CMSIS_5/CMSIS/Core_R/Include', + cwd + '/fsp/inc', + cwd + '/fsp/inc/api', + cwd + '/fsp/inc/instances',] + +if GetDepend('BSP_USING_ETHERCAT_EOE'): + src += Glob('./fsp/src/rm_ethercat_ssc_port/*.c') + CPPPATH += [cwd + '/fsp/src/rm_ethercat_ssc_port'] + +group = DefineGroup('rzn', src, depend = [''], CPPPATH = CPPPATH) +Return('group') +``` + +2. **Modify Kconfig**: Open the file located at `projects\etherkit_ethercat_eoe\board\Kconfig`. Add the EOE configuration under the *Onboard Peripheral Drivers* section: + +```c + config BSP_USING_ETHERCAT_EOE + bool "Enable EtherCAT EOE example" + select BSP_USING_ETH + default n + if BSP_USING_ETHERCAT_EOE + config RT_LWIP_IPADDR + string "set static ip address for eoe slaver" + default "192.168.10.100" + config RT_LWIP_GWADDR + string "set static gateway address for eoe slaver" + default "192.168.10.1" + config RT_LWIP_MSKADDR + string "set static mask address for eoe slaver" + default "255.255.255.0" + endif +``` + +As shown in the following figure: + +![image-20241216133719165](figures/image-20241216133719165.png) + +3. **Development Environment**: + - If you are using Studio for development, right-click the project and select **Sync SCons Configuration to Project**. + - If you are using IAR for development, right-click in the current project directory to open the environment and execute: + ```bash + scons --target=iar + ``` + to regenerate the configuration. + ## RT-Thread Studio Configuration After completing the FSP configuration, pin and peripheral initialization is done. Now, we need to enable the EtherCAT EOE example. Open Studio, click RT-Thread Settings, and enable the EOE example: ![image-20241126113041985](figures/image-20241126113041985.png) +Next, we need to configure the system to disable DHCP and use a static IP. Click on the component -> enable the lwip stack, and select to disable DHCP: + +![image-20241213114404172](figures/image-20241213114404172.png) + Once enabled, save the settings and synchronize the scons configuration. Then compile and download the program. After resetting the development board, observe the serial log: ![image-20241126175253263](figures/image-20241126175253263.png) @@ -190,4 +264,44 @@ At this point, you can use DHCP to configure an automatic IP or manually assign ![image-20241126113612960](figures/image-20241126113612960.png) -Once configured, the EOE App will work, allowing communication over EtherCAT! \ No newline at end of file +Once configured, the EOE App will work, allowing communication over EtherCAT! + +## Extension Explanation: 3-Port Ethernet EOE Communication + +The example project currently defaults to a 2-port Ethernet EOE configuration. If you need to use a 3-port EOE communication setup, please follow the instructions in this chapter for configuration. + +### FSP Configuration + +First, open the FSP configuration file in the project. We will add a third PHY for the SSC stack. + +![image-20241217181157005](figures/image-20241217181157005.png) + +Next, configure the channel count for PHY2 to 2, and set the PHY address to 3 (as referenced from the schematic manual). Also, configure the network card model as user-defined and set the Ethernet initialization callback function. + +![image-20241217181209037](figures/image-20241217181209037.png) + +Then, configure the pins to enable ETH2. + +![image-20241217181218646](figures/image-20241217181218646.png) + +Next, configure the ESC corresponding to the ETH2 LINK pins, setting ESC_LINKACT2 (P22_1) and ESC_PHYLINK2 (P00_5). Note: **If P22_1 is already in use, you must first manually disable its multiplexing function before enabling this option**. + +![image-20241217181235776](figures/image-20241217181235776.png) + +After completing the above configurations, you can click to generate the source code, return to the project, compile it, and download the program to the development board. + +### ESI Firmware Update + +Similarly, we need to wait for the development board's EOE slave to successfully run. Then, open the TwinCAT 3 software to scan for devices. Once the EtherCAT device is found, do not activate it immediately. In the pop-up window, click "No." + +![image-20241217181259080](figures/image-20241217181259080.png) + +Refer to the **"Update EEPROM Firmware"** section. Follow the same steps, but this time, select the firmware to be updated as: Renesas EtherCAT RZ/N2 EoE 3port [2308 / 768], and click to flash the firmware. + +![image-20241217181338720](figures/image-20241217181338720.png) + +Once the flashing is complete, we need to delete the device again and scan it once more. You should see that the slave device description has been updated to "Box 1 (Renesas EtherCAT RZ/N2 EoE 3port)." + +![image-20241217181350020](figures/image-20241217181350020.png) + +For further EOE development, please refer to the previous chapters. \ No newline at end of file diff --git a/projects/etherkit_ethercat_eoe/README_zh.md b/projects/etherkit_ethercat_eoe/README_zh.md index 99e1f1a..bbcf6f9 100644 --- a/projects/etherkit_ethercat_eoe/README_zh.md +++ b/projects/etherkit_ethercat_eoe/README_zh.md @@ -122,12 +122,80 @@ ethernet中断触发回调设置为:user_ether0_callback 最后点击Generate Project Content生成底层驱动源码。 +## 构建配置 + +1. 修改sconscript:进入工程找到指定路径下的文件:.\rzn\SConscript,替换该文件为如下内容: + +```c +Import('RTT_ROOT') +Import('rtconfig') +from building import * +from gcc import * + +cwd = GetCurrentDir() +src = [] +group = [] +CPPPATH = [] + +if rtconfig.PLATFORM in ['iccarm']: + Return('group') +elif rtconfig.PLATFORM in GetGCCLikePLATFORM(): + if GetOption('target') != 'mdk5': + src += Glob('./fsp/src/bsp/mcu/all/*.c') + src += Glob('./fsp/src/bsp/mcu/all/cr/*.c') + src += Glob('./fsp/src/bsp/mcu/r*/*.c') + src += Glob('./fsp/src/bsp/cmsis/Device/RENESAS/Source/*.c') + src += Glob('./fsp/src/bsp/cmsis/Device/RENESAS/Source/cr/*.c') + src += Glob('./fsp/src/r_*/*.c') + CPPPATH = [ cwd + '/arm/CMSIS_5/CMSIS/Core_R/Include', + cwd + '/fsp/inc', + cwd + '/fsp/inc/api', + cwd + '/fsp/inc/instances',] + +if GetDepend('BSP_USING_ETHERCAT_EOE'): + src += Glob('./fsp/src/rm_ethercat_ssc_port/*.c') + CPPPATH += [cwd + '/fsp/src/rm_ethercat_ssc_port'] + +group = DefineGroup('rzn', src, depend = [''], CPPPATH = CPPPATH) +Return('group') +``` + +2. Kconfig修改:打开工程下的文件(projects\etherkit_ethercat_eoe\board\Kconfig),在Onboard Peripheral Drivers选项中加入EOE配置: + +```c + config BSP_USING_ETHERCAT_EOE + bool "Enable EtherCAT EOE example" + select BSP_USING_ETH + default n + if BSP_USING_ETHERCAT_EOE + config RT_LWIP_IPADDR + string "set static ip address for eoe slaver" + default "192.168.10.100" + config RT_LWIP_GWADDR + string "set static gateway address for eoe slaver" + default "192.168.10.1" + config RT_LWIP_MSKADDR + string "set static mask address for eoe slaver" + default "255.255.255.0" + endif +``` + +如下图所示: + +![image-20241216133719165](figures/image-20241216133719165.png) + +3. 使用studio开发的话需要右键工程点击 **同步scons配置至项目**;如果是使用IAR开发请在当前工程下右键打开env,执行:scons –target=iar 重新生成配置。 + ## RT-Thread Studio配置 完成FSP配置之后,引脚及外设的初始化就暂告一段落了,接下来需要我们使能EtherCAT EOE示例,打开Studio,点击 RT-Thread Settings,使能EOE示例: ![image-20241126113041985](figures/image-20241126113041985.png) +下面我们还需要配置禁用dhcp功能并使用静态IP,点击组件->使能lwip堆栈,选择禁用DHCP; + +![image-20241213114304739](figures/image-20241213114304739.png) + 使能完毕后我们保存settings配置并同步scons配置,同时编译并下载程序,复位开发板后观察串口日志: ![image-20241126175253263](figures/image-20241126175253263.png) @@ -211,4 +279,44 @@ ethernet中断触发回调设置为:user_ether0_callback * 主站IP:192.168.10.99 * 从站IP:192.168.10.100 -![image-20241126113612960](figures/image-20241126113612960.png) \ No newline at end of file +![image-20241126113612960](figures/image-20241126113612960.png) + +## 拓展说明:3端口以太网EOE通信 + +目前示例工程默认为2端口以太网EOE,如需使用三网口EOE通信请遵循本章说明进行配置; + +### FSP配置 + +首先仍然是打开工程下的FSP配置文件,我们为SSC stack添加第三个phy; + +![image-20241217181157005](figures/image-20241217181157005.png) + +然后配置phy2的通道数为2,phy address为3(根据原理图手册查询可知),同时配置网卡型号为用户自定义,并且设置以太网初始化回调函数; + +![image-20241217181209037](figures/image-20241217181209037.png) + +接下来配置引脚,使能ETH2; + +![image-20241217181218646](figures/image-20241217181218646.png) + +接着我们配置ESC对应ETH2的LINK引脚,分别配置ESC_LINKACT2(P22_1)和ESC_PHYLINK2(P00_5);此处需要注意:**此处如果P22_1被占用,需要先手动将该引脚复用功能禁用后,再使能此项**; + +![image-20241217181235776](figures/image-20241217181235776.png) + +完成上述配置后就可以点击生成源码了,回到工程编译并将程序下载开发板中; + +### ESI固件更新 + +同样首先我们需要等待开发板EOE从站成功运行,接着我们打开TwinCAT 3软件扫描设备,扫描到EtherCAT设备后先暂时不激活,弹窗点击否即可; + +![image-20241217181259080](figures/image-20241217181259080.png) + +参考**“更新EEPROM固件”**一节,一样的步骤,只不过这次需要选择更新的固件为:Renesas EtherCAT RZ/N2 EoE 3port [2308 / 768],点击烧录固件; + +![image-20241217181338720](figures/image-20241217181338720.png) + +烧录完成后我们需要重新删除设备并再次扫描,可以看到从站设备描述已经更新为Box 1 (Renesas EtherCAT RZ/N2 EoE 3port); + +![image-20241217181350020](figures/image-20241217181350020.png) + +后续EOE开发请参考前几章节。 \ No newline at end of file diff --git a/projects/etherkit_ethercat_eoe/figures/image-20241213114304739.png b/projects/etherkit_ethercat_eoe/figures/image-20241213114304739.png new file mode 100644 index 0000000..540cf37 Binary files /dev/null and b/projects/etherkit_ethercat_eoe/figures/image-20241213114304739.png differ diff --git a/projects/etherkit_ethercat_eoe/figures/image-20241213114404172.png b/projects/etherkit_ethercat_eoe/figures/image-20241213114404172.png new file mode 100644 index 0000000..540cf37 Binary files /dev/null and b/projects/etherkit_ethercat_eoe/figures/image-20241213114404172.png differ diff --git a/projects/etherkit_ethercat_eoe/figures/image-20241216133719165.png b/projects/etherkit_ethercat_eoe/figures/image-20241216133719165.png new file mode 100644 index 0000000..929bb01 Binary files /dev/null and b/projects/etherkit_ethercat_eoe/figures/image-20241216133719165.png differ diff --git a/projects/etherkit_ethercat_eoe/figures/image-20241217181157005.png b/projects/etherkit_ethercat_eoe/figures/image-20241217181157005.png new file mode 100644 index 0000000..294a5dc Binary files /dev/null and b/projects/etherkit_ethercat_eoe/figures/image-20241217181157005.png differ diff --git a/projects/etherkit_ethercat_eoe/figures/image-20241217181209037.png b/projects/etherkit_ethercat_eoe/figures/image-20241217181209037.png new file mode 100644 index 0000000..07a516a Binary files /dev/null and b/projects/etherkit_ethercat_eoe/figures/image-20241217181209037.png differ diff --git a/projects/etherkit_ethercat_eoe/figures/image-20241217181218646.png b/projects/etherkit_ethercat_eoe/figures/image-20241217181218646.png new file mode 100644 index 0000000..4666f6f Binary files /dev/null and b/projects/etherkit_ethercat_eoe/figures/image-20241217181218646.png differ diff --git a/projects/etherkit_ethercat_eoe/figures/image-20241217181235776.png b/projects/etherkit_ethercat_eoe/figures/image-20241217181235776.png new file mode 100644 index 0000000..4b9bc69 Binary files /dev/null and b/projects/etherkit_ethercat_eoe/figures/image-20241217181235776.png differ diff --git a/projects/etherkit_ethercat_eoe/figures/image-20241217181259080.png b/projects/etherkit_ethercat_eoe/figures/image-20241217181259080.png new file mode 100644 index 0000000..fc90d53 Binary files /dev/null and b/projects/etherkit_ethercat_eoe/figures/image-20241217181259080.png differ diff --git a/projects/etherkit_ethercat_eoe/figures/image-20241217181338720.png b/projects/etherkit_ethercat_eoe/figures/image-20241217181338720.png new file mode 100644 index 0000000..815c1e7 Binary files /dev/null and b/projects/etherkit_ethercat_eoe/figures/image-20241217181338720.png differ diff --git a/projects/etherkit_ethercat_eoe/figures/image-20241217181350020.png b/projects/etherkit_ethercat_eoe/figures/image-20241217181350020.png new file mode 100644 index 0000000..d23379d Binary files /dev/null and b/projects/etherkit_ethercat_eoe/figures/image-20241217181350020.png differ diff --git a/projects/etherkit_profinet_pnet/README.md b/projects/etherkit_profinet_pnet/README.md index 3e57a02..c2d76fd 100644 --- a/projects/etherkit_profinet_pnet/README.md +++ b/projects/etherkit_profinet_pnet/README.md @@ -17,48 +17,65 @@ In this example, we will use the P-Net software package to implement PROFINET ma - [CODESYS](https://us.store.codesys.com/) (PROFINET master simulation) - CODESYS - CODESYS Gateway (Gateway device) - - CODESYS Control Win SysTray (PLC device) + - CODESYS Control Win SysTray (Soft PLC device) +- [Npcap](https://npcap.com/dist/npcap-1.80.exe)(The software is running CODESYS must, need installed in advance!) **Hardware Environment**: - EtherKit development board -## Software Package Configuration - -Double-click to open RT-Thread Settings, go to **-> RT-Thread online packages -> IoT**, find **[\*] P-Net stack for Profinet device implementation --->** and enable it. Below is the related user configuration information explanation: - -```c --*- Default netif name for P-NET ---> - -> (e00) default ethernet interface name for p-net app, default as 'e00' --*- Enable P-NET sample board config ---> - -> (0x0209) p-net user led pin - -> (0x0005) p-net user key pin --*- Default root filesystem path for P-NET ---> - -> [*] p-net using ramfs filesystem by default, or you can turn this off and choose another way to enable the filesystem - -> (8192) default memory size for ramfs --*- P-NET sample slave network ip config ---> - -> (192.168.137.196) set static IP address for PROFINET slave - -> (192.168.137.1) set static gateway address for PROFINET slave - -> (255.255.255.0) set static mask address for PROFINET slave -version (latest) ---> -``` +## FSP Configuration Instructions + +Open the project configuration file `configuration.xml` and add the `r_gamc` stack: + +![image-20241126104408737](figures/image-20241126104408737-17340606619556.png) + +Next, click on `g_ether0 Ethernet`, and configure the interrupt callback function to `user_ether0_callback`: + +![image-20241126104422910](figures/image-20241126104422910-17340606619557.png) + +Now configure the PHY settings. Select `g_ether_phy0`, set the common configuration to "User Own Target", change the PHY LSI address to `1` (refer to the schematic for the exact address), and set the PHY initialization callback function to `ether_phy_targets_initialize_rtl8211_rgmii()`. Also, set the MDIO to GMAC. + +![image-20241126104437432](figures/image-20241126104437432-17340606619558.png) + +Next, configure `g_ether_selector0`, set the Ethernet mode to "Switch Mode", set the PHY link to "Default Active-Low", and choose "RGMII" for the PHY interface mode. + +![image-20241126104519290](figures/image-20241126104519290-17340606619569.png) + +Configure the Ethernet pin parameters and select the operating mode to RGMII: -- **Default netif name for p-net**: p-net network interface name, default is `e00`; -- **Enable pnet sample board config**: p-net app user LED and key configuration; -- **Default root filesystem path for p-net**: p-net filesystem configuration, default uses ramfs with 8K memory allocation; -- **P-NET sample slave network ip config**: Static IP configuration for the p-net slave device (**Make sure to disable RT_LWIP_DHCP and use static IP**). +![image-20241126104533098](figures/image-20241126104533098-173406066195610.png) -After configuring these settings, compile and download the program to the development board. +Finally, configure `ETHER_GMAC`: + +![image-20241213113648018](figures/image-20241213113648018.png) + +## RT-Thread Settings Configuration + +Double-click to open RT-Thread Settings, search for the p-net package in the search bar and enable it. Below are the related user configuration details: + +![image-20241217153316489](figures/image-20241217153316489.png) + +- **Default netif name for p-net**: The interface name for the p-net network card device, default is e00. +- **Enable pnet sample board config**: Configuration for user LED and button on the p-net application. +- **Default root filesystem path for p-net**: Configuration for the p-net filesystem, default is using ramfs, with 8K of memory space allocated by default. +- **P-NET sample slave network ip config**: Static IP configuration for the p-net slave device (**Please disable RT_LWIP_DHCP functionality and use static IP**). + +Next, we need to configure the system to disable DHCP and use a static IP. Click on the component -> enable the lwip stack, and select to disable DHCP: + +![image-20241213113246597](figures/image-20241213113246597.png) + +After completing the above configurations, compile the program and download it to the development board. ## Network Configuration Connect the development board to the PC using an Ethernet cable, and configure a static IP on the PC: -![image-20241126114040869](figures/image-20241126114040869.png) +![image-20241217145852034](figures/image-20241217145852034.png) Check the IP information on the development board and test connectivity: -![image-20241126114049493](figures/image-20241126114049493.png) +![image-20241217153547501](figures/image-20241217153547501.png) ## Soft PLC Startup @@ -76,7 +93,7 @@ First, open **CODESYS V3.5 SP20 Patch 3**, choose **New Project** -> **Projects* ![image-20241126114127411](figures/image-20241126114127411.png) -In the pop-up window, keep the default configuration and click **OK**: +After the following popup, keep the default Settings (CODESYS Control Win V3 (CODESYS)/x64 (CODESYS)) and click OK: ![image-20241126114137199](figures/image-20241126114137199.png) @@ -149,17 +166,17 @@ After installation, you should see the **P-Net slave description file**: ### Network Configuration -- **Ethernet Configuration**: Double-click **Ethernet (Ethernet)** in the left navigation bar -> **General**, and modify the network interface to the one connected to the development board (ensure the correct master IP is selected if using multiple stations). +- **Ethernet Configuration**: Double-click **Ethernet (Ethernet)** in the left navigation bar -> **General**, and modify the network interface to the one connected to the development board. -![image-20241126114448562](figures/image-20241126114448562.png) +![image-20241217150217077](figures/image-20241217150217077.png) - **PN_Controller Configuration**: Double-click **PN_Controller (PN-Controller)** -> **General**, and modify the default slave IP parameters as needed. - **P-Net Slave Network Configuration**: Double-click **P-Net-multiple-module sample app** -> **General**, and modify the IP parameters to match the development board’s IP: -![image-20241126114459034](figures/image-20241126114459034.png) +![image-20241217150534826](figures/image-20241217150534826.png) -![image-20241126114512924](figures/image-20241126114512924.png) +![image-20241217150820978](figures/image-20241217150820978.png) ### Compile and Debug the Project @@ -169,9 +186,15 @@ After installation, you should see the **P-Net slave description file**: You should see the PN master successfully online: -![image-202411261145266 +![image-20241126114526657](figures/image-20241126114526657.png) + +## profinet starts from the station application -57](figures/image-20241126114526657.png) +After the development board is powered on, once the NIC link up is detected, the secondary PN station is automatically started: + +![image-20241217152754556](figures/image-20241217152754556.png) + +![image-20241217153012620](figures/image-20241217153012620.png) ## PROFINET Slave Application Startup @@ -197,4 +220,67 @@ At the same time, PNIO will update the slave station configuration: ![image-20241209170011069](figures/image-20241209170011069.png) -We can click to view the I&M again, and we will see that the I&M data has been successfully modified! \ No newline at end of file +We can click to view the I&M again, and we will see that the I&M data has been successfully modified! + +### PLC Programming and PNIO Control + +First, we click on the left panel under Device -> PLC Logic -> Application -> PLC_PRG (PRG), and use ST language to program the variable and program code: + +* **Variable Definition**: These variables define the input state of the button (in_pin_button_LED), the output state of the LED (out_pin_LED), and the state variable controlling whether the LED should blink (flashing). The oscillator state (oscillator_state) and oscillator cycle counter (oscillator_cycles) are used to achieve a timed blinking effect. + +```st +PROGRAM PLC_PRG +VAR + in_pin_button_LED: BOOL; + out_pin_LED: BOOL; + in_pin_button_LED_previous: BOOL; + flashing: BOOL := TRUE; + oscillator_state: BOOL := FALSE; + oscillator_cycles: UINT := 0; +END_VAR +``` + +* **Program Definition**: + 1. First, in each cycle, the `oscillator_cycles` increases by 1. When the counter exceeds 200, the counter is reset, and the `oscillator_state` is toggled (TRUE or FALSE), achieving a periodic change. + 2. If the button is pressed (in_pin_button_LED is TRUE), and the button state in the previous cycle was FALSE, the `flashing` state is toggled. That is, every time the button is pressed, the LED blinking state is toggled. + 3. If `flashing` is TRUE, the LED will blink according to the oscillator state (`oscillator_state`). If `flashing` is FALSE, the LED will turn off directly. + 4. At the end of each cycle, the current button state is saved in `in_pin_button_LED_previous` to check the button press event in the next cycle. + +```st +oscillator_cycles := oscillator_cycles + 1; +IF oscillator_cycles > 200 THEN + oscillator_cycles := 0; + oscillator_state := NOT oscillator_state; +END_IF +IF in_pin_button_LED = TRUE THEN + IF in_pin_button_LED_previous = FALSE THEN + flashing := NOT flashing; + END_IF + out_pin_LED := TRUE; +ELSIF flashing = TRUE THEN + out_pin_LED := oscillator_state; +ELSE + out_pin_LED := FALSE; +END_IF +in_pin_button_LED_previous := in_pin_button_LED; +``` + +The configuration in the project is shown in the image below: + +![image-20241217154402755](figures/image-20241217154402755.png) + +Next, we need to add a built-in IO module. Right-click on `P_Net_multi_module_sample_app` and add an IO module (DIO 8xLogicLevel), as shown in the image below: + +![image-20241217154411140](figures/image-20241217154411140.png) + +Then, double-click on the `DIO_8xLogicLevel` node, select the `PNIO Module I/O Mapping`, edit Input Bit 7 and Output Bit 7, and bind the PLC variables: + +![image-20241217154418088](figures/image-20241217154418088.png) + +Next, click on the **Build -> Generate Code** in the navigation bar, then select **Online -> Login**, and run to observe the behavior: + +![image-20241217154427784](figures/image-20241217154427784.png) + +Next, go back to CODESYS, double-click **Device -> PLC Logic -> Application** and open the `PLC_PRG (PRG)`. At this point, you can dynamically observe the program's running state. For example, if you press and hold the KEY0 on the EtherKit development board, you will find that both `in_pin_button_LED` and `in_pin_button_LED_previous` are FALSE. When you release KEY0, you will see that the `flashing` value toggles once. + +![image-20241217154439788](figures/image-20241217154439788.png) \ No newline at end of file diff --git a/projects/etherkit_profinet_pnet/README_zh.md b/projects/etherkit_profinet_pnet/README_zh.md index cf1a32e..39234e5 100644 --- a/projects/etherkit_profinet_pnet/README_zh.md +++ b/projects/etherkit_profinet_pnet/README_zh.md @@ -15,51 +15,67 @@ P-Net协议是一个开源的PROFINET实现,专门用于嵌入式设备的实 软件环境: - [CODESYS](https://us.store.codesys.com/)(profinet主站模拟) - - - CODESYS - CODESYS Gateway(网关设备) - - CODESYS Control Win SysTray(PLC设备) + - CODESYS Control Win SysTray(软PLC设备) +- [Npcap](https://npcap.com/dist/npcap-1.80.exe)(该软件是运行CODESYS必须的,需要提前安装好!) 硬件环境: - EtherKit开发板 -## 软件包配置 - -双击打开 RT-Thread Settings,进入 **->RT-Thread online packages->IoT**,找到 **[\*] P-Net stack for Profinet device implementation --->** 使能,下面是相关用户配置信息说明: - -```c --*- Default netif name for P-NET ---> - -> (e00) default ethernet interface name for p-net app, default as 'e00 --*- Enable P-NET sample board config ---> - -> (0x0209) p-ent user led pin - -> (0x0005) p-net user key pin --*- Default root filesystem path for P-NET ---> - -> [*] p-net using ramfs filesystem by default, or you can turn this off and choose another way to enable the filesystem - -> (8192) default memory size for ramfs --*- P-NET sample slave network ip config ---> - -> (192.168.137.196) set static ip address for profinet slaver - -> (192.168.137.1) set static gateway address for profinet slaver - -> (255.255.255.0) set static mask address for profinet slaver - version (latest) ---> -``` +## FSP配置 + +打开工程配置文件configuration.xml,新增r_gamc Stack: + +![image-20241126104408737](figures/image-20241126104408737.png) + +点击g_ether0 Ethernet,配置中断回调函数为user_ether0_callback: + +![image-20241126104422910](figures/image-20241126104422910.png) + +下面配置phy信息,选择g_ether_phy0,Common配置为User Own Target;修改PHY LSI地址为1(根据原理图查询具体地址);设置phy初始化回调函数为ether_phy_targets_initialize_rtl8211_rgmii();同时设置MDIO为GMAC。 + +![image-20241126104437432](figures/image-20241126104437432.png) + +配置g_ether_selector0,选择以太网模式为交换机模式,PHY link设置为默认active-low,PHY接口模式设置为RGMII。 + +![image-20241126104519290](figures/image-20241126104519290.png) + +网卡引脚参数配置,选择操作模式为RGMII: + +![image-20241126104533098](figures/image-20241126104533098.png) + +ETHER_GMAC配置: + +![image-20241213113637153](figures/image-20241213113637153.png) + +## RT-Thread Settings 配置 + +双击打开 RT-Thread Settings,在搜索栏检索p-net软件包并使能,下面是相关用户配置信息说明; + +![image-20241217153300229](figures/image-20241217153300229.png) - **Default netif name for p-net**:p-net 网卡设备接口名称,默认为 e00 ; - **Enable pnet sample board config**:p-net app 用户LED及按键配置; - **Default root filesystem path for p-net**:p-net 文件系统配置,默认使用 ramfs ,默认分配 8K 内存空间; - **P-NET sample slave network ip config**:p-net 从站设备静态IP配置(**请关闭 RT_LWIP_DHCP 功能,使用静态IP**) +下面我们还需要配置禁用dhcp功能并使用静态IP,点击组件->使能lwip堆栈,选择禁用DHCP; + +![image-20241213113246597](figures/image-20241213113246597.png) + 完成上述配置后,将程序编译下载至开发板。 ## 网络配置 我们使用一根网线连接开发板与PC,同时在PC端配置静态IP: -![image-20241126114040869](figures/image-20241126114040869.png) +![image-20241217145852034](figures/image-20241217145852034.png) 检查开发板端的 IP 信息,并测试联通性: -![image-20241126114049493](figures/image-20241126114049493.png) +![image-20241217153606384](figures/image-20241217153606384.png) ## 软PLC启动 @@ -79,7 +95,7 @@ CODESYS简介:CODESYS是德国3S公司开发的PLC软件,集成了PLC逻辑 ![image-20241126114127411](figures/image-20241126114127411.png) -弹出下面这个弹窗后保持默认配置点击确定: +弹出下面这个弹窗后保持默认配置(CODESYS Control Win V3 (CODESYS) / x64 (CODESYS))点击确定: ![image-20241126114137199](figures/image-20241126114137199.png) @@ -126,7 +142,7 @@ GSD(Generic Station Description file):即通用站点描述文件,主要用 ![image-20241126114257110](figures/image-20241126114257110.png) -### 20.5.4 设备添 +### 设备添加 - Ethernet添加:左侧导航栏点击Device并右键添加设备,选择以太网适配器; @@ -142,7 +158,7 @@ GSD(Generic Station Description file):即通用站点描述文件,主要用 ![image-20241126114354826](figures/image-20241126114354826.png) -### 20.5.5 任务响应 +### 任务响应 - Main Tasks 配置:左侧导航栏选择 Application -> 任务配置 -> 双击MainTask(IEC-Tasks),优先级设置为1,类型选择循环,周期选择 4ms; @@ -154,16 +170,16 @@ GSD(Generic Station Description file):即通用站点描述文件,主要用 ### 网络配置 -- Ethernet 配置:双击左侧导航栏中的Ethernet(Ethernet) -> 通用,修改网络接口为连接到开发板的以太网端口(这里由于我开启了PRONETA,所以在同一网段下分配了两个主站IP,这里需要注意选择正确的那一个) +- Ethernet 配置:双击左侧导航栏中的Ethernet(Ethernet) -> 通用,修改网络接口为连接到开发板的以太网端口; -![image-20241126114448562](figures/image-20241126114448562.png) +![image-20241217150217077](figures/image-20241217150217077.png) - PN_Controller 配置:双击左侧导航栏 PN_Controller(PN-Controller) -> 通用,并正确修改默认从站IP参数的区间,根据提示修改即可。 -- P-Net 从站网络配置:双击左侧导航栏 P-Net-multiple-module sample app -> 通用, 修改IP参数为开发板IP +- P-Net 从站网络配置:双击左侧导航栏 P-Net-multiple-module sample app -> 通用, 修改IP参数为开发板IP -![image-20241126114459034](figures/image-20241126114459034.png) +![image-20241217150604096](figures/image-20241217150604096.png) -![image-20241126114512924](figures/image-20241126114512924.png) +![image-20241217150820978](figures/image-20241217150820978.png) ### 工程编译并启动调试 @@ -177,11 +193,11 @@ GSD(Generic Station Description file):即通用站点描述文件,主要用 ## profinet 从站应用启动 -开发板端启动 PN 从站,执行命令:pnet_app: +开发板端上电后,一旦检测到网卡 link up,则会自动启动 PN 从站: -![image-20241126114538916](figures/image-20241126114538916.png) +![image-20241217152733493](figures/image-20241217152733493.png) -![image-20241126114547482](figures/image-20241126114547482.png) +![image-20241217153026315](figures/image-20241217153026315.png) ## PN协议栈运行demo @@ -207,4 +223,67 @@ GSD(Generic Station Description file):即通用站点描述文件,主要用 ![image-20241209170011069](figures/image-20241209170011069.png) -我们再次点击查看 I&M,即可发现 I&M 修改成功! \ No newline at end of file +我们再次点击查看 I&M,即可发现 I&M 修改成功! + +### PLC编程及PNIO控制 + +首先我们点击左侧面板的Device->PLC逻辑->Application->PLC_PRG(PRG),使用ST语言编程,编写变量及程序代码: + +* 变量定义:这些变量定义了按钮的输入状态(in_pin_button_LED),LED 的输出状态(out_pin_LED)以及控制 LED 是否闪烁的状态变量(flashing)。振荡器状态(oscillator_state)和振荡器周期计数器(oscillator_cycles)用来实现定时闪烁效果。 + +```st +PROGRAM PLC_PRG +VAR + in_pin_button_LED: BOOL; + out_pin_LED: BOOL; + in_pin_button_LED_previous: BOOL; + flashing: BOOL := TRUE; + oscillator_state: BOOL := FALSE; + oscillator_cycles: UINT := 0; +END_VAR +``` + +* 程序定义: + 1. 首先在每次循环中,oscillator_cycles 增加 1。当计数器超过 200 时,重置计数器并切换 oscillator_state 的状态(TRUE 或 FALSE),实现周期性变化; + 1. 如果按钮被按下(in_pin_button_LED 为 TRUE),并且在上一周期按钮状态是 FALSE,则切换 flashing 状态。即每次按钮按下时,切换 LED 是否闪烁的状态。 + 1. 如果 flashing 为 TRUE,则 LED 会根据振荡器状态 (oscillator_state) 闪烁;如果 flashing 为 FALSE,LED 直接关闭。 + 1. 在每次循环结束时,将当前按钮的状态保存在 in_pin_button_LED_previous 中,以便在下次判断按钮按下的事件。 + +```st +oscillator_cycles := oscillator_cycles + 1; +IF oscillator_cycles > 200 THEN + oscillator_cycles := 0; + oscillator_state := NOT oscillator_state; +END_IF +IF in_pin_button_LED = TRUE THEN + IF in_pin_button_LED_previous = FALSE THEN + flashing := NOT flashing; + END_IF + out_pin_LED := TRUE; +ELSIF flashing = TRUE THEN + out_pin_LED := oscillator_state; +ELSE + out_pin_LED := FALSE; +END_IF +in_pin_button_LED_previous := in_pin_button_LED; +``` + +工程中的配置位置如下图所示: + +![image-20241217154402755](figures/image-20241217154402755.png) + +接下来我们还需要添加一个内置的IO模块,右键点击P_Net_multi_module_sample_app然后添加一个IO模块(DIO 8xLogicLevel),如下图所示: + +![image-20241217154411140](figures/image-20241217154411140.png) + +接下来双击DIO_8xLogicLevel节点,选择PNIO Module I/O映射,编辑Input Bit 7和Output Bit 7并绑定PLC变量: + +![image-20241217154418088](figures/image-20241217154418088.png) + +接着我们点击上方导航栏的编译->生成代码,然后选择在线->登录,运行查看现象; + +![image-20241217154427784](figures/image-20241217154427784.png) + +接下来回到CODESYS,再次双击Device->PLC逻辑->Application下的PLC_PRG(PRG),此时便可动态观察程序运行状态,例如我们按住etherkit开发板上的KEY0,可以发现in_pin_button_LED及in_pin_button_LED_previous 这两个变量值为FALSE,此时再松开KEY0,可以发现flashing值反转一次。 + +![image-20241217154439788](figures/image-20241217154439788.png) \ No newline at end of file diff --git a/projects/etherkit_profinet_pnet/figures/image-20241126104408737-17340606619556.png b/projects/etherkit_profinet_pnet/figures/image-20241126104408737-17340606619556.png new file mode 100644 index 0000000..4412a71 Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241126104408737-17340606619556.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241126104408737.png b/projects/etherkit_profinet_pnet/figures/image-20241126104408737.png new file mode 100644 index 0000000..4412a71 Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241126104408737.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241126104422910-17340606619557.png b/projects/etherkit_profinet_pnet/figures/image-20241126104422910-17340606619557.png new file mode 100644 index 0000000..9fa321d Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241126104422910-17340606619557.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241126104422910.png b/projects/etherkit_profinet_pnet/figures/image-20241126104422910.png new file mode 100644 index 0000000..9fa321d Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241126104422910.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241126104437432-17340606619558.png b/projects/etherkit_profinet_pnet/figures/image-20241126104437432-17340606619558.png new file mode 100644 index 0000000..b4e6fde Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241126104437432-17340606619558.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241126104437432.png b/projects/etherkit_profinet_pnet/figures/image-20241126104437432.png new file mode 100644 index 0000000..b4e6fde Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241126104437432.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241126104519290-17340606619569.png b/projects/etherkit_profinet_pnet/figures/image-20241126104519290-17340606619569.png new file mode 100644 index 0000000..4c34f31 Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241126104519290-17340606619569.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241126104519290.png b/projects/etherkit_profinet_pnet/figures/image-20241126104519290.png new file mode 100644 index 0000000..4c34f31 Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241126104519290.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241126104533098-173406066195610.png b/projects/etherkit_profinet_pnet/figures/image-20241126104533098-173406066195610.png new file mode 100644 index 0000000..fea03f1 Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241126104533098-173406066195610.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241126104533098.png b/projects/etherkit_profinet_pnet/figures/image-20241126104533098.png new file mode 100644 index 0000000..fea03f1 Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241126104533098.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241126114040869.png b/projects/etherkit_profinet_pnet/figures/image-20241126114040869.png deleted file mode 100644 index ced8c1d..0000000 Binary files a/projects/etherkit_profinet_pnet/figures/image-20241126114040869.png and /dev/null differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241126114049493.png b/projects/etherkit_profinet_pnet/figures/image-20241126114049493.png deleted file mode 100644 index f18efa6..0000000 Binary files a/projects/etherkit_profinet_pnet/figures/image-20241126114049493.png and /dev/null differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241126114448562.png b/projects/etherkit_profinet_pnet/figures/image-20241126114448562.png deleted file mode 100644 index f6a60f4..0000000 Binary files a/projects/etherkit_profinet_pnet/figures/image-20241126114448562.png and /dev/null differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241126114459034.png b/projects/etherkit_profinet_pnet/figures/image-20241126114459034.png deleted file mode 100644 index bdd3ed2..0000000 Binary files a/projects/etherkit_profinet_pnet/figures/image-20241126114459034.png and /dev/null differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241126114512924.png b/projects/etherkit_profinet_pnet/figures/image-20241126114512924.png deleted file mode 100644 index 79c34de..0000000 Binary files a/projects/etherkit_profinet_pnet/figures/image-20241126114512924.png and /dev/null differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241126114538916.png b/projects/etherkit_profinet_pnet/figures/image-20241126114538916.png deleted file mode 100644 index ebcf1f2..0000000 Binary files a/projects/etherkit_profinet_pnet/figures/image-20241126114538916.png and /dev/null differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241126114547482.png b/projects/etherkit_profinet_pnet/figures/image-20241126114547482.png deleted file mode 100644 index 96bf2c5..0000000 Binary files a/projects/etherkit_profinet_pnet/figures/image-20241126114547482.png and /dev/null differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241213113246597.png b/projects/etherkit_profinet_pnet/figures/image-20241213113246597.png new file mode 100644 index 0000000..540cf37 Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241213113246597.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241213113637153.png b/projects/etherkit_profinet_pnet/figures/image-20241213113637153.png new file mode 100644 index 0000000..3095ace Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241213113637153.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241213113648018.png b/projects/etherkit_profinet_pnet/figures/image-20241213113648018.png new file mode 100644 index 0000000..3095ace Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241213113648018.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241217145852034.png b/projects/etherkit_profinet_pnet/figures/image-20241217145852034.png new file mode 100644 index 0000000..ae9ae84 Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241217145852034.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241217150217077.png b/projects/etherkit_profinet_pnet/figures/image-20241217150217077.png new file mode 100644 index 0000000..85f4c8e Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241217150217077.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241217150534826.png b/projects/etherkit_profinet_pnet/figures/image-20241217150534826.png new file mode 100644 index 0000000..1a356d7 Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241217150534826.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241217150604096.png b/projects/etherkit_profinet_pnet/figures/image-20241217150604096.png new file mode 100644 index 0000000..1a356d7 Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241217150604096.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241217150820978.png b/projects/etherkit_profinet_pnet/figures/image-20241217150820978.png new file mode 100644 index 0000000..d185064 Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241217150820978.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241217152733493.png b/projects/etherkit_profinet_pnet/figures/image-20241217152733493.png new file mode 100644 index 0000000..a288f9c Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241217152733493.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241217152754556.png b/projects/etherkit_profinet_pnet/figures/image-20241217152754556.png new file mode 100644 index 0000000..f3478df Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241217152754556.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241217153012620.png b/projects/etherkit_profinet_pnet/figures/image-20241217153012620.png new file mode 100644 index 0000000..d6d4da3 Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241217153012620.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241217153026315.png b/projects/etherkit_profinet_pnet/figures/image-20241217153026315.png new file mode 100644 index 0000000..d6d4da3 Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241217153026315.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241217153300229.png b/projects/etherkit_profinet_pnet/figures/image-20241217153300229.png new file mode 100644 index 0000000..d77e02c Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241217153300229.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241217153316489.png b/projects/etherkit_profinet_pnet/figures/image-20241217153316489.png new file mode 100644 index 0000000..d77e02c Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241217153316489.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241217153547501.png b/projects/etherkit_profinet_pnet/figures/image-20241217153547501.png new file mode 100644 index 0000000..9bf7ffc Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241217153547501.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241217153606384.png b/projects/etherkit_profinet_pnet/figures/image-20241217153606384.png new file mode 100644 index 0000000..9bf7ffc Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241217153606384.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241217154402755.png b/projects/etherkit_profinet_pnet/figures/image-20241217154402755.png new file mode 100644 index 0000000..799654e Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241217154402755.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241217154411140.png b/projects/etherkit_profinet_pnet/figures/image-20241217154411140.png new file mode 100644 index 0000000..50a93e2 Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241217154411140.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241217154418088.png b/projects/etherkit_profinet_pnet/figures/image-20241217154418088.png new file mode 100644 index 0000000..8a07025 Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241217154418088.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241217154427784.png b/projects/etherkit_profinet_pnet/figures/image-20241217154427784.png new file mode 100644 index 0000000..cff024e Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241217154427784.png differ diff --git a/projects/etherkit_profinet_pnet/figures/image-20241217154439788.png b/projects/etherkit_profinet_pnet/figures/image-20241217154439788.png new file mode 100644 index 0000000..76cf8cf Binary files /dev/null and b/projects/etherkit_profinet_pnet/figures/image-20241217154439788.png differ diff --git a/projects/etherkit_usb_pcdc/README.md b/projects/etherkit_usb_pcdc/README.md index 94b2372..afe5f3f 100644 --- a/projects/etherkit_usb_pcdc/README.md +++ b/projects/etherkit_usb_pcdc/README.md @@ -32,6 +32,51 @@ EtherKit provides a USB-Device peripheral, located on the development board as s ![image-20241126111620891](figures/image-20241126111620891.png) +## Build Configuration + +Locate the file at the specified path in the project: `.\rzn\SConscript`, and replace its content with the following: + +```c +Import('RTT_ROOT') +Import('rtconfig') +from building import * +from gcc import * + +cwd = GetCurrentDir() +src = [] +group = [] +CPPPATH = [] + +if rtconfig.PLATFORM in ['iccarm']: + Return('group') +elif rtconfig.PLATFORM in GetGCCLikePLATFORM(): + if GetOption('target') != 'mdk5': + src += Glob('./fsp/src/bsp/mcu/all/*.c') + src += Glob('./fsp/src/bsp/mcu/all/cr/*.c') + src += Glob('./fsp/src/bsp/mcu/r*/*.c') + src += Glob('./fsp/src/bsp/cmsis/Device/RENESAS/Source/*.c') + src += Glob('./fsp/src/bsp/cmsis/Device/RENESAS/Source/cr/*.c') + src += Glob('./fsp/src/r_*/*.c') + src += Glob('./fsp/src/r_usb_basic/src/driver/*.c') + src += Glob('./fsp/src/r_usb_basic/src/hw/*.c') + src += Glob('./fsp/src/r_usb_pcdc/src/*.c') + CPPPATH = [ cwd + '/arm/CMSIS_5/CMSIS/Core_R/Include', + cwd + '/fsp/inc', + cwd + '/fsp/src/inc', + cwd + '/fsp/inc/api', + cwd + '/fsp/inc/instances', + cwd + '/fsp/src/r_usb_basic/src/driver/inc', + cwd + '/fsp/src/r_usb_basic/src/hw/inc', + cwd + '/fsp/src/r_usb_pcdc/src/inc',] + +group = DefineGroup('rzn', src, depend = [''], CPPPATH = CPPPATH) +Return('group') +``` + +If you are using Studio for development, right-click on the project and select **Sync SCons Configuration to Project**. + For IAR development, right-click within the current project to open the environment, and run the following command to regenerate the configuration: + `scons --target=iar` + ## RT-Thread Settings Configuration The USB example currently uses the FreeRTOS interface driver, so we also need to enable the FreeRTOS compatibility layer package: diff --git a/projects/etherkit_usb_pcdc/README_zh.md b/projects/etherkit_usb_pcdc/README_zh.md index 7aede88..42ce3a9 100644 --- a/projects/etherkit_usb_pcdc/README_zh.md +++ b/projects/etherkit_usb_pcdc/README_zh.md @@ -32,6 +32,49 @@ EtherKit提供一个USB-Device外设,位于开发板的位置如下所示: ![image-20241126111620891](figures/image-20241126111620891.png) +## 构建配置 + +进入工程找到指定路径下的文件:.\rzn\SConscript,替换该文件为如下内容: + +```c +Import('RTT_ROOT') +Import('rtconfig') +from building import * +from gcc import * + +cwd = GetCurrentDir() +src = [] +group = [] +CPPPATH = [] + +if rtconfig.PLATFORM in ['iccarm']: + Return('group') +elif rtconfig.PLATFORM in GetGCCLikePLATFORM(): + if GetOption('target') != 'mdk5': + src += Glob('./fsp/src/bsp/mcu/all/*.c') + src += Glob('./fsp/src/bsp/mcu/all/cr/*.c') + src += Glob('./fsp/src/bsp/mcu/r*/*.c') + src += Glob('./fsp/src/bsp/cmsis/Device/RENESAS/Source/*.c') + src += Glob('./fsp/src/bsp/cmsis/Device/RENESAS/Source/cr/*.c') + src += Glob('./fsp/src/r_*/*.c') + src += Glob('./fsp/src/r_usb_basic/src/driver/*.c') + src += Glob('./fsp/src/r_usb_basic/src/hw/*.c') + src += Glob('./fsp/src/r_usb_pcdc/src/*.c') + CPPPATH = [ cwd + '/arm/CMSIS_5/CMSIS/Core_R/Include', + cwd + '/fsp/inc', + cwd + '/fsp/src/inc', + cwd + '/fsp/inc/api', + cwd + '/fsp/inc/instances', + cwd + '/fsp/src/r_usb_basic/src/driver/inc', + cwd + '/fsp/src/r_usb_basic/src/hw/inc', + cwd + '/fsp/src/r_usb_pcdc/src/inc',] + +group = DefineGroup('rzn', src, depend = [''], CPPPATH = CPPPATH) +Return('group') +``` + +使用studio开发的话需要右键工程点击 **同步scons配置至项目**;如果是使用IAR开发请在当前工程下右键打开env,执行:scons –target=iar 重新生成配置。 + ## RT-Thread Settings配置 USB示例目前使用的是freertos接口驱动,因此我们还需要使能Freertos兼容层软件包; diff --git a/projects/etherkit_usb_pmsc/README.md b/projects/etherkit_usb_pmsc/README.md index bcf4cf5..b1a4b2f 100644 --- a/projects/etherkit_usb_pmsc/README.md +++ b/projects/etherkit_usb_pmsc/README.md @@ -32,6 +32,49 @@ EtherKit provides a USB-Device peripheral, located on the development board as s ![image-20241126111620891](figures/image-20241126111620891.png) +## Build Configuration + +Locate the file at the specified path in the project: `.\rzn\SConscript` and replace its content with the following: + +```c +Import('RTT_ROOT') +Import('rtconfig') +from building import * +from gcc import * + +cwd = GetCurrentDir() +src = [] +group = [] +CPPPATH = [] + +if rtconfig.PLATFORM in ['iccarm']: + Return('group') +elif rtconfig.PLATFORM in GetGCCLikePLATFORM(): + if GetOption('target') != 'mdk5': + src += Glob('./fsp/src/bsp/mcu/all/*.c') + src += Glob('./fsp/src/bsp/mcu/all/cr/*.c') + src += Glob('./fsp/src/bsp/mcu/r*/*.c') + src += Glob('./fsp/src/bsp/cmsis/Device/RENESAS/Source/*.c') + src += Glob('./fsp/src/bsp/cmsis/Device/RENESAS/Source/cr/*.c') + src += Glob('./fsp/src/r_*/*.c') + src += Glob('./fsp/src/r_usb_basic/src/driver/*.c') + src += Glob('./fsp/src/r_usb_basic/src/hw/*.c') + src += Glob('./fsp/src/r_usb_pmsc/src/*.c') + CPPPATH = [ cwd + '/arm/CMSIS_5/CMSIS/Core_R/Include', + cwd + '/fsp/inc', + cwd + '/fsp/src/inc', + cwd + '/fsp/inc/api', + cwd + '/fsp/inc/instances', + cwd + '/fsp/src/r_usb_basic/src/driver/inc', + cwd + '/fsp/src/r_usb_basic/src/hw/inc', + cwd + '/fsp/src/r_usb_pmsc/src/inc',] + +group = DefineGroup('rzn', src, depend = [''], CPPPATH = CPPPATH) +Return('group') +``` + +If you are using Studio for development, right-click the project and select **Sync SCons Configuration to Project**. For IAR development, right-click within the current project to open the environment, and run the command:`scons --target=iar` to regenerate the configuration. + ## RT-Thread Settings Configuration The USB example currently uses the FreeRTOS interface driver, so we also need to enable the FreeRTOS compatibility layer package: diff --git a/projects/etherkit_usb_pmsc/README_zh.md b/projects/etherkit_usb_pmsc/README_zh.md index b09635f..62d0ff1 100644 --- a/projects/etherkit_usb_pmsc/README_zh.md +++ b/projects/etherkit_usb_pmsc/README_zh.md @@ -32,6 +32,49 @@ EtherKit提供一个USB-Device外设,位于开发板的位置如下所示: ![image-20241126111620891](figures/image-20241126111620891.png) +## 构建配置 + +进入工程找到指定路径下的文件:.\rzn\SConscript,替换该文件为如下内容: + +```c +Import('RTT_ROOT') +Import('rtconfig') +from building import * +from gcc import * + +cwd = GetCurrentDir() +src = [] +group = [] +CPPPATH = [] + +if rtconfig.PLATFORM in ['iccarm']: + Return('group') +elif rtconfig.PLATFORM in GetGCCLikePLATFORM(): + if GetOption('target') != 'mdk5': + src += Glob('./fsp/src/bsp/mcu/all/*.c') + src += Glob('./fsp/src/bsp/mcu/all/cr/*.c') + src += Glob('./fsp/src/bsp/mcu/r*/*.c') + src += Glob('./fsp/src/bsp/cmsis/Device/RENESAS/Source/*.c') + src += Glob('./fsp/src/bsp/cmsis/Device/RENESAS/Source/cr/*.c') + src += Glob('./fsp/src/r_*/*.c') + src += Glob('./fsp/src/r_usb_basic/src/driver/*.c') + src += Glob('./fsp/src/r_usb_basic/src/hw/*.c') + src += Glob('./fsp/src/r_usb_pmsc/src/*.c') + CPPPATH = [ cwd + '/arm/CMSIS_5/CMSIS/Core_R/Include', + cwd + '/fsp/inc', + cwd + '/fsp/src/inc', + cwd + '/fsp/inc/api', + cwd + '/fsp/inc/instances', + cwd + '/fsp/src/r_usb_basic/src/driver/inc', + cwd + '/fsp/src/r_usb_basic/src/hw/inc', + cwd + '/fsp/src/r_usb_pmsc/src/inc',] + +group = DefineGroup('rzn', src, depend = [''], CPPPATH = CPPPATH) +Return('group') +``` + +使用studio开发的话需要右键工程点击 **同步scons配置至项目**;如果是使用IAR开发请在当前工程下右键打开env,执行:scons –target=iar 重新生成配置。 + ## RT-Thread Settings配置 USB示例目前使用的是freertos接口驱动,因此我们还需要使能Freertos兼容层软件包; diff --git a/rt-thread/components/drivers/rtc/alarm.c b/rt-thread/components/drivers/rtc/alarm.c index dece455..b78528a 100644 --- a/rt-thread/components/drivers/rtc/alarm.c +++ b/rt-thread/components/drivers/rtc/alarm.c @@ -42,11 +42,7 @@ static rt_err_t alarm_set(struct rt_alarm *alarm) struct rt_rtc_wkalarm wkalarm; rt_err_t ret; -#ifdef RT_USING_SOFT_RTC - device = rt_device_find("sw_rtc"); -#else device = rt_device_find("rtc"); -#endif if (device == RT_NULL) { diff --git a/rt-thread/components/drivers/rtc/soft_rtc.c b/rt-thread/components/drivers/rtc/soft_rtc.c index dcd4721..8d1e0fb 100644 --- a/rt-thread/components/drivers/rtc/soft_rtc.c +++ b/rt-thread/components/drivers/rtc/soft_rtc.c @@ -226,8 +226,11 @@ static int rt_soft_rtc_init(void) { return 0; } - /* make sure only one 'sw_rtc' device */ - RT_ASSERT(!rt_device_find("sw_rtc")); + /* make sure only one 'rtc' device */ +#if defined(RT_USING_SOFT_RTC) && defined(RT_USING_RTC) +#warning "Please note: Currently only one RTC device is allowed in the system, and the name is "rtc"." +#endif + RT_ASSERT(!rt_device_find("rtc")); #ifdef RT_USING_ALARM rt_timer_init(&alarm_time, @@ -258,7 +261,7 @@ static int rt_soft_rtc_init(void) /* no private */ soft_rtc_dev.user_data = RT_NULL; - rt_device_register(&soft_rtc_dev, "sw_rtc", RT_DEVICE_FLAG_RDWR); + rt_device_register(&soft_rtc_dev, "rtc", RT_DEVICE_FLAG_RDWR); source_device = &soft_rtc_dev;