Skip to content
This repository was archived by the owner on Apr 18, 2023. It is now read-only.
This repository was archived by the owner on Apr 18, 2023. It is now read-only.

The code is not working on the Raspberry Pi. #1

@smulikHakipod

Description

@smulikHakipod

Hey,
First of all thank you for this piece of code, this made my work much easier.
I compiled the code on the Raspberry Pi and connected all the pins but it didn't work.
I took some time but I find out the problem, I based my research on the working cclil project and cc_flahser:
https://github.com/tobyjaffey/cctl/tree/master/ccpil
http://sourceforge.net/projects/ccflasher/
From this project you can get several things:

  1. You need to put delays in some areas of the code because the Pi is too fast fot the CC2530.
    For example here is your code with my added delays:
static void delay_ns(unsigned int ns)
{
    struct timespec sleeper, dummy;
    sleeper.tv_sec  = 0;
    sleeper.tv_nsec = ns ;
    nanosleep (&sleeper, &dummy) ;
}

void delay (unsigned int millis)
{
  struct timespec sleeper, dummy ;

  sleeper.tv_sec  = (time_t)(millis / 1000) ;
  sleeper.tv_nsec = (long)(millis % 1000) * 1000000 ;
  nanosleep (&sleeper, &dummy) ;
}


/*
 * Hold reset low while raising clock twice
 */

static int cc2530_leave_debug(void)
{
    gpio_set_value(RST_GPIO, 0);
    delay(100);
    gpio_set_value(RST_GPIO, 1);
    return 0;
}

static int cc2530_enter_debug(void)
{

    cc2530_leave_debug();
    gpio_set_value(CCLK_GPIO, 0);
    gpio_set_value(DATA_GPIO, 0);


    gpio_set_value(RST_GPIO, 0);
    delay(10);
    gpio_set_value(CCLK_GPIO, 0);
    delay(1);
    gpio_set_value(CCLK_GPIO, 1);
    delay(1);
    gpio_set_value(CCLK_GPIO, 0);
    delay(1);
    gpio_set_value(CCLK_GPIO, 1);
    delay(1);
    gpio_set_value(CCLK_GPIO, 0);
    delay(1);
    gpio_set_value(RST_GPIO, 1);
    delay(10);

    debug_enabled = 1;

    return 0;
}


/*
 * Bit-bang a byte on the GPIO data line
 */
static inline void send_byte(unsigned char byte)
{
    int i;

    /* Data setup on rising clock edge */
    for (i = 7; i >= 0; i--) {
        //
        if (byte & (1 << i))
            gpio_set_value(DATA_GPIO, 1);
        else
            gpio_set_value(DATA_GPIO, 0);


        gpio_set_value(CCLK_GPIO, 1);
        delay_ns(1);

        gpio_set_value(CCLK_GPIO, 0);
        delay_ns(1);
    }
}

/*
 * Clock in a byte from the GPIO line
 */
static inline void read_byte(unsigned char *byte)
{
    int i;
    bool val;
    *byte = 0;

    /* data read on falling clock edge */
    for (i = 7; i >= 0; i--) {

        gpio_set_value(CCLK_GPIO, 1);
        delay_ns(1);

        gpio_get_value(DATA_GPIO, &val);

        if (val)
            *byte |= (1 << i);

        gpio_set_value(CCLK_GPIO, 0);

    }
  1. Delays alone won't make this code work, I find out that you need to reset the debug port before you init it. I don't know how to explain this but its working that way.

After this changes I was able to get this code program the chip and verify it, but still the code doesn't appear to be running. I halted the cpu and checked the pc register and it point to zero. I suspect it has to do with the output format of the IAR compiler. which format should be used with this programmer? raw-binary? simple-code? intel-extened?
hope you can help me and many thanks for this work!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions