Skip to content

Commit

Permalink
Merge pull request #53 from mortenmjelva/ARDIN-80-bootloader-support
Browse files Browse the repository at this point in the history
Ardin 80 bootloader support
  • Loading branch information
daviddedwin committed Feb 27, 2015
2 parents 30cd292 + 0fe4af2 commit c5f94ff
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,13 @@ void bootloader_jump_check (void)
}
}

void bootloader_jump(void)
void bootloader_jump(aci_state_t *state)
{
Serial.println("Jumping to bootloader");
delay(100);

if ((aci_state.data_credit_available != aci_state.data_credit_total)) {
return;
}

if (!lib_aci_is_pipe_available(&aci_state,
PIPE_NORDIC_DEVICE_FIRMWARE_UPDATE_SERVICE_DFU_PACKET_RX)) {
return;
}

if (!lib_aci_is_pipe_available(&aci_state,
PIPE_NORDIC_DEVICE_FIRMWARE_UPDATE_SERVICE_DFU_CONTROL_POINT_TX)) {
return;
}

if (!lib_aci_is_pipe_available(&aci_state,
PIPE_NORDIC_DEVICE_FIRMWARE_UPDATE_SERVICE_DFU_CONTROL_POINT_RX_ACK_AUTO)) {
return;
}

/* Wait until ready line goes low before jump */
while (digitalRead(aci_state.aci_pins.rdyn_pin));
while (digitalRead(state->aci_pins.rdyn_pin));

/* Set the special bootloader key value */
boot_key = BOOTLOADER_KEY;
Expand All @@ -85,7 +66,7 @@ void bootloader_jump(void)
* connection advertisement interval.
*/
bool bootloader_data_store (aci_state_t *state, uint16_t conn_timeout,
uint16_t adv_interval)
uint16_t adv_interval, uint8_t *pipes, uint8_t n_pipes)
{
const uint16_t eeprom_base_addr = E2END - BOOTLOADER_EEPROM_SIZE;

Expand All @@ -100,11 +81,6 @@ bool bootloader_data_store (aci_state_t *state, uint16_t conn_timeout,
uint8_t valid_app = 1;
uint8_t valid_ble = 1;
uint8_t *p = (uint8_t *) &(state->aci_pins);
uint8_t pipes[] = {
PIPE_NORDIC_DEVICE_FIRMWARE_UPDATE_SERVICE_DFU_PACKET_RX,
PIPE_NORDIC_DEVICE_FIRMWARE_UPDATE_SERVICE_DFU_CONTROL_POINT_TX,
PIPE_NORDIC_DEVICE_FIRMWARE_UPDATE_SERVICE_DFU_CONTROL_POINT_RX_ACK_AUTO
};
uint8_t timeout_h = (uint8_t) conn_timeout >> 8;
uint8_t timeout_l = (uint8_t) conn_timeout >> 0;
uint8_t interval_h = (uint8_t) adv_interval >> 8;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <lib_aci.h>

/* This value should be set to the starting address of the bootloader on your
* device. On Arduino platforms using the ATMega328(p), 0x7000 is correct.
*/
Expand All @@ -16,7 +18,7 @@
* Returns true if the write was successful, or false
*/
bool bootloader_data_store (aci_state_t *state, uint16_t conn_timeout,
uint16_t adv_interval);
uint16_t adv_interval, uint8_t *pipes, uint8_t n_pipes);

/* bootloader_jump_check is placed in the .init3 section, which means it runs
* before ordinary C code on reset.
Expand All @@ -26,4 +28,4 @@ bool bootloader_data_store (aci_state_t *state, uint16_t conn_timeout,
void bootloader_jump_check(void) __attribute__ ((used, naked, section (".init3")));

/* Perform the jump to bootloader. Returns only if the jump wasn't possible. */
void bootloader_jump(void);
void bootloader_jump(aci_state_t *state);
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Note: Pin #6 on Arduino -> PAIRING CLEAR pin: Connect to 3.3v to clear the pairi
#include "immediate_alert.h"
#include "link_loss.h"
#include <EEPROM.h>
#include <bootloader_setup.h>

/**
Put the nRF8001 setup in the RAM of the nRF8001.
Expand Down Expand Up @@ -299,6 +300,11 @@ void aci_loop()
{
static bool setup_required = false;
static bool bootloader_jump_required = false;
static uint8_t pipes[] = {
PIPE_NORDIC_DEVICE_FIRMWARE_UPDATE_SERVICE_DFU_PACKET_RX,
PIPE_NORDIC_DEVICE_FIRMWARE_UPDATE_SERVICE_DFU_CONTROL_POINT_TX,
PIPE_NORDIC_DEVICE_FIRMWARE_UPDATE_SERVICE_DFU_CONTROL_POINT_RX_ACK_AUTO
};

// We enter the if statement only when there is a ACI event available to be processed
if (lib_aci_event_get(&aci_state, &aci_data))
Expand Down Expand Up @@ -368,7 +374,7 @@ void aci_loop()
}
}

if (!bootloader_data_store(&aci_state, 180, 0x0050))
if (!bootloader_data_store(&aci_state, 180, 0x0050, pipes, sizeof(pipes)))
{
Serial.println(F("Unable to write connection data to EEPROM. Bootloading over BLE will not work"));
}
Expand Down Expand Up @@ -601,12 +607,19 @@ void aci_loop()
}

/* If the bootloader_jump_required flag has been set, we attempt to jump to bootloader.
* The bootloader_jump() function will do a series of checks before jumping.
* We do a series of checks before jumping.
*/
if (bootloader_jump_required)
if (bootloader_jump_required &&
aci_state.data_credit_available == aci_state.data_credit_total &&
lib_aci_is_pipe_available(&aci_state,
PIPE_NORDIC_DEVICE_FIRMWARE_UPDATE_SERVICE_DFU_PACKET_RX) &&
lib_aci_is_pipe_available(&aci_state,
PIPE_NORDIC_DEVICE_FIRMWARE_UPDATE_SERVICE_DFU_CONTROL_POINT_TX) &&
lib_aci_is_pipe_available(&aci_state,
PIPE_NORDIC_DEVICE_FIRMWARE_UPDATE_SERVICE_DFU_CONTROL_POINT_RX_ACK_AUTO))
{
lib_aci_connect(180/* in seconds */, 0x0020 /* advertising interval 20ms*/);
bootloader_jump();
bootloader_jump(&aci_state);
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ The following instructions describe the steps to be made on the Windows PC:
#include <aci_setup.h>
#include "uart_over_ble.h"
#include <avr/io.h>
#include <bootloader_setup.h>

/**
Put the nRF8001 setup in the RAM of the nRF8001.
Expand Down Expand Up @@ -269,6 +270,11 @@ void aci_loop()
{
static bool setup_required = false;
static bool bootloader_jump_required = false;
static uint8_t pipes[] = {
PIPE_NORDIC_DEVICE_FIRMWARE_UPDATE_SERVICE_DFU_PACKET_RX,
PIPE_NORDIC_DEVICE_FIRMWARE_UPDATE_SERVICE_DFU_CONTROL_POINT_TX,
PIPE_NORDIC_DEVICE_FIRMWARE_UPDATE_SERVICE_DFU_CONTROL_POINT_RX_ACK_AUTO
};

// We enter the if statement only when there is a ACI event available to be processed
if (lib_aci_event_get(&aci_state, &aci_data))
Expand Down Expand Up @@ -309,7 +315,7 @@ void aci_loop()
Serial.println(F("Advertising started"));
}

if (!bootloader_data_store(&aci_state, 180, 0x0050))
if (!bootloader_data_store(&aci_state, 180, 0x0050, pipes, sizeof(pipes)))
{
Serial.println(F("Unable to write connection data to EEPROM. Bootloading over BLE will not work"));
}
Expand Down Expand Up @@ -484,11 +490,19 @@ void aci_loop()
}

/* If the bootloader_jump_required flag has been set, we attempt to jump to bootloader.
* The bootloader_jump() function will do a series of checks before jumping.
* We do a series of checks before jumping.
*/
if (bootloader_jump_required)
if (bootloader_jump_required &&
aci_state.data_credit_available == aci_state.data_credit_total &&
lib_aci_is_pipe_available(&aci_state,
PIPE_NORDIC_DEVICE_FIRMWARE_UPDATE_SERVICE_DFU_PACKET_RX) &&
lib_aci_is_pipe_available(&aci_state,
PIPE_NORDIC_DEVICE_FIRMWARE_UPDATE_SERVICE_DFU_CONTROL_POINT_TX) &&
lib_aci_is_pipe_available(&aci_state,
PIPE_NORDIC_DEVICE_FIRMWARE_UPDATE_SERVICE_DFU_CONTROL_POINT_RX_ACK_AUTO))
{
bootloader_jump();
lib_aci_connect(180/* in seconds */, 0x0020 /* advertising interval 20ms*/);
bootloader_jump(&aci_state);
}
}

Expand Down

This file was deleted.

0 comments on commit c5f94ff

Please sign in to comment.