Author Topic: Basic (first) STM32F1 program  (Read 5011 times)

0 Members and 1 Guest are viewing this topic.

Offline JackPTopic starter

  • Regular Contributor
  • *
  • Posts: 185
  • Country: gb
Basic (first) STM32F1 program
« on: March 21, 2015, 08:05:23 pm »
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
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Basic (first) STM32F1 program
« Reply #1 on: March 21, 2015, 08:57:51 pm »
Quote
how do I use the GPIO on this?

The 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.
================================
https://dannyelectronics.wordpress.com/
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4078
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: Basic (first) STM32F1 program
« Reply #2 on: March 21, 2015, 09:21:31 pm »
So my main question is how do I use the GPIO on this?
-First you configure the C-runtime environment. Or you leave that to the template startup.s file that your IDE inserts in your projects. This will suffice for most applications.
-Check if the startup.s file 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.
« Last Edit: March 21, 2015, 09:24:00 pm by Jeroen3 »
 

Offline JackPTopic starter

  • Regular Contributor
  • *
  • Posts: 185
  • Country: gb
Re: Basic (first) STM32F1 program
« Reply #3 on: March 21, 2015, 09:23:15 pm »
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
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4078
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: Basic (first) STM32F1 program
« Reply #4 on: March 21, 2015, 09:26:48 pm »
No. It's not in the datasheet. The datasheet contains specifications and pinouts. Sometimes pin multiplexer details.
The peripherals are described in the reference manual. The core is described in the programming 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.
« Last Edit: March 21, 2015, 09:31:05 pm by Jeroen3 »
 

Offline JackPTopic starter

  • Regular Contributor
  • *
  • Posts: 185
  • Country: gb
Re: Basic (first) STM32F1 program
« Reply #5 on: March 21, 2015, 09:32:00 pm »
OK thank you for your help, it seems I have some reading to do.
 

Offline JackPTopic starter

  • Regular Contributor
  • *
  • Posts: 185
  • Country: gb
Re: Basic (first) STM32F1 program
« Reply #6 on: April 19, 2015, 07:51:06 pm »
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.
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Basic (first) STM32F1 program
« Reply #7 on: April 19, 2015, 08:56:52 pm »
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=partnumber

Reference manual is in the Design Resources tab.
http://www.st.com/st-web-ui/static/active/en/resource/technical/document/reference_manual/DM00096844.pdf

Decision 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/0123854776
where 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).

 

Offline IconicPCB

  • Super Contributor
  • ***
  • Posts: 1537
  • Country: au
Re: Basic (first) STM32F1 program
« Reply #8 on: April 20, 2015, 12:18:00 am »
Have a look at the arduino like environment ( Maple and leaflabs.com for IDE )

You might like it.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf