Atom Pro C/C++ Code

I thought it would be fun to at least experiment with C and C++ code on the atom pro. So I thought I would try a simple hello world type application and try to blink the RED led on the ABB board. So I went into the BAP ide and did a create of a C project. I then tried to compile the code and found that it had problems finding the compiler pieces. I went into my Vista system CPL and changed the PATH environment to find the compiler pieces and got everything to compile. :smiley:

Next was to put the code in to change the IO ports. I first did this with the regdefs.h file that was created in my project, but later found a header file that had all of the registers defined in structures. I first got the blink working with some simple delay loops. Then I wanted to use a timer interrupt to make it work properly. I am basically working with no instructions for the C compiler, but I now have it somewhat working. The timer interupt gets set up properly until the first reset. Still need to figure that part out. Anyone had any better luck? I thought I would post parts of the code as it now sits:

form hwinit.c:

void hw_initialise (void)
{
  	IO.PMR5.BYTE &= 0x70;		// make sure P54 P55 P56 are standard IO pins
  	IO.PCR5 |= 0x70;		//Make sure P54 is output pin
	IO.PDR5.BIT.B4 = 0;		// start off in some known state
	IO.PDR5.BIT.B5 = 1;		// start off in some known state
	IO.PDR5.BIT.B6 = 0;		// start off in some known state

}

from my HelloWorld.cpp:

[code]#include <signal.h>
//#include “regdefs.h”

extern “C” {
#include “3664s.h”
};

volatile short int ms_count;

/*

  • ms_sleep() - delay for specified number of milliseconds
    */
    void ms_sleep(short int ms)
    {
    #if 1
    //TCA = 0;
    ms_count = 0;
    while (ms_count != ms)
    ;
    #else
    int i;
    int j;
    int k;

    j = 0;
    for (i=0; i < 1000; i++)
    {
    for (j = 0; j < 32767; j++)
    k = k + 1;
    }
    #endif
    }

/*

  • millisecond counter interrupt vector
    */
    extern “C” void TIMERAV();

#pragma interrupt(TIMERAV)
void TIMERAV()
{
ms_count++;
IO.PDR5.BIT.B6 = 1; // See if this gets called
IRR1.BIT.IRRTA = 0;
}

/*

  • initialize timer 0 to generate an interrupt every millisecond.
    /
    void init_timer(void)
    {
    /

    • Initialize timer0 to generate an output compare interrupt, and
    • set the output compare register so that we get that interrupt
    • every millisecond.

    */
    //ONINTERRUPT TIMERAINT,handle_timera

    TA.TMA.BYTE=4; //increments on clock/256

    IENR1.BIT.IENTA = 1; // ENABLE TIMERAINT
    }

int main(void)
{
init_timer();

// IO.PMR5.BYTE &= 0x10; // make sure P54 is standard IO pin
// IO.PCR5 |= 0x10; //Make sure P54 is output pin
IO.PDR5.BIT.B4 = 0x1; // start off in some known state

while (1) {
    ms_sleep(512);    /* wait 0.5 seconds */
	IO.PDR5.BIT.B6 = 0x1;		// start off in some known state
	IO.PDR5.BIT.B4 = 0x0;    /* toggle LED */
	ms_sleep(512);
	IO.PDR5.BIT.B4 = 0x1;    /* toggle LED */
}

}

[/code]
from vects.c:

[code]void start(void); /* Startup code (in start.s) */

asm ("	.section .vects");
asm("jmp @_start"); //_RESET
            ...
asm("jmp @_TIMERAV"); //_TIMERAV:
...

[/code]

Anyone had any better luck? Any suggestions? Any other examples?

Thanks
Kurt

This afternoon I did get the timer interrupt to work properly (I think). :smiley:

The secret was that after the atom code reboots it leaves all but the NMI Interrupts disabled… Will look later to see if there is some type of C helper function, but I was able to get the interrupts enabled again by adding a line:
ldc.b #00:8,ccr
to the start.s function, which clears at the status register including the bit that disabled the interrputs.

10 PRINT “HELLO WORLD”

Neat project!

I’m intending to order an Atom Pro some time in the near future (as soon as the new ABB is released), so please excuse my ignorance. Are the ISP pins exposed on the Atom Pro, or do they have a bootloader or some other setup to allow you to program it with custom binaries?

Thank you. So far I can blink lights. Soon I will soon try to output the text string back to the terminal connection (RS-232), probably as well as to a serial LCD.

I will first have to replicate a lot of the functionality of the SEROUT command. It is too bad that there are not libraries that we can link to do this as to not have to reinvent the wheel. But I do have some source code that I used to bit bang out to the serial port on an ATMEGA32, so it should not be difficult. I need to figure out which pins they use for serial communication (S_OUT, S_IN).

Yes there is a form of bootloader built in. You simply use the Program button or menu item to download your program to the chip. How this works is covered in I believe Chapter 7 of the H83664 manual.

Kurt

That’s handy.

This is what I get for not searching the forums this thread of yours is also full of interesting information.

Have Fun!!

Actually the bootloader on the AtomPro is proprietary. The way we load it on a blank chip is what is described in the ROM chapter of the H8 hardware manual. The builtin loader routine(ROM chapter) always erases the entire chip before programming which is why we don’t use that to load a normal AtomPro program(or in your case a compiled C program).

This looks like the same mode of addressing I/O pins used with the Renesas H8 Starter Kit I have. If so, I should be able to make an io.h for the Atom PRO pretty easily from what I am doing with the H8/36077. :smiley: I see possibilities here. :wink:

8-Dale

It would not supprise me. I am using a source header file I downloaded from the renesas web site. The zip file I downloaded was:
include_h8_070420.zip
The file I am using is in the zip file is:
include_h8\300h\3664s.h

Kurt

Yes, it is the same format used in the iodefine.h file that comes with the Renesas H8 Starter Kit. :smiley: This is great news because it means I can definitely create a version of my io.h and such to work with the Atom PRO. :wink:

8-Dale