MICROPROCESSOR TECHNOLOGY II LAB1.pdf · project in uVision ... basic knowledge about Microprocessor Technology, ... Create your first program by adding following content to main.c
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
AGH University of Science and Technology
Faculty of Computer Science, Electronics and Telecommunications Department of Electronics
MICROPROCESSOR TECHNOLOGY II
LAB 1
Introduction to Keil environment and Kinetis family
Program always starts from attached header files. In this case this header file holds only register
“masks" and names which allow us for more intuitive use of those registers. If you wish to look into
the file, just right click on header name and select Open Document <MKL46Z4.H>. For the most part,
the masks are named based on the KL46 reference manual in the form 'CHAPTER NAME'_'REGISTER
NAME'_'BIT NAME'_MASK. Secondly there is a definition of green LED, as an index in mask, created in
the next line of code. Whole program consist of modules:
InitLED,
BlinkLED,
main.
InitLED is a function to initialize GPIO port (General Purpose Input Output). For correct configuration
we will be modifying registers listed below:
System Integration Module (SIM) – this module gives control of which peripherals are clocked.
By leaving them without access to the clock we save power, but leave them inoperable.
o System Clock Gating Control Register 5 (SIM_SCGC5) – this register holds the clock
enable for the various ports. In order to use any pins on a port this must be enabled
for that port (in our case port D).
Port Control and Interrupts (PORT) – this register determines which pins are used for which
peripheral (page 172 in KL46_RM)
o Pin Control Register (PORTD_PCR5) – setting up a function on a multiplekser, which
pin will fulfill; we will be using 5 pin on port D to control green LED
General Purpose Input Output (GPIO) – once a pin is configured as GPIO this register
determines whether it is an input or an output
o Port Data Direction Register (GPIO_PDDR) – 1 = output, 0 = input
o Port Data Output Register (GPIO_PDOR) – change of value on pin
o Port Data Set Register (GPIO_PSOR) – setting value 1
o Port Data Clear Register (GPIO_PCOR) – setting value 0
o Port Data Toggle Register (GPIO_PTOR) – changing value for opposite form current
o Port Data Input Register (GPIO_PDIR) – for reading value when selected input option
BlinkLED is a function to implement one from many ways for blinking LED. There was chosen
GPIO_PTOR register.
Main is a master function, which perform initialization of GPIO ports, and then starts blinking of a LED
in the loop.
3.4 EXERCISE Based on above description of program functionality and Reference Manual, add in your own words
comment to every line of the code in main.c file. In what purpose in lines 7 and 9 there is |= sign?
Place answer as an equation in comment.
3.5 EXERCISE Run application on the FRDM-KL46Z set:
WARNING! On this stage please make sure that on your evaluation board are loaded correct CMSIS
drivers. Please go back to PRE LAB instruction and procced according to section 4.
1. After making file main.c complete please build project. We can do this by selecting from the
menu Project > Build Target, or by pressing F7 key.
2. Next once we should configure debugger. For this purpose click on Options for Target …
3. In newly opened window choose Debug tab, and from list in „Use” look for „CMSIS-DAP
Debugger”.
4. Then click on Settings, and there from list for Port choose „SW”.
5. Additionally in Flash Download tab select „Reset and Run” option.
6. After actualization of every settings, in main window in toolbar click on
Flash > Download (or icon).
3.6 EXERCISE When programming the essential feature is the ability to debug code. Therefore, now check how our
first program work.
WARNING! During the debugging or simulating program please do not close the windows with files
that are open in this perspective. Their closure may threatens suspension of the program.
1. In main.c file please choose the line of code in which there is the procedure for changing value
of pin 5 in port D (PTD->PTOR), and press F9 key (you can also click on red ball icon). In this
way we assign the Breakpoint. There could be only one during debugging.
2. Then to start debug session please press Ctrl+F5 combination or (In case of using
evaluation version there will appear message about code size limitations)
3. Open content of GPIO ports: Peripherals > System Viewer > GPIO > PTD
4. Several times press F5 key (Run) and check what kind of changes occurred in individual
registers.
5. Close debug perspective by clicking on „d” icon, or by Ctrl+F5 shortcut.
3.7 EXERCISE Often we do not have access to hardware during creating software. This is when we use simulator.
1. To run simulator go to debuger configuration, that is
2. Then in tab „Debug” choose Use Simulator (A).
3. Next to window titled: „Initialization File” click on three dots icon (B), enter „init” name and
confirm it by Open button. Accept creating new file.
4. Then we must modify this initialization file. Therefore open it by Edit button (C) (it will open in
the background). Window „Options of Target …” close by OK button.
5. To init.ini file copy:
1. MAP 0x40000000, 0x400FFFFF read write
6. Save file, and next localize and open „system_MKL46Z.c” file (in Project sub-window, Device)
7. In opened file find and comment (by adding in the front of each of them //) following lines:
124. 125. 126. 127.
while((MCG->S & MCG_S_IREFST_MASK) == 0x00U) { /* Check that the source of the …. } while((MCG->S & 0x0CU) != 0x00U) { /* Wait until output of the FLL is selected */ }
8. Save and build whole project (shortcut F7)
9. Next repeat steps from exercise 3.6
A
B
C
4 HOMEWORK
In order to practice setting ports please modify main program according to tasks:
1. Add support of red LED (schematics of FRDM-KL46Z) by using mask (modify existing one for
both LEDs)
2. Add function of blinking red LED with different than green one frequency, and using other
than GPIO_PTOR register.
3. Try to simulate program only on core registers.