Beginning Cortex M3, but so lost!! - Page 1
Forum section: electronics / general

author: dt
author_rank: Newbie
timestamp: January 06, 2012, 07:23:11 am
content: Hi everyone,After spending a few days researching on what MCU I should invest my time on learning, I concluded to go with the Cortex M3 family. But man, where do I start!? The documentation is really fragmented and no implementor seems to have their house in order, looks chaotic for a beginner. Could someone please outline what to read and in what sequence, and link to relevant docs? I'm looking for material that starts from step 1, i.e., what tools to use, what is the development process, mcu architecture and instruction set, code samples, etc..Many thanks!!

author: Psi
author_rank: Super Contributor
timestamp: January 06, 2012, 07:27:11 am
content: Quote from: dt on January 06, 2012, 07:23:11 amDo you plan to code the ARM in ASM?In my opinion that really isn't needed, especially with such a modern/fast cpu.C would be a much better choice.All you really need to get is a M3 chip + board, a programmer and compiler/ide. (A good ARM M3 dev board would come with all three)Once you have that you can compile some one line code onto the micro and then start expanding on it.etc, checking the datasheet for register names, turn ports on/off, enabling timers etc.However, maybe that's just me. I learn by doing and only read docs if there's something info i need.

author: dt
author_rank: Newbie
timestamp: January 06, 2012, 07:31:11 am
content: Quote from: Psi on January 06, 2012, 07:27:11 amI'd probably avoid it where I can, but I would like to keep the options open.In any case, I'm stuck at a much earlier step, I don't seem to be able to find an authoritative development guide explaining how to put together the required toolchain. There seem to be a lot of tools around, some free, some for a fee, doing different things. But how do they fit together, and which ones do I need to get started?

author: Psi
author_rank: Super Contributor
timestamp: January 06, 2012, 07:34:41 am
content: Although it's good to know ASM, so you have an understanding of what's happening behind your C code, i think its perfectly ok to learn C first.Then, if you need it, learn some ASM later.Chances are you wont need it for quite a while, if at all.

author: dt
author_rank: Newbie
timestamp: January 06, 2012, 07:45:54 am
content: I'm on Mac OS X BTW. I'm now wondering if it would be possible to setup xcode for the task, and if so, whether it would be a good idea in the first place (i.e., would in-circuit debugging or ice work?)

author: Psi
author_rank: Super Contributor
timestamp: January 06, 2012, 07:53:13 am
content: I'm afraid i know nothing about macs.

author: AndreasF
author_rank: Frequent Contributor
timestamp: January 06, 2012, 08:01:42 am
content: I don't know which exact device you are planning on using, but Atmel has an application note "GNU-Based Software Development on AT91SAM Microcontrollers" (link), which may be of some use. It does, however, also only mention Windows and Linux environments, so I don't know if this will be of much help to you.

author: dt
author_rank: Newbie
timestamp: January 06, 2012, 11:26:05 am
content: Thanks guys, I bumped into this link which has a good collection of info so it will get me started:http://milksnot.com/content/arm-cortex-m3-getting-startedAlso, here's a guide on how to set up a toolchain on OS X, based on the GCC compiler:http://www.coactionos.com/index.php/getting-started/9-cortex-m3-compiler-osx

author: Short Circuit
author_rank: Frequent Contributor
timestamp: January 06, 2012, 12:33:45 pm
content: Do yourself a favor and get a normal PC (normal as in Windows).Then you have access to plenty ready to run development environments (Raisonance, Keil, IAR, etc) so you can focus on the Cortex itself instead of being bothered by all the quirks of OSS. Having the compiler is one thing, but you also want a reasonable IDE, and a debugger. Getting all that together and up and running on weird host systems is a waste of time.And you'll need that time to get around with the Cortex itselfGreat micro, but so many features that it can be a pita to get things like periperals up and running. After a few times, you get familiar with it, and such things become more obvious, but in the beginning it can be a serious problem.

author: ToBeFrank
author_rank: Regular Contributor
timestamp: January 06, 2012, 03:15:08 pm
content: Quote from: Short Circuit on January 06, 2012, 12:33:45 pmI agree. I also run Mac OS X so I have my Cortex dev environments installed in a virtual machine. I've had no problems doing that. I looked into getting everything set up on Mac and concluded it's just not worth the hassle. Rowley Crossworks runs on Mac, but the cheapest version is $150 and that's only if you don't ever plan to sell anything you write with it.I started with theNXP LPCXpresso. It's a $30 dev board that includes a JTAG/SWD programmer. When you're ready to move on to your own projects you can separate the programmer and use it for your own boards. The IDE and compiler that is part of LPCXpresso is free for anything under 128KB of flash. It's based on Eclipse and it works pretty well. The LPC1768 LPCXpresso seems to be a popular M3 dev board and there are plenty of examples out there for it. I just read the LPC1768 user guide and looked at examples and I was up and running.

author: bruce273
author_rank: Contributor
timestamp: January 06, 2012, 05:39:33 pm
content: The documentation will be per procosser so you'll need to determine which chip you want to use first as they all have different internal peripherals. If you choose the stm32 m3 chips they'll normally call the most usful document the reference manual it contains all the register definitions and how they work.The programming manual normally gives information on memory addressing modes and the instruction set of the processor which isn't that important for C programming.The datasheet itself is also quite helpful as it gives the electrical characteristics, so read up on it an check the maximum current draw, and be careful as the specifications of the pins occasionally change if there function is changedI started on windows using the attolic IDE for stm chips. it isn't amazing but it's an ok starting point as it has all the necessary header files for C which allow you to use premapped function registers.Macs and linux pcs are not quite as easy for a bigginer unless you are already used to makefiles and such and I think codeblocks has reasonably nice arm compiler support if you prefer the open source route on any platform aswell. Just takes a little more effort to set up and you'll have yet more manuals to read for the compilers aswell down that route.I used a midibox based stm32 board. But stm provide a discovery board which is similar to the nxp. It does run at 72MHz rather than 100MHz so if speed is important.

author: bruce273
author_rank: Contributor
timestamp: January 06, 2012, 05:42:42 pm
content: Quote from: ToBeFrank on January 06, 2012, 03:15:08 pmHave you tried wine for mac this guys made a nice user interface for ithttp://winebottler.kronenberg.org/it's open and free. Think crossworks is based on wine aswell.

author: steff
author_rank: Contributor
timestamp: January 06, 2012, 06:01:25 pm
content: Not M3, but as a very simple environment in which to get used to ARM, you might want to have a look athttp://mbed.org/

author: dt
author_rank: Newbie
timestamp: January 06, 2012, 08:54:08 pm
content: Quote from: Short Circuit on January 06, 2012, 12:33:45 pmHehe, for an increasing number of people the "normal PC" is the Mac, whereas Windows is the unstable, slow and fiddly thing of the past. I have a bunch of vista boxes sitting in the closet and the idea of using them for anything is a nightmare that makes me wonna cryMore seriously now: I'm just a beginner hobbyist in electronics but have a 15y old career in Software eng. I have developed software in all the popular platforms and then some, and I can honestly say that the xcode platform on the mac (which is really a unix OS with a nice UI and extensions) is by faaaaar the most advanced AND user friendly IDE for software dev. And I'm not only talking about code completion and other similar features that everyone has, but for a collection of highly sophisticated static analysis and profiler tools that help the average Joe truly optimize their code. And they are so user-friendly that it makes you wonna cry. No one else offers this degree of sophistication in their IDE, while it comes for free with any modern Mac.xcode uses the gcc compiler so pretty much any hardware can be targeted, has assembler/disassembler, linker, debugger, etc.., etc.. Of course, the problem in question is how to integrate JTAG, which is an area that I'll have to investigate further. The argument on spending time on setting up the toolchain rather than learning to program the cortex does not have a straight forward answer. Having a good toolchain in place is guaranteed to speed up development in the long run, so in my opinion the time spent in setting up a good environment is an investment. But I'm sure people can argue either wayAnyhoo, I now understand a bit more about the process and thanks everyone for your input. Reading the documentation from Keil, IAR, and Crossworks were the best pointers, ironically.

author: Unknown
author_rank: Unknown
timestamp: January 06, 2012, 09:57:54 pm
content: Quote from: steff on January 06, 2012, 06:01:25 pmMost mbed's are based on the LPC 1768, a Cortex M3. I believe there is a new version based on the M0, but I'm not sure if it's available yet.Quote from: dt on January 06, 2012, 08:54:08 pmNothing wrong with choosing your own IDE, you'll just have more work getting it to work compared to complete packages of IDE, compilers, programmers and debuggers like Code Red.Quote from: steff on January 06, 2012, 06:01:25 pmNXP, STM and TI are the places to be for ARM Cortex M3 for hobbyists in my opinion. Atmel seems to be behind (did they release their M0 parts yet?), and most others seem purely focused on industry. Choose whichever appears to have the best toolchain support. I believe the JTAG dongle part of the LPCXpresso is closed, there is some support for the STM32 Discovery JTAG interface by flashing it with a different firmware. This does not matter if you use a different JTAG interface. OpenOCD UrTAG will probably have Mac support. Note that many of the low pin count ARMs will use SWD, not the traditional JTAG. Other useful search terms may be Codesourcery Lite, they make a free GCC toolchain for ARM, although they may not have binaries for Mac, and CMSIS, which is a kind of standardized hardware abstraction for ARM Cortex.

author: westfw
author_rank: Super Contributor
timestamp: January 07, 2012, 10:09:54 am
content: QuoteWhen you've got XCODE working and cross compiling for some CM3 ARM chip, be sure to write up how you managed to do it!The compiler is relatively easy; the core libraries (libgcc, libc, cmsis) are a pain in the license, and the peripheral libraries are going to be vastly different on a per-manufacturer basis. You'd definitely have an easier time using one of the pre-packaged IDEs.

author: McMonster
author_rank: Frequent Contributor
timestamp: January 07, 2012, 12:35:05 pm
content: I've heard that manufacturer supplied libraries for some ARMs are nothing but crap, so at least this shouldn't be a problem. I'm starting using ARMs too, but I've choosen Eclipse (yeah, I know it's a bloated hog, but it keeps all my coding work in a single, well known and configured environment, sometimes simplicity is just not enough) as IDE, CodeSourcery's G++ Lite toolchain and OpenOCD as debugging backend (there's a guide how to set this up, but unfortunately in Polish).After extensive analyzing of what's available to get I've choosen SMT32s, they have a really wide choice of chips and dev boards including their dirt cheap discovery boards, less than 20$ shipped and with integrated SWD programmer that can work as standalone. I'm actually getting one discovery board and one more powerful with Ethernet, USB and JTAG interfaces and with most of the IO pins routed to goldpins. I don't really like all-in-one, expensive boards with tons of devices hardwired and no user access to IO pins directly, but I really wanted built-in Ethernet for future use. I already have a JTAG, a hobbyist designed and produced device that's comparable in availability to Dave's uCurrent. Once in a while a small batch appears and is sold out in the matter of 2-3 hours.It's a really great FT232 based programmer with integrated JTAG, RS232 and UART interfaces, I can do a small teardown/review if you want (again original materials are all in Polish).

author: steff
author_rank: Contributor
timestamp: January 07, 2012, 01:02:52 pm
content: Quote from: alm on January 06, 2012, 09:57:54 pmGood point. I'd misremembered - been a while since I touched one, and of course the front page is shouting about the new version to confuse me further. I do recall it being a nice easy introduction though, so the recommendation stands.

author: benemorius
author_rank: Regular Contributor
timestamp: January 08, 2012, 06:15:35 am
content: I've used GCC with kdevelop on linux. I forget what toolchain I decided on, but I believe I used both codesourcery and gnuarm. I was able to get jtag debugging going in kdevelop through GDB and openocd. It was very buggy, but I think that was mostly or entirely due to kdevelop. I believe you should be able to use all of the above with xcode on osx.I know exactly how you feel about sticking with xcode. I had the pleasure of using it pretty extensively a few years ago. Since then, using any other IDE just hasn't been as enjoyable as it use to be. I've been spoiled for sure.I'm looking forward to using to it again more permanently on an airbook as soon as they release one with a proper macbook-worthy LCD so I'm pretty interested to hear about your experiences. I do hope you don't give in before you get it working. It's certainly true that getting everything going on that other OS is less trouble, but working within a foreign environment is quite a distasteful solution for something you're going to be using regularly and that's true regardless of which OS is the "other" one to you.