<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5711171076422957585</id><updated>2011-12-02T07:48:12.033+01:00</updated><category term='arduino'/><category term='Jyetech'/><category term='RTOS'/><category term='imu'/><category term='UART'/><category term='FabLab'/><category term='LM2574'/><category term='Cortex-M3'/><category term='segway'/><category term='Oscilloscope'/><category term='HP48'/><category term='STM32'/><category term='H-bridge'/><category term='MP3Player'/><category term='HIP4081'/><category term='USART2'/><title type='text'>Embedded Spare Time</title><subtitle type='html'>A blog about my spare time projects in the microcontroller electronics area. My recent projects include a simple PIC-based television remote control and an MP3 player, based on the PIC 18F25J10 and the VS1011 MP3 decoder. Currently I am learning more about the Cortex M3 CPU, developing a simple RTOS running on the STM32 microcontroller.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://embedded-sparetime.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://embedded-sparetime.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Marcus</name><uri>http://www.blogger.com/profile/08582830497995396149</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>19</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5711171076422957585.post-4436943015710313048</id><published>2011-06-29T22:27:00.004+02:00</published><updated>2011-06-29T22:50:09.406+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='H-bridge'/><category scheme='http://www.blogger.com/atom/ns#' term='LM2574'/><category scheme='http://www.blogger.com/atom/ns#' term='HIP4081'/><title type='text'>Starting construction of H-bridge module.</title><content type='html'>I got the components from ELFA and Lawicel a few days ago. The first step was to set up the LM2574-based step-down converter, supposed to deliver a stable 12V supply to the HIP4081, on a breadboard. The schottky diode which is part of the circuit had pins so thick, I had to sandpaper them down to be able to push them into the breadboard holes... :)&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I had no batteries at hand that could deliver the 24V I plan to use for the finished Segway clone construction, so I had to borrow a battery from my lawn trimmer, providing 21V. The circuit proved to work fine, at least on a quick minimal load test.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;meta equiv="content-type" content="text/html; charset=utf-8"&gt;&lt;a href="http://3.bp.blogspot.com/-Eq8juNbuCKY/TguOihOn3UI/AAAAAAAAAKE/mHk64zJUTbI/s1600/IMAG0591.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img src="http://3.bp.blogspot.com/-Eq8juNbuCKY/TguOihOn3UI/AAAAAAAAAKE/mHk64zJUTbI/s320/IMAG0591.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5623745283388595522" style="cursor: pointer; width: 320px; height: 192px; " /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5711171076422957585-4436943015710313048?l=embedded-sparetime.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://embedded-sparetime.blogspot.com/feeds/4436943015710313048/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embedded-sparetime.blogspot.com/2011/06/starting-construction-of-h-bridge.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/4436943015710313048'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/4436943015710313048'/><link rel='alternate' type='text/html' href='http://embedded-sparetime.blogspot.com/2011/06/starting-construction-of-h-bridge.html' title='Starting construction of H-bridge module.'/><author><name>Marcus</name><uri>http://www.blogger.com/profile/08582830497995396149</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-Eq8juNbuCKY/TguOihOn3UI/AAAAAAAAAKE/mHk64zJUTbI/s72-c/IMAG0591.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5711171076422957585.post-9181648050952445334</id><published>2011-06-23T23:51:00.002+02:00</published><updated>2011-06-24T00:15:51.819+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='H-bridge'/><title type='text'>More components ordered.</title><content type='html'>Next step is to design a powerful H-bridge that can drive larger DC motors that can actually drive a full-scale Segway clone. Yesterday I ordered a bunch of components, most notably:&lt;br /&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;1 &lt;b&gt;HIP4081AIP&lt;/b&gt; H-bridge driver IC.&lt;/li&gt;&lt;li&gt;4 &lt;b&gt;IRFZ44N&lt;/b&gt; N-channel MOSFET transistor, capable of controlling 49 amps at 55 volts.&lt;/li&gt;&lt;li&gt;1 &lt;b&gt;LM2574N-12&lt;/b&gt; step-down switch regulator to provide the 12 volts required by the HIP4081AIP, from a 24-28 volt power supply (sealed lead-acid batteries).&lt;/li&gt;&lt;/ul&gt;My plan is to build a prototype motor driver on a breadboard and try it out for smaller currents, measuring timing and voltage levels on eg. the MOSFET gates. When it all seems to work, I will design a PCB capable of handling the full 25-40 amps required by larger motors.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;One source of inspiration (an open-source, open-hardware motor driver):&lt;/div&gt;&lt;div&gt;&lt;meta equiv="content-type" content="text/html; charset=utf-8"&gt;&lt;a href="http://www.robotpower.com/products/osmc_info.html"&gt;http://www.robotpower.com/products/osmc_info.html&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5711171076422957585-9181648050952445334?l=embedded-sparetime.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://embedded-sparetime.blogspot.com/feeds/9181648050952445334/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embedded-sparetime.blogspot.com/2011/06/more-components-ordered.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/9181648050952445334'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/9181648050952445334'/><link rel='alternate' type='text/html' href='http://embedded-sparetime.blogspot.com/2011/06/more-components-ordered.html' title='More components ordered.'/><author><name>Marcus</name><uri>http://www.blogger.com/profile/08582830497995396149</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5711171076422957585.post-1558703316445231942</id><published>2011-06-23T23:44:00.002+02:00</published><updated>2011-06-23T23:50:56.575+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='arduino'/><category scheme='http://www.blogger.com/atom/ns#' term='segway'/><category scheme='http://www.blogger.com/atom/ns#' term='imu'/><title type='text'>Balancing robot starts to work.</title><content type='html'>After a little Arduino sketch hacking the robot is now balancing. It works pretty well on carpets, not so well on wooden floors, probably due to small friction. Carpets seem to reduce oscillations in the control algorithm.&lt;br /&gt;&lt;br /&gt;&lt;iframe width="425" height="349" src="http://www.youtube.com/embed/yYn76m1Ywic" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5711171076422957585-1558703316445231942?l=embedded-sparetime.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://embedded-sparetime.blogspot.com/feeds/1558703316445231942/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embedded-sparetime.blogspot.com/2011/06/balancing-robot-starts-to-work.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/1558703316445231942'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/1558703316445231942'/><link rel='alternate' type='text/html' href='http://embedded-sparetime.blogspot.com/2011/06/balancing-robot-starts-to-work.html' title='Balancing robot starts to work.'/><author><name>Marcus</name><uri>http://www.blogger.com/profile/08582830497995396149</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://img.youtube.com/vi/yYn76m1Ywic/default.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5711171076422957585.post-422674664250054212</id><published>2011-05-10T22:20:00.005+02:00</published><updated>2011-05-10T22:36:06.287+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='arduino'/><category scheme='http://www.blogger.com/atom/ns#' term='segway'/><category scheme='http://www.blogger.com/atom/ns#' term='imu'/><title type='text'>Testing the H-bridge.</title><content type='html'>&lt;div&gt;&lt;meta equiv="content-type" content="text/html; charset=utf-8"&gt;I assembled the motors, wheels and electronics in a rather ugly way, but hopefully it will be enough to test all concepts. Behold:&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;a href="http://1.bp.blogspot.com/-XYRVhRyqbV0/TcmfMwoGinI/AAAAAAAAAJg/GjKs-jTmaI4/s1600/IMAG0524.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 192px;" src="http://1.bp.blogspot.com/-XYRVhRyqbV0/TcmfMwoGinI/AAAAAAAAAJg/GjKs-jTmaI4/s320/IMAG0524.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5605186252799642226" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/-_3L9cF4yM8s/TcmfMnTUwQI/AAAAAAAAAJY/k1ApCyaNi1o/s1600/IMAG0524.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;/a&gt;&lt;div&gt;&lt;a href="http://2.bp.blogspot.com/-_3L9cF4yM8s/TcmfMnTUwQI/AAAAAAAAAJY/k1ApCyaNi1o/s1600/IMAG0524.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 192px;" src="http://2.bp.blogspot.com/-_3L9cF4yM8s/TcmfMnTUwQI/AAAAAAAAAJY/k1ApCyaNi1o/s320/IMAG0524.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5605186250296574210" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/-LLHmP5FQ6pA/TcmfMfEqYfI/AAAAAAAAAJQ/0GclWBR2kNQ/s1600/IMAG0522.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://3.bp.blogspot.com/-LLHmP5FQ6pA/TcmfMfEqYfI/AAAAAAAAAJQ/0GclWBR2kNQ/s1600/IMAG0522.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 192px;" src="http://3.bp.blogspot.com/-LLHmP5FQ6pA/TcmfMfEqYfI/AAAAAAAAAJQ/0GclWBR2kNQ/s320/IMAG0522.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5605186248087593458" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I hacked some Arduino sketches to test the H-bridge. It seems to work fine, but I'm a little worried about the dead band around zero percent PWM duty cycle. Hopefully it doesn't matter,  or I can compensate for it in software.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;iframe width="425" height="349" src="http://www.youtube.com/embed/zzV5SEFm1c4" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5711171076422957585-422674664250054212?l=embedded-sparetime.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://embedded-sparetime.blogspot.com/feeds/422674664250054212/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embedded-sparetime.blogspot.com/2011/05/testing-h-bridge.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/422674664250054212'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/422674664250054212'/><link rel='alternate' type='text/html' href='http://embedded-sparetime.blogspot.com/2011/05/testing-h-bridge.html' title='Testing the H-bridge.'/><author><name>Marcus</name><uri>http://www.blogger.com/profile/08582830497995396149</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-XYRVhRyqbV0/TcmfMwoGinI/AAAAAAAAAJg/GjKs-jTmaI4/s72-c/IMAG0524.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5711171076422957585.post-3898364076817181925</id><published>2011-04-22T22:20:00.006+02:00</published><updated>2011-04-27T09:28:51.741+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='arduino'/><category scheme='http://www.blogger.com/atom/ns#' term='segway'/><category scheme='http://www.blogger.com/atom/ns#' term='imu'/><title type='text'>IMU Measurements</title><content type='html'>&lt;div&gt;Just got the components from Sparkfun now, and started experimenting, initially with the Arduino and the IMU. I was impressed by how easy it was to get started with the development environment. I hooked up the IMU's &lt;i&gt;XACCEL&lt;/i&gt; output to the &lt;i&gt;A0&lt;/i&gt; input of the Arduino Pro Mini and basically just adapted to AnalogInOutSerial example to output the raw accelerometer value, together with two averaging functions. These were dumped to a file and I fed them into &lt;b&gt;gnuplot&lt;/b&gt; to get a hint of how a low-pass filter would perform. This is how it looks:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;meta equiv="content-type" content="text/html; charset=utf-8"&gt;&lt;a href="http://4.bp.blogspot.com/-ikogyjugH2g/TbHlFUaLFKI/AAAAAAAAAJI/nArKtolsfLI/s1600/accel.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img src="http://4.bp.blogspot.com/-ikogyjugH2g/TbHlFUaLFKI/AAAAAAAAAJI/nArKtolsfLI/s320/accel.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5598507691338831010" style="cursor: pointer; width: 320px; height: 240px; " /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;Red line is the unfiltered input from the accelerometer. Green is filtered using a weighted average algorithm. So is the blue line, but it takes very little of the the fresh input into consideration.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5711171076422957585-3898364076817181925?l=embedded-sparetime.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://embedded-sparetime.blogspot.com/feeds/3898364076817181925/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embedded-sparetime.blogspot.com/2011/04/just-got-components-from-sparkfun-now.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/3898364076817181925'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/3898364076817181925'/><link rel='alternate' type='text/html' href='http://embedded-sparetime.blogspot.com/2011/04/just-got-components-from-sparkfun-now.html' title='IMU Measurements'/><author><name>Marcus</name><uri>http://www.blogger.com/profile/08582830497995396149</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-ikogyjugH2g/TbHlFUaLFKI/AAAAAAAAAJI/nArKtolsfLI/s72-c/accel.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5711171076422957585.post-7272184029366293635</id><published>2011-04-15T22:14:00.003+02:00</published><updated>2011-04-15T22:19:01.213+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='arduino'/><category scheme='http://www.blogger.com/atom/ns#' term='segway'/><category scheme='http://www.blogger.com/atom/ns#' term='imu'/><title type='text'>New project</title><content type='html'>&lt;meta equiv="content-type" content="text/html; charset=utf-8"&gt;&lt;div&gt;Time for a new project, just like most of them it will probably not be finished in less than 3 or so years. However; the intention this time is to learn a little more about the following things:&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;Electronics, especially handling analog sensors such as gyros and accelerometers&lt;/li&gt;&lt;li&gt;Motor drivers, based on H bridges and MOSFETs&lt;/li&gt;&lt;li&gt;The Arduino platform (and thus, the AVR-based ATmega328 µC)&lt;/li&gt;&lt;li&gt;Mechanical constructions&lt;/li&gt;&lt;li&gt;Control theory and basic digital implementations of control loops&lt;/li&gt;&lt;/ul&gt;I have always been impressed by the Segway and my first aim is to build a small and simple clone of it based on an Arduino, a couple of gearmotors and wheels from Pololu, an IMU (Inertial Measurement Unit), a motor driver and some other stuff, mostly aquired from &lt;a href="http://www.sparkfun.com/"&gt;http://www.sparkfun.com/&lt;/a&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Today, the first components arrived (from Sweden-based &lt;a href="http://www.lawicel-shop.se/"&gt;http://www.lawicel-shop.se/&lt;/a&gt;):&lt;/div&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/-e7HBi6F9J6E/TainmJYUDiI/AAAAAAAAAJA/9Em5T4bS_SY/s1600/IMAG0478.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 192px;" src="http://3.bp.blogspot.com/-e7HBi6F9J6E/TainmJYUDiI/AAAAAAAAAJA/9Em5T4bS_SY/s320/IMAG0478.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5595906810802605602" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5711171076422957585-7272184029366293635?l=embedded-sparetime.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://embedded-sparetime.blogspot.com/feeds/7272184029366293635/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embedded-sparetime.blogspot.com/2011/04/new-project.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/7272184029366293635'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/7272184029366293635'/><link rel='alternate' type='text/html' href='http://embedded-sparetime.blogspot.com/2011/04/new-project.html' title='New project'/><author><name>Marcus</name><uri>http://www.blogger.com/profile/08582830497995396149</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-e7HBi6F9J6E/TainmJYUDiI/AAAAAAAAAJA/9Em5T4bS_SY/s72-c/IMAG0478.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5711171076422957585.post-6700839311889150139</id><published>2010-02-13T22:01:00.004+01:00</published><updated>2010-02-13T22:12:31.496+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='STM32'/><category scheme='http://www.blogger.com/atom/ns#' term='Jyetech'/><category scheme='http://www.blogger.com/atom/ns#' term='UART'/><title type='text'>Debugging serial device driver with the Jyetech oscilloscope</title><content type='html'>It's really fun to actually use the home-soldered oscilloscope for something real. In this case I watch the 9600 bps traffic from my STM32 dev board:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_9r8FcA7q7iQ/S3cUFTD00NI/AAAAAAAAAEY/Oz5AOu91-hQ/s1600-h/DSCF3657.JPG"&gt;&lt;img style="cursor: pointer; width: 320px; height: 240px;" src="http://3.bp.blogspot.com/_9r8FcA7q7iQ/S3cUFTD00NI/AAAAAAAAAEY/Oz5AOu91-hQ/s320/DSCF3657.JPG" alt="" id="BLOGGER_PHOTO_ID_5437837156321382610" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;And then, a closeup of the oscilloscope screen:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_9r8FcA7q7iQ/S3cVDSzb_8I/AAAAAAAAAEg/GgF-DQRDr8o/s1600-h/DSCF3658.JPG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 320px; height: 240px;" src="http://2.bp.blogspot.com/_9r8FcA7q7iQ/S3cVDSzb_8I/AAAAAAAAAEg/GgF-DQRDr8o/s320/DSCF3658.JPG" alt="" id="BLOGGER_PHOTO_ID_5437838221404536770" border="0" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5711171076422957585-6700839311889150139?l=embedded-sparetime.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://embedded-sparetime.blogspot.com/feeds/6700839311889150139/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embedded-sparetime.blogspot.com/2010/02/debugging-serial-device-driver-with.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/6700839311889150139'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/6700839311889150139'/><link rel='alternate' type='text/html' href='http://embedded-sparetime.blogspot.com/2010/02/debugging-serial-device-driver-with.html' title='Debugging serial device driver with the Jyetech oscilloscope'/><author><name>Marcus</name><uri>http://www.blogger.com/profile/08582830497995396149</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_9r8FcA7q7iQ/S3cUFTD00NI/AAAAAAAAAEY/Oz5AOu91-hQ/s72-c/DSCF3657.JPG' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5711171076422957585.post-6120337989273429421</id><published>2010-02-12T17:36:00.003+01:00</published><updated>2010-02-12T17:52:13.779+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='RTOS'/><category scheme='http://www.blogger.com/atom/ns#' term='UART'/><title type='text'>IPC considerations.</title><content type='html'>My kernel currently has one message inbox for each process. I am thinking of letting each process have as many inboxes as it desires (possibly limited to 32). That way, a process can have one inbox for high priority messages received from eg. an interrupt handler and another inbox for application IPC.&lt;br /&gt;&lt;br /&gt;I ran into these thoughts when writing the USART device driver. I want to have one process in charge for the communication. Sending a message to it transmits the message contents over the wire. However, the process in charge needs to be aware of if the serial port data register is empty. The interrupt handler could, when it has sent the last byte of a message, send a message to the process in charge of communication, to it's "device driver" inbox.&lt;br /&gt;&lt;br /&gt;This should be analog to a solution where reading from an inbox can be done, specifying what message types are wanted. The benefit of this solution is that the kernel always returns the first message in the queue, increasing performance. The drawback is that the number of selectable message types (when receiving) will be limited.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5711171076422957585-6120337989273429421?l=embedded-sparetime.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://embedded-sparetime.blogspot.com/feeds/6120337989273429421/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embedded-sparetime.blogspot.com/2010/02/ipc-considerations.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/6120337989273429421'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/6120337989273429421'/><link rel='alternate' type='text/html' href='http://embedded-sparetime.blogspot.com/2010/02/ipc-considerations.html' title='IPC considerations.'/><author><name>Marcus</name><uri>http://www.blogger.com/profile/08582830497995396149</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5711171076422957585.post-2522405900246279581</id><published>2010-01-31T14:02:00.004+01:00</published><updated>2010-01-31T14:28:07.756+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Oscilloscope'/><category scheme='http://www.blogger.com/atom/ns#' term='HP48'/><category scheme='http://www.blogger.com/atom/ns#' term='Jyetech'/><title type='text'>DIY Oscilloscope</title><content type='html'>A friend of mine convinced me to buy &lt;a href="http://www.jyetech.com/"&gt;a kit&lt;/a&gt; to build a simple oscilloscope. At first, I thought it would not be very useful because the analog bandwidth is not more than 1 MHz. On the other hand, most of the times I have needed an oscilloscope, it has been to debug simple and slow data lines, such as SPI and RS232, so I decided to give it a chance. It was a real challenge to solder, because there were a lot of really small surface mount components (mostly capacitors and resistors) to solder. After a few evenings of soldering I was ready to try it out. &lt;br /&gt;&lt;br /&gt;Here are a few pictures. First of all I measured the oscilloscope's built-in 500 Hz test signal:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_9r8FcA7q7iQ/S2WCEBCVI9I/AAAAAAAAAEI/rmuT_BcIB70/s1600-h/DSCF3623.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="http://1.bp.blogspot.com/_9r8FcA7q7iQ/S2WCEBCVI9I/AAAAAAAAAEI/rmuT_BcIB70/s320/DSCF3623.JPG" alt="" id="BLOGGER_PHOTO_ID_5432891531001668562" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Second, I measured the 9600 bps serial output from my HP48SX calculator. You can see that the output is not proper RS232 signal levels. I guess this is a way to save battery power on the calculator:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_9r8FcA7q7iQ/S2WDfS6pk1I/AAAAAAAAAEQ/YsAIAwDFj68/s1600-h/DSCF3625.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://2.bp.blogspot.com/_9r8FcA7q7iQ/S2WDfS6pk1I/AAAAAAAAAEQ/YsAIAwDFj68/s320/DSCF3625.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5432893099169387346" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;After a little testing, I am really impressed by the oscilloscope, especially as it was priced just over 500 swedish kronor (less than $80). It was also fun and interesting to solder all the small parts!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5711171076422957585-2522405900246279581?l=embedded-sparetime.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://embedded-sparetime.blogspot.com/feeds/2522405900246279581/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embedded-sparetime.blogspot.com/2010/01/diy-oscilloscope.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/2522405900246279581'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/2522405900246279581'/><link rel='alternate' type='text/html' href='http://embedded-sparetime.blogspot.com/2010/01/diy-oscilloscope.html' title='DIY Oscilloscope'/><author><name>Marcus</name><uri>http://www.blogger.com/profile/08582830497995396149</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_9r8FcA7q7iQ/S2WCEBCVI9I/AAAAAAAAAEI/rmuT_BcIB70/s72-c/DSCF3623.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5711171076422957585.post-1853211138325809591</id><published>2010-01-17T20:39:00.009+01:00</published><updated>2010-01-17T21:23:55.601+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='STM32'/><category scheme='http://www.blogger.com/atom/ns#' term='Cortex-M3'/><category scheme='http://www.blogger.com/atom/ns#' term='RTOS'/><category scheme='http://www.blogger.com/atom/ns#' term='USART2'/><category scheme='http://www.blogger.com/atom/ns#' term='UART'/><title type='text'>Serial port insanity.</title><content type='html'>After oceans of time I am back again. The kernel now implements the following system calls:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;rtos_yield&lt;/span&gt; (yield to another process)&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;rtos_allocate&lt;/span&gt; (allocate a 64 byte message buffer from the buffer collection)&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;rtos_transmit&lt;/span&gt; (hand over a message to another process)&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;rtos_accept&lt;/span&gt; (accept a message from another process)&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;rtos_dispose&lt;/span&gt; (dispose of a buffer)&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;rtos_delay&lt;/span&gt; (delay a specified number of system ticks)&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;The final names are yet to be decided. I also implemented support for the Cortex-M3 SysTick timer (which is mandatory in all Cortex-M3 based chips). It's exception handler increases the system tick counter and releases processes that have blocked themselves using &lt;span style="font-style: italic;"&gt;rtos_delay&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;I also started implementing support for USART2 in the STM32. That is because this USART is connected to the RS232 DSUB connector on the STM32-P103 dev board I use. To start with, I hooked the port up to my laptop using a RS232-USB adapter, trying a number of different serial port sniffer/terminal programs to see the dev board output. With little success! After a few hours, I grabbed my old HP 48SX calculator, which has an RS232 port on it. A few simple commands allow me to configure the serial port settings and then everything worked perfectly fine!&lt;br /&gt;&lt;br /&gt;To set up USART2 for just using the transmitter, you have to do the following:&lt;br /&gt;&lt;br /&gt;&lt;pre class="source-code"&gt;&lt;code&gt;&lt;br /&gt;  /* Enable PCLK1 (USART2 is on APB1). */&lt;br /&gt;  *STM32_RCC_APB1ENR |= (0x1 &lt;&lt; 17); /* USART2EN - Enable USART2 clock. */&lt;br /&gt;&lt;br /&gt;  /* Enable PCLK2 (GPIOA is used by USART2). */&lt;br /&gt;  *STM32_RCC_APB2ENR |= (1 &lt;&lt; 2); /* IOPAEN - Enable GPIOA clock. */&lt;br /&gt;  &lt;br /&gt;  /* Set up the PA2 pin for alternate function push/pull. This is the&lt;br /&gt;     TX pin for USART2. */&lt;br /&gt;  *STM32_GPIOA_CRL =&lt;br /&gt;     (2 &lt;&lt; 10) | /* CNF2  - Alternate function output push/pull. */&lt;br /&gt;     (1 &lt;&lt; 8);   /* MODE2 - Output mode, max 10 MHz. */&lt;br /&gt;&lt;br /&gt;  /* Set up the Baud Rate Register for 9600 bps. See RM0008, chapter&lt;br /&gt;     24.3.4. The value to be programmed in the BRR should be 234.375.&lt;br /&gt;     DIV_Mantissa=234 DIV_Fraction=6. */&lt;br /&gt;  *STM32_USART2_BRR = (234 &lt;&lt; 4) | 6; /* 9600 bps */ &lt;br /&gt;&lt;br /&gt;  /* After-reset default values for other registers are suitable for an&lt;br /&gt;     8-N-1 setup without enabled interrupts and DMA. */&lt;br /&gt;  &lt;br /&gt;  /* Enable the USART and the transmitter. */&lt;br /&gt;  *STM32_USART2_CR1 = (1 &lt;&lt; 13) | (1 &lt;&lt; 3);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;As I mentioned, I did not set up the receiver as this code is just a simple test to output characters over a serial line. Most of the lines are pretty self-explanatory I think, but there are a few thing worth noting. First, you have to enable clocking not only of the USART, but also for the corresponding GPIO port (in this case GPIOA). Second, when setting up the baud rate register, the fraction value is 16 times the fraction (0.375) i.e. 6. This is the value to be used when the clock frequency used for APB1 is 36 MHz (which is the maximum allowed frequency for APB1, and half the system clock). Do not forget to set up the APB1 clock prescaler!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5711171076422957585-1853211138325809591?l=embedded-sparetime.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://embedded-sparetime.blogspot.com/feeds/1853211138325809591/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embedded-sparetime.blogspot.com/2010/01/serial-port-insanity.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/1853211138325809591'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/1853211138325809591'/><link rel='alternate' type='text/html' href='http://embedded-sparetime.blogspot.com/2010/01/serial-port-insanity.html' title='Serial port insanity.'/><author><name>Marcus</name><uri>http://www.blogger.com/profile/08582830497995396149</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5711171076422957585.post-4099122421207770748</id><published>2009-09-10T21:19:00.016+02:00</published><updated>2009-09-10T22:39:01.428+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='STM32'/><category scheme='http://www.blogger.com/atom/ns#' term='Cortex-M3'/><category scheme='http://www.blogger.com/atom/ns#' term='RTOS'/><title type='text'>Some things have happened.</title><content type='html'>I have to apologize for the very bad update ratio on the blog. Hopefully someone will return to it anyway!&lt;br /&gt;&lt;br /&gt;Since my last post, some 3 months ago, the kernel now implements 5 different system calls. These are:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;yield&lt;/li&gt;&lt;li&gt;allocate a buffer&lt;br /&gt;&lt;/li&gt;&lt;li&gt;transmit a buffer to another process&lt;br /&gt;&lt;/li&gt;&lt;li&gt;receive a buffer from some other process&lt;br /&gt;&lt;/li&gt;&lt;li&gt;dispose of a buffer&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;The kernel is now a very simple message passing based one. It also handles different priorities, so that at every moment, the highest-prioritized ready process will run. Processes can now be written in C, as system call library functions are provided.&lt;br /&gt;&lt;br /&gt;A couple of months ago, someone asked about a description of the entire process from booting up to scheduling. I will attempt to describe a few important steps:&lt;br /&gt;&lt;br /&gt;First of all, the kernel and applications only run from RAM. Some basic support for running from ROM is implemented in the kernel and in the BSP (startup routines). There should not really need to be a lot of differences between these two cases and support for running from ROM will be there in time.&lt;br /&gt;&lt;br /&gt;The way I run the system right now is using OpenOCD and GDB to download an &lt;span style="font-style: italic;"&gt;elf &lt;/span&gt;file to the board. The elf file contains the monolith consisting of the kernel, the BSP and the application, everything linked to run from RAM. After downloading, I reset the board and let it run.&lt;br /&gt;&lt;br /&gt;The first thing that happens is that the CPU is reset, which means that it will use the default exception vector location (which is at address 0x00000000, i.e. in flash) to find the reset routine. I have (once and for all) put a small assembly routine in flash, which is pointed out by the reset vector. This routine reads the desired reset vector from RAM (at 0x20000004), the initial &lt;span style="font-weight: bold;"&gt;main stack pointer&lt;/span&gt; (at 0x20000000) and simply jumps to the boot routine pointed out by the address in 0x20000004, which is the BSP startup. This bootstrapping assembly routine is not part of the OS, nor the BSP.&lt;br /&gt;&lt;br /&gt;The &lt;span style="font-weight: bold;"&gt;BSP startup routine&lt;/span&gt; first of all sets up the STM32 clocks, so that the CPU core runs at 72 MHz (SYSCLK) which is generated from an 8 MHz external crystal which is multiplied by 9 using a PLL. AHB and APB2 clocks are also set up properly.&lt;br /&gt;&lt;br /&gt;After setting up all clocks, the BSS segment is cleared. The area to be cleared is obtained by getting the addresses of the &lt;span style="font-weight: bold;"&gt;_bss_start&lt;/span&gt; and &lt;span style="font-weight: bold;"&gt;_bss_end&lt;/span&gt; symbols. These symbols are defined in the linker command file which is supplied by the BSP.&lt;br /&gt;&lt;br /&gt;Next, by writing to the &lt;span style="font-weight: bold;"&gt;NVIC_VTOR&lt;/span&gt; register, the exception table location is moved to RAM (where it already is loaded). The &lt;span style="font-weight: bold;"&gt;GPIO&lt;/span&gt; module is set up to allow flashing the status LED.&lt;br /&gt;&lt;br /&gt;After that, the BSP is almost finished setting up the board. There is one more thing to consider before handing over to the kernel.&lt;br /&gt;&lt;br /&gt;All kernel setup processes (kernel initialization, process creation) must run from &lt;span style="font-weight: bold;"&gt;handler&lt;/span&gt; mode. I'll get back to the reason for that later. The default CPU mode after reset is &lt;span style="font-weight: bold;"&gt;thread&lt;/span&gt; mode, and the only way to switch to handler mode is through an exception. Therefore, the BSP writes the address of the &lt;span style="font-weight: bold;"&gt;kernel startup routine&lt;/span&gt;,&lt;br /&gt;to the &lt;span style="font-weight: bold;"&gt;SVC&lt;/span&gt; (system call) vector in RAM and triggers it by issuing an &lt;span style="font-weight: bold;"&gt;svc&lt;/span&gt; instruction. This results in a switch to handler mode and a jump to the kernel.&lt;br /&gt;&lt;br /&gt;The &lt;span style="font-weight: bold;"&gt;kernel startup routine&lt;/span&gt; clears the kernel pool area, then calls a hook which the application is supposed to implement. This hook function should do a number of &lt;span style="font-weight: bold;"&gt;rtos_create_process&lt;/span&gt; calls. This call allows the application to specify a process entry point, a priority and a stack size. For each call, a PCB is created in the kernel pool area, as well as a stack. The PCB is sorted into a &lt;span style="font-weight: bold;"&gt;readylist&lt;/span&gt;. After all these calls, the kernel is ready to start the highest prioritized process.&lt;br /&gt;&lt;br /&gt;I mentioned earlier that the kernel startup must run from handler mode. The reason for this is that when the first process is scheduled, it will be started in the same way as if it was resumed after preemption. Therefore, for each created process, the architecture specific code is called to prepare the &lt;span style="font-weight: bold;"&gt;process stack&lt;/span&gt; in a way such that returning to the process and resuming it actually starts the process from the first instruction and with an empty stack.&lt;br /&gt;&lt;br /&gt;When an application issues a system call, this is done by putting the syscall id (an integer, ranging from 0 to 4) in register r12 (done by an inline assembly routine). The scratch registers r0-r3 are transparently sent from the function call to the svc exception handler. The exception handler uses r12 as an offset into a jump table. Then a jump is taken to the system call implementation.&lt;br /&gt;&lt;br /&gt;No interrupt handling is implemented yet, i.e. I haven't had to deal with critical regions in the kernel yet. It is still to be decided for instance what exception priority levels will be used for the &lt;span style="font-weight: bold;"&gt;SVC&lt;/span&gt; call in relation to other exceptions (interrupts from peripherals).&lt;br /&gt;&lt;br /&gt;There is yet some more to be written about for instance context switching using the &lt;span style="font-weight: bold;"&gt;PendSV&lt;/span&gt; exception. I'll return to that later!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5711171076422957585-4099122421207770748?l=embedded-sparetime.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://embedded-sparetime.blogspot.com/feeds/4099122421207770748/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embedded-sparetime.blogspot.com/2009/09/some-things-have-happened.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/4099122421207770748'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/4099122421207770748'/><link rel='alternate' type='text/html' href='http://embedded-sparetime.blogspot.com/2009/09/some-things-have-happened.html' title='Some things have happened.'/><author><name>Marcus</name><uri>http://www.blogger.com/profile/08582830497995396149</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5711171076422957585.post-4854684308953137869</id><published>2009-06-10T09:04:00.004+02:00</published><updated>2009-06-10T09:25:05.993+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='STM32'/><category scheme='http://www.blogger.com/atom/ns#' term='Cortex-M3'/><category scheme='http://www.blogger.com/atom/ns#' term='RTOS'/><title type='text'>Flash a LED!</title><content type='html'>Yesterday, I configured GPIO port C to be able to flash the status LED. I now have two processes yielding to each other. One of them turns on the LED, the other turns it off. Here is one of them. It writes to the GPIO C BSRR (bit set/reset register) to set port C bit 12 high, which turns the LED off.&lt;br /&gt;&lt;br /&gt;&lt;pre class="source-code"&gt;&lt;code&gt;&lt;br /&gt;    .global CM3_proc0&lt;br /&gt;    .thumb_func&lt;br /&gt;&lt;br /&gt;CM3_proc0:&lt;br /&gt;    ldr    r1,    =0x40011010 @ PORT C BSRR register.&lt;br /&gt;    mov    r2,    0x00001000  @ Set bit 12.&lt;br /&gt;    str    r2,    [r1]&lt;br /&gt;    mov    r0,    0x1         @ Yield system call.&lt;br /&gt;    svc                       @ Perform the system call.&lt;br /&gt;    mov    r0,    0x800000    @ Delay loop.&lt;br /&gt;loop0:&lt;br /&gt;    sub    r0,    0x1&lt;br /&gt;    cmp    r0,    0x0&lt;br /&gt;    bne    loop0&lt;br /&gt;    b      CM3_proc0&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/lmsj_AePV0c&amp;hl=sv&amp;fs=1&amp;color1=0x3a3a3a&amp;color2=0x999999"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/lmsj_AePV0c&amp;hl=sv&amp;fs=1&amp;color1=0x3a3a3a&amp;color2=0x999999" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5711171076422957585-4854684308953137869?l=embedded-sparetime.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://embedded-sparetime.blogspot.com/feeds/4854684308953137869/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embedded-sparetime.blogspot.com/2009/06/flash-led.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/4854684308953137869'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/4854684308953137869'/><link rel='alternate' type='text/html' href='http://embedded-sparetime.blogspot.com/2009/06/flash-led.html' title='Flash a LED!'/><author><name>Marcus</name><uri>http://www.blogger.com/profile/08582830497995396149</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5711171076422957585.post-2314525383045154022</id><published>2009-05-26T08:07:00.004+02:00</published><updated>2009-05-26T08:46:03.169+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='FabLab'/><category scheme='http://www.blogger.com/atom/ns#' term='MP3Player'/><title type='text'>A Fablab opens up in Malmö!</title><content type='html'>A couple of days ago I read about the &lt;a href="http://en.wikipedia.org/wiki/Fab_lab"&gt;Fablab&lt;/a&gt; opening up soon in Malmö in the southern part of Sweden. I am really happy about this. At least a couple of my sparetime electronic projects have ended up as a PCB without a box or any mechanics at all. For instance, my MP3 player looks like this:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_9r8FcA7q7iQ/ShuJd93D3gI/AAAAAAAAADI/vKh_ZUblHyE/s1600-h/IMGP4765.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="http://4.bp.blogspot.com/_9r8FcA7q7iQ/ShuJd93D3gI/AAAAAAAAADI/vKh_ZUblHyE/s320/IMGP4765.JPG" alt="" id="BLOGGER_PHOTO_ID_5340012931092569602" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;When I designed the PCB, I was planning to design and build a box afterwards, but I realize I'll never get down to actually doing that, drilling and sawing acrylic plastic is just too cumbersome. With a fablab, I will be able to design and mill my own boxes and mechanics without an enormous budget.&lt;br /&gt;&lt;br /&gt;Be sure to check in &lt;a href="http://www.fablab.se/"&gt;http://www.fablab.se/.&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5711171076422957585-2314525383045154022?l=embedded-sparetime.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://embedded-sparetime.blogspot.com/feeds/2314525383045154022/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embedded-sparetime.blogspot.com/2009/05/fablab-opens-up-in-malmo.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/2314525383045154022'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/2314525383045154022'/><link rel='alternate' type='text/html' href='http://embedded-sparetime.blogspot.com/2009/05/fablab-opens-up-in-malmo.html' title='A Fablab opens up in Malmö!'/><author><name>Marcus</name><uri>http://www.blogger.com/profile/08582830497995396149</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_9r8FcA7q7iQ/ShuJd93D3gI/AAAAAAAAADI/vKh_ZUblHyE/s72-c/IMGP4765.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5711171076422957585.post-7983053167749444885</id><published>2009-05-13T14:36:00.004+02:00</published><updated>2009-05-13T14:50:03.196+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='STM32'/><category scheme='http://www.blogger.com/atom/ns#' term='Cortex-M3'/><category scheme='http://www.blogger.com/atom/ns#' term='RTOS'/><title type='text'>First successful context switch!</title><content type='html'>A couple of days ago, I ran my first fully working context switches. I have two small test processes that actually just &lt;span style="font-style: italic;"&gt;yield&lt;/span&gt; to each other:&lt;br /&gt;&lt;br /&gt;&lt;pre class="source-code"&gt;&lt;code&gt;/* Test processes. */&lt;br /&gt;__attribute__ ((naked)) static void proc0()&lt;br /&gt;{&lt;br /&gt;  for (;;)&lt;br /&gt;  {&lt;br /&gt;     asm("mov r0, 0x1\n\t"&lt;br /&gt;         "svc\n\t");&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;__attribute__ ((naked)) static void proc1()&lt;br /&gt;{&lt;br /&gt;  for (;;)&lt;br /&gt;  {&lt;br /&gt;     asm("mov r0, 0x1\n\t"&lt;br /&gt;         "svc\n\t");&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The code is really an ugly mix of C and assembly, and it seems like the &lt;span style="font-weight: bold;"&gt;__attribute__ ((naked))&lt;/span&gt; thing completely fools gdb as well. If i put a breakpoint on one of these two functions gdb does not put it on the first instruction, as you would probably want it to. Instead, it puts it one instruction after the first instruction. My guess is that gdb believes the first instruction to be a preamble for setting up the stack frame. But we don't have any stack frames here, due to the special attribute used. The workaround is to put a breakpoint on the &lt;span style="font-weight: bold;"&gt;address&lt;/span&gt; of the first instruction.&lt;br /&gt;&lt;br /&gt;The processes put &lt;span style="font-weight: bold;"&gt;1&lt;/span&gt; in &lt;span style="font-weight: bold;"&gt;r0&lt;/span&gt;, which means call the &lt;span style="font-style: italic;"&gt;yield&lt;/span&gt; system call, which in turns causes the simple scheduler to switch to the other process.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5711171076422957585-7983053167749444885?l=embedded-sparetime.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://embedded-sparetime.blogspot.com/feeds/7983053167749444885/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embedded-sparetime.blogspot.com/2009/05/first-successful-context-switch.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/7983053167749444885'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/7983053167749444885'/><link rel='alternate' type='text/html' href='http://embedded-sparetime.blogspot.com/2009/05/first-successful-context-switch.html' title='First successful context switch!'/><author><name>Marcus</name><uri>http://www.blogger.com/profile/08582830497995396149</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5711171076422957585.post-3143035604378861407</id><published>2009-05-07T06:42:00.006+02:00</published><updated>2009-05-07T08:10:15.754+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='STM32'/><category scheme='http://www.blogger.com/atom/ns#' term='Cortex-M3'/><category scheme='http://www.blogger.com/atom/ns#' term='RTOS'/><title type='text'>A few shots of the development board.</title><content type='html'>Yesterday, I took a few pictures of the development board and the OCD module I use.&lt;br /&gt;&lt;br /&gt;This is the STM32-P103 from Olimex. It features an STM32F103RBT6 µC from ST Microelectronics. It is based on the Cortex M3 architecture from ARM. The 32-bit CPU runs at up to 72 MHz. Equipped with 128 KiB of flash and 20 KiB of SRAM, it should be enough for many fun projects:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_9r8FcA7q7iQ/SgJnXyIFjyI/AAAAAAAAACg/0WqKuakhfqQ/s1600-h/DSCF2425.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://1.bp.blogspot.com/_9r8FcA7q7iQ/SgJnXyIFjyI/AAAAAAAAACg/0WqKuakhfqQ/s320/DSCF2425.JPG" alt="" id="BLOGGER_PHOTO_ID_5332938567050432290" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;A view from the bottom side, showing the SD/MMC card connector:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_9r8FcA7q7iQ/SgJpi7-wC0I/AAAAAAAAACo/Oo_PnxiTnEo/s1600-h/DSCF2426.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://4.bp.blogspot.com/_9r8FcA7q7iQ/SgJpi7-wC0I/AAAAAAAAACo/Oo_PnxiTnEo/s320/DSCF2426.JPG" alt="" id="BLOGGER_PHOTO_ID_5332940957697444674" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The ARM-USB-OCD adapter that I use to hook the board up to my Linux laptop:&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_9r8FcA7q7iQ/SgJrGUR904I/AAAAAAAAAC4/mFjz87BVMng/s1600-h/DSCF2428.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://3.bp.blogspot.com/_9r8FcA7q7iQ/SgJrGUR904I/AAAAAAAAAC4/mFjz87BVMng/s320/DSCF2428.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5332942665027539842" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5711171076422957585-3143035604378861407?l=embedded-sparetime.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://embedded-sparetime.blogspot.com/feeds/3143035604378861407/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embedded-sparetime.blogspot.com/2009/05/few-shots-of-development-board.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/3143035604378861407'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/3143035604378861407'/><link rel='alternate' type='text/html' href='http://embedded-sparetime.blogspot.com/2009/05/few-shots-of-development-board.html' title='A few shots of the development board.'/><author><name>Marcus</name><uri>http://www.blogger.com/profile/08582830497995396149</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_9r8FcA7q7iQ/SgJnXyIFjyI/AAAAAAAAACg/0WqKuakhfqQ/s72-c/DSCF2425.JPG' height='72' width='72'/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5711171076422957585.post-4975395482293279152</id><published>2009-05-04T10:33:00.002+02:00</published><updated>2009-05-04T10:56:12.093+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='STM32'/><category scheme='http://www.blogger.com/atom/ns#' term='Cortex-M3'/><category scheme='http://www.blogger.com/atom/ns#' term='RTOS'/><title type='text'>stmdb, ldmdb, stmfd etc...</title><content type='html'>It seems that I am getting quite close to my first working context switch right now. As recommended for RTOS:es on Cortex-M3, my context switches actually takes place in the PendSV handler which looks like this:&lt;br /&gt;&lt;br /&gt;&lt;pre class="source-code"&gt;&lt;code&gt;    .global    CM3_handler_pendsv&lt;br /&gt;    .thumb_func&lt;br /&gt;    .extern current_pcb&lt;br /&gt;    .extern new_pcb&lt;br /&gt;CM3_handler_pendsv:&lt;br /&gt;    mrs    r12,   PSP          @ Get PSP for current process.&lt;br /&gt;    &lt;b&gt;stmfd&lt;/b&gt;  r12!,  {r4-r11}     @ Save remaining registers.&lt;br /&gt;    ldr    r0,    =current_pcb @ r0 = &amp;amp;current_pcb.&lt;br /&gt;    ldr    r0,    [r0]         @ r0 = current_pcb &lt;br /&gt;    str    r12,   [r0, 8]      @ Update SP in PCB.&lt;br /&gt;    ldr    r0,    =new_pcb     @ r0 = &amp;amp;new_pcb&lt;br /&gt;    ldr    r0,    [r0]         @ r0 = new_pcb &lt;br /&gt;    ldr    r12,   [r0, 8]      @ r12 = SP for new process.&lt;br /&gt;    &lt;b&gt;ldmfd&lt;/b&gt;  r12!,  {r4-r11}     @ Restore r4-r11 for new process.&lt;br /&gt;    msr    PSP,   r12          @ Update SP for new process.&lt;br /&gt;    ldr    lr,    =0xfffffffd  @ Use process stack when returning.&lt;br /&gt;    bx     lr                  @ Return to new process.&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Make sure to use the proper variants of the stm&lt;xx&gt; and ldm&lt;xx&gt; instructions.The &lt;b&gt;fd&lt;/b&gt; suffix stands for &lt;i&gt;full descending&lt;/i&gt; which means that the stack pointer decreases before data is written to the stack using it. Therefore, the stack is always &lt;b&gt;full&lt;/b&gt; ie. the stack pointer always points at valid data. When reading from the stack, the stack pointer increases after the reading operation.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5711171076422957585-4975395482293279152?l=embedded-sparetime.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://embedded-sparetime.blogspot.com/feeds/4975395482293279152/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embedded-sparetime.blogspot.com/2009/05/stmdb-ldmdb-stmfd-etc.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/4975395482293279152'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/4975395482293279152'/><link rel='alternate' type='text/html' href='http://embedded-sparetime.blogspot.com/2009/05/stmdb-ldmdb-stmfd-etc.html' title='stmdb, ldmdb, stmfd etc...'/><author><name>Marcus</name><uri>http://www.blogger.com/profile/08582830497995396149</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5711171076422957585.post-5293086443506310855</id><published>2009-04-28T10:07:00.007+02:00</published><updated>2009-04-28T12:10:35.498+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='STM32'/><category scheme='http://www.blogger.com/atom/ns#' term='Cortex-M3'/><category scheme='http://www.blogger.com/atom/ns#' term='RTOS'/><title type='text'>Fighting the GNU as assembler (contd.)</title><content type='html'>Okay, yesterday I tested the RTOS prototype with the exception vectors put in an assembly language file instead. It did not work quite as expected...&lt;br /&gt;&lt;br /&gt;To begin with, I should tell you that my code is linked to be run from the embedded SRAM in the STM32. This is because I think it is prettier to not have to erase and reprogram the flash all the time. On the other hand, the Cortex-M3 always has it's exception vectors placed at &lt;span style="font-weight: bold;"&gt;0x0&lt;/span&gt; out of reset, and that is within the flash area. That means that following a reset, the CPU will always start executing from the reset vector at &lt;span style="font-weight: bold;"&gt;0x4&lt;/span&gt;. It is possible to relocate the exception vectors to 0x20000000 (SRAM) by modifying the &lt;span style="font-style: italic;"&gt;vector table offset register&lt;/span&gt; once you're running and thereby pointing out your own vectors placed in SRAM.&lt;br /&gt;&lt;br /&gt;To be able to practically run my code from SRAM I implemented a minimal bootstrap routine that I put into the flash area:&lt;br /&gt;&lt;br /&gt;&lt;pre class="source-code"&gt;&lt;code&gt;static void reset();&lt;br /&gt;&lt;br /&gt;unsigned int *vectors[2] __attribute__ ((section(".vectors"))) = {&lt;br /&gt;(unsigned int *)     0, /* No stack used. */&lt;br /&gt;(unsigned int *)     reset&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;__attribute__ ((naked)) static void reset()&lt;br /&gt;{&lt;br /&gt;/* We enter here, running as privileged in thread mode. TRM 2.2.&lt;br /&gt;  We use SP_main. TRM 2.2.1 and 5.4.&lt;br /&gt;  NVIC interrupts disabled. NMI and Hard Fault disabled. TRM 5.9. */&lt;br /&gt;&lt;br /&gt;/* Remap vectors to 0x20000000.&lt;br /&gt;  Read stack top and entry point from&lt;br /&gt;  user's RAM-based vectors. Jump to&lt;br /&gt;  entry point. */&lt;br /&gt;asm("mov r0, #0x20000000\n\t"&lt;br /&gt;   "ldr r1, =0xE000ED08\n\t"&lt;br /&gt;   "str r0, [r1]\n\t"&lt;br /&gt;   "ldr sp, [r0]\n\t"&lt;br /&gt;   "ldr pc, [r0, #4]");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;span style="font-weight: bold;"&gt;TRM&lt;/span&gt; refers to the Cortex-M3 Technical Reference Manual. The reset routine reads the initial stack pointer and SRAM-based boot routine address from the user's exception vector at 0x20000000. It set the vector table offset register and jumps to the user's reset routine. This way, it appears like the board boots from SRAM.&lt;br /&gt;&lt;br /&gt;So first, load your code including your exception vectors to SRAM, then issue a system reset to the board.&lt;br /&gt;&lt;br /&gt;The problem I ran into yesterday was when performing an &lt;span style="font-style: italic;"&gt;svc&lt;/span&gt; (system call). The CPU properly jumped to my exception handler:&lt;br /&gt;&lt;br /&gt;&lt;pre class="source-code"&gt;&lt;code&gt;  .global  CM3_handler_svc&lt;br /&gt;.extern  portable_syscall&lt;br /&gt;CM3_handler_svc:&lt;br /&gt;bl  portable_syscall&lt;br /&gt;bx  lr&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;Problem was that when executing the first instruction (the &lt;span style="font-style: italic;"&gt;bl&lt;/span&gt;), an exception occured. I noticed that the &lt;span style="font-weight: bold;"&gt;T-bit&lt;/span&gt; in the xPSR register was cleared when taking the svc exception. Executing instructions in the Cortex-M3 with the T-bit (thumb mode) cleared is not allowed. The fix was to add the &lt;span style="font-style: italic;"&gt;pseudo-op&lt;/span&gt; &lt;span style="font-weight: bold;"&gt;.thumb_func&lt;/span&gt; before the exception handler code. That way, the exception table entry corresponding to svc sets the LSB of the jump address and the T-bit gets set when running the svc handler. Haven't tested this yet, but it should work.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5711171076422957585-5293086443506310855?l=embedded-sparetime.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://embedded-sparetime.blogspot.com/feeds/5293086443506310855/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embedded-sparetime.blogspot.com/2009/04/okay-yesterday-i-tested-rtos-prototype.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/5293086443506310855'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/5293086443506310855'/><link rel='alternate' type='text/html' href='http://embedded-sparetime.blogspot.com/2009/04/okay-yesterday-i-tested-rtos-prototype.html' title='Fighting the GNU as assembler (contd.)'/><author><name>Marcus</name><uri>http://www.blogger.com/profile/08582830497995396149</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5711171076422957585.post-6187642725553019624</id><published>2009-04-27T11:17:00.009+02:00</published><updated>2009-05-11T13:23:32.608+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='STM32'/><category scheme='http://www.blogger.com/atom/ns#' term='Cortex-M3'/><category scheme='http://www.blogger.com/atom/ns#' term='RTOS'/><title type='text'>Fighting the GNU as assembler.</title><content type='html'>For my RTOS experiments, I need vectors to be nicely linked into the binary, which I download to the Cortex M3 target, being an &lt;a href="http://www.olimex.com/dev/stm32-p103.html"&gt;STM32 development board from Olimex&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;To start with, I used to put exception vectors in the C source file, in the following way:&lt;br /&gt;&lt;br /&gt;&lt;pre class="source-code"&gt;&lt;code&gt;&lt;br /&gt;/* Vector Table */&lt;br /&gt;unsigned int *vectors[12]&lt;br /&gt;__attribute__ ((section(".vectors")))= {&lt;br /&gt;  (unsigned int *)     START_STACK_TOP,&lt;br /&gt;  (unsigned int *)     boot_rtos,&lt;br /&gt;  (unsigned int *)     0x00000000,&lt;br /&gt;  (unsigned int *)     0x00000000,&lt;br /&gt;  (unsigned int *)     0x00000000,&lt;br /&gt;  (unsigned int *)     0x00000000,&lt;br /&gt;  (unsigned int *)     0x00000000,&lt;br /&gt;  (unsigned int *)     0x00000000,&lt;br /&gt;  (unsigned int *)     0x00000000,&lt;br /&gt;  (unsigned int *)     0x00000000,&lt;br /&gt;  (unsigned int *)     0x00000000,&lt;br /&gt;  (unsigned int *)     CM3_SVC&lt;br /&gt;};&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;That way, I tell gcc to put the array of vectors in the .vectors section. As I use OpenOCD to communicate with the board, using the &lt;a href="http://www.olimex.com/dev/arm-usb-ocd.html"&gt;ARM-USB-OCD&lt;/a&gt;, I can download the executable directly from gdb, using the "load" command.&lt;br /&gt;&lt;br /&gt;However, I would like to have the vectors defined in an assembly language source file, together with a few of my Cortex M3 specific routines (such as system call handling etc). Therefore I tried to put the vectors in the .s file:&lt;br /&gt;&lt;br /&gt;&lt;pre class="source-code"&gt;&lt;code&gt;    .section        .vectors,&amp;quot;aw&amp;quot;&lt;br /&gt;    .global    CM3_vectors&lt;br /&gt;    .extern    boot_rtos&lt;br /&gt;CM3_vectors:&lt;br /&gt;        .word   START_STACK_TOP&lt;br /&gt;        .word   boot_rtos&lt;br /&gt;        .word   0&lt;br /&gt;        .word   0&lt;br /&gt;        .word   0&lt;br /&gt;        .word   0&lt;br /&gt;        .word   0&lt;br /&gt;        .word   0&lt;br /&gt;        .word   0&lt;br /&gt;        .word   0&lt;br /&gt;        .word   0&lt;br /&gt;        .word   CM3_handler_svc&lt;br /&gt;        .word   0&lt;br /&gt;        .word   0&lt;br /&gt;        .word   CM3_handler_pendsv&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;However, I initially did not use the &lt;span style="font-weight:bold;"&gt;"aw"&lt;/span&gt; attribute to the &lt;span style="font-weight:bold;"&gt;.section&lt;/span&gt; operator. This resulted in the vectors area being considered a debug symbol when using &lt;span style="font-weight:bold;"&gt;nm&lt;/span&gt;. Therefore, gdb did not download it to the board.&lt;br /&gt;&lt;br /&gt;Using the &lt;span style="font-weight:bold;"&gt;-S&lt;/span&gt; flag to gcc, I could examine the assembly output from gcc and that way find out that I should use the &lt;span style="font-weight:bold;"&gt;"aw"&lt;/span&gt; attribute. Apparently GNU as does not apply any default attributes on a section called .vectors.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5711171076422957585-6187642725553019624?l=embedded-sparetime.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://embedded-sparetime.blogspot.com/feeds/6187642725553019624/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embedded-sparetime.blogspot.com/2009/04/fighting-gnu-as-assembler.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/6187642725553019624'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/6187642725553019624'/><link rel='alternate' type='text/html' href='http://embedded-sparetime.blogspot.com/2009/04/fighting-gnu-as-assembler.html' title='Fighting the GNU as assembler.'/><author><name>Marcus</name><uri>http://www.blogger.com/profile/08582830497995396149</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5711171076422957585.post-4827569753552912166</id><published>2009-04-27T10:12:00.000+02:00</published><updated>2009-04-27T10:30:44.389+02:00</updated><title type='text'>First entry...</title><content type='html'>Hello!&lt;br /&gt;&lt;br /&gt;I intend to write a few lines now and then about my electronics projects. Hopefully, it will be of interest to someone! :-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5711171076422957585-4827569753552912166?l=embedded-sparetime.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://embedded-sparetime.blogspot.com/feeds/4827569753552912166/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://embedded-sparetime.blogspot.com/2009/04/first-entry.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/4827569753552912166'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5711171076422957585/posts/default/4827569753552912166'/><link rel='alternate' type='text/html' href='http://embedded-sparetime.blogspot.com/2009/04/first-entry.html' title='First entry...'/><author><name>Marcus</name><uri>http://www.blogger.com/profile/08582830497995396149</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
