| Author |
Message |
|
|
Posted: Jul 25, 2012 - 01:22 AM |
|

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
|
| |
|
|
|
|
|
Posted: Jul 25, 2012 - 02:12 AM |
|


Joined: Mar 28, 2001
Posts: 20381
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
|
| |
|
|
|
|
|
Posted: Jul 25, 2012 - 02:35 AM |
|

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. |
|
|
| |
|
|
|
|
|
Posted: Jul 25, 2012 - 02:45 AM |
|


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.
You are not stuck with Atmel Studio 5.
Atmel Studio 6 is free. It does not cost anything. There is no demo that expires. So, go ahead, download it and use it.  |
_________________ Larry
Those afraid to embrace the future will quickly fade into the past. - larryvc
|
| |
|
|
|
|
|
Posted: Jul 25, 2012 - 02:58 AM |
|


Joined: Mar 28, 2001
Posts: 20381
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.  |
_________________ John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
|
| |
|
|
|
|
|
Posted: Jul 25, 2012 - 02:58 AM |
|

Joined: Apr 02, 2012
Posts: 56
|
|
Well, thanks a lot then, thats kind of questions you get from newbies  |
|
|
| |
|
|
|
|
|
Posted: Jul 25, 2012 - 03:06 AM |
|

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.  |
|
|
| |
|
|
|
|
|
Posted: Jul 25, 2012 - 03:20 AM |
|


Joined: Mar 28, 2001
Posts: 20381
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
|
| |
|
|
|
|
|
Posted: Jul 25, 2012 - 03:53 AM |
|

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  |
|
|
| |
|
|
|
|
|
Posted: Jul 25, 2012 - 08:45 AM |
|


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
|
| |
|
|
|
|
|
Posted: Jul 25, 2012 - 08:58 AM |
|


Joined: Mar 28, 2001
Posts: 20381
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
|
| |
|
|
|
|
|
Posted: Jul 25, 2012 - 06:25 PM |
|

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.
I also added BADISR to catch any ISR, but it doesn't work either, so I guess its sei() problem.  |
|
|
| |
|
|
|
|
|
Posted: Jul 25, 2012 - 06:27 PM |
|

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  |
|
|
| |
|
|
|
|
|
Posted: Jul 26, 2012 - 01:16 AM |
|

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  |
|
|
| |
|
|
|
|
|
Posted: Jul 26, 2012 - 12:22 PM |
|


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 News • ABI • Options • 4.8-Windows • Inline Asm
|
| |
|
|
|
|
|
Posted: Jul 27, 2012 - 05:49 AM |
|

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
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 |
|
|
| |
|
|
|
|
|
Posted: Jul 27, 2012 - 06:53 AM |
|

Joined: Oct 10, 2011
Posts: 242
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
|
| |
|
|
|
|
|
Posted: Jul 27, 2012 - 07:37 AM |
|

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.  |
|
|
| |
|
|
|
|
|
Posted: Jul 27, 2012 - 08:23 AM |
|


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. |
|
|
| |
|
|
|
|
|
Posted: Jul 27, 2012 - 09:30 AM |
|

Joined: Apr 02, 2012
Posts: 56
|
|
Thanks man, I'll check it out  |
|
|
| |
|
|
|
|
|