Author Topic: STM32F103 any good?  (Read 57512 times)

0 Members and 1 Guest are viewing this topic.

Offline HackedFridgeMagnet

  • Super Contributor
  • ***
  • Posts: 2028
  • Country: au
Re: STM32F103 any good?
« Reply #25 on: April 23, 2015, 12:41:28 am »
That's pretty slick, this article explains it pretty well: http://spin.atomicobject.com/2013/02/08/bit-banding/
IMO that article just confuses me.
the link on the ARM website doesn't help much either.
Then the example? I should submit this code to www.thedailywtf.com Why the mailbox analogy?? for something supposedly atomic. Is it like an example of a single bit mailbox between processes?
Quote
#define BITBAND_SRAM_REF 0x20000000#define BITBAND_SRAM_BASE 0x22000000#define BITBAND_SRAM(a,b) ((BITBAND_SRAM_BASE + (a-BITBAND_SRAM_REF)*32 \    + (b*4))) // Convert SRAM address#define BITBAND_PERI_REF 0x40000000#define BITBAND_PERI_BASE 0x42000000#define BITBAND_PERI(a,b) ((BITBAND_PERI_BASE + (a-BITBAND_PERI_REF)*32 \    + (b*4))) // Convert PERI address
#define MAILBOX 0x20004000#define TIMER 0x40004000// Mailbox bit 0#define MBX_B0 *((volatile unsigned int *)(BITBAND_SRAM(MAILBOX,0)))// Mailbox bit 7#define MBX_B7 *((volatile unsigned int *)(BITBAND_SRAM(MAILBOX,7)))// Timer bit 0#define TIMER_B0 *((volatile unsigned char *)(BITBAND_PERI(TIMER,0)))// Timer bit 7#define TIMER_B7 *((volatile unsigned char *)(BITBAND_PERI(TIMER,7)))
int main(void){    unsigned int temp = 0;
    MBX_B0 = 1; // Word write    temp = MBX_B7; // Word read    TIMER_B0 = temp; // Byte write    return TIMER_B7; // Byte read}
"// Convert PERI address" what a useless comment, it only makes sense if you know what they are doing.
Is it implemented in hardware? I guess you have to set up the bit banding to work in certain memory areas and by default they are normally turned off.
If you set it up for an area then you reduce the memory available drastically.
Is it only for peripherals? It seems not, the mailbox is in RAM.
Can anyone explain it a bit more clearly? Or have another link?

 

Offline MuxrTopic starter

  • Super Contributor
  • ***
  • Posts: 1369
  • Country: us
Re: STM32F103 any good?
« Reply #26 on: April 23, 2015, 03:02:23 am »
That's pretty slick, this article explains it pretty well: http://spin.atomicobject.com/2013/02/08/bit-banding/
IMO that article just confuses me.
the link on the ARM website doesn't help much either.
Then the example? I should submit this code to www.thedailywtf.com Why the mailbox analogy?? for something supposedly atomic. Is it like an example of a single bit mailbox between processes?
Quote
#define BITBAND_SRAM_REF 0x20000000#define BITBAND_SRAM_BASE 0x22000000#define BITBAND_SRAM(a,b) ((BITBAND_SRAM_BASE + (a-BITBAND_SRAM_REF)*32 \    + (b*4))) // Convert SRAM address#define BITBAND_PERI_REF 0x40000000#define BITBAND_PERI_BASE 0x42000000#define BITBAND_PERI(a,b) ((BITBAND_PERI_BASE + (a-BITBAND_PERI_REF)*32 \    + (b*4))) // Convert PERI address
#define MAILBOX 0x20004000#define TIMER 0x40004000// Mailbox bit 0#define MBX_B0 *((volatile unsigned int *)(BITBAND_SRAM(MAILBOX,0)))// Mailbox bit 7#define MBX_B7 *((volatile unsigned int *)(BITBAND_SRAM(MAILBOX,7)))// Timer bit 0#define TIMER_B0 *((volatile unsigned char *)(BITBAND_PERI(TIMER,0)))// Timer bit 7#define TIMER_B7 *((volatile unsigned char *)(BITBAND_PERI(TIMER,7)))
int main(void){    unsigned int temp = 0;
    MBX_B0 = 1; // Word write    temp = MBX_B7; // Word read    TIMER_B0 = temp; // Byte write    return TIMER_B7; // Byte read}
"// Convert PERI address" what a useless comment, it only makes sense if you know what they are doing.
Is it implemented in hardware? I guess you have to set up the bit banding to work in certain memory areas and by default they are normally turned off.
If you set it up for an area then you reduce the memory available drastically.
Is it only for peripherals? It seems not, the mailbox is in RAM.
Can anyone explain it a bit more clearly? Or have another link?

I am going to try and explain my understanding of it. Let's first explain what issue it's trying to solve.

Suppose you have a register in memory that is of value 01001001. And suppose the first bit of that byte (currently 0) determines the GPIO pin mode and you want to flip it. You would have to load the entire byte 01001001 just to manipulate that one bit.

Why is this bad, you might ask? Well depending on how you manipulate it your manipulation might take multiple clock cycles to flip just that one bit, because you're dealing with a much bigger chunk of data. If your flipping of that bit takes multiple CPU cycles chances are something else might try to manipulate that byte and cause a race condition. It's basically equivalent of multiple people editing their local copies of the same spreadsheet, you get a mess, you don't know which one is the correct one.

For example, let's call your main program flow, program A, and some piece of code that runs on an interrupt, interrupt B.

Your program A is trying to flip the first bit, it reads the register. So far so good, but before it gets a chance to write the modified version of it, interrupt B piece of code flips a different bit in that byte. And since your program A is unaware it tries to save a stale version of the register byte into the memory, overwriting the change interrupt B was trying to accomplish. Very bad.

So to help developers avoid race condition Bit-banding was implemented. Bit-banding is a pseudo memory location with an interesting property. It's basically a mirror of all the registers but instead of storing 8 bits per byte it only stores one significant bit per byte.

So our little 01001001 becomes 8 distinct bytes in the bit-banding space: 00000000 (only holding the our first bit), 0100000 (only holding the 2nd bit)...etc The bytes in the bit-banding space are interconnected behind the scenes, and flipping a bit in one space, alters it in the other.

So now you can safely take a byte from the bit-banding location to only modify one bit without the fear of accidentally overwriting other bits with stale state. There is also a mention that manipulation bit-banding bytes is a single clock cycle operation making it fully atomic (impervious to race conditions, even on the same bit).

ps. bit-banding sounds terribly memory inefficient, you know "exploding" a byte into 8 bytes each containing 1 bit, but most likely it's all done logically so no memory is actually wasted, it's just wired like that behind the scenes.
« Last Edit: April 23, 2015, 03:14:35 am by Muxr »
 

Offline HackedFridgeMagnet

  • Super Contributor
  • ***
  • Posts: 2028
  • Country: au
Re: STM32F103 any good?
« Reply #27 on: April 23, 2015, 03:38:58 am »
Thanks for the attempt, but you explained the bit that I do know and not the bit that I don't know.
How is it wired behind the scenes?
What limitations, restrictions or compromises are there? 
I guess I could look it up in the M4 data sheet but until I get the time or use the something of the M4 series I wont worry.
I guess once you get the macros done it is easy to use, but the macros look fairly intimidating at the moment.
 

Offline MuxrTopic starter

  • Super Contributor
  • ***
  • Posts: 1369
  • Country: us
Re: STM32F103 any good?
« Reply #28 on: April 23, 2015, 03:53:47 am »
There is a bit more info on LinkedIN of all places: https://www.linkedin.com/groups/How-is-Bitbanding-actually-implemented-85447.S.5834088429486354434
Quote
Senior Embedded Technology Manager at ARM

The AHB interface on the processor automatically remap and generate the two bus accesses. it have a side band signal to indicate the read-modify-write sequence is locked (atomic). So even if there is a separate bus master in the system, the other bus master should not be able to inject another transfer in between. (That's assumed the bus interconnect in the system was designed properly :-) )

Quote
Applications Engineer at ARM

Try: http://infocenter.arm.com/help/topic/com.arm.doc.set.amba/index.html#amba3

You should find AHB-Lite under AMBA Specifications / AMBA 3
 

Offline poorchava

  • Super Contributor
  • ***
  • Posts: 1672
  • Country: pl
  • Troll Cave Electronics!
Re: STM32F103 any good?
« Reply #29 on: April 23, 2015, 11:30:17 am »
I will make an attempt to explain.

Suppose you have a register under address A with 32 bits in it. In order to change a bit you'd need to read the register, make a logic operation (for example |= 0x01 to set LSB high) and write it back. If the value in that register has changed in the meantime this change will be overwritten. Thi also takes more time as you have to read, modify and write.

Now the bitbanding works like that: for every bit-band-aliased register under address A, every bit X has an alias-address B which is a function of A and X. This address does not correspond to entire register, but rather to the bit X in register A. You can write a logic value L into address B, which will result in value of bit X in register A changing to L. So in short, every bit in a bit-band-aliased register has its own address somewhere in the address space. Formulas and macros for calculating bit-band alias addresses are availale on ARM website.

In the end if your macro and compile settings are done right, your instruction to switch bit 17 in register 0xDEADBEEF should compile to a single STR instruction (given, that number if bit is known at compile time). This way you could theoretically toggle a gpio pin with FPCU/2 frequency (leaving aside the limitations of gpio ports themselves and assuming that toggling is unrolled and not looped - looping overead in CM3 and CM4 is terribl)
I love the smell of FR4 in the morning!
 

Offline HackedFridgeMagnet

  • Super Contributor
  • ***
  • Posts: 2028
  • Country: au
Re: STM32F103 any good?
« Reply #30 on: April 23, 2015, 12:16:11 pm »
Thanks again for explaining. But I still haven't got to the nub of what doesn't seem right.

I can see how it works for registers, this doesn't seem hard at all, some RAM must be permanently dedicated to alias the registers, easy.

What I couldn't see was how it works to bitband some RAM.
Or is it only registers that are aliased? Initially I thought this but the sample code seem to be bit banding the RAM.
Which RAM is an alias for which RAM.
How do you set up a memory map for this?
Ok I will read the doco. I should address my ignorance. No pun intended.

 

Offline poorchava

  • Super Contributor
  • ***
  • Posts: 1672
  • Country: pl
  • Troll Cave Electronics!
Re: STM32F103 any good?
« Reply #31 on: April 23, 2015, 12:45:20 pm »
I don't think that bulk RAM is bit-banded. And if it is I have never used this feature.

The alias addresses are not in RAM, they are simply in address space. When CPU detects write instruction to particular alias register is calculated backwards which bit in which register it should write.
I love the smell of FR4 in the morning!
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4067
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: STM32F103 any good?
« Reply #32 on: April 23, 2015, 01:10:44 pm »
Here you find official documentation from ARM regarding bit-banding. With drawing  :-+
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0337h/Behcjiic.html
 

Offline HackedFridgeMagnet

  • Super Contributor
  • ***
  • Posts: 2028
  • Country: au
Re: STM32F103 any good?
« Reply #33 on: April 23, 2015, 02:03:54 pm »
Ok thanks now I got it.
 

Offline MuxrTopic starter

  • Super Contributor
  • ***
  • Posts: 1369
  • Country: us
Re: STM32F103 any good?
« Reply #34 on: April 23, 2015, 02:10:01 pm »
They map two different regions: the lowest 1Mb in SRAM gets mapped as well as the peripheral 1Mb registers get mapped into 2x32Mb bit-banding regions.

While this doesn't take any actual RAM it does eat away 64Mb of the available addressing space which is now 4Gb-64Mb.
 

Offline old gregg

  • Regular Contributor
  • *
  • Posts: 130
  • Country: 00
Re: STM32F103 any good?
« Reply #35 on: April 30, 2015, 12:34:18 pm »
Hi,

I've bought one of those : http://www.ebay.com/itm/311156408508?_trksid=p2060353.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

I wanted to jump into ARM processor for some time and I thought this could be a good start. Being from China, no documentation comes with it and what made hesistant abouf ARM is the large choise of IDE/dev board. Is Coocox sufficient ?
 

Offline FreddyVictor

  • Regular Contributor
  • *
  • Posts: 164
  • Country: gb
Re: STM32F103 any good?
« Reply #36 on: April 30, 2015, 04:58:31 pm »
ST are very good at doing their own boards at a reasonable price: F103 version
not as cheap as your ebay one, but it does come with builtin STLink for easy code upload/debugging plus lots of documentation on their website

an alternative to the F103 is the F401 which I believe includes floating point unit
 

Offline donotdespisethesnake

  • Super Contributor
  • ***
  • Posts: 1093
  • Country: gb
  • Embedded stuff
Re: STM32F103 any good?
« Reply #37 on: April 30, 2015, 05:24:20 pm »
Hi,

I've bought one of those : http://www.ebay.com/itm/311156408508?_trksid=p2060353.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

I wanted to jump into ARM processor for some time and I thought this could be a good start. Being from China, no documentation comes with it and what made hesistant abouf ARM is the large choise of IDE/dev board. Is Coocox sufficient ?

CooCox should work, I had trouble when I tried it. I found emblocks worked better for me, together with an STLINK JTAG-SWD adapter which works well and is a lot cheaper then Segger.

If you are at all Arduino inclined you might look at www.st32duino.org, for an Arduino STM32 compatible package.
Bob
"All you said is just a bunch of opinions."
 

Offline old gregg

  • Regular Contributor
  • *
  • Posts: 130
  • Country: 00
Re: STM32F103 any good?
« Reply #38 on: May 02, 2015, 04:39:58 pm »
thanks,

actually I've just realised that I needed an external programmer. I'm on the hunt for that now. I've documetation to read I think.

Those uC seem to be very interesting.

I don't know emblocks, I'm gonna do some homework.

Quote
If you are at all Arduino inclined you might look at www.st32duino.org, for an Arduino STM32 compatible package.

I'm not really keen on Arduino but I must admit that their plug-and-play system is sometime very enviable.
 

Online ajb

  • Super Contributor
  • ***
  • Posts: 2582
  • Country: us
Re: STM32F103 any good?
« Reply #39 on: May 02, 2015, 06:46:38 pm »
Hi,

I've bought one of those : http://www.ebay.com/itm/311156408508?_trksid=p2060353.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

I wanted to jump into ARM processor for some time and I thought this could be a good start. Being from China, no documentation comes with it and what made hesistant abouf ARM is the large choise of IDE/dev board. Is Coocox sufficient ?

CooCox should work, I had trouble when I tried it. I found emblocks worked better for me, together with an STLINK JTAG-SWD adapter which works well and is a lot cheaper then Segger.
I'll second this.  CoIDE was great and easy to use when it worked, but would frequently fail to build or debug a project for no obvious reason, would occasionally crash and destroy my project file in the process, and finally crashed so badly I had to reinstall it.  I didn't have the patience for all the configuration that Eclipse required, so I finally landed on Em::Blocks and am pretty happy. 

If you go with one of ST's dev boards they typically have a built in debugger, so no external tools is required.

If you're already comfortable with AVR, Atmel does make ARM MCUs as well, and they are fully supported by Atmel Studio just as their AVRs are.
 

Offline old gregg

  • Regular Contributor
  • *
  • Posts: 130
  • Country: 00
Re: STM32F103 any good?
« Reply #40 on: May 03, 2015, 12:59:06 pm »
Yes I'm comfortable with AVR but I don't use their software, it crashed the machine at the first run  :-DD . I'm using AVRdude but I won't say no to debugger/simulator now...

Quote
If you go with one of ST's dev boards they typically have a built in debugger, so no external tools is required.

that was actually my first entention, buy a "discovery board" to get started. I think I still buy one, they're so cheap that it won't be a pain on the wallet.

I think there's also a ARM facility in code::block now that I'm writting this.



 

Offline old gregg

  • Regular Contributor
  • *
  • Posts: 130
  • Country: 00
Re: STM32F103 any good?
« Reply #41 on: September 05, 2015, 05:44:33 pm »
I bring life back to the thread.

I've this board that I'd like to use for a small thing


but I saw it mentioned along with Arduino or Mapple and wonder if I can program it without both. I know there's the SWD pin header which supposes that I can but maybe I'm missing something.  I've got a discovery board from ST that I can, apparantly, use as a programmer for external chip. I tried but nothing good.

Some people had experience with this board ?

 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4067
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: STM32F103 any good?
« Reply #42 on: September 05, 2015, 06:09:06 pm »
The shown board does not pass the absolute minimum to operate. Because it lacks capacitors. Or is the bottom loaded?

Also, if programming fails. The headers are for the bootloader, which should have no effect for swd, but still.
You do also know the Discovery board has headers you must change to use it as ST-Link only?
 
 

Offline Hideki

  • Frequent Contributor
  • **
  • Posts: 256
  • Country: no
Re: STM32F103 any good?
« Reply #43 on: September 05, 2015, 06:40:55 pm »
I have used that board before with no trouble. There are more components on the bottom, including capacitors.

You will need a programmer. I used a cheap ST-LINK V2 clone like this  http://www.ebay.com/itm/ST-Link-V2-Mini-Metal-Shell-STM8-STM32-Emulator-Downloader-Programming-good-/251642538698?hash=item3a97106aca
I'm sure you can use the ST-LINK on the discovery board instead. It may have to be disconnected from the onboard chip first. I suggest reading the docs.

The header at the bottom is SWD. Connect up four wires from the programmer to the board and off you go (look up the pinout first).
 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4392
  • Country: dk
Re: STM32F103 any good?
« Reply #44 on: September 05, 2015, 07:36:54 pm »
I have used that board before with no trouble. There are more components on the bottom, including capacitors.

You will need a programmer. I used a cheap ST-LINK V2 clone like this  http://www.ebay.com/itm/ST-Link-V2-Mini-Metal-Shell-STM8-STM32-Emulator-Downloader-Programming-good-/251642538698?hash=item3a97106aca
I'm sure you can use the ST-LINK on the discovery board instead. It may have to be disconnected from the onboard chip first. I suggest reading the docs.

The header at the bottom is SWD. Connect up four wires from the programmer to the board and off you go (look up the pinout first).

using a discovery board as st-link is simple, theres a six pin connector with the debug signals and then you move two jumpers

 

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1198
  • Country: fi
Re: STM32F103 any good?
« Reply #45 on: September 05, 2015, 08:23:58 pm »
I've this board that I'd like to use for a small thing but I saw it mentioned along with Arduino or Mapple and wonder if I can program it without both.
The chip has a ROM serial bootloader. The two jumpers control the boot mode. Read the documentation for details.

Offline SundayProgrammer

  • Contributor
  • Posts: 33
  • Country: fi
Re: STM32F103 any good?
« Reply #46 on: September 06, 2015, 02:58:55 pm »
Too bad that 48pin F103C8 does not have any DAC(s)...
(Dacs are only included in high density devices)

Axel.
 

Offline poorchava

  • Super Contributor
  • ***
  • Posts: 1672
  • Country: pl
  • Troll Cave Electronics!
Re: STM32F103 any good?
« Reply #47 on: September 06, 2015, 03:11:14 pm »
DACs on most STM32 chips suck. They have trouble reaching the bottom rail (minimum is like 30mV). If you enable output buffer,  then it gets completely ridiculous (like 0.3V). In general external rail to rail buffer is almost necessity...

Wys?ane z mojego HTC One M8s przy u?yciu Tapatalka

I love the smell of FR4 in the morning!
 

Offline Rolo

  • Regular Contributor
  • *
  • Posts: 206
  • Country: nl
Re: STM32F103 any good?
« Reply #48 on: September 06, 2015, 04:06:33 pm »
I bring life back to the thread.

I've this board that I'd like to use for a small thing


but I saw it mentioned along with Arduino or Mapple and wonder if I can program it without both. I know there's the SWD pin header which supposes that I can but maybe I'm missing something.  I've got a discovery board from ST that I can, apparantly, use as a programmer for external chip. I tried but nothing good.

Some people had experience with this board ?

You could also take a look at the Maple Mini clone boards that are available all over ebay. They have the STM32F103CBT6 MCU that has 128 Kb flash, the board in your picture you has 64K. You must make the translation from the Maple pin numbers but that's easy, all the original docu about the Maple Mini is still online. Extra bonus is that these boards can be used in mbed, just select the NucleoF103RB as platform.  Flash the bin file with the ST Link V2 programmer. One thing, the nucleo MCU has more pins so keep in mind not to use them in your code for the maple mini. In mbed the USB port on the Maple Mini does not work,  I use it as 5 volt supply in this setup. The USB pins are on the header so can be used as I/O.
« Last Edit: September 06, 2015, 04:38:29 pm by Rolo »
 

Offline old gregg

  • Regular Contributor
  • *
  • Posts: 130
  • Country: 00
Re: STM32F103 any good?
« Reply #49 on: September 06, 2015, 08:38:40 pm »
I managed to flash the chip. I'll try to hook up some SPI dac and potentiometers in the next few days.

Quote
You could also take a look at the Maple Mini clone boards that are available all over ebay. They have the STM32F103CBT6 MCU that has 128 Kb flash, the board in your picture you has 64K

thanks I will. Right now it's more about the clock speed and processing than the memory size. By the way, is there any other ARM boards with other cortex? I can't really work with such small package (not equiped for) and these boards are better than nothing.
« Last Edit: September 06, 2015, 11:46:17 pm by old gregg »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf