lab4 writing basic software applications lab: microblaze

48
Lab4 Writing Basic Software A pplications Lab: MicroBl aze

Post on 22-Dec-2015

226 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lab4 Writing Basic Software Applications Lab: MicroBlaze

Lab4Writing Basic Software Applications Lab: MicroBlaze

Page 2: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 2

Objectives Write a basic application to access an IP

peripheral. Utilize XPS to generate a MSS file. Generate a bit file. Download the bit file and verify in

hardware. Develop a simple linker script.

Page 3: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 3

Procedure The first three labs defined the hardware for the

processor system. This lab comprises several steps, including the writing of a basic software application to access one of the peripherals specified in Lab2.

Below each general instruction for a given procedure, you will find accompanying step-by-step directions and illustrated figures providing more detail for performing the general instruction. If you feel confident about a specific instruction, feel free to skip the step-by-step directions and move on to the next general instruction in the procedure.

Page 4: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 4

Opening the Project Create a lab4 folder in the X:\EDKLab\ directory. If you wish t

o continue with your completed design from lab3 then copy the contents of the lab3 folder into the lab4 folder.

1. 2. 3. 4.

Page 5: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 5

Opening the Project Open XPS, click File → Open Project and browse to the proje

ct which is in the directory: X:\EDKLab\lab4, then click system.xmp to open the project.

1.

2.

Page 6: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 6

Creating a BSP Double-click microblaze_0 from the System BSP

hierarchy, as shown in following Figure. You can also open the same dialog box by clicking Project Software Platform Settings.

Page 7: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 7

Creating a BSP This will open the

Software Platform Settings dialog with the Software Platform tab. In the Software Platform tab, the Driver can be selected for each of the peripherals in the system. You can also select the Kernel and Operating Systems for each of the processor instances. In addition, supporting libraries can be selected if they will be used.

Page 8: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 8

Creating a BSP Click on the Processor an

d Driver Parameters tab and specify the following parameters:

Processor Parameters: Compiler – mb-gcc Archiver – mb-ar EXTRA_COMPILER_FLAG

S – -g xmdstub_peripheral – n

one CORE_CLOCK_FREQ_HZ

– 50000000 Driver Parameters:

Leave Blank

Page 9: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 9

Creating a BSP Click the Library/OS Parameters tab. Click the Current Value field for stdin and sele

ct RS232. Similarly, click the Current Value field for stdout and select RS232. This will assign the uart device as the stdin and stdout. Base System Builder already set these when the RS232 peripheral was included. If a system does not have any stdin/stdout devices, then keep the current value as None. Leave the Current Value for need_xil_malloc as false because your application does not use any malloc function call.

Click 確定 to accept the settings.

Page 10: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 10

Generate the BSP Double-click the system.mss file under the Syste

m tab in XPS, as shown in following Figure.

Page 11: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 11

Generate the BSP This will open the MSS file for this project. XPS has written th

e parameters that are specified in the Peripheral Options to the system.mss file.

Close the system.mss file.

Page 12: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 12

Generate the BSP Generate the BSP by clicking Tools Generate Li

braries or click the button. This will run LibGen on the system.mss file to generate the BSP library files.

Page 13: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 13

Creating a Basic C File In the Applications Tab double Click on Software

Projects. This will open a dialog box to create a new project.

Enter the name MyProj and click OK.

1.

2.

Page 14: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 14

Creating a Basic C File Click File New. This will open a dialog box

to create a new project and open a new document in the XPS editor.

Page 15: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 15

Creating a Basic C File The first step is to add the header

files for the required functions. All of the header files related to this project were placed in the …\microblaze_0\include directory when LibGen was run.

Add the following to the C file: #include "xparameters.h" #include "xgpio.h“

Page 16: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 16

Creating a Basic C File Click File Save As, this will open the Save As dialog. Create

a new directory named code in the lab4mb directory and save the file as system.c, as shown in following Figure.

1. 2

.3.

Page 17: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 17

Creating a Basic C File Add the following to the C file.

main() {

The first step in main is to initialize the GPIO peripheral.

Page 18: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 18

Creating a Basic C File From the Windows start menu Click 開始 程式集 Xilinx Platfor

m Studio 6.3i Documentation EDK 6.3i Reference & User Guides.

Scroll down and click Driver Reference Guide.

1.

2.

Page 19: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 19

Creating a Basic C File Scroll down and click Driver API Links.

Scroll down and click 2.00.a of the gpio.

This will open the Xilinx Processor IP Library to gpio v2_00_a.

1.

2.

Page 20: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 20

Creating a Basic C File Click Globals to view list of all documented functions, varia

bles, defines, enums, and typedefs with links to the documentation.

Click xgpio.c of XGpio_Initialize().

1.

2.

Page 21: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 21

Creating a Basic C File This documentation contains a detailed description of the X

Gpio_Initialize function. The documentation outlines two parameters that XGpio_Initialize requires:

InstancePtr is a pointer to an XGpio instance. The memory the pointer references must be pre-allocated by the caller. Further calls to manipulate the component through the XGpio API must be made with this pointer.

DeviceId is the unique id of the device controlled by this XGpio component. Passing in a device id associates the generic XGpio instance to a specific device, as chosen by the caller or application developer.

Page 22: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 22

Creating a Basic C File Define an XGpio type variable named gp_out. This variable

will be used as the first parameter in the Xgpio_Initialize function call. Add the variable to the function call. It should now look like the following:

XGpio_Initialize(&gp_out,

The second parameter is the device ID for the device that you want to initialize. This information can be found in the xparameters.h file.

Page 23: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 23

Creating a Basic C File Under the System BSP microblaze_0 instance, double-click

the Generated Header: microblaze_0/include/xparameters.h entry, as shown in following Figure.

Page 24: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 24

Creating a Basic C File LibGen writes the xparameters.h file, and the file provides cr

itical information for driver function calls. This function call initializes the GPIO that is used as an outpu

t for the LEDs found on the board. In the xparameters.h file, find the following #define used to identify the LEDS_1BIT peripheral:

#define XPAR_LEDS_1BIT_DEVICE_ID 1

Page 25: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 25

Creating a Basic C File This #define can be used as the device ID in the function call.

Add the device ID to the function call so that it looks like the following:

XGpio gp_out; XGpio_Initialize(&gp_out, XPAR_LEDS_1BIT_DEVICE_ID);

The file should now look like following Figure.

Page 26: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 26

Creating a Basic C File Refer to the documentation to determine how to set all of th

e bits of the GPIO bus as outputs. This will involve using the XGpio_SetDataDirection function call. Add code to perform this function, and then save the file.

XGpio_SetDataDirection (&gp_out, 1, 0x0);

Page 27: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 27

Creating a Basic C File Write code to implement a counter that continuously counts from 0

to 1(Only 1 led on the board). The count will be used to drive the output of the LEDs_1Bit peripheral. The following code is provided as an example:

Int j=0; while (1) { j = (j+1) % 2; }

You will also need to include the declaration of the variable j. Output the current value of j to the LEDs_1Bit. Using the information in the gpio.h documentation, the function XGpio_DiscreteWrite() will be used.

XGpio_DiscreteWrite (&gp_out, 1, j);

Page 28: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 28

Creating a Basic C File Because the MicroBlaze™ processor does not have an internal timer

or counter, a delay loop must be created in the software. Add the following code to create a software delay to pause between each count that gets displayed:

int i=0; for (i=0; i<10; i++);

Save and close the file.

Page 29: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 29

Compile the source code Click the Application tab to view the current project’s Compiler Options a

nd Sources. Right-click Project: TestApp and unselect Mark to Initialize BRAMs. Verify t

hat the small green arrow next to Project: MyProj does not have a red x through it. If it does, Right-click Project: MyProj and toggle Mark to Initialize BRAMs.

1.

2.

Page 30: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 30

Compile the source code Right-click Sources under Project: MyProj and sel

ect Add File. Browse to the code directory under the current project (lab4) and select the system.c file.

1.

2.

3.

Page 31: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 31

Compile the source code Double-click Compiler Options under

Project: MyProj in the Application tab. Click the Directories tab to set the directory options.

Change the Output ELF File entry to place the executable.elf file in the microblaze_0\code directory under the current project directory.

For Linker Script Browse to the TestAppLinkScr file in the TestApp\Src directory.

The directory options should be set as shown in following Figure.

Click 確定 to accept the setting.

Page 32: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 32

Compile the source code Compile the C code by clicking the button.

After the program has compiled determine the sizes of the program sections.

Page 33: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 33

Linker Script Start a Xygwin shell by clicking the button. This should pla

ce you in the project directory. Change the directory to …\lab4\microblaze_0\code by usin

g the cd command.

Type mb-objdump –h executable.elf at the prompt in the Xygwin shell window to list various sections of the program, along with the starting address and size of each section.

Page 34: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 34

Linker Script There are many sections are listed in the

output.

Page 35: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 35

Linker Script In XPS, go to Tools

Generate Linker Script…

In the Select Object window, verify that MyProj is chosen as the SW application project and click OK.

Page 36: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 36

Linker Script In the Generate Linker Script window, verify that the correct

path is set to the TestAppLinkScr linker script, change the stack size to 0x100 and click Generate.

Page 37: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 37

Linker Script Double-click Linker Script under Compiler Options in the A

pplications tab to verify that 0x100 has been entered as the stack size.

Recompile the program.

Page 38: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 38

Linker Script Execute the mb-objdump command in the Xygwin shell.

Page 39: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 39

Linker Script Change the linker script file to include a heap definition of 25

6 bytes near the top of the linker script as shown below. To do this, double click on the Linker Script under Project: MyProj as follows:

Add the _HEAP_SIZE definition near the top as shown below:

Page 40: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 40

Linker Script Add the three lines shown below to the .bss_stack section of

the linker script as shown below. . = ALIGN(16); _heap_end = .;

Save the linker script, then recompile the program.

Page 41: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 41

Linker Script Execute the mb-objdump command in the Xygwin shell.

Page 42: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 42

Linker Script Edit the system.c file to define a local variable, k, initialized

with a value of 0, and increment it by 1 inside the for loop. Change the system.c file to define a local variable and increment it in the for loop. The code should look like the following:

int k=0; k = k + 1;

Save the system.c file, then recompile the code.

Page 43: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 43

Linker Script Execute the mb-objdump command in the Xygwin shell.

Page 44: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 44

Linker Script Edit the system.c file to add a statement that will output the

value of the variable k to the LEDs. Change the system.c file to add a statement that outputs the value of variable k to the LEDs. The code should look like the following:

XGpio_DiscreteWrite (&gp_out, 1, k);

Save the system.c file, then recompile the code.

Page 45: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 45

Linker Script Execute the mb-objdump command in the Xygwin shell.

Page 46: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 46

Verifying in Hardware In the source code

file, comment out all lines which refer to variable k.

Change i<10 to i<1600000 in the for loop and save the file.

Recompile the source file.

Page 47: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 47

Verifying in Hardware Click Tools Update Bitstream and implement and generat

e the BIT file. Download the generated bit file by clicking Tools Downloa

d. After the board is programmed, you will see that the LEDs are

turning ON and OFF in the desired sequence.

Page 48: Lab4 Writing Basic Software Applications Lab: MicroBlaze

for EDK 6.3i 48

Conclusion XPS can be used to define, develop, and integrate t

he software components of the embedded system. A device driver interface can be defined for each of the peripherals and the processor. XPS creates an MSS file that represents the software side of the processor system. The peripheral-specific functional software can be developed and compiled. The executable file can be generated from the compiled object codes and libraries. The linker script can be edited to control placement of various code segments into target memory.