Assembly Language Programming: Difference between revisions

From Class Wiki
Jump to navigation Jump to search
Line 47: Line 47:
=====MSP430 TI C Compiler=====
=====MSP430 TI C Compiler=====
*[http://www.ti.com/lit/ug/slau132j/slau132j.pdf MSP430 Optimizing C/C++ Compiler] (See Section 6.5 and following for how to mix C/C++ and Assembly. It is really best to read the entire chapter though, as it is all pertinent to mixing C and Assembly. It will also help you if you want to program in C, as it tells how the C compiler uses the memory, the stack, the registers, etc., and once you understand the processor as you learn to do when you learn its assembly language, it is very interesting to see how that all works in C.)
*[http://www.ti.com/lit/ug/slau132j/slau132j.pdf MSP430 Optimizing C/C++ Compiler] (See Section 6.5 and following for how to mix C/C++ and Assembly. It is really best to read the entire chapter though, as it is all pertinent to mixing C and Assembly. It will also help you if you want to program in C, as it tells how the C compiler uses the memory, the stack, the registers, etc., and once you understand the processor as you learn to do when you learn its assembly language, it is very interesting to see how that all works in C.)
**[http://processors.wiki.ti.com/index.php/Printf_support_for_MSP430_CCSTUDIO_compiler Here] is how to use printf() statements with Code Composer Studio.**[http://people.wallawalla.edu/~rob.frohne/ClassHandouts/Assembly/example_workspace.zip TI C Examples Workspace] This is a CCS workspace with all the C examples from TI for the MSP430F5529. It is useful to work around a bug in MSPWare that broke the feature that you could use in the Examples to create an instance of an example in your workspace. You can import projects from this workspace into your regular one, so you don't have to switch workspaces to see the examples. You can read the descriptions for these examples in the Examples feature of Code Composer Studio. You just can't import them into your workspace until TI fixes the bug. When they do, this will no longer be useful. Soon I hope!
**[http://processors.wiki.ti.com/index.php/Printf_support_for_MSP430_CCSTUDIO_compiler Here] is how to use printf() statements with Code Composer Studio.
=====IAR Tools=====
=====IAR Tools=====
IAR also makes a toolchain. It is not free, but you will sometimes find code that was developed for it, and it is slightly different from that developed for Code Composer Studio using either the TI or GCC compilers/assemblers.
IAR also makes a toolchain. It is not free, but you will sometimes find code that was developed for it, and it is slightly different from that developed for Code Composer Studio using either the TI or GCC compilers/assemblers.
Line 70: Line 70:
#error Compiler not supported!
#error Compiler not supported!
#endif
#endif

</nowiki>
</nowiki>
Note that you need to substitute the appropriate ISR vectors in your code.
Note that you need to substitute the appropriate ISR vectors in your code.
Line 76: Line 75:
*[https://hassanolity.files.wordpress.com/2013/11/the_c_programming_language_2.pdf Kerningham & Richie's famous book], The C Programming Language.
*[https://hassanolity.files.wordpress.com/2013/11/the_c_programming_language_2.pdf Kerningham & Richie's famous book], The C Programming Language.
Put a section here with |= and &= ~something, etc, that will help students understand how to translate from C to assembly.
Put a section here with |= and &= ~something, etc, that will help students understand how to translate from C to assembly.
===Logic Analyzer Information===

These logic analyzers are clones of the original [https://www.saleae.com/ Saleae] analyzer. They have software compatible with this analyzer, but they don't like you to use it.
*[http://sigrok.org/ The Sigrok project] provides open source software for this logic analyzer and other laboratory instruments. I recommend this software. The latest features can be had by compiling from the source code.
**[http://sigrok.org/wiki/Downloads Sigrok software downloads] are here. It runs on Linux, Windows, OS X and even Android, as well as FreeBSD and a bunch of other operating systems.
**[http://sigrok.org/wiki/Building Here are instructions to build from source.]
[[Image:Logic_Analyzer.png|thumb|widthpx|450 ]]
===Other Miscellaneous Interesting Reading===
*[http://kysmykseka.net/koti/wizardry/Programming/Misc/Charles%20Petzold%20-%20Code%20-%20The%20Hidden%20Language%20of%20Computer%20Hardware%20and%20Software.pdf Code: The Hidden Language of Computer Hardware and Software by Charles Petzold] This is a good read about the history of the subject which gives the reader a good understanding of the subject.
===MSP430F5529 Specific Data===
===MSP430F5529 Specific Data===
*[http://www.ti.com/lit/ug/slau208o/slau208o.pdf MSP430x5xx and MSP430x6xx Family User's Guide] This is the most important reference for the MSP430F5529. Read it carefully (as a reference).
*[http://www.ti.com/lit/ug/slau208o/slau208o.pdf MSP430x5xx and MSP430x6xx Family User's Guide] This is the most important reference for the MSP430F5529. Read it carefully (as a reference).
*[http://www.ti.com/lit/ds/symlink/msp430f5529.pdf MSP430F5529 Data Sheet]
*[http://www.ti.com/lit/ds/symlink/msp430f5529.pdf MSP430F5529 Data Sheet]
*[http://www.ti.com/product/msp430f5529 TI web page on the MSP430F5529]
*[http://www.ti.com/product/msp430f5529 TI web page on the MSP430F5529]**[[MSP430F5529 Memory Map]] is in the ti/ccsv6/ccs_base/msp430/include/msp430f5529.cmd file.

===Evaluation Board Data===
*[http://www.ti.com/tool/msp-exp430f5529lp MSP430 F5529 LaunchPad Evaluation Kit Resource Page]
**[http://processors.wiki.ti.com/index.php/MSP430F5529_LaunchPad TI MSP430F5529 Launchpad Wiki Page] This page has the nice pin out card that came with your Launchpad.
**[http://www.ti.com/lit/pdf/slau533 MSP-EXP430F5529LP Launchpad Development Kit User's Guide]
**[http://people.wallawalla.edu/~rob.frohne/ClassHandouts/Assembly/example_workspace.zip TI C Examples Workspace] This is a CCS workspace with all the C examples from TI.
**[https://roboticsclub.org/redmine/projects/infotron/wiki/ProgramMSP430 Infotron Tutorials on Programming the MSP430 LaunchPads]
**[[MSP430F5529 Memory Map]] is in the ti/ccsv6/ccs_base/msp430/include/msp430f5529.cmd file.
**[http://mostlyanalog.blogspot.com/2015/04/clocking-msp430f5529-launchpad.html Setting the clock frequency for the F5529 Launchpad]
**[http://mostlyanalog.blogspot.com/2015/04/clocking-msp430f5529-launchpad.html Setting the clock frequency for the F5529 Launchpad]
**[https://e2e.ti.com/support/microcontrollers/msp430/f/166/p/362204/1366058#1366058 How to program other MSP430s with your Launchpad]
**[https://e2e.ti.com/support/microcontrollers/msp430/f/166/p/294330/1026499 Some notes on porting MSP430G2553 code to the MSP430F5529]. Here is a [http://www.ti.com/lit/an/slaa396/slaa396.pdf TI App Note on the differences between the 5xxx and the previous MSP430 processors.] Note: There are differences in the following:
**[https://e2e.ti.com/support/microcontrollers/msp430/f/166/p/294330/1026499 Some notes on porting MSP430G2553 code to the MSP430F5529]. Here is a [http://www.ti.com/lit/an/slaa396/slaa396.pdf TI App Note on the differences between the 5xxx and the previous MSP430 processors.] Note: There are differences in the following:
***The F5xxx has USB and a bunch more features.
***The F5xxx has USB and a bunch more features.
Line 97: Line 94:
***The USCI (UART, SPI and I2C serial communications) Interrupts have been consolidated. For example see section 39.3.15 of the [http://www.ti.com/lit/ug/slau208o/slau208o.pdf F5xxx User Guide].
***The USCI (UART, SPI and I2C serial communications) Interrupts have been consolidated. For example see section 39.3.15 of the [http://www.ti.com/lit/ug/slau208o/slau208o.pdf F5xxx User Guide].
***The MSP430F5529 has more than 128K of memory. The normal 16 bits will only allow accessing the first 64K. To access the rest it uses 20 bits. This is enabled with the [http://www.ti.com/lit/ml/slap109/slap109.pdf Extended Instructions] like MOVX.W. For class, we can get by with the lower 64K just fine and can ignore these extended instructions, however, good programming practice calls for using CALLA, RETA, and BRA instead of CALL, RET, and BR. If you want to use the rest of the memory sometime, look into [http://www.ti.com/lit/ml/slap109/slap109.pdf this].
***The MSP430F5529 has more than 128K of memory. The normal 16 bits will only allow accessing the first 64K. To access the rest it uses 20 bits. This is enabled with the [http://www.ti.com/lit/ml/slap109/slap109.pdf Extended Instructions] like MOVX.W. For class, we can get by with the lower 64K just fine and can ignore these extended instructions, however, good programming practice calls for using CALLA, RETA, and BRA instead of CALL, RET, and BR. If you want to use the rest of the memory sometime, look into [http://www.ti.com/lit/ml/slap109/slap109.pdf this].
===Evaluation Board Data===
**[http://www.ti.com/lit/an/slaa334a/slaa334a.pdf How Flash works, and how you can write to it from your program.]
*[http://www.ti.com/tool/msp-exp430f5529lp MSP430 F5529 LaunchPad Evaluation Kit Resource Page]
**[http://processors.wiki.ti.com/index.php/MSP430F5529_LaunchPad TI MSP430F5529 Launchpad Wiki Page] This page has the nice pin out card that came with your Launchpad.
**[http://www.ti.com/lit/pdf/slau533 MSP-EXP430F5529LP Launchpad Development Kit User's Guide]
**[https://roboticsclub.org/redmine/projects/infotron/wiki/ProgramMSP430 Infotron Tutorials on Programming the MSP430 LaunchPads]
**[https://e2e.ti.com/support/microcontrollers/msp430/f/166/p/362204/1366058#1366058 How to program other MSP430s with your Launchpad]
===Code Examples from Class===
===Code Examples from Class===
*[[MSP430 C Code Examples from Class]]
*[[MSP430 C Code Examples from Class]]
Line 142: Line 144:
**[http://userweb.eng.gla.ac.uk/john.davies/mspbook/jhdoddans.pdf Solutions to odd problems in Davies' book]
**[http://userweb.eng.gla.ac.uk/john.davies/mspbook/jhdoddans.pdf Solutions to odd problems in Davies' book]
**[https://github.com/adamcohen/msp430-ccs-examples Example Code from Davies' book ported to Code Composer Studio]
**[https://github.com/adamcohen/msp430-ccs-examples Example Code from Davies' book ported to Code Composer Studio]
*[http://www.ti.com/lit/an/slaa334a/slaa334a.pdf How Flash works, and how you can write to it from your program.]
===Project Related Links and Notes===
====CC3100 SimpleLink Wi-Fi Family====
====CC3100 SimpleLink Wi-Fi Family====
*[http://www.ti.com/lit/ug/swru375a/swru375a.pdf CC3100 BoosterPack Getting Started Guide]
*[http://www.ti.com/lit/ug/swru375a/swru375a.pdf CC3100 BoosterPack Getting Started Guide]
Line 151: Line 155:
**[http://e2e.ti.com/support/wireless_connectivity/f/968/p/387348/1369052#1369052 How to Build for the CC3100 using Linux]
**[http://e2e.ti.com/support/wireless_connectivity/f/968/p/387348/1369052#1369052 How to Build for the CC3100 using Linux]
*[http://people.wallawalla.edu/~Rob.Frohne/for_ti/ Here are the files for compiling SimpleLink using the GCC compiler.]
*[http://people.wallawalla.edu/~Rob.Frohne/for_ti/ Here are the files for compiling SimpleLink using the GCC compiler.]

====2014 Robot Information===
====2014 Robot Information===
*[http://www.lynxmotion.com/images/data/hsr1425cr.pdf HSR-1425CR Continuous Rotation Servo Datasheet]
*[http://www.lynxmotion.com/images/data/hsr1425cr.pdf HSR-1425CR Continuous Rotation Servo Datasheet]
Line 167: Line 170:
*I count 20 holes, on the encoder wheels. This gives 20 periods per revolution. The wheel diameter is about 0.066 meters, so the radius is 0.033 meters. This gives about 0.21 meters per revolution. It seems a pretty fast speed is about 1 meter per second, which means that we have about 5 revolutions per second, or 100 cycles per second, or about 0.01 seconds per period at high speed.
*I count 20 holes, on the encoder wheels. This gives 20 periods per revolution. The wheel diameter is about 0.066 meters, so the radius is 0.033 meters. This gives about 0.21 meters per revolution. It seems a pretty fast speed is about 1 meter per second, which means that we have about 5 revolutions per second, or 100 cycles per second, or about 0.01 seconds per period at high speed.
*[http://www.phidgets.com/docs/DC_Motor_and_Controller_Primer Applying Feedback] makes the robot easier to control. This web page gives a somewhat helpful primer on that process.
*[http://www.phidgets.com/docs/DC_Motor_and_Controller_Primer Applying Feedback] makes the robot easier to control. This web page gives a somewhat helpful primer on that process.

===Logic Analyzer Information===
These logic analyzers are clones of the original [https://www.saleae.com/ Saleae] analyzer. They have software compatible with this analyzer, but they don't like you to use it.
*[http://sigrok.org/ The Sigrok project] provides open source software for this logic analyzer and other laboratory instruments. I recommend this software. The latest features can be had by compiling from the source code.
**[http://sigrok.org/wiki/Downloads Sigrok software downloads] are here. It runs on Linux, Windows, OS X and even Android, as well as FreeBSD and a bunch of other operating systems.
**[http://sigrok.org/wiki/Building Here are instructions to build from source.]
[[Image:Logic_Analyzer.png|thumb|widthpx|450 ]]
===Other Miscellaneous Interesting Reading===
*[http://kysmykseka.net/koti/wizardry/Programming/Misc/Charles%20Petzold%20-%20Code%20-%20The%20Hidden%20Language%20of%20Computer%20Hardware%20and%20Software.pdf Code: The Hidden Language of Computer Hardware and Software by Charles Petzold] This is a good read about the history of the subject which gives the reader a good understanding of the subject.

Revision as of 16:46, 3 December 2015


ARM7 Links

Raspberry Pi

Depending on the version, your pi may use ARM6 or ARM7. There is actually quite a lot of good assembly language information for programming the raspberry pi.

TI MSP430 Links

Toolchain

There are various toolchains (build tools) for the MSP430. TI provides the Code Composer Studio (both desktop, and browser based) toolchain. At this point, the desktop version is much more powerful than the browser based version, and you need it for this class. There are also some other toolchains that cost something, but I prefer Code Composer Studio.

Code Composer Studio

  • CCS will work with Linux and Windows, and now a beta is available for OS X.
    • To install CCSV6.1 on Ubuntu 15.04, you need to
$ unset JAVA_TOOL_OPTIONS 

before running the installer. There is some more information for Linux installs here. I also found out that installing Grace from the App Center makes the App Center blank thereafter, unless you reinstall CCSV6.1.

MSP430 Assembly using the TI Assembler
MSP430 TI C Compiler
  • MSP430 Optimizing C/C++ Compiler (See Section 6.5 and following for how to mix C/C++ and Assembly. It is really best to read the entire chapter though, as it is all pertinent to mixing C and Assembly. It will also help you if you want to program in C, as it tells how the C compiler uses the memory, the stack, the registers, etc., and once you understand the processor as you learn to do when you learn its assembly language, it is very interesting to see how that all works in C.)
    • Here is how to use printf() statements with Code Composer Studio.**TI C Examples Workspace This is a CCS workspace with all the C examples from TI for the MSP430F5529. It is useful to work around a bug in MSPWare that broke the feature that you could use in the Examples to create an instance of an example in your workspace. You can import projects from this workspace into your regular one, so you don't have to switch workspaces to see the examples. You can read the descriptions for these examples in the Examples feature of Code Composer Studio. You just can't import them into your workspace until TI fixes the bug. When they do, this will no longer be useful. Soon I hope!
IAR Tools

IAR also makes a toolchain. It is not free, but you will sometimes find code that was developed for it, and it is slightly different from that developed for Code Composer Studio using either the TI or GCC compilers/assemblers.

GCC Compiler

You may use the GCC compiler from within Code Composer Studio. It is not limited in the size of the code that it can compile. There are some differences between it and the TI compiler. I find that the TI compiler usually works more easily, with TI examples especially.

To make your program using interrupt service routines compile with either the TI or the GCC compiler, you need some #ifdef's like this:

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR (void)
#else
#error Compiler not supported!
#endif

Note that you need to substitute the appropriate ISR vectors in your code.

C Language References

Put a section here with |= and &= ~something, etc, that will help students understand how to translate from C to assembly.

Logic Analyzer Information

These logic analyzers are clones of the original Saleae analyzer. They have software compatible with this analyzer, but they don't like you to use it.

450

Other Miscellaneous Interesting Reading

MSP430F5529 Specific Data

Evaluation Board Data

Code Examples from Class

Other Course Materials for the MSP430 Family

Project Related Links and Notes

CC3100 SimpleLink Wi-Fi Family

=2014 Robot Information

  • HSR-1425CR Continuous Rotation Servo Datasheet
  • Schematics These are rather crude schematics of the robot circuit board. There are two cuts and jumps that are not reflected, at least on the last one. The effect is to change the photo transistors from a common emitter to a common collector configuration. You can see the change scratched in just below the word Fairchild on the hand drawn schematic. Basically the resistor and photo transistor are reversed in order. I believe both photo transistors are swapped to common collector configuration.

2015 Robot Information

  • Building Tips
  • L9110 H Bridge Data Sheet
    • HG7881 Dual H Bridge Module This suggests putting the PWM signal on one input and the direction control on the other. If you do that, you need to invert the PWM input when you change directions as well. See the data sheet above.
  • Bluetooth UART HC-05 and HC-06
  • Blueberry Android Bluetooth Remote Control App
  • HY301-07A Photo Interrupter Datasheet From the datasheet, we will choose a forward current on the LED to be 5 mA because we don't want to waste batteries, and that is the lowest the data sheet shows it working. That leads us to a forward voltage across the diode of 1.3 volts. If we run things on 3.3 volts that gives us a voltage drop of 3.3-1.3=2.0 volts. Ohms law says a resistor of R=V/I=2volts/5mA = 400 ohms. We will pick 390 ohms since it is an available 5% value. For the phototransistor, we see that the current for the forward diode current we picked should be about 0.2 mA. If we want the output to drop to 0.5 volts with the LED on, that leaves 3.3 volts - 0.5 volts = 2.8 volts across the collector resistor, so using Ohm's Law again, we need a collector resistor of 2.8 volts/0.2mA = 14 Kohms, so we will pick 15 Kohms because it is a standard value. The 15 Kohm resistors are optional as you can use the built in ones on the MSP430 controlled by PREN.
  • I count 20 holes, on the encoder wheels. This gives 20 periods per revolution. The wheel diameter is about 0.066 meters, so the radius is 0.033 meters. This gives about 0.21 meters per revolution. It seems a pretty fast speed is about 1 meter per second, which means that we have about 5 revolutions per second, or 100 cycles per second, or about 0.01 seconds per period at high speed.
  • Applying Feedback makes the robot easier to control. This web page gives a somewhat helpful primer on that process.