[tiny10] Cannot increment byte above n

Go To Last Post
18 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I'm using tiny10 to run a simple state machine like part of software.

After the first attempt there was a issue with non-existing registers... This toolchain is updated now, and that problem is fixed.

However, it still seems like the tiny10 is not supported by the compiler in as6.

I have a simple state machine like this:

volatile uint8_t state;
volatile uint8_t delay;
int main(){
	while(1){
		if(state == 0){
			do something with leds based on ADC
			if(delay > 20){ // interesing condition
				state = 1;
			}else{
				delay++;
			}
			}
		if(state == 1){
			enable red led
		}
		if(...){
		..
		}	
	}
}

If in (delay > x) x is 9 or higher, this never turns true.
(delay > 5) becomes true.
(delay > 20) never becomes true.
led changes on adc input is a good way to see if it turned true. However this does not cover failure of the state variable. But that does not seem very likely.

I've looked in the .lss to see if the optimizer (-Os) destroys it. But the only diffence between the two is the argument in the CPI instruction, which is perfectly reasonable.

Whats the status of tiny10 support by AS6?
Or did I forget something while working on cortex m4/m0's?

Do I really need to search for an alternate brand of sot23 package mcu if I do not want assembly programming?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would guess that with only 32bytes of RAM, your stack is overflowing into your static variables, perhaps on interrupts.

Good luck find an Sot23 mcu that is C-friendly :-(

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you sure the compiler generates code to initialize state to 0?
I would do

volatile uint8_t state = 0;

just to be sure.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are the variables changed in the interrupt service typed as "volatile"?

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@westfw, I can find bga16 arm m0's c++ friendly, but pcb cost are too high.

However, I removed ALL functions. And it seems working.
Only one level of an inline function call is enough for a stack overflow apparently.
The "inline" keyword is not what I thought it should be.

Also, I cannot use interrupts, since interrupt.h does not contain tiny10 device. I have to find a workaround for this.

Conclusion, you can use C, but code it as assembler.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You need Atmel toolchain 3.4.1 or newer for the tiny10 family. Do you have that?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jeroen3 wrote:
Only one level of an inline function call is enough for a stack overflow apparently
I do not use neither new AVR Studio nor tiny10. Just curious, what kind of code is generated for the main? Does declaring main as something like this help:
__attribute__((OS_main)) int main(void)
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm using ASF 3.5.1

Using attribute as described above creates the following assember.

int main(void){
  6c:	cf 93       	push	r28
  6e:	df 93       	push	r29
  70:	00 d0       	rcall	.+0      	; 0x72 
  72:	cd b7       	in	r28, 0x3d	; 61
  74:	de b7       	in	r29, 0x3e	; 62
__attribute__((OS_main))
int main(void){


  6c:	00 d0       	rcall	.+0      	; 0x6e 
  6e:	cd b7       	in	r28, 0x3d	; 61
  70:	de b7       	in	r29, 0x3e	; 62

Looks like main is not considered a function anymore, since the Y register is not pushed anymore.

Saved 2 bytes of valueable sram :D

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jeroen3 wrote:
I'm using ASF 3.5.1
It's the toolchain version that's relevant.

Look in Tools/Extension Manager/Installed Extensions and AVR GCC. The AVR8-GNU Version should be at least 3.4.1.798. Versions before that was very buggy for the tiny10 family. I haven't seen anything strange from that version, and interrupts do work.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As copied from about:

Installed Packages: AVRAssembler - 2.1.51.64 
AVR Assembler 
Version: 2.1.39.232 

Installed Packages: AVRGCC - 3.4.1.95 
AVR Toolchain 8 Bit 
Version: 3.4.1.830 - GCC 4.6.2 

I'm sure interrupts do work, yet it kept telling me "misspelled handler". However, this seems fixed now.
There is a file called iotn10.h which was not there a version before.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That version looks OK.

What ISR is it that it say is misspelled? Or was that fixed?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

_VECTOR(4) was misspelled. Probably due to missing header. This problem is also fixed.

Using tiny10 is an entire different world compared to a dual core cortex m4/m0... It feels like stone age :p

The issues I was experiencing are fixed, thanks!
If anyone knows how to reduce rw-data and/or stack usage, I'm open for any tricks or reference material.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

About inline functions, I have found that using the inline keyword is not enough. To make sure a function gets inlined I do something like this:

static inline void f() __attribute__((always_inline));

static inline void f()
{
}

Sid

Life... is a state of mind

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's good that things start to work.

But how was _VECTOR(4) misspelled? It's hard to tell if you're doing anything wrong, since you don't show any code. But if you refer to timer0 overflow interrupt, it's supposed to be written like this

ISR(TIM0_OVF_vect)
{
  // ...
}

And I don't think it's stone age, it's just a very small MCU.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I can find bga16 arm m0's c++ friendly, but pcb cost are too high.

Well, ONE bga16 ARM. It sure was cute, and I have a sample around somewhere (safely encapsulated on its little card.) I also found the PCB issues insurmountable.
(how can NXP be trying so hard, and be so ... clueless. "no one's buying our 16pin BGA. Let's try a 0.6inch DIP!")

Other tiny-packages include PICs and 8051s, neither of which I would rate as "C-friendly."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

TIM0_OVF_vect is just a define for _VECTOR(4)...
However, that was related due to missing specific header for tiny10.

I'll look into __attribute__((always_inline)); I like functions to keep code more readable. However, you can do a lot by using define macro's.

BGA is outside hobby scope, use them on a commercial product, like a multi-layer high class motherboard, and there is no issue with pcb mountability.

(On NXP, with their 800 series, which looks promising, more sot23 mcu's might become available in the future...
Until then, I'll try to sqeeze it into a tiny10.)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

their 800 series, which looks promising

I'll say. Santa is bringing me the 800 eval board from Mouser I hope! ;-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ha! I am getting my very own diamond! (Rats, just found out it is a kit. Lump of coal and a note attached saying 'Sit on it!')