Author Topic: One Dollar One Minute ARM Development  (Read 135186 times)

0 Members and 1 Guest are viewing this topic.

Offline paulieTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 849
  • Country: us
Re: One Dollar One Minute ARM Development
« Reply #275 on: October 11, 2014, 07:52:18 am »
Another first!

I've managed to attach a complete C compiler toolset to reply slot #5. A little bigger than I first thought but still only about a megabyte. Extract with 7zip and just like before hit 'a'. This time the hex file is also automatically flashed into the chip. AFAIK it don't get any easier than this.

ps. Here's a peek at the hello world source file:

Code: [Select]
/*    uartsxx.c    uart tx string    created by paulie on eevblog.com 10/8/2014
01 minimum*/
#include "stm8s.h"

int tx_string(const char *str)
 { unsigned char i;
   i=0; while(str[i])  { while(!(USART1_SR&USART_SR_TXE)); USART1_DR=str[i++]; }
   return(i);
 }

int main()
 { unsigned long l=0;
   CLK_DIVR=0x00; //frequency 16 MHz #0x50c0
   USART1_CR2=USART_CR2_TEN; //en TX RX #0x5235
   USART1_BRR1=0x11; //368=9800 11=57k baud #0x5232
   while(1) { tx_string("Hello World! ");  l=720000; while (l--); } //1 sec
 }
« Last Edit: October 11, 2014, 08:15:55 am by paulie »
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4192
  • Country: us
Re: One Dollar One Minute ARM Development
« Reply #276 on: October 11, 2014, 08:00:30 am »
(really wishing the STM8 stuff was in a separate thread...)

I have an ARM asm interrupt-driving UART receiver working.  It needs cleaning up (and probably adding the tx half) before I post it.  It was ... interesting.  I have to confess that I'm using the Keil simulator to debug some of this code; debugging with print statements and LEDs doesn't work too well until after you get rid of the infinite-fault generating code...
Code size now 636 bytes, BTW.  I put the vector table in RAM and fill the unused vectors at runtime (memset(), essentially, sacrificing RAM to save flash space.  Which is good, because there are 300+ bytes of vector space.  (although of course it takes some code to implement the fill, and some more to add the vectors that are actually used.)
« Last Edit: October 11, 2014, 08:06:56 am by westfw »
 

Offline paulieTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 849
  • Country: us
Re: One Dollar One Minute ARM Development
« Reply #277 on: October 11, 2014, 09:13:12 am »
(really wishing the STM8 stuff was in a separate thread...)

This didn't seem too upsetting taking up half the "STM32 Ghetto" thread. Cortex M7 and STM4 did'nt strike me as particularly ghetto either so I'm guessing the viewing audience will survive. I considered putting some of this in that thread but decided against it in view of the drastic fear of asm there. Anyway getting this C compiler down to where it would fit as a forum attachment has me feeling quite pleased with myself. :)

ARM notwithstanding, STM8 is the first really impressive technology to catch my eye in a long time due to being "Worlds Lowest Cost MCU". I must admit I owe it all to that great humanitarian and Super Contributor dannyf.
 

Offline paulieTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 849
  • Country: us
Re: One Dollar One Minute ARM Development
« Reply #278 on: October 11, 2014, 12:17:18 pm »
To avoid derailing the SuzyC thread any further it might be more polite to continue here since this is already a total train wreck.

Last year you might have been right but this year the shift has already begun and it is shifting towards the new low cost champion: the cortexM0
...
The single reason is that the M0 is being made in a much smaller nm chip processing technology than the STM8

Yes, tiny die is great but the problem is they have chosen pure "Unobtanium" as a doping agent. An element so rare it has never been detected on earth or anywhere else in the universe by spectroscopic analysis. Additionally predicted to not exist at any time in the future either due to unique paradoxical atomic properties. I would love to be proven wrong here but to my knowledge this is actually the Worlds Cheapest MCU:



This was located after less than a minutes search and, as mentioned previously, I've purchased these for 2 cents less. I challenge anybody to find anything with vaguely similar capability and availability.

ps. It is also a requirement to consider shipping charges because they actually are included in the "free shipping" on all Ebay and Aliexpress deals.
« Last Edit: October 11, 2014, 12:39:18 pm by paulie »
 

Online Kjelt

  • Super Contributor
  • ***
  • Posts: 6458
  • Country: nl
Re: One Dollar One Minute ARM Development
« Reply #279 on: October 11, 2014, 02:22:46 pm »
Paulie: this is not how you compare prices, the reason that some person on Ebay can sell you some processor for a low price can have numerous causes, one that he overordered for a cancelled production and likes to see some return on his lost money (semiconductors can never be given back), another that he found some reels in a container in the alley and took them home.
Does that mean he can sell you 1 million of those processors if you wanted to go full production: NO.
Does that mean that this is the real cost of that processor: NO.
Does that mean ST sells them for that price: NO.
Give you an example, if you ask nicely I can sent you 10pcs of a STM8S208K8 for the shipping costs of the envelope, does that mean those processors cost 0,00 so are free? NO.

So to compare fairly you should talk to the manufacturer or use the quotes from the same source. Now lets take for instance Farnell that always has too high prices but that is because they give you a service namely you don't have to buy 1 million processors if you only want a few, they have large warehouses where they keep your stuff dry, a lot of personell that will get your stuff and sent it for the next day courier delivery, while on the other hand you had to wait for your container to arrive from China by boat in 2 months time  :).  Anyway that costs a lot extra so those prices are ofcourse much higher than if you ordered directly with the manufacturer BUT you can at least have a fair comparison if the source is equal.

Take your STM8S003F3P6 and look at Farnell: they cost € 0,365  ex VAT per 1000 pieces and €0,351 per 8000 pieces.
Then look at the STM32F030 and they cost € 0,412 ex VAT per 1000 pieces.

So the cortex M0 costs 13% more than the STM8 (1000 pieces) BUT  the Cortex M0 has double flash, quadruple RAM and four times more speed AND it is 32 bits.

                                 STM8S0                           STM32F0
Program Memory Size:   8 KB                               16 KB
RAM Memory Size:         1 KB                                 4 KB
CPU Speed:                 16 MHz                             48 MHz
No. of I/O's:                16                                    15

I can not disclose or at liberty to disclose the prices what these devices cost if you buy them in large quantities but as I stated in the other topic, the CortexM0 is going to win on price and the reasons are the smaller nm production process (more dies per waver) and also important there are going to be a lot of competitors that are offering the Cortex M0.

« Last Edit: October 11, 2014, 02:25:19 pm by Kjelt »
 

Offline mrflibble

  • Super Contributor
  • ***
  • Posts: 2051
  • Country: nl
Re: One Dollar One Minute ARM Development
« Reply #280 on: October 11, 2014, 02:39:46 pm »
Yup, the price point of cortex-M0 is going to be interesting the coming year or so. Aren't ST & NXP migrating some M0/M0+ designs from 90 nm to 40 nm? That would be even better for price per die.

Mmh, just checked the article I was thinking of ... that was about "some cortex-M series" being migrated, so not necessarily M0/M0+. But we'll see. Either way, cheaper cortex-M-anything is good news. :)
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4192
  • Country: us
Re: One Dollar One Minute ARM Development
« Reply #281 on: October 12, 2014, 04:57:27 am »
Meh, we'll see.  I have some $0.25 ATtiny11s that I bought, shortly before they were made unobtainium.  TI has essentially gotten rid of their entire line of CM3 chips.  When you base a "buy" decision on essentially random factors (like whether they're really cheap from aliexpress), you're at the whim of the manufacturer and whatever distribution chain got them to you.   At least with a cortex chip, it's looking extremely likely that there will be some sort of "nearby" replacement, even if (say) NXP decides that the DIP-packaged ARMs are too unprofitable to continue....

Aside from the dilution of ARM content here, I also think that the STM8s have enough interest to justify their own thread...
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4192
  • Country: us
Re: One Dollar One Minute ARM Development
« Reply #282 on: October 12, 2014, 05:16:00 am »
So here's the interrupt-driven "Hello World."
There are several interesting "features" exhibited in the new code:
1) Use of the ".bss" directive to create data in RAM.
2) Remember the STRUCTDEF macro I created to create peripheral register offsets from the C structure definitions?  It turns out to be useful for user-defined data structures as well.  Like the FIFO queues for the uart.
3) double register indexing is used for both the memory fill (   str r0, [r1, r2, lsl #2]) and FIFO code.
4) With my simple queue structure, it turns out that that ISR/Thread concurrency is a big issue.  I added "critical section" code.
5) I sweat that ARM implemented their assembly-language instruction set in such a way as to make it intentionally difficult for assembly programmers to know what is going on, code-size wise.  "adds r1, #1" (set condition codes) is a 16bit instruction, while "add r1, #1" is a 32bit instruction.   But any add to "lr" is 32bits.  Ah well, I suppose it's good for the compiler folk.
6) Speaking of C, I was curious if C would generate code similar to my assembly code for q_get and q_put, given the same basic logic (as close as C could come, anyway.)  I could, and it did.  Almost identical.  except....
7) Oh look!  There are cbz and cbnz instructions; those will be handy.
8) When dealing with code addresses in (for example) vector tables ("pointers to functions"), don't forget to add one to the actual address, to select Thumb mode.  Otherwise, your exception/fault handler will cause a fault, which ...
9) As code complexity increases, the tradeoffs between "fixed ABI" and "carefully crafted register use" become blurrier.  I'm using r0-r3 for almost everything, which C considers "not preserved" by subroutines, but I need to preserve them :-(
I could be using r4-r7 ("preserved"), but then I'd have to move them in and out of the r0..r3 argument registers.

Anyway, here it is...
« Last Edit: October 12, 2014, 07:25:27 am by westfw »
 

Offline true

  • Frequent Contributor
  • **
  • Posts: 329
  • Country: us
  • INTERNET
Re: One Dollar One Minute ARM Development
« Reply #283 on: October 12, 2014, 09:25:07 am »
Yup, the price point of cortex-M0 is going to be interesting the coming year or so. Aren't ST & NXP migrating some M0/M0+ designs from 90 nm to 40 nm? That would be even better for price per die.
If you see process move, you'll only see this on faster / higher performing parts for quite some time yet. There is little advantage over a proven, cheap low-leakage process to having an even smaller low end core when the bonding pads, higher power portions, etc. still take up a large space. Low power medium-to-low performance parts especially will probably stick on a larger low power process for quite a while.
 

Offline paulieTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 849
  • Country: us
Re: One Dollar One Minute ARM Development
« Reply #284 on: October 13, 2014, 07:52:17 am »
So here's the interrupt-driven "Hello World."

The new name and reformatting sure speeds things up but there are some problems getting it to compile. SCB_BASE and NVIC_BASE undefined and '.bss will not fit in ram' errors. Maybe you are using a different linker script? Or maybe mine is not correct for the 103c?

Speaking of C, I was curious if C would generate code similar to my assembly code

I'm curious too. Would it be possible for you to post the C version ELF file. Source is nice too but my netbook is not set up with the full GCC C compiler ATM and we can generate that from ELF in addition to HEX and LST.

ps. I see there are big changes afoot on the avatar area. I was pretty sure you were UK but now see you're a real live nephew of my Uncle Sam. Also I was pleased as punch to see somebody else has immortalized me in his avatar byline. It's true! LOL.
« Last Edit: October 13, 2014, 07:55:46 am by paulie »
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4192
  • Country: us
Re: One Dollar One Minute ARM Development
« Reply #285 on: October 13, 2014, 08:00:43 am »
Oops.  The existing .ld file has an incorrect RAM amount, and I had to add the SCB/etc to the .asmh file as well.
I should put this stuff in a github repository or something...
 

Offline paulieTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 849
  • Country: us
Re: One Dollar One Minute ARM Development
« Reply #286 on: October 13, 2014, 08:11:58 am »
Say, in case you missed it would it be possible for you to put up the ELF file for your C version? I'm very curious about the difference compared to asm.
 

Offline paulieTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 849
  • Country: us
Re: One Dollar One Minute ARM Development
« Reply #287 on: October 13, 2014, 08:33:40 am »
Oops.  The existing .ld file has an incorrect RAM amount

Did the GCC dudes make a mistake or did I pick the wrong one?

I should put this stuff in a github repository or something...

Personally I dislike all of those repositories so hopefully you will continue to post here too. I know the hotshots love those because it protects their exclusive club and shows how smart they are  but note that 90% of lurkers are too lazy to even click on an attachment and 99% won't go to another site. I try to make things as simple and accessible a possible.
 

Offline mrflibble

  • Super Contributor
  • ***
  • Posts: 2051
  • Country: nl
Re: One Dollar One Minute ARM Development
« Reply #288 on: October 13, 2014, 08:51:27 am »
I should put this stuff in a github repository or something...
That might indeed help in keeping things a bit organized. Especially over time.

Incidentally, bitbucket is a nice free alternative. AFAIK github used to have a free version, but last I checked they required you to enter credit card information even for the free version.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4192
  • Country: us
Re: One Dollar One Minute ARM Development
« Reply #289 on: October 13, 2014, 09:08:13 am »
Quote
Did the GCC dudes make a mistake or did I pick the wrong one? [with stm32.ld]
Hmm.  I can't tell.  Where exactly did yours come from?  My gcc download from launchpad.net doesn't seem to have any .ld files for the ST microcontrollers.  The Nucleo package, the VLDiscovery package, and chibios, have "correct" versions for slightly different chips with the same memory (103R8, which is the 64pin version), but they all have big copyright notices plastered in them.  I can't find anything that looks like the .ld file you had posted (nor a .ld file explicitly for the 103c8...)

I've already got the githib account (https://github.com/westfw ), so I guess I'm grandfathered.  I'm pretty sure they're still free for "open source" projects, though they've "always" charged for closed projects (um, yes:  https://github.com/pricing )  Google code is another possibility (https://code.google.com/u/103342639718054305536/ )   I don't like their organization as much (not "user" based?), but I like their bug tracker better.  Eventually you end up with your "stuff" and your attention scattered all the hell over everywhere :-(

 

Offline paulieTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 849
  • Country: us
Re: One Dollar One Minute ARM Development
« Reply #290 on: October 13, 2014, 03:58:13 pm »
Where exactly did yours come from?

It took me a while to figure it out because there were several slightly different versions on my hard drive but looks like this was the one I used for Harakiri flight controller. Probably because it's the only one with the 128k flash entry required by that. Looks like none of them used more than 8k RAM but in any case the correction to 20k is now included.

BTW after your fixes the ISP version works fine for me now.
 

Offline paulieTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 849
  • Country: us
Re: One Dollar One Minute ARM Development
« Reply #291 on: October 13, 2014, 09:54:29 pm »
I just got a request offline to "convert" westf's latest files. LOL. Doesn't anybody bother to keep up with latest posts?

A. Westfw files don't need any converting now. They are already text format and compatible with page one schematic.

B. For convenience have been reposted on page one. It's a good idea to check there once in a while because it's always being updated.

I always test them myself before passing on to fellow $1 buddies.
 

Offline neslekkim

  • Super Contributor
  • ***
  • Posts: 1305
  • Country: no
Re: One Dollar One Minute ARM Development
« Reply #292 on: October 13, 2014, 09:59:02 pm »
For convenience, the code should have been in Github or something.. lot easier to read the code along with the discussions here
 

Offline paulieTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 849
  • Country: us
Re: One Dollar One Minute ARM Development
« Reply #293 on: October 13, 2014, 10:30:24 pm »
Maybe good for gurus but I guarantee that would not make it easier on the noobs who barely understand clicking on an attachment. Scattering files all over the internet will stop quite a few right there in their tracks. Here in the outside world I'm working with a bunch of guys who have hardware experience at best. Only one is more experienced than me and he agrees that code repositories are more of a cult than useful for casual projects like this.

IMO keeping files in one place means the forum or whatever where the topic originated. Maybe not the Mikkelsen way (bet you thought I couldn't read backwards, LOL) but easier for those who dont speak git. I admit it's better than some of those repositories that are just weird and better now with the zip button but still...
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4192
  • Country: us
Re: One Dollar One Minute ARM Development
« Reply #294 on: October 14, 2014, 05:35:32 am »
I started: https://github.com/WestfW/Minimal-ARM

Comments welcome.  I somewhat intend to flesh out the wiki with some content extracted from these threads.  Eventually, and if I can figure out a good way to  incorporate the sense of "forward progress" that you can get from a forum but tends to disappear in static documentation.

One of the nice things about github is that you can browse the source code for something without committing to actually downloading anything.

Quote
easier on the noobs
Oh come on.  We're talking about programming RISC microcontrollers in ASSEMBLER, in the absence of much support from either the vendors or the general community for doing so.  Because we're masochistic old farts reliving our pasts, or something.  This is not the place for someone who "barely understands clicking on an attachment"...
« Last Edit: October 14, 2014, 05:42:41 am by westfw »
 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: One Dollar One Minute ARM Development
« Reply #295 on: October 14, 2014, 05:47:32 am »
Where is westfwMacros.S?

It's no where in the Git
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4192
  • Country: us
Re: One Dollar One Minute ARM Development
« Reply #296 on: October 14, 2014, 05:57:39 am »
Quote
would it be possible for you to put up the ELF file for your C version? I'm very curious about the difference compared to asm.
I didn't write all the code in C; just the q_get and q_put functions.  So it didn't get as far as a .elf file, though I can (and will) attached the .o and source.

The C code looks like:
Code: [Select]
Disassembly of section .text.q_get:

00000000 <q_get>:
   0:   f890 3022       ldrb.w  r3, [r0, #34]   ; 0x22
   4:   b163            cbz     r3, 20 <q_get+0x20>
   6:   f890 2021       ldrb.w  r2, [r0, #33]   ; 0x21
   a:   3b01            subs    r3, #1
   c:   1c51            adds    r1, r2, #1
   e:   5c82            ldrb    r2, [r0, r2]
  10:   f001 011f       and.w   r1, r1, #31
  14:   f880 3022       strb.w  r3, [r0, #34]   ; 0x22
  18:   f880 1021       strb.w  r1, [r0, #33]   ; 0x21
  1c:   4610            mov     r0, r2
  1e:   4770            bx      lr
  20:   f04f 30ff       mov.w   r0, #4294967295 ; 0xffffffff
  24:   4770            bx      lr
  26:   bf00            nop

Disassembly of section .text.q_put:

00000000 <q_put>:
   0:   f890 3022       ldrb.w  r3, [r0, #34]   ; 0x22
   4:   b410            push    {r4}
   6:   2b1f            cmp     r3, #31
   8:   d80a            bhi.n   20 <q_put+0x20>
   a:   f890 2020       ldrb.w  r2, [r0, #32]
   e:   3301            adds    r3, #1
  10:   1c54            adds    r4, r2, #1
  12:   f004 041f       and.w   r4, r4, #31
  16:   f880 3022       strb.w  r3, [r0, #34]   ; 0x22
  1a:   5481            strb    r1, [r0, r2]
  1c:   f880 4020       strb.w  r4, [r0, #32]
  20:   f85d 4b04       ldr.w   r4, [sp], #4
  24:   4770            bx      lr
  26:   bf00            nop

And that part of the assembler code looks like this:
Code: [Select]
0000001c <q_get>:
  1c:   f891 0022       ldrb.w  r0, [r1, #34]   ; 0x22
  20:   0000            movs    r0, r0
  22:   d00c            beq.n   3e <qg_exit>
  24:   b404            push    {r2}
  26:   3801            subs    r0, #1
  28:   f881 0022       strb.w  r0, [r1, #34]   ; 0x22
  2c:   f891 2021       ldrb.w  r2, [r1, #33]   ; 0x21
  30:   5c88            ldrb    r0, [r1, r2]
  32:   3201            adds    r2, #1
  34:   f002 021f       and.w   r2, r2, #31
  38:   f881 2021       strb.w  r2, [r1, #33]   ; 0x21
  3c:   bc04            pop     {r2}

0000003e <qg_exit>:
  3e:   4770            bx      lr

00000040 <q_put>:
  40:   b504            push    {r2, lr}
  42:   f891 2022       ldrb.w  r2, [r1, #34]   ; 0x22
  46:   2a20            cmp     r2, #32
  48:   da0a            bge.n   60 <qp_exit>
  4a:   3201            adds    r2, #1
  4c:   f881 2022       strb.w  r2, [r1, #34]   ; 0x22
  50:   f891 2020       ldrb.w  r2, [r1, #32]
  54:   5488            strb    r0, [r1, r2]
  56:   3201            adds    r2, #1
  58:   f002 021f       and.w   r2, r2, #31
  5c:   f881 2020       strb.w  r2, [r1, #32]

00000060 <qp_exit>:
  60:   bd04            pop     {r2, pc}

The main differences are that I use the Z flag for return value in the assembler (which C can't do), and I preserve R0..R3 while the assembler preserves r4... (and lets r0..r3 be trashed.)


 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4192
  • Country: us
Re: One Dollar One Minute ARM Development
« Reply #297 on: October 14, 2014, 06:02:21 am »
Quote
Where is westfwMacros.S?
Added.  I thought I had eliminated it's use (it doesn't have much in it yet...)
 

Offline paulieTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 849
  • Country: us
Re: One Dollar One Minute ARM Development
« Reply #298 on: October 14, 2014, 09:07:29 am »
This is not the place for someone who "barely understands clicking on an attachment"...

Maybe it's a "hardware" thing but for guys who know nothing about assembler or C the former was considered a breakthrough event for more than a couple members at the local ham radio club. They commented that "all that programming stuff" was mumbo jumbo but when the LED went on a few weeks back during my friends demo I could see their eyes light up and the  light bulb above their heads too. Loading a value into a register and putting it out on a latch was a piece of cake compared to all those "symbols and curly cue stuff".

I think what happens here is that once we go through the pain and barriers in understanding required for something like C programming we forget what it was like in those early days. Or maybe some peoples brains are prewired for it. In any case I have personally observed a real world situation where attempts were made first at introducing HLL to beginners and then the bare metal approach. One got nowhere and the other resulted in firing up interest, initially in a small handful, but now more than couple dozen "hardheads".

There has been since some progress in re-introducing HLL concepts but I won't even bring up what happened when C++/OOP reared it's ugly head.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4192
  • Country: us
Re: One Dollar One Minute ARM Development
« Reply #299 on: October 14, 2014, 09:16:57 am »
Ah.  That's true.  I had forgotten about the the "interesting subsets" of would-be microcontroller users: those that have a significant hardware design background, but little knowledge of software, and those that have a significant software background but little knowledge of electronics...
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf