Professional Documents
Culture Documents
Linux, programming, hacking, electronics, Python These are the things I love.
Overview
First get a GCC cross compiler for ARM Install the lm4flash tool Build OpenOCD with ICDI support Compile and flash the demo project Debug the example with Nemiver, OpenOCD and GDB Running GDB manually Launchpads serial connection The bad stuff References/Further Reading:
STM32 microcontrollers are very nice and the STM32F0/ STM32VL/ STM32F3/ STM32F4/ STM32L- Discovery boards with the integrated debugger are well supported under Linux, in contrast to the LPCXpresso boards from NXP, so in principle there is no need to look further for other microcontrollers but I like trying new stuff and bought two cheep EK-LM4F120XL Stellaris LM4F120 LaunchPad Evaluation Boards for the promotional price of $4.99 each with free shipping from TI. Im planing to use them with some cheap nRF24L01 wireless modules from eBay, but this is the subject of another blog post.
[ c h r i s @ t h i n k p a dA R M ] $g i tc l o n eg i t : / / g i t . c o d e . s f . n e t / p / o p e n o c d / c o d e o p e n o c d . g i t [ c h r i s @ t h i n k p a dA R M ] $c do p e n o c d . g i t [ c h r i s @ t h i n k p a do p e n o c d . g i t ] $. / b o o t s t r a p [ c h r i s @ t h i n k p a do p e n o c d . g i t ] $. / c o n f i g u r ep r e f i x = / u s re n a b l e m a i n t a i n e r m o d ee n a b l e s t l i n ke n a b l e t i i c d i [ c h r i s @ t h i n k p a do p e n o c d . g i t ] $m a k e [ c h r i s @ t h i n k p a do p e n o c d . g i t ] $s u d om a k ei n s t a l l
Note
As Leo Tindle has pointed out in the comments, the StellarisWare is also available on GitHub: https://github.com/yuvadm/stellaris.
[ c h r i s @ t h i n k p a dT I ] $g i tc l o n eh t t p s : / / g i t h u b . c o m / y u v a d m / s t e l l a r i s . g i t [ c h r i s @ t h i n k p a ds t e l l a r i s . g i t ] $c ds t e l l a r i s . g i t / d r i v e r l i b / [ c h r i s @ t h i n k p a dd r i v e r l i b ] $m a k ec l e a n [ c h r i s @ t h i n k p a dd r i v e r l i b ] $m a k e [ c h r i s @ t h i n k p a dT I ] $c d. . / b o a r d s / e k l m 4 f 1 2 0 x l / p r o j e c t 0 / [ c h r i s @ t h i n k p a dp r o j e c t 0 ] $m a k e C C p r o j e c t 0 . c C C s t a r t u p _ g c c . c L D g c c / p r o j e c t 0 . a x f [ c h r i s @ t h i n k p a dp r o j e c t 0 ] $
Compile everything:
Add a new udev rule to let normal users access the LaunchPad and program it with OpenOCD:
[ c h r i s @ t h i n k p a dS t e l l a r i s W a r e ] $s u d ov i m/ e t c / u d e v / r u l e s . d / 1 0 l o c a l . r u l e s [ c h r i s @ t h i n k p a dS t e l l a r i s W a r e ] $c a t/ e t c / u d e v / r u l e s . d / 1 0 l o c a l . r u l e s A T T R { i d V e n d o r } = = " 1 5 b a " ,A T T R { i d P r o d u c t } = = " 0 0 0 4 " ,G R O U P = " p l u g d e v " ,M O D E = " 0 6 6 0 " #O l i m e xL t d .O p e n O C DJ T A GT I N Y A T T R { i d V e n d o r } = = " 0 6 7 b " ,A T T R { i d P r o d u c t } = = " 2 3 0 3 " ,G R O U P = " p l u g d e v " ,M O D E = " 0 6 6 0 " #P r o l i f i cT e c h n o l o g y ,I n c .P L 2 3 0 3S e r i a lP o r t A T T R { i d V e n d o r } = = " 1 0 c 4 " ,A T T R { i d P r o d u c t } = = " e a 6 0 " ,G R O U P = " p l u g d e v " ,M O D E = " 0 6 6 0 " #U S BS e r i a l A T T R { i d V e n d o r } = = " 1 c b e " ,A T T R { i d P r o d u c t } = = " 0 0 f d " ,G R O U P = " p l u g d e v " ,M O D E = " 0 6 6 0 " #T IS t e l l a r i sL a u n c h p a d [ c h r i s @ t h i n k p a dS t e l l a r i s W a r e ] $s u d ou d e v a d mc o n t r o lr e l o a d r u l e s
Modify the M a k e f i l ein S t e l l a r i s W a r e / b o a r d s / e k l m 4 f 1 2 0 x l / p r o j e c t 0 /and add the flash rule (use a tabulator for indention like in the other make targets):
# #T h ed e f a u l tr u l e ,w h i c hc a u s e st h eP r o j e c tZ e r oE x a m p l et ob eb u i l t . # a l l :$ { C O M P I L E R } a l l :$ { C O M P I L E R } / p r o j e c t 0 . a x f # #T h er u l et of l a s ht h ep r o g r a mt ot h ec h i p . # f l a s h : l m 4 f l a s hg c c / p r o j e c t 0 . b i n
[ c h r i s @ t h i n k p a dS t e l l a r i s W a r e ] $c db o a r d s / e k l m 4 f 1 2 0 x l / p r o j e c t 0 / [ c h r i s @ t h i n k p a dp r o j e c t 0 ] $m a k ec l e a n [ c h r i s @ t h i n k p a dp r o j e c t 0 ] $m a k e C C p r o j e c t 0 . c C C s t a r t u p _ g c c . c L D g c c / p r o j e c t 0 . a x f [ c h r i s @ t h i n k p a dp r o j e c t 0 ] $m a k ef l a s h l m 4 f l a s hg c c / p r o j e c t 0 . b i n F o u n dI C D Id e v i c ew i t hs e r i a l :0 E 1 0 2 3 9 7 I C D Iv e r s i o n :9 2 7 0 [ c h r i s @ t h i n k p a dp r o j e c t 0 ] $
d e b u g _ n e m i v e r . s h :
# ! / b i n / b a s h #l o c a t i o no fO p e n O C DB o a r d. c f gf i l e s O P E N O C D _ B O A R D _ D I R = / u s r / s h a r e / o p e n o c d / s c r i p t s / b o a r d #s t a r tx t e r mw i t ho p e n o c di nt h eb a c k g r o u n d x t e r meo p e n o c df$ O P E N O C D _ B O A R D _ D I R / e k l m 4 f 1 2 0 x l . c f g& #s a v et h eP I Do ft h eb a c k g r o u n dp r o c e s s X T E R M _ P I D = $ ! #w a i tab i tt ob es u r et h eh a r d w a r ei sr e a d y s l e e p2 #e x e c u t es o m ei n i t i a l i s a t i o nc o m m a n d sv i ag d b a r m n o n e e a b i g d bb a t c hc o m m a n d = i n i t . g d bg c c / p r o j e c t 0 . a x f #s t a r tt h eg d bg u i n e m i v e rr e m o t e = l o c a l h o s t : 3 3 3 3g d b b i n a r y = " $ ( w h i c ha r m n o n e e a b i g d b ) " g c c / p r o j e c t 0 . a x f #c l o s ex t e r mw h e nt h eu s e rh a se x i t e dn e m i v e r k i l l$ X T E R M _ P I D
i n i t . g d b :
#S p e c i f yr e m o t et a r g e t t a r g e te x t e n d e d r e m o t e: 3 3 3 3 #R e s e tt ok n o w ns t a t e m o n i t o rr e s e th a l t l o a d m o n i t o rr e s e ti n i t #S e tab r e a k p o i n ta tm a i n ( ) . b r e a km a i n #R u nt ot h eb r e a k p o i n t . c o n t i n u e
After this everything you have to do to start a new debug session is to run m a k ed e b u g :
[ c h r i s @ t h i n k p a dp r o j e c t 0 ] $m a k ed e b u g C C p r o j e c t 0 . c C C s t a r t u p _ g c c . c L D g c c / p r o j e c t 0 . a x f . / d e b u g _ n e m i v e r . s h 0 x 0 0 0 0 0 0 0 0i ng _ p f n V e c t o r s( ) t a r g e ts t a t e :h a l t e d t a r g e th a l t e dd u et od e b u g r e q u e s t ,c u r r e n tm o d e :T h r e a d x P S R :0 x 0 1 0 0 0 0 0 0p c :0 x 0 0 0 0 0 2 b cm s p :0 x 2 0 0 0 0 1 0 0 L o a d i n gs e c t i o n. t e x t ,s i z e0 x 5 e 4l m a0 x 0 S t a r ta d d r e s s0 x 2 b d ,l o a ds i z e1 5 0 8 T r a n s f e rr a t e :6K B / s e c ,1 5 0 8b y t e s / w r i t e . t a r g e ts t a t e :h a l t e d t a r g e th a l t e dd u et od e b u g r e q u e s t ,c u r r e n tm o d e :T h r e a d x P S R :0 x 0 1 0 0 0 0 0 0p c :0 x 0 0 0 0 0 2 b cm s p :0 x 2 0 0 0 0 1 0 0 B r e a k p o i n t1a t0 x 2 6 e :f i l ep r o j e c t 0 . c ,l i n e6 8 . N o t e :a u t o m a t i c a l l yu s i n gh a r d w a r eb r e a k p o i n t sf o rr e a d o n l ya d d r e s s e s . B r e a k p o i n t1 ,m a i n( )a tp r o j e c t 0 . c : 6 8 6 8 S y s C t l C l o c k S e t ( S Y S C T L _ S Y S D I V _ 4 | S Y S C T L _ U S E _ P L L | S Y S C T L _ X T A L _ 1 6 M H Z |
Now you have an easy and fast way to debug your programs.
Running $ m a k ed e b u g
You may need to rebuild all libraries in debug mode to have debugging information available for library functions:
[ c h r i s @ t h i n k p a dp r o j e c t 0 ] $c d. . / . . / . . / [ c h r i s @ t h i n k p a dS t e l l a r i s W a r e ] $m a k ec l e a n m a k e [ 1 ] :E n t e r i n gd i r e c t o r y` / h o m e / c h r i s / s t u f f / A R M / T I / S t e l l a r i s W a r e / d r i v e r l i b ' . . . [ c h r i s @ t h i n k p a dS t e l l a r i s W a r e ] $m a k eD E B U G = 1 m a k e [ 1 ] :E n t e r i n gd i r e c t o r y` / h o m e / c h r i s / s t u f f / A R M / T I / S t e l l a r i s W a r e / d r i v e r l i b ' m a k e [ 2 ] :E n t e r i n gd i r e c t o r y` / h o m e / c h r i s / s t u f f / A R M / T I / S t e l l a r i s W a r e / d r i v e r l i b ' C C a d c . c C C c a n . c C C c o m p . c C C c p u . c . . . L D g c c / p r o j e c t 0 . a x f . . / . . / . . / d r i v e r l i b / g c c c m 4 f / l i b d r i v e r c m 4 f . a ( g p i o . o ) :I nf u n c t i o n ` G P I O D i r M o d e S e t ' : / h o m e / c h r i s / s t u f f / A R M / T I / S t e l l a r i s W a r e / d r i v e r l i b / g p i o . c : 2 8 8 :u n d e f i n e d r e f e r e n c et o` _ _ e r r o r _ _ ' . . . m a k e [ 3 ] :* * *[ g c c / p r o j e c t 0 . a x f ]E r r o r1 m a k e [ 3 ] :L e a v i n gd i r e c t o r y` / h o m e / c h r i s / s t u f f / A R M / T I / S t e l l a r i s W a r e / b o a r d s / e k l m 4 f 1 2 0 x l / p r o j e c t 0 ' m a k e [ 2 ] :* * *[ a l l ]E r r o r2 m a k e [ 2 ] :L e a v i n gd i r e c t o r y` / h o m e / c h r i s / s t u f f / A R M / T I / S t e l l a r i s W a r e / b o a r d s / e k l m 4 f 1 2 0 x l ' m a k e [ 1 ] :* * *[ a l l ]E r r o r2 m a k e [ 1 ] :L e a v i n gd i r e c t o r y` / h o m e / c h r i s / s t u f f / A R M / T I / S t e l l a r i s W a r e / b o a r d s ' m a k e :* * *[ a l l ]E r r o r2 [ c h r i s @ t h i n k p a dS t e l l a r i s W a r e ] $
http://e2e.ti.com/support/microcontrollers/stellaris_arm_cortexm3_microcontroller/f/471/t/44656.aspx:
The undefined reference to __error__ problem you are seeing most likely indicates that you have a mismatch between debug and release versions of the DriverLib library you are linking and your application code. Alternatively, you may be using the ASSERT() macro without having defined the __error__() function in your application. In a debug build (when you define label DEBUG either in your IDE or using DDEBUG passed to your compiler), error checking code is included in DriverLib via the macro ASSERT(). This macro generates a call to function __error__ if the assert fails and it is expected that the application code will include this function. Typically, all it does is enter a while(1) to stop execution and allow you to debug the problem but you can also add other code there to dump status or provide other useful information. To get rid of the problem, you have a couple of choiced. First, you can rebuild DriverLib without DEBUG defined then link this version to your application code (assuming you dont use ASSERT() anywhere in the app). The other option, if you want to use the debug features, is to add a function to your application along the lines of the following:
# i f d e fD E B U G v o i d_ _ e r r o r _ _ ( c h a r* p c F i l e n a m e ,u n s i g n e dl o n gu l L i n e ) { / / / /S o m e t h i n gh o r r i b l eh a p p e n e d !Y o un e e dt ol o o k / /a tf i l e" p c F i l e n a m e "a tl i n e" u l L i n e "t os e e / /w h a te r r o ri sb e i n gr e p o r t e d . / / w h i l e ( 1 ) { } } # e n d i f
After adding that function to p r o j e c t 0 . ccompiling in debug mode is successful and debugging information is available for the underlying library functions:
Second terminal:
[ c h r i s @ t h i n k p a dp r o j e c t 0 ] $a r m n o n e e a b i g d bg c c / p r o j e c t 0 . a x f G N Ug d b( G N UT o o l sf o rA R ME m b e d d e dP r o c e s s o r s )7 . 4 . 1 . 2 0 1 3 0 3 1 2 c v s C o p y r i g h t( C )2 0 1 2F r e eS o f t w a r eF o u n d a t i o n ,I n c . L i c e n s eG P L v 3 + :G N UG P Lv e r s i o n3o rl a t e r< h t t p : / / g n u . o r g / l i c e n s e s / g p l . h t m l > T h i si sf r e es o f t w a r e :y o ua r ef r e et oc h a n g ea n dr e d i s t r i b u t ei t . T h e r ei sN OW A R R A N T Y ,t ot h ee x t e n tp e r m i t t e db yl a w . T y p e" s h o wc o p y i n g " a n d" s h o ww a r r a n t y "f o rd e t a i l s . T h i sG D Bw a sc o n f i g u r e da s" h o s t = i 6 8 6 l i n u x g n ut a r g e t = a r m n o n e e a b i " . F o rb u gr e p o r t i n gi n s t r u c t i o n s ,p l e a s es e e : < h t t p : / / w w w . g n u . o r g / s o f t w a r e / g d b / b u g s / > . . . R e a d i n gs y m b o l sf r o m/ h o m e / c h r i s / P r o j e c t s / A R M / T I / s t e l l a r i s . g i t / b o a r d s / e k l m 4 f 1 2 0 x l / p r o j e c t 0 / g c c / p r o j e c t 0 . a x f . . . d o n e . ( g d b )t a r g e te x t e n d e d r e m o t e: 3 3 3 3 R e m o t ed e b u g g i n gu s i n g: 3 3 3 3 0 x 0 0 0 0 0 0 0 0i ng _ p f n V e c t o r s( ) ( g d b )m o n i t o rr e s e th a l t t a r g e ts t a t e :h a l t e d t a r g e th a l t e dd u et od e b u g r e q u e s t ,c u r r e n tm o d e :T h r e a d x P S R :0 x 0 1 0 0 0 0 0 0p c :0 x 0 0 0 0 0 a f 4m s p :0 x 2 0 0 0 0 9 1 0 ( g d b )l o a d L o a d i n gs e c t i o n. t e x t ,s i z e0 x 9 f 8l m a0 x 0 S t a r ta d d r e s s0 x 2 b d ,l o a ds i z e2 5 5 2 T r a n s f e rr a t e :7K B / s e c ,2 5 5 2b y t e s / w r i t e . ( g d b )m o n i t o rr e s e ti n i t t a r g e ts t a t e :h a l t e d t a r g e th a l t e dd u et od e b u g r e q u e s t ,c u r r e n tm o d e :T h r e a d x P S R :0 x 0 1 0 0 0 0 0 0p c :0 x 0 0 0 0 0 2 b cm s p :0 x 2 0 0 0 0 1 0 0 ( g d b )m o n i t o rr e s e ti n i t t a r g e ts t a t e :h a l t e d t a r g e th a l t e dd u et od e b u g r e q u e s t ,c u r r e n tm o d e :T h r e a d x P S R :0 x 0 1 0 0 0 0 0 0p c :0 x 0 0 0 0 0 2 b cm s p :0 x 2 0 0 0 0 1 0 0 ( g d b )r u n T h ep r o g r a mb e i n gd e b u g g e dh a sb e e ns t a r t e da l r e a d y . S t a r ti tf r o mt h eb e g i n n i n g ?( yo rn )y S t a r t i n gp r o g r a m :/ h o m e / c h r i s / P r o j e c t s / A R M / T I / s t e l l a r i s . g i t / b o a r d s / e k l m 4 f 1 2 0 x l / p r o j e c t 0 / g c c / p r o j e c t 0 . a x f c ^ C 0 x 0 0 0 0 0 8 7 6i nS y s C t l D e l a y( u l C o u n t = 1 7 6 3 5 5 4 ,u l C o u n t @ e n t r y = 2 0 0 0 0 0 0 )a t s y s c t l . c : 1 8 5 6 1 8 5 6 _ _ a s m ( " s u b s r 0 ,# 1 \ n " ( g d b )c C o n t i n u i n g . ^ C P r o g r a mr e c e i v e ds i g n a lS I G I N T ,I n t e r r u p t . S y s C t l D e l a y( u l C o u n t = 1 3 6 1 5 ,u l C o u n t @ e n t r y = 2 0 0 0 0 0 0 )a ts y s c t l . c : 1 8 5 6 1 8 5 6 _ _ a s m ( " s u b s r 0 ,# 1 \ n " ( g d b )b r e a kp r o j e c t 0 . c : 8 5 B r e a k p o i n t1a t0 x 2 8 2 :f i l ep r o j e c t 0 . c ,l i n e8 5 . ( g d b )c C o n t i n u i n g . N o t e :a u t o m a t i c a l l yu s i n gh a r d w a r eb r e a k p o i n t sf o rr e a d o n l ya d d r e s s e s . B r e a k p o i n t1 ,m a i n( )a tp r o j e c t 0 . c : 8 5 8 5 G P I O P i n W r i t e ( G P I O _ P O R T F _ B A S E ,R E D _ L E D | B L U E _ L E D | G R E E N _ L E D , R E D _ L E D ) ; ( g d b )
You know I mean the viral open-source part. And TI please fix your website, lots of 404 links, just use such a viral open-source script to check all links.
References/Further Reading:
http://www.ti.com/tool/EK-LM4F120XL http://processors.wiki.ti.com/index.php/Stellaris_LaunchPad http://processors.wiki.ti.com/index.php/Stellaris_Launchpad_with_OpenOCD_and_Linux http://www.ti.com/ww/en/launchpad/stellaris_head.html http://www.ti.com/product/lm4f120h5qr http://hackaday.com/tag/stellaris-launchpad/ http://recursive-labs.com/blog/2012/10/28/stellaris-launchpad-gnu-linux-getting-started/ https://eehusky.wordpress.com/2012/12/04/using-gcc-with-ti-stellaris-launchpad-amore-in-depth-look/
8 Comments
Sort by Oldest
jann.cc
Share
Login
Favorite
a year ago
Thanks for the post, I'll certainly be referring to this when my Stellaris arrives.
Reply Share
S Leo Tindle
a year ago
You might be interested to know that the StellarisWare drivers are now under the TI BSD License. The version of StellarisWare you cite (9453) is under this license. Just look at the license section of any of the driver source files and the TI-BSD-EULA.txt file at the root of the extracted SW-EK-LM4F120XL-9453.exe archive. It looks like they forgot to change the license header on the examples, though. BTW, very informative post. Helped get up and running on Kubuntu 12.10.
Reply Share
Christian Jann
Mod
Thank you for pointing this out, I've seen that some files have a better license but I'm more interested in the question whether it is allowed to copy the StellarisWare to GitHub and why nobody has done this already. It would be so much nicer if I could do a g i tc l o n eto get the StellarisWare and a g i tp u l lto check for updates so that I can easily integrate the StellarisWare into my project without telling everybody that they have to register at TI and get the StellarisWare from there. OK I've found the reason, now I have to complain abut the EULA (TI StellarisWare Crippleware Software License Agreement (SLA)): g. Restrictions. You shall maintain the source code versions of the Licensed Materials under password control protection and shall not disclose such source code versions of the Licensed Materials, or any derivative thereof, to any person other than your employees and contractors whose job performance requires access.
Reply Share
S Leo Tindle
S Leo Tindle
Sorry, Christian, I forgot to add the github link. Someone already has: https://github.com/yuvadm/stel.... It may not be official, but TI hasn't tried to take it down yet. Yeah, their EULA sucks, but the license for the driver lib is under BSD explicitly which means you can pull the BSD code out and use it wherever. I have half a mind to just write a bootstrap that pulls all the needed components from github in to a virtual environment. I modified your instructions so that all the software compiled exist in ~/workspace/stellarisware/usr and added ~/workspace/stellarisware/usr/bin to my PATH. A simple bash file can do the modification to the PATH and other variables not unlike how virtenv asks you to source a bash file to enter the environment.
1
Reply Share
Christian Jann
Mod
Very nice, I must have overseen that when googling, thank you. I've added a link.
Reply Share
JohnCC
Note that the Note is inserted in an unlucky place (above). It gives the impression that some other compilation is necessary after the instructions for the Note itself. And, the cd stellaris.git should be just cd stellaris. Other than that, thanks for the info! The git copy is still up and working.
Reply Share
Name
11 months ago
I don't think TI means harm by calling some open source licenses viral, it's quite a common term. http://en.wikipedia.org/wiki/V...
1
Reply Share
Christian Jann
Mod
Yes, I know, they are just lazy and following another philosophy and don't care about the open source community. Like most corporations they don't have a "keep it open, unless there's a good reason to close it" mentality. Instead, they have a "keep it closed, unless there's a good/legal reason to open it" mentality. Even when there is no reason to not release such small hello-world examples as public domain they will keep it closed. Probably they think that they can make you dependent on their hardware through their software which is perfectly viable but I don't like it.
Reply Share
ALSO ON JANN.CC
WHAT'S THIS?
EUR 22 / USD 35
3 comments 4 months ago
post above.