Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
Gytis111
PostPosted: Jul 25, 2012 - 01:22 AM
Wannabe


Joined: Apr 02, 2012
Posts: 56


hello experts,

I am writing xmodem based bootloader (actually just editing the one found on internet) for self learning and ran into problems with avr studio 5. The thing is that after I run timer1 and get TOV1, simulator just hangs and is "running" and there is no jump into ISR. I read in the posts that there are problems with timer1 overflow, but it shouldn't be that because I get TOV1. Thought maybe somebody can give me a hand here.

purge.c

Code:

#include "xmodem.h"

extern struct global
{
  volatile unsigned char *recv_ptr;
  volatile unsigned char buffer_status;
  volatile unsigned char recv_error;
  volatile unsigned char t1_timed_out;
} gl;



unsigned char flush;

void purge(void)
{
    gl.t1_timed_out = FALSE;

   
    TCNT0 = 0xF1;   //dummy value to not wait long
    TCCR0 = 0x02;    // prescaler /8
   
    while (gl.t1_timed_out != TRUE)   // read uart until done
    {
        flush = UDR;
    }
    TCCR0 = 0x00;   // disable timer/counter 1 clock
   
   PORTC |= (1 << DDC2); //just to see what is going on
}

ISR (TIMER0_OVF_vect)
{
    gl.t1_timed_out = TRUE;
   PORTC |= (1 << DDC7); //to see what is going on
   
}



xmodem.h


Code:

#include <stdint.h>
#include <avr/io.h>
#include <avr/boot.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>
#include <util/delay.h>
#include <avr/wdt.h>


#define SOH 01
#define EOT 04
#define ACK 06
#define NAK 21
#define Konst 'C'

#define WAIT_VALUE 5000

#define TRUE 0x01
#define FALSE 0x0

#define full 0xff
#define empty 0x00

#define bad 0x00
#define good 0x01
#define dup 0x02
#define end 0x03
#define err 0x04
#define out 0x05

#define DEBUG_PIN     PORTD_Bit5 // spare pin used for debug signalling only
// Usage:
// DEBUG_PIN=0;
// DEBUG_PIN=1;

uint16_t addr;

// function prototypes
void receive(volatile unsigned char *bufptr1);
void purge(void);
void init(void);
unsigned char validate_packet(unsigned char *bufptr, unsigned char *packet_number);

uint16_t writeFlashPage(uint16_t, volatile unsigned char *);

void suolis(void);

void respond(unsigned char packet);
void recv_wait(void);
void sendc(void);
int calcrc(unsigned char *ptr, int count);


Last edited by Gytis111 on Jul 26, 2012 - 01:07 AM; edited 7 times in total
 
 View user's profile Send private message  
Reply with quote Back to top
js
PostPosted: Jul 25, 2012 - 02:12 AM
10k+ Postman


Joined: Mar 28, 2001
Posts: 20347
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)

It may help if you tell us which chip you are using.
Quote:
ran into problems with avr studio 5
As you may be aware Version 5 has been superseeded by version6 which is presumably less prone to bugs, just in case. Don't know I'm still on Ver 4.18.

_________________
John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Gytis111
PostPosted: Jul 25, 2012 - 02:35 AM
Wannabe


Joined: Apr 02, 2012
Posts: 56


Hi, I'm using mega16.
I thought I have to pay for studio 6 after demo expires and I have win7 64 bit, so I don't think I can use studio4. I guess I'm stuck with studio 5.
 
 View user's profile Send private message  
Reply with quote Back to top
larryvc
PostPosted: Jul 25, 2012 - 02:45 AM
Raving lunatic


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA

Gytis111 wrote:
I thought I have to pay for studio 6 after demo expires and I have win7 64 bit, so I don't think I can use studio4. I guess I'm stuck with studio 5.

Shocked

You are not stuck with Atmel Studio 5. Confused

Atmel Studio 6 is free. It does not cost anything. There is no demo that expires. So, go ahead, download it and use it. Very Happy

_________________
Larry

Those afraid to embrace the future will quickly fade into the past. - larryvc
 
 View user's profile Send private message  
Reply with quote Back to top
js
PostPosted: Jul 25, 2012 - 02:58 AM
10k+ Postman


Joined: Mar 28, 2001
Posts: 20347
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)

Quote:
Hi, I'm using mega16.
In which case this
Code:
PORTC |= (1 << DDC2); //just to see what is going on
will NOT work unless you turn off JTAG which uses PC2-PC5 by default.
Quote:
I have win7 64 bit, so I don't think I can use studio4.
I don't think there are any issues with that combination but don't really know.

I still have a couple of years life and support in win XP so I'm happy with what I have. Wink

_________________
John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Gytis111
PostPosted: Jul 25, 2012 - 02:58 AM
Wannabe


Joined: Apr 02, 2012
Posts: 56


Well, thanks a lot then, thats kind of questions you get from newbies Smile
 
 View user's profile Send private message  
Reply with quote Back to top
Gytis111
PostPosted: Jul 25, 2012 - 03:06 AM
Wannabe


Joined: Apr 02, 2012
Posts: 56


js wrote:
Quote:
Hi, I'm using mega16.
In which case this
Code:
PORTC |= (1 << DDC2); //just to see what is going on
will NOT work unless you turn off JTAG which uses PC2-PC5 by default.

Thats true, but I don't get to that code yet, program hangs and "is running" when it must jump to ISR. Confused
 
 View user's profile Send private message  
Reply with quote Back to top
js
PostPosted: Jul 25, 2012 - 03:20 AM
10k+ Postman


Joined: Mar 28, 2001
Posts: 20347
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)

ISR will NOT fire unless you enable the interrupts with sei(); is that present in you init? Is #include <avr/interrupt.h> anywhere in your code?

_________________
John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Gytis111
PostPosted: Jul 25, 2012 - 03:53 AM
Wannabe


Joined: Apr 02, 2012
Posts: 56


Quote:
ISR will NOT fire unless you enable the interrupts with sei(); is that present in you init? Is #include <avr/interrupt.h> anywhere in your code?

It's all there, (#include <avr/interrupt.h> in xmodem.h file, sei() in xmodem.c). I tried to run code without PORTC line, not helping. Thats confusing, if ISR would be wrong, program would just jump to reset. Now it's doing nothing, just like program is over Smile
 
 View user's profile Send private message  
Reply with quote Back to top
sternst
PostPosted: Jul 25, 2012 - 08:45 AM
Raving lunatic


Joined: Jul 23, 2001
Posts: 2438
Location: Osnabrueck, Germany

Quote:
simulator just hangs and is "running" and there is no jump into ISR.
And you have single stepped over the sei(), haven't you? There is a bug in the simulator that prevents sei to work correctly in single stepping. Set a breakpoint and let the simulator "run" over the sei().

_________________
Stefan Ernst
 
 View user's profile Send private message  
Reply with quote Back to top
js
PostPosted: Jul 25, 2012 - 08:58 AM
10k+ Postman


Joined: Mar 28, 2001
Posts: 20347
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)

And as you have posted everything else please post xmodem.h, someone may be able to try and build the code.

_________________
John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Gytis111
PostPosted: Jul 25, 2012 - 06:25 PM
Wannabe


Joined: Apr 02, 2012
Posts: 56


sternst wrote:
Quote:
simulator just hangs and is "running" and there is no jump into ISR.
And you have single stepped over the sei(), haven't you? There is a bug in the simulator that prevents sei to work correctly in single stepping. Set a breakpoint and let the simulator "run" over the sei().

So I tried it and didn't get it right, then dumped studio 5, installed studio 6 and tried debugging again.
This time cursor doesn't disappear, it just start a new cicle without jumping to ISR. I checked SREG I-bit and it doesn't change after sei(). If I change it manually during debug, that doesn't help. Confused
I also added BADISR to catch any ISR, but it doesn't work either, so I guess its sei() problem. Confused
 
 View user's profile Send private message  
Reply with quote Back to top
Gytis111
PostPosted: Jul 25, 2012 - 06:27 PM
Wannabe


Joined: Apr 02, 2012
Posts: 56


js wrote:
And as you have posted everything else please post xmodem.h, someone may be able to try and build the code.

Didn't manage to get more than 3 files to upload, so I added it to text Rolling Eyes
 
 View user's profile Send private message  
Reply with quote Back to top
Gytis111
PostPosted: Jul 26, 2012 - 01:16 AM
Wannabe


Joined: Apr 02, 2012
Posts: 56


Finally I made it - ran to the breakpoint in ISR and it jumped, but only when modified to timer0, with the same code and timer1 it didn't work for me.
Thanks everyone for help Wink
 
 View user's profile Send private message  
Reply with quote Back to top
SprinterSB
PostPosted: Jul 26, 2012 - 12:22 PM
Posting Freak


Joined: Dec 21, 2006
Posts: 1483
Location: Saar-Lor-Lux

Is .recv_ptr intentionally non-volatile?
Do you change the envolved objects (pointers, structs) atomically where needed?

_________________
avr-gcc NewsABIOptions4.8-WindowsInline Asm
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Gytis111
PostPosted: Jul 27, 2012 - 05:49 AM
Wannabe


Joined: Apr 02, 2012
Posts: 56


SprinterSB wrote:
Is .recv_ptr intentionally non-volatile?
Do you change the envolved objects (pointers, structs) atomically where needed?

Thanks, I'm checking now all that atomic stuff. Actually I managed to make program work with timer1 also (at least first part of it), probably messed up somewhere with registers Smile
However, I don't understand your question about .recv_ptr, I mean
Code:
volatile *recv_ptr
is normal usage with ISR routines (nonvolatile pointer to volatile variable) as far as I understand
 
 View user's profile Send private message  
Reply with quote Back to top
gregd99
PostPosted: Jul 27, 2012 - 06:53 AM
Hangaround


Joined: Oct 10, 2011
Posts: 238
Location: Sydney, Australia

you might have missed one of the comments above.

if you step through sei().... it doesn't work. this is a bug in studio.

you need to set a bp on the other side of the sei() for the interrupt bit to be set!!

this is very frustrating at first but once you know it is not a problem.

_________________
regards
Greg
 
 View user's profile Send private message  
Reply with quote Back to top
Gytis111
PostPosted: Jul 27, 2012 - 07:37 AM
Wannabe


Joined: Apr 02, 2012
Posts: 56


gregd99 wrote:
you might have missed one of the comments above.

if you step through sei().... it doesn't work. this is a bug in studio.

you need to set a bp on the other side of the sei() for the interrupt bit to be set!!

this is very frustrating at first but once you know it is not a problem.

Thanks man, but I did that already. It's working now with both timer0 and timer1. Smile
 
 View user's profile Send private message  
Reply with quote Back to top
SprinterSB
PostPosted: Jul 27, 2012 - 08:23 AM
Posting Freak


Joined: Dec 21, 2006
Posts: 1483
Location: Saar-Lor-Lux

Gytis111 wrote:
However, I don't understand your question about .recv_ptr, I mean
Code:
volatile *recv_ptr
is normal usage with ISR routines (nonvolatile pointer to volatile variable) as far as I understand
Yes, that's the semantics of that declaration.

I did not read your program, but because the other components of the struct are volatile an this is the only component that is not, I suspected .recv_ptr might be unintentionaly non-volatile.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Gytis111
PostPosted: Jul 27, 2012 - 09:30 AM
Wannabe


Joined: Apr 02, 2012
Posts: 56


Thanks man, I'll check it out Smile
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits