【转】使用Matlab 2015a进行Altera SoC软硬件协同设计
[复制链接]
链接:http://cn.mathworks.com/help/hdl ... a-soc-platform.html
This example shows how to use the HDL Coder™ to generate a custom HDL IP core which blinks LEDs on the Arrow® SoCKit® evaluation kit, and shows how to use Embedded Coder® to generate C code that runs on the ARM® processor to control the LED blink frequency.
Introduction This example is a step-by-step guide that helps introduce you to the hardware-software codesign workflow. You can use MATLAB® and Simulink® to design, simulate, and verify your application, perform what-if scenarios with algorithms, and optimize parameters. You can then prepare your design for hardware and software implementation on the Altera Cyclone V SoC by deciding which system elements will be performed by the programmable logic, and which system elements will run on the ARM Cortex-A9. Using the guided workflow shown in this example, you automatically generate HDL code for the programmable logic using HDL Coder, generate C code for the ARM using Embedded Coder, and implement the design on the Altera SoC Platform. In this workflow, you perform the following steps: Set up your Altera SoC hardware and tools. Partition your design for hardware and software implementation. Generate an HDL IP core using HDL Workflow Advisor. Integrate the IP core into a Altera Qsys project and program the Altera SoC hardware. Generate a software interface model. Generate C code from the software interface model and run it on the ARM Cortex-A9 processor. Tune parameters and capture results from the Altera SoC hardware using External Mode.
For more information, refer to other more advanced examples, and the HDL Coder and Embedded Coder documentation. Requirements Altera Quartus 13.1 Altera SoC Embedded Design Suite Arrow SoCKit Cyclone V SoC evaluation kit HDL Coder Support Package for Altera SoC Platform Embedded Coder Support Package for Altera SoC Platform
Set up Altera SoC hardware and tools 1. Set up the Arrow SoCKit evaluation kit as shown in the figure below. To learn more about the Arrow SoCKit hardware setup, please refer to the board documentation.
1.1 Set up SW4 switch (JTAG chain select) as shown in the figure below. Position 1 : OFF; Position 2 : ON. This configuration includes HPS in JTAG chain, and bypasses HSMC.
1.2 Set up JP2 as shown in the figure below to adjust the I/O Standard of the FPGA/HSMC pins. Short Pin 5 and 6 to set the I/O voltage to 2.5V.
1.3 Set up J17 - J19 as shown in the figure above to boot HPS from SD card. J17: Short Pin 1 and 2; J18: Short Pin 1 and 2; J19: Short Pin 2 and 3. 1.4 Set up J15 - J16 as shown in the figure above for HPS clock setting. J15: Short Pin 2 and 3; J16: Short Pin 2 and 3. 1.5 Set up SW6 on the back side of the board as shown in the figure below. This switch set the FPGA configuration mode. Set all 6 positions to ON.
1.6 Make sure your USB device drivers, such as for the FTDI USB to UART, are installed correctly. If not, search for the drivers online and install them. 1.7 Connect your computer to the USB UART connector using a Micro-USB cable. 1.8 Connect your computer to the USB Blaster connector using a Micro-USB cable. 1.9 Connect your computer and the Arrow SoCKit board using an Ethernet cable. 2. Install the HDL Coder and Embedded Coder Support Packages for Altera SoC Platform if you haven't already. To start the installer, go to the MATLAB toolstrip and clickAdd-Ons > Get Hardware Support Packages. For more information, please refer to the Support Package Installation documentation. 3. Make sure you are using the SD card image provided by the Embedded Coder Support Package for Altera SoC Platform. If you need to update your SD card image, run the Support Package Firmware Updater by running the following command at the MATLAB prompt: targetupdater
4. Test the serial connection using the following configuration. Baud rate: 115200; Data bits: 8; Stop bits: 1; Parity: None; Flow control: None. 5. Test the Ethernet connection, make sure your computer and the Arrow SoCkit board can ping each other. The default Arrow SoCkit IP address is 192.168.1.101. You can change the IP address in Support Package Firmware Updater. Set up the Ethernet network adapter on your computer to use an IP address on the same subnet, for example,192.168.1.1. Set the subnet mask to 255.255.255.0. 6. Set up the Altera Quartus synthesis tool path using the following command in the MATLAB command window. Use your own Quartus installation path when you run the command. hdlsetuptoolpath('ToolName', 'Altera Quartus II', 'ToolPath', 'C:\Altera\13.1\quartus\bin64\quartus.exe');
7. Set up the Arrow SoCKit hardware connection by entering the following command in the MATLAB command window: h = alterasoc();
The alterasoc method logs in to the hardware via COM port and runs the ifconfig command to obtain the IP address of the board. Partition your design for hardware and software implementation The first step of the Altera SoC hardware-software codesign workflow is to decide which parts of your design to implement on the programmable logic, and which parts to run on the ARM processor. Group all the blocks you want to implement on programmable logic into an atomic subsystem. This atomic subsystem is the boundary of your hardware-software partition. All the blocks inside this subsystem will be implemented on programmable logic, and all the blocks outside this subsystem will run on the ARM processor. In this example, the subsystem led_counter is the hardware subsystem. It models a counter that blinks the LEDs on an FPGA board. Two input ports, Blink_frequency andBlink_direction, are control ports that determine the LED blink frequency and direction. All the blocks outside of the subsystem led_counter are for software implementation. In Simulink, you can use the Slider Gain or Manual Switch block to adjust the input values of the hardware subsystem. In the embedded software, this means the ARM processor controls the generated IP core by writing to the AXI interface accessible registers. The output port of the hardware subsystem, LED, connects to the LED hardware. The output port, Read_Back, can be used to read data back to the processor. open_system('hdlcoder_led_blinking_4bit');
Generate an HDL IP core using the HDL Workflow Advisor Using the IP Core Generation workflow in the HDL Workflow Advisor enables you to automatically generate a sharable and reusable IP core module from a Simulink model. The generated IP core is designed to be connected to an embedded processor on an FPGA device. HDL Coder generates HDL code from the Simulink blocks, and also generates HDL code for the AXI interface logic connecting the IP core to the embedded processor. HDL Coder packages all the generated files into an IP core folder. You can then integrate the generated IP core with a larger FPGA embedded design in the Altera Qsys environment. 1. Start the IP core generation workflow. 1.1. Open the HDL Workflow Advisor from the hdlcoder_led_blinking_4bit/led_counter subsystem by right-clicking the led_counter subsystem, and choosing HDL Code > HDL Workflow Advisor. 1.2. In the Set Target > Set Target Device and Synthesis Tool task, for Target workflow, select IP Core Generation. 1.3. For Target platform, select Arrow SoCKit development board. If you don't have this option, select Get more to open the Support Package Installer. In the Support Package Installer, select Altera SoC and follow the instructions provided by the Support Package Installer to complete the installation. 1.4. Click Run This Task to run the Set Target Device and Synthesis Tool task.
2. Configure the target interface. Map each port in your DUT to one of the IP core target interfaces. In this example, input ports Blink_frequency and Blink_direction are mapped to the AXI4 interface, so HDL Coder generates AXI interface accessible registers for them. The LED output port is mapped to an external interface, LEDs General Purpose [0:3], which connects to the LED hardware on the Altera SoC board. 2.1 In the Set Target > Set Target Interface task, choose AXI4 for Blink_frequency, Blink_direction, and Read_back. 2.2 Choose LEDs General Purpose [0:3] for LED.
3. Generate the IP Core. To generate the IP core, right-click the Generate RTL Code and IP Core task and select Run to Selected Task.
4. Generate and view the IP core report. After you generate the custom IP core, the IP core files are in the ipcore folder within your project folder. An HTML custom IP core report is generated together with the custom IP core. The report describes the behavior and contents of the generated custom IP core.
Integrate the IP core with the Altera Qsys environment In this part of the workflow, you insert your generated IP core into a embedded system reference design, generate an FPGA bitstream, and download the bitstream to the Altera SoC hardware. The reference design is a predefined Altera Qsys project. It contains all the elements the Altera software needs to deploy your design to the Altera SoC platform, except for the custom IP core and embedded software that you generate. 1. To integrate with the Altera Qsys environment, select the Create Project task under Embedded System Integration, and click Run This Task. Both an Altera Qsys project and an Altera Quartus project are generated, with links to the projects provided in the dialog window. You can optionally open up the projects to take a look.
2. If you have an Embedded Coder license, you can generate a software interface model in the next task, Generate Software Interface Model. The details of the software interface model are explained in the next section of this example, "Generate a software interface model". 3. Build the FPGA bitstream in the Build FPGA Bitstream task. Make sure the Run build process externally option is checked, so the Altera synthesis tool will run in a separate process from MATLAB. Wait for the synthesis tool process to finish running in the external command window.
4. After the bitstream is generated, select the Program Target Device task and click Run This Task to program the Altera SoC hardware.
After you program the FPGA hardware, the LED starts blinking on your Altera SoC board.
Next, you will generate C code to run on the ARM processor to control the LED blink frequency and direction. Generate a software interface model In the HDL Workflow Advisor, after you generate the IP core and insert it into the Qsys reference design, you can optionally generate a software interface model in theEmbedded System Integration > Generate Software Interface Model task. The software interface model contains the part of your design that runs in software. It includes all the blocks outside of the HDL subsystem, and replaces the HDL subsystem with AXI driver blocks. If you have an Embedded Coder license, you can automatically generate embedded code from the software interface model, build it, and run the executable on Linux on the ARM processor. The generated embedded software includes AXI driver code, generated from the AXI driver blocks, that controls the HDL IP core. Run the Generate Software Interface Model task and see that a new model is generated. The task dialog shows a link to the model.
In the generated software interface model, the "led_counter" subsystem is replaced with the AXI driver blocks which generate the interface logic between the ARM processor and FPGA.
Run the software interface model on Altera SoC hardware In this part of the workflow, you configure the generated software interface model, automatically generate embedded C code, and run your model on the ARM processor in the Altera SoC hardware in External mode. When you are prototyping and developing an algorithm, it is useful to monitor and tune the algorithm while it runs on hardware. The External mode feature in Simulink enables this capability. In this mode, your algorithm is first deployed to the ARM processor in the Altera SoC hardware, and then linked with the Simulink model on the host computer through an Ethernet connection. The main role of the Simulink model is to tune and monitor the algorithm running on the hardware. Because the ARM processor is connected to the HDL IP core through the AXI interface, you can use External mode to tune parameters, and capture data from the FPGA.
In the generated model, open the Configuration Parameters dialog box. Select Solver and set "Stop Time" to "inf". From the model menu, select Simulation > Mode > External. Click the Run button on the model toolstrip. Embedded Coder builds the model, downloads the ARM executable to the Altera SoC hardware, executes it, and connects the model to the executable running on the Altera SoC hardware. Double-click the Slider Gain block. Change the Slider Gain value and observe the change in frequency of the LED array blinking on the Altera SoC hardware. Double-click the Manual Switch block to switch the direction of the blinking LEDs. Double-click the scope connected to the Read_back output port and observe that the output data of the FPGA IP core is captured and sent back to the Simulink scope. When you are done changing model parameters, click the Stop button on the model. Observe that the system command window opened in the previous step indicates that the model has been stopped. At this point, you can close the system command window.
Summary This example shows how the hardware and software codesign workflow helps automate the deployment of your MATLAB and Simulink design to the Altera SoC platform. You can explore the best ways to partition and deploy your design by iterating through the workflow. The following diagram shows the high-level picture of the workflow you went through in this example. To learn more about the hardware and software codesign workflow, please refer to the HDL Coder documentation.
|