Debug session is acting strangely

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

Hi Freaks !

 

So I'm facing some strange behavior of a debugWire session on a custom made Attiny84 board.

 

Everything seemed to work correctly (I was able to program using SPI, the code was running, then I started to debug and add functions, it was working ok), then It started to... be weird, not going throught functions etc. I finally started all over with a new project and made a really simple code, just to check the debug.

 

#include <avr/io.h>

int main(void)
{
	int a = 2;
	int b = 18;
    while (1)
    {
		a = a+1;
		b = a-b;
    }
}

 

Now if I place a breakpoint on any of the line and launch the session, it says thgat the breakpoint will not be hit. the session starts and the arrow stays on "{" of the main function.

I changed the micro controler to a known functioning arduino board, same behavior.

 

I guess this is very simple and I'm just missing something...?

 

I'm using an Atmel ICE running last firwmare version and atmel studio 7.0.1645

 

For information, this is the original code I was having a weird thing, It never hit the "VBat++;"

 


#include <avr/io.h>
#include <avr/eeprom.h>

#define LIGHT_MODE_MEMORY_ADDRESS 0x10
#define NUMBER_OF_MODE 5

uint8_t CurrentMode = 0;

/*ModeList, changed on boot.
0 100%
1 50%
2 10%
3 Strob
4 Sos
*/

void setBrightness(uint8_t Value);
void restoreMode();
void pinInit();
void pwmSetup();
void adcInit();
uint16_t getVbat();

uint16_t VBat;

int main(void)
{
	/*
	Todo:
		- Measure input Vbat
		- Measure Driver temp, LED temp and Bat temp
		- Derate when temp is High
		- Create Modes : Full, 50%, 10%, Strob, SOS
		- Memorize modes in eeprom
	*/

	pinInit();
	pwmSetup();
	adcInit();
	//restoreMode();
	setBrightness(255);
	switch (CurrentMode)
	{
		case 0:
			setBrightness(255);
		break;

		case 1:
			setBrightness(127);
		break;

		case 2:
			setBrightness(25);
		break;

		case 3:
			setBrightness(0);
		break;

		case 4:
			setBrightness(0);
		break;

		default:
		break;
	}

	VBat = getVbat();
    while (true)
    {
		VBat++;
    }
}

void setBrightness(uint8_t Value)
{
	OCR0A = Value;
}
/*
void restoreMode()
{
	CurrentMode = eeprom_read_byte((uint8_t *)LIGHT_MODE_MEMORY_ADDRESS);
	CurrentMode = (CurrentMode+1)%NUMBER_OF_MODE;
	eeprom_write_byte((uint8_t *)LIGHT_MODE_MEMORY_ADDRESS, (uint8_t)CurrentMode);
}*/

void pinInit()
{
	DDRB = 1<<DDB2 | 1<<DDB0;
	//DDRA = 1<<DDA7;
}

void adcInit()
{
	ADCSRA |= 1<<ADEN;
	ADMUX = 1<<MUX2 | 1<<MUX1 | 1<<MUX0;
}

void pwmSetup()
{
	TCCR0A  = ((1 << COM0A1) | (1 << WGM01) | (1 << WGM00));
	TCCR0B = ((1 << CS01) | (0 << CS00));
}

uint16_t getVbat()
{
	PORTB |= 1<<PB0;
	ADCSRA |= 1<<ADSC;
	while (ADCSRA & 1<<ADSC);
	PINB |= 1<<PINB0;
	return ADC;
}

 

This topic has a solution.
Last Edited: Tue. May 15, 2018 - 12:34 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The compiler optimised useless code out. This is the second question regarding this today.
https://www.avrfreaks.net/forum/code-jumps-while-debugging

Last Edited: Tue. May 15, 2018 - 12:16 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks a Lot... 

I was sure this was already treated but I had a hard time trying to express this as a research... (English is not my native language)

 

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

You'll probably get to this via the links Andy gave but I would recommend this:  https://www.avrfreaks.net/forum/tutcoptimization-and-importance-volatile-gcc

 

(written by an utter genius!)

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

clawson wrote:
the links Andy gave

in the thread mentioned by Kartman in #2

 

(in case you were wondering why you couldn't see anything from me here).

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah, good point - it was an Andy link in the thread that Russell linked to that I meant - doh! blush

 

I would say "more caffeine needed here" - but there's already a double-shot expresso sitting here on my desk - better drink it quick.