Lesson 001: Basic Blinky

Received my DK-S7G2 today and started working on the very first application, a simple Hello World!

I decided not to use the Blinky starter app, instead, I’d work on developing everything from ‘scratch’ using the configurator.

Ok, so, do the normal stuff, create a new Synergy project, choose my board, etc, etc.

A few more clicks away, and BAM! I have a project.

Simple Goal, turn on AN LED!

Now to get those darn pins to turn on. Where to start…

I start looking through the Synergy User Manual under the HAL interface and find a Ports section. I see the R_IOPORT_Init function, which looks like I have to initialize a bunch of stuff. Hmm, time to look at some example code.

Err, example code? Where are you example code?!?!

So, the manual has no examples…guess I need to look at that default Blinky project…

The Blinky project get’s the board LED’s, sticks them in an array, and low and behold, there is the line:

g_ioport.p_api->pinWrite(leds.p_leds[i], level);

Looking back at the manual, pinWrite is actually what I need. But what about initialization and where the heck did g_ioport come from?? F12 to the rescue!

g_ioport is derived in hal_data.c, with a big comment at the top saying not to modify this file. Back to my project, and indeed there is a hal_data.c file also with a definition for g_ioport.

A few more pieces of information that I’ll need. First, which port/pins are the LEDs on? Looking at the User’s Manual for the DK-S7G2 there is a section on User LED’s.

It says:

LED Color Pin
LED1 Green P8_7
LED1 Red P8_8
LED2 Green P8_9
LED2 Red P8_10

OK, so I need port 8 pin 7. How do I specify this in my code??

Back to the stock blinky and a bunch of F12’s later, I finally find the definition! It’s buried in the file hw_ioport_s7g2.h.

The value I’m looking for is IOPORT_PORT_08_PIN_07. IOPORT_LEVEL_HIGH is defined as a 1 and IOPORT_LEVEL_LOW is a zero. Makes sense!

To turn on the LED’s, the code is…drumroll…..

g_ioport.p_api->pinWrite(IOPORT_PORT_08_PIN_07, 1);

Pretty simple (once you know where to look for stuff!)

 

Next step, make it blink!

The “correct” way to do this is to use a timer. Not what I want for now. I just want it to blink at some rate, I don’t really care what it is as long as I can see it blink.

My first attempt:

void hal_entry(void)
{
    bool isOn = true;
    while(1)
    {
        g_ioport.p_api->pinWrite(IOPORT_PORT_08_PIN_07, isOn);
        isOn = !isOn;
        for (int i = 0; i < 100E6; i++)
        {

        }
    }
}

The Light comes on, and after a loooong time, it turns off. Counting to 100 million takes forever (guess the instruction clock doesn’t match the primary oscillator).

 

void hal_entry(void)
{
    bool isOn = true;
    while(1)
    {
        g_ioport.p_api->pinWrite(IOPORT_PORT_08_PIN_07, isOn);
        isOn = !isOn;
        for (int i = 0; i < 1E6; i++)
        {

        }
    }
}

It blinks at a decent rate!

Day 2 will cover a few IDE annoyances…

Day 3 will replace the for loop with a timer…

Advertisements

13 thoughts on “Lesson 001: Basic Blinky

  1. Thanks for reading and following. I don’t see the missing comma in the examples above, but if it is missing, you are right, it should be there.

    Like

  2. Eric, thank you for putting together this wonderful site. We are thinking of building an community site with more usage guides and would like to include information on you and your site. Can you send me a note at craig @ oppkey.com so we can get more info. Thanks.

    Like

  3. Hi Eric,

    Thanks for doing these lessons. I have an SK-S7G2 board (rev 3.1) from one of the recent Renesas seminars, so I’m going to be trying to recreate the projects for my board, at least to some extent if possible. (I know, not everything will run.)

    For this code, the essential knowledge (in page 12 of the schematics) is that the three LEDs are on Port 6 Pin 0 (green), 1 (red) and 2 (yellow).

    Also I added some code to make sure all the LEDs were off, where I learned that (at least on the SK board) they are active-low pins, so you write the opposite state of the values. This means to get the LED to go ON, you need to write a 0 level, and write a 1 to get them OFF.

    I hope this information helps others who are trying to port this lesson to the SK board.

    As they warn all over their websites, *always have the most up-to-date documentation for your board*. It’s hard to do that for such a fast-moving product family (I only have the 3.0 board schematics and layout, for example, even though my board is 3.1). And no matter when you get the hardware, you lose interest in all the board revisions that come afterwards. Lol. Now if someone could come up with a way to update hardware as easily as software … (no, not everything is an FPGA yet.. maybe next year? but then that wouldn’t really work either …)

    Thanks again for the fun. Best wishes to you for your trail-blazing.

    Regards,
    Mike

    Like

    1. Mike,
      Thanks for your comments. The SSP platform is pretty easy to use once you get the hang of it. Good luck with the hardware and the examples I’ve put up. If you have any questions, or would like to see a tutorial on something, please let me know.

      -Eric

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s