Basic (first) STM32F1 program - Page 1
Forum section: electronics / beginners

author: JackP
author_rank: Regular Contributor
timestamp: March 21, 2015, 08:05:23 pm
content: After playing around with AVR for a while, I have decided that ARM is the platform I want to really hone my C skills on. I have come to this decision mainly due to their advanced capabilities (clock speeds) and peripherals. I have downloaded CoIDE, which looks to be a very user friendly IDE to start on; I also tried out Keil uVision, but did not find that as intuitive. I have sorted my toolchain as well. However, I have some questions I would like to ask before I make the required purchases. I am thinking of buying (from eBay) some cheap dev boards for about £3 each (they all use the STM32F103C8T6), a £3 ST-LINK knock off and a £7 J-LINK J-TAG programmer; I'm aware I could make do with just the ST-LINK, but there's no harm in getting something else for a sanity check.So my main question is how do I use the GPIO on this? On the AVR, it is so easy to just manipulate the bits in a register. What libraries do I need to flash an LED, if any? Is it possible to directly manipulate the pins in such a simple way? I know these questions must make you laugh, but I just can't find the information anywhere. I'd rather not splash out for a dev board from TI or STM, and I should mention that my only avenues for purchase are eBay and Amazon. If anyone can help me out, I'd be very grateful.Kind regards,JackP

author: dannyf
author_rank: Super Contributor
timestamp: March 21, 2015, 08:57:51 pm
content: QuoteThe same principle: you can set/clear a few bits directly or through the libraries you use. Datasheet has all the information you need for that, if you want to go direct.

author: Jeroen3
author_rank: Super Contributor
timestamp: March 21, 2015, 09:21:31 pm
content: Quote from: JackP on March 21, 2015, 08:05:23 pm-First you configure the C-runtime environment. Or you leave that to the templatestartup.sfile that your IDE inserts in your projects. This will suffice for most applications.-Check if thestartup.sfile also sets up the clock to an appropriate speed. Some do, some don't.-Then you enable the clocks to the GPIOx block.-Then you configure the pin multiplexer accordingly, to GPIO. Don't forget to enable push-pull.-Now you can use the GPIO data/set/reset/toggle registers to manipulate the output.- Either use the Systick (to create software timers) to blink LED's.- Or use for loop delays. I do not recommend this, try the above.

author: JackP
author_rank: Regular Contributor
timestamp: March 21, 2015, 09:23:15 pm
content: How do I enable and set up these things? I'm working my way through the datasheet as I type this, so will it be in there?Thanks again

author: Jeroen3
author_rank: Super Contributor
timestamp: March 21, 2015, 09:26:48 pm
content: No. It's not in the datasheet. The datasheet contains specifications and pinouts. Sometimes pin multiplexer details.The peripherals are described in thereference manual. The core is described in theprogramming manual, which is where you find details about the systick, because thats part of all ARM cores.Try looking for- Power control (PWR)I do not recall the F1 family being capable of powering off separate peripherals- Reset and clock control (RCC)- General-purpose and alternate-function I/Os (GPIOs and AFIOs)The systick is ready to use with the CMSIS library functions. Your IDE should have them ready.

author: JackP
author_rank: Regular Contributor
timestamp: March 21, 2015, 09:32:00 pm
content: OK thank you for your help, it seems I have some reading to do.

author: JackP
author_rank: Regular Contributor
timestamp: April 19, 2015, 07:51:06 pm
content: OK, I've changed my mind on a few things. I have decided to go for one of the STM32 Nucleo dev boards (the STM32F401RET6), so I have a known quantity in case of any manufacturing errors from China. For just £10 I think it is worth it. Before ordering, I looked through the datasheet, and tried to find the reference manual; could you point me towards it please, I have had no success in finding it? I'll look for the programming manual, and hopefully will get somewhere with it. I have also changed my IDE from CoIDE to Keil due to the better support.Thanks again.

author: Yansi
author_rank: Super Contributor
timestamp: April 19, 2015, 08:56:52 pm
content: Documentation is usually on the manufacturer's website. Go there, search your product, download it. It is that easy.http://www.st.com/web/catalog/mmc/FM141/SC1169/SS1577/LN1810/PF258797?s_searchtype=partnumberReference manual is in theDesign Resourcestab.http://www.st.com/st-web-ui/static/active/en/resource/technical/document/reference_manual/DM00096844.pdfDecision to stick with Keil first was good. But to start with F401 is not so good for a beginner (if you do not want to use slaptogether libraries for absolute dummies). If you are interested in really understanding the basics of STM32 / ARM archittecture, better choice is possibly STM32F0 series. They are the simplest (Cortex M0) devices.I also highly recommend getting a book:http://www.amazon.com/The-Definitive-Guide-ARM-Cortex-M0/dp/0123854776where the basics of ARM architecture are described. (Note that Yiu has written book also for Cortex M3 and M4 devices too)Then by using the datasheet and reference manual, you should be capable of writing yourself a simple "LED blinking demo" without using any complex libraries, just by direct accessing the registers. (It is not complicated, trust me*) The next step of your learning curve should be the libraries - I recommend using StdPeriph instead of STM32Cube, especially for smaller devices.*for the first time, you won't need any clock setting, you can run on the default clock source. (typically HSI).

author: IconicPCB
author_rank: Super Contributor
timestamp: April 20, 2015, 12:18:00 am
content: Have a look at the arduino like environment ( Maple and leaflabs.com for IDE )You might like it.