cancel
Showing results for 
Search instead for 
Did you mean: 

C skeleton for stm32F10xx series?

rael
Associate II
Posted on May 09, 2009 at 03:58

C skeleton for stm32F10xx series?

16 REPLIES 16
rael
Associate II
Posted on May 17, 2011 at 13:11

Hi All,

I'm new to the ARM and C

I've done a lot of assembler in the past on AVR, PIC, (and older), but not ventured into C yet.

What I'm looking for, is some C code set up to use some of the libraries, preferably v3.0.0 onwards, that has minimal application specific code, as I have a CNC PCB of my own design. I have the ''Flash Loader Demo'', and it sucessfully communicates with the STM32F103VBT6 I'm using.

I have the original STM Circle, with RIDE7 set up on a EEEBOX PC, but if possible, I'd like skeleton code without copious extraneous stuff.

Thanks, Graham.

rael
Associate II
Posted on May 17, 2011 at 13:11

I'm slowly figuring it out, it feels a bit like being in the deep end of the pool, but some stuff is becoming less murky. :o

However, ''stm32f10x_stdperiph_lib_v3.0.0.zip'' from STM seems to be in the middle of a transitional process, and I'm unsure as to how the CM3 directory relates to the templates directory within that zip file.

Unfortunately, I'm having to learn all this at once, rather than just as version changes.

Any hints gratefully recieved ! :D

relaxe
Associate II
Posted on May 17, 2011 at 13:11

Hi there!

I've taken those steps too.

First, use an exemple app from the library. The readme accompanying the demos are pretty straight forward.

To get around the library, the ''Firmware Library Reference'' document describe every function in the Lib. I keep it always open somewhere.

There is a file named stm32f10x_it.c wich contains the interrupt vectors, so any code inside one of these function will service the int.

As for skeleton code (template?), I would advise to use any example app not using DMA or interrupt, then delete any unneeded code.

-Relaxe

rael
Associate II
Posted on May 17, 2011 at 13:11

Hi relaxe,

I actually end up with lots of inc files when I do a big assembler project, to segment different pheripheral and task functions. It's just seeing lots of c and h files is overwhelming still for me, having to learn it all at once. :( however, I will keep at it. I see ''stm32f10x.h'' has lots of definitions in it.

I'm a bit hesitant to use a sample application and modify it, because I want to start with the full range of definitions, and then implement a large number of them. However... It may yet be the best way. I'm using all the PWM, most of the ADC, serial, USB, SD card etc etc :D I plan to use the MMU, but not immediately :-?

Because I'm not using a demo board, I have to go through all the pheripherals on a 100 pin chip, and check the mapping of alternate pin functions, I/O selection, pull up/downs etc, before I even start diagnostics on my board ! it's a bit scary when most of my previous applications have been on 44 pins or less, and with 8 bit micros.

Thanks for the tips relaxe.

jj
Associate II
Posted on May 17, 2011 at 13:11

Strongly suggest that you reconsider the decision ''not'' to use a ''known good'' demo/eval board - which includes many tested software examples.

Without reliable hardware - you will again & again - wonder, ''is this problem hw or software?'' We call this maximum randomness - this will ''eat'' time and is demoralizing.

Further suggest that you study & experiment with ''one'' peripheral at a time - and closely document your results. (we like to start with gpio - several blinking leds build your confidence and can later serve to ''prove'' that your code reached critical points)

Allow plenty of time - the vast number of features adds complexity. (things that were simple/automatic w/8 bit require exact specification, peripheral AND peripheral clock enabling - this ''gets'' everyone...)

rael
Associate II
Posted on May 17, 2011 at 13:11

Hi jj-sprague,

I saw that about the pheripheral clock gating !

I'm thinking it opens the possibility of slowing ports (and power consumption ) right down if you are doing something like talking to a slow device, i.e an LCD, or a human interface, keyboard for example.

But, I had forgotten until you mentioned it, thanks.

The term you have, ''Maximum randomness'', I like it ! :D

I've done it before though, I made an add on interface board out of veroboard and z80 pheripheral chips, stuck it on an Amstrad CPC664, and then wrote a cross assembler for it, to program Motorolla 68HC11. That was my first entry into the world of microcontrollers, and not just assembly. As it was, I decided that the chip was too expensive for my project, but I did sucessfully program it via my cross assembly program and self made editor.

So, that had quite a few element of randomness to it.

In this example, I have pins connected to known external PCB functions, I have my power supply proven to ALL the chip pins, my bootload serial port works, and the ARM seems to be sitting at close to ambient temperature with the power on, for the last couple of days :D

My big random elements are:

1) C

&

2) the ARM

Both are well documented, the issue is me, I'm a beginner on these two particular elements. :-?

However, I did well at assembler, the task ahead of me would be a lot easier if I were 20 again and not 42, Also, perhaps if I'd not pickled my brain for a few years with diet coke aspartame as approved by the FDA, following Mon Santo's employment of many of their top officials. :o

I will still stuff the knowledge in my skull somewhere :|

I follow your reasoning on the known board coupled with working software, to change things one tweak at a time, but much of what I'll be doing is easy.

I have to write some ports for stepper operation, that's a combination of masking and or bit banding. Later, I'll be looking at combining that with indexed table writes to the PWM, due to the 3-D aspect, these may not be co synchronous in speed, but they still have to be synchronised rigidly to rotation.

I have a couple of status LEDs designed in, a Piezo designed in for audible status, the serial boot port can double for debugging, the servo connections, opto encoder inputs, buffered outputs, all are basic I/O

I have RS485 and I2C available, but don't anticipate work on those soon.

I'm very familiar with my circuitboard, as I designed it myself.

The only problem is me, picking up the new skills 🙂

[ This message was edited by: rael on 05-05-2009 13:16 ]

relaxe
Associate II
Posted on May 17, 2011 at 13:11

Learning C (in an Embedded context, at least) =AND= a new hardware core is a pretty daunting task, at least for a 42 year old, aspartame soaked brain //JOKE! This is supposed to be funny :-] //

The thing about using an example as a template, is that the examples are pretty small and clean. Just delete the Main() section, and you've got yourself a template! :D

I would heavily recommend getting a ref board, just to try things and demistify what is what. Digikey has some of them:

http://search.digikey.com/scripts/DkSearch/dksus.dll?Cat=2621773&keywords=stm32

Also, the examples are usually the way to start. Get a GPIO toggle set up, watch that pin go up and down, then adapt your peripheral from other examples...

I had experiences with PIC16 in ASM, PIC18 and dsPIC30 in C, then the STM32. I have to say I was surprised at how easy it is to learn. I was always stuck with the C18 and other non-standard C compiler crap from microchip, and with the space and speed of the ARM, I simply code and it works....

Hope you have fun! Keep us informed of your progress :D

-Relaxe

hholms
Associate II
Posted on May 17, 2011 at 13:11

I would also find a simple sample c-program for the STM32, ST have some in their download department - It will be the nearest thing you come to a template.

- If you do not know C, Get a reference book or something like that.. It will help you learn the basics of C.

I learned using this one:

http://www.amazon.com/Programming-Language-Prentice-Hall-Software/dp/0131103628

- Get the sample working on your board

rael
Associate II
Posted on May 17, 2011 at 13:11

relaxe,

I did some coding with the Pic 16C and 16F series too.

I found the conditional jumps non intuitive, but I got by and did quite a few small applications with it.

Then, I switched to the AVR, and was amazed by it's speed, and found that my code would work bug free for quite large sections, it did what I thought it would first time.

I know C has some issues that ''Get'' people, I suspect it will take me a bit to figure out the addressing modes and pointer, by val, by address referencing options.

I've got plenty of easy I/O to fiddle with though, so once I figure out how to map the pheripherals to the correct(/alternate?) pins, I will start with the simple stuff.

Progress is going on this thread in the reprap forums:

http://forums.reprap.org/read.php?13,21002,page=2

I will check in the Library for some books on C over the weekend, not too worried about the ARM cortex itself, as I will be pulling in so much C code from things like SD card demo routines, that I would be setting myself up for a lot more work to try and interface them in assembler.

I've got an STM circle, but I don't want to try stuff out on that at the moment, as I would be diverting too much time to ''non productive'' testing.

I have other boards to populate if I inadvertantly ''cook'' something, and I have polyswitch fuses on all my stepper coils.

LCDs can be fussy about power sequencing... but I can probable even find some existing arm code ? else convert some of my assembler code to C, with huge delays.

I might use an already developed R.T.O.S., if I can find one I like

Graham. 🙂