Author Topic: STM32, ghetto style  (Read 148033 times)

0 Members and 1 Guest are viewing this topic.

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #50 on: August 21, 2014, 11:19:44 am »
Quote
$3 for two, not bad.

It is almost criminal not to get some at those prices, :)

A STM32F030F board would be even better.

Quote
No western company can do this

Maybe if we mandate higher minimum wages, more regulation, .....

================================
https://dannyelectronics.wordpress.com/
 

Offline neslekkim

  • Super Contributor
  • ***
  • Posts: 1305
  • Country: no
Re: STM32, ghetto style
« Reply #51 on: August 21, 2014, 07:53:45 pm »
Ordered that,  a couple stm32f103 boards and the stlink clone
Will be interesting to test

Sent from my SM-T520 using Tapatalk

 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #52 on: August 21, 2014, 08:43:12 pm »
If you need help with wiring, please let me know.

I just received 5 STM8S003F chips: at $0.30/each, it is hard to go wrong, :)
================================
https://dannyelectronics.wordpress.com/
 

Offline neslekkim

  • Super Contributor
  • ***
  • Posts: 1305
  • Country: no
Re: STM32, ghetto style
« Reply #53 on: August 22, 2014, 09:06:33 am »
I bought these exact items
stm8 board:
http://www.ebay.com/itm/171346510522
stlink clone:
http://www.ebay.com/itm/131072534999
two different stm32 boards:
http://www.ebay.com/itm/261472191025
http://www.ebay.com/itm/171275016235

Could have bought some loose chips and soldered on an adapter pcb, but the prices on these was cheap, and they have crystal, and I guess decoupling caps and everything is ok.
Not the same stm32 as you mentioned earlier, but I guess there is not that big difference on those?
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #54 on: August 22, 2014, 11:00:03 am »
It should be identical: swd for stm32 and swim for stm8.
================================
https://dannyelectronics.wordpress.com/
 

Offline neslekkim

  • Super Contributor
  • ***
  • Posts: 1305
  • Country: no
Re: STM32, ghetto style
« Reply #55 on: August 22, 2014, 12:19:43 pm »
yeah, meant the chip itself: STM32F030F4 vs STM32F103C8T6
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #56 on: August 22, 2014, 04:40:32 pm »
There are some hardware differences between the two but non in regards to debugging.

I am not sure how familiar you are with the chips / tools, but it helps if you try out some of those tools and get yourself comfortable with them. Software side of the things will be the biggest challenge early on in the process.
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #57 on: August 22, 2014, 05:21:20 pm »
Quote
Software side of the things will be the biggest challenge early on in the process.

On that front, I thought I would post a quick software tutorial so that people can get started quickly, again ghetto style, :)

I have been asked if I could post my complete projects used earlier in this thread. My projects utilize tons of middleware so it is quite "bloated" - a blinky for example takes over 2 minutes to compile on a dual quad-Xeon (3.0+ghz), 12GB machine, for example.

Instead, in line with the ghetto spirit, I would post 1 single file that can be compiled under CoIDE to blink an led - that would greatly simplify your life.

The code posted will be code in such a way that if you wish, can be split into multiple modules for future uses.

First of all, pre-requisites:

1) you have CoIDE installed. I am running 1.7.4, with updated components. You can download the latest one and install.
2) you have gcc-arm installed. I am running an old version (4.6 or 4.7 I think). I think the latest is 4.8 but I never bothered to try it.

Once CoIDE is installed and gcc-arm linked in (you only need to do this once), you are ready to go.
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #58 on: August 22, 2014, 05:28:19 pm »
At this point, CoIDE has included a minimalist main.c for you.

Code: [Select]

int main(void)
{

    while(1)
    {
    }
}

You can compile and link this main.c and a hex file will be created for download. Obviously, it does nothing.

================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #59 on: August 22, 2014, 05:57:10 pm »
3. compile

Hit compile or build, and you will get something like this in the console:

Code: [Select]
Program Size:
      text    data     bss     dec     hex filename
      1684      20       4    1708     6ac f0 getto.elf

BUILD SUCCESSFUL
Total time: 6 seconds

indicating that the build is successful, obviously.

================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #60 on: August 22, 2014, 06:09:18 pm »
4.1 debug - step through:

once you are in the debug mode, you have a new set of controls to explore, highlighted in red on the upper left corner.

The source code that is to be executed is highlighted in light green, by a yellow arrow, in the middle of the screen.

You can explore a bunch of things but here, we just wanted to see F_CPU (aka SystemCoreClock, a global variable). Right click in the "Variables" window on the lower right corner of the screen, you pick SystemCoreClock to display. As you step through the code, you will see how its value changed from 48000000(hz) to 8000000(hz).

================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #61 on: August 22, 2014, 06:29:22 pm »
The code will run on other compilers as well, with minimum modifications.

Once you have mastered CoIDE / Eclipse, it is an easy transition to other IDEs: Keil  / IAR for example are considerably simpler to navigate.
================================
https://dannyelectronics.wordpress.com/
 

Offline SirNick

  • Frequent Contributor
  • **
  • Posts: 589
Re: STM32, ghetto style
« Reply #62 on: August 22, 2014, 07:11:11 pm »
Not bad, sir.  :clap:

Side question:  You used the symbol 'F_CPU'... I had always assumed that was Atmel lingo.  Are you using it here because it's familiar to you (and probably many others), or is that more prevalent than I thought?
 

Offline Laurynas

  • Contributor
  • Posts: 47
  • Country: lt
Re: STM32, ghetto style
« Reply #63 on: August 22, 2014, 09:24:42 pm »
Great stuff!
Maybe you'll do a "hello world"/blinky with software steps for stm8 as well? :)
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #64 on: August 22, 2014, 10:12:16 pm »
8) set up the environment:

Under "C/C++ Compiler->Preprocessor", fill in the settings.

The items highlighted in red will need to change if your library folder locations are different or your chips are different.
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #65 on: August 22, 2014, 10:18:58 pm »
10) Comile / build:

at this point, you are ready to build your project. It should compile flawlessly.

After that, click the "Download and debug" button - highlighted in red below.

================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #66 on: August 22, 2014, 10:21:44 pm »
11) debugging:

Now, your stlink should have downloaded the code to your chip and the execution is halted on the first line of your main() - highlighted in green by EWSTM.

Your then can explore all the nice features of the IDE + debugger + chip.


Hope it helps.
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #67 on: August 22, 2014, 10:24:13 pm »
STM8 is really a nice family of chips that offer tremendous amount of performance and at incredible prices. Vs. the traditional 8-bitters, the hardware debugger is really valuable in getting your code to work.

It is a shame that more people aren't using them.
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #68 on: August 22, 2014, 10:31:58 pm »
Code: [Select]
void chip_init(void) {
//SystemCoreClockHSI_2MHz(); //set clock to hsi, _2MHz, _4MHz, _8MHz, _16MHz
//CLK->PCKENR1=CLK->PCKENR2=0x00; //optional - disable all peripheral clocks
}

Two things about this little piece:

1) I commented out SystemCoreClockHSI_2Mhz(). It and its siblings allow you to set up the chip to run off different oscillators and at different speeds. You may wish to implement them later on. When you do, make sure that those routines update SystemCoreClock appropriately. So the delay routines will run correctly.

2) The PCKENR1/R2 registers default to turn on all peripherals -> like in PIC or AVR. Turning them off here (uncomment that line) will give you current consumption closer to STM8L chips - that may be important for battery-powered applications. You will then need to pipe clock to a peripheral before you use it. Look to stm8s_clk.h/.c files for help there.
================================
https://dannyelectronics.wordpress.com/
 

Offline diyaudio

  • Frequent Contributor
  • **
  • !
  • Posts: 683
  • Country: za
Re: STM32, ghetto style
« Reply #69 on: August 22, 2014, 11:07:04 pm »
11) debugging:

Now, your stlink should have downloaded the code to your chip and the execution is halted on the first line of your main() - highlighted in green by EWSTM.

Your then can explore all the nice features of the IDE + debugger + chip.


Hope it helps.

Great explanation. ta!
 

Offline neslekkim

  • Super Contributor
  • ***
  • Posts: 1305
  • Country: no
Re: STM32, ghetto style
« Reply #70 on: August 23, 2014, 10:00:57 am »
Fantastic!, thanks for this explanation.
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #71 on: August 23, 2014, 01:55:39 pm »
It was pointed out to me, rightfully so, that the use of a commercial IDE (EWSTM) isn't exactly "ghetto".

I picked IAR because of its user friendliness and my familiarity with it. If you are comfortable with other compilers / IDEs (STVD, IDEA, etc.), feel free to use them - as the code is written heavily on the ST library, its compiler dependence is minimum - for example, for the piece I posted earlier, I compiled it successfully on Cosmic / STVD, without any modification.

The detailed steps of setting up a project is obviously IDE / compiler specific but they follow the same principle.
================================
https://dannyelectronics.wordpress.com/
 

Offline Kjelt

  • Super Contributor
  • ***
  • Posts: 6459
  • Country: nl
Re: STM32, ghetto style
« Reply #72 on: August 23, 2014, 02:27:31 pm »
It was pointed out to me, rightfully so, that the use of a commercial IDE (EWSTM) isn't exactly "ghetto".
Baaah, the IAR STM8 version is free of charge till 8kB so what is cheaper then free exactly ?  ;)
Alternative would be the STVD environment downloadable free of charge from ST and the free Cosmic STM8 compiler (also 8kB limit). Install the compiler first then STVD and in the menu:
Project
project settings
Tab Genera
Toolset choose STM8 Cosmicl
Root path: \Program Files (x86)\COSMIC\CXSTM8 if not already done automatically
include path: Hstm8
Library path: lib
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32, ghetto style
« Reply #73 on: August 23, 2014, 04:01:25 pm »
Quote
STVD

ST is very much like Microchip: great hardware, shitty software. STVD is so 1990s in terms of its interface and user-friendliness. It is up there with Mplab, :)

Quote
the free Cosmic STM8 compiler (also 8kB limit).

If you are going to be limited, you might as well be limited by EWSTM rather than Cosmic / STVD - IDEA is only marginally better than STVD.
================================
https://dannyelectronics.wordpress.com/
 

Offline Kjelt

  • Super Contributor
  • ***
  • Posts: 6459
  • Country: nl
Re: STM32, ghetto style
« Reply #74 on: August 23, 2014, 04:30:34 pm »
ST is very much like Microchip: great hardware, shitty software. STVD is so 1990s in terms of its interface
Yeah you might be right there, I am using it when I started with the ST7's that was begin 2000's, it was great then, even the simulator worked (never worked for the STM8 but the real time debug (SWIM) interface made that not such a pain anyway).
Now they even have given up development on STVD I believe, so maybe not the first tool to choose if you start afresh. I am still a bit stuck on it since I need the 32kB free Cosmic compiler for my projects, 8k does not cut it. Can you integrate a third party compiler with EWSTM and still swim debug?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf