Full Version : Using C++ on BTNODEv3 (AVR ATMEGA128)
avr >>BASIC & OTHER AVR LANGUAGES >>Using C++ on BTNODEv3 (AVR ATMEGA128)


Saif- 01-11-2008
Hello,

I am using:
eclipse-platform-3.2-win32
btnut_system_1.8
and WinAVR-20070525

When i burn the .hex file on BTNODEv3 hardware i get the following warning:
[LPM] Device is not responding correctly
All four LED's of BTNODE hardware are blinking continously, but when i connect it using hyperterminal there is no output, even i have certain printf code in my main.

My main file look like(i simply used the cppdemo available in btnut-system, how ever even cppdemo .hex file is not working on BTNODE):

#include "Main.h"
// Trivial C++ Demo for NutOS.
/*!
* $Log: cppdemo.cc,v $
* Revision 1.3 2006/07/10 14:24:11 haraldkipp
* Header files replaced by platform independent variants.
* Contributed by Matthias Wilde.
*
* Revision 1.2 2005/08/02 17:46:44 haraldkipp
* Major API documentation update.
*
*/
/*!
* \example cppdemo/cppdemo.cc
*
* This sample demonstrates the usage of Nut/OS with C++.
*
* You should carefully think about using C++ with tiny embedded systems.
* This sample just proofs, that it basically works.
*/
#include <cpp/nutcpp.h>
extern "C" {
#include <dev/board.h>
#include <sys/version.h>
#include <inttypes.h>
#include <io.h>
#include <stdio.h>
}

template<class tp_type> class TemplateCounter
{
protected:
tp_type m_value;
public:
tp_type value() const { return m_value; }
void inc() { m_value++; }
void dec() { m_value--; }
void set(const tp_type &newValue) { m_value = newValue; }
};

class Counter: public TemplateCounter<uint8_t>
{
public:
void print(FILE *stream);
Counter(uint8_t initValue=10);
};

void Counter::print(FILE* stream)
{
fprintf(stream, "\nCounter value = %i\n", value());
}

Counter::Counter(uint8_t initValue)
{
m_value = initValue;
}
void init_term(void) {
FILE *uart_terminal;
u_long baud = 57600;
NutRegisterDevice(&APP_UART, 0, 0);
uart_terminal = fopen(APP_UART.dev_name, "r+");
_ioctl(_fileno(uart_terminal), UART_SETSPEED, &baud);
freopen(APP_UART.dev_name, "w", stdout);
}
int main(void){
printf("\nAm i happy with this :-) Yes ofcourse");
u_long baud = 115200;
NutRegisterDevice(&DEV_UART0, 0, 0);
FILE *stream = fopen(DEV_UART0_NAME, "r+");
_ioctl(_fileno(stream), UART_SETSPEED, &baud);
fprintf(stream, "\n\nC++ Demo on Nut/OS %s ready.\n", NutVersionString());
Counter counter;
counter.print(stream);
for (;;) {
char c;
fread(&c, sizeof©, 1, stream);
switch © {
case '+':
counter.inc();
counter.print(stream);
break;
case '-':
counter.dec();
counter.print(stream);
break;
case 'r':
counter.set(0);
counter.print(stream);
break;
default:
fprintf(stream, "Unknown command.\n");
}
}
return 0;
}

Following is the build output:
make btnode3
makefile:60: warning: overriding commands for target `clean'
../Makerules:285: warning: ignoring old commands for target `clean'
avr-g++ -c -mmcu=atmega128 -Os -Wall -Werror -Wa,-ahlms=Main.btnode3.lst -D__HARVARD_ARCH__ -D__BTNODE3__ -D btnode3 -IC:/workspace/btnut/btnode/include -IC:/workspace/btnut/../nut/include -IC:/workspace/btnut/extras -IC:/WinAVR/avr/include -IC:/workspace/Db/nut/include/cpp Main.cc -o Main.btnode3.o
#avr-g++ Main.btnode3.o C:/workspace/btnut/lib/btnode3/nutinit.o -Wl,--start-group -LC:/workspace/btnut/lib/btnode3 -mmcu=atmega128 -Wl,--defsym=main=0,-Map=Main.btnode3.map,--cref -LC:/workspace/btnut/lib/btnode3 -LC:/ethernut/nutbld/lib -lnutcpp /nutinit.o -lnutcpp -lnutos -lnutcrt -lnutarch -lnutdev -lnutos -lnutcrt -lnutdev -lnutfs -lnutnet -lnutpro -lnutarch -lbt -lhardware -lcm -leepromdb -lsuart -lled -lcc -ldev -ldebug -lmhop -lsync -lutils -lterminal -lsupport -ltime -lcdist -lbtsense -ltecossmall -lsecurity -lnutcpp -Wl,--end-group -o Main.btnode3.elf
avr-g++ Main.btnode3.o C:/ethernut/nut/lib/gcc/atmega128/nutinit.o -D btnode3 -Wl,--start-group -LC:/workspace/btnut/lib/btnode3 -mmcu=atmega128 -Wl,--defsym=main=0,-Map=Main.btnode3.map,--cref -LC:/workspace/btnut/lib/btnode3 -LC:/ethernut/nutbld/lib -lnutos -lnutcrt -lnutdev -lnutfs -lnutnet -lnutpro -lnutarch -lbt -lhardware -lcm -leepromdb -lsuart -lled -lcc -ldev -ldebug -lmhop -lsync -lutils -lterminal -lsupport -ltime -lcdist -lbtsense -ltecossmall -lsecurity -lnutcpp -Wl,--end-group -o Main.btnode3.elf
avr-size Main.btnode3.elf
text data bss dec hex filename
14336 386 121 14843 39fb Main.btnode3.elf
cp Main.btnode3.elf Main.elf
avr-objcopy -O ihex Main.btnode3.elf Main.btnode3.hex
rm Main.btnode3.elf

I want to make the C++ code run on BTNODEv3. Can any one have any idea how to make it work???

Saif.


Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.