Porting Mega code to T3_2 and softReset

Status
Not open for further replies.

MatrixRat

Well-known member
Hi folks and thanks for reading.

The device has three buttons and two pots and a led display as a user interface and has the capability of being controlled remotely so therefore the code has two first-run compile options which are responsible for loading device parameters into EEprom.

First-run with hardware interface the code uploads, the board reboots then the user holds down the three buttons and press/releases Reset (on the Mega) to initialise the device, LEDs blink and we're in. Note that if power is cycled after upload then initialisation fails

First-run for remote control softReset is called.

I've connected a button to the reset pad of the T3.2 and after some code shuffling have got the device working on it however a block of data ain't finding it's way into EEprom.

The device code is a rabbithole in itself so for starters, looking at softReset.h

Code:
// Copyright (C) 2012 by Victor Aprea <victor.aprea@wickeddevice.com>

#ifndef _SOFT_RESTART_H
#define _SOFT_RESTART_H

#include <avr/wdt.h>

#define soft_restart()        \
do                          \
{                           \
    wdt_enable(WDTO_15MS);  \
    for(;;)                 \
    {                       \
    }                       \
} while(0)

#endif

And softReset.cpp

Code:
// Copyright (C) 2012 by Victor Aprea <victor.aprea@wickeddevice.com>
#include <avr/wdt.h>

void wdt_init(void) __attribute__((naked)) __attribute__((section(".init3")));
// Function Implementation
void wdt_init(void)
{
    MCUSR = 0;
    wdt_disable();

    return;
}

After digging in this forum found:-

Code:
#define RESTART_ADDR       0xE000ED0C
#define READ_RESTART()     (*(volatile uint32_t *)RESTART_ADDR)
#define WRITE_RESTART(val) ((*(volatile uint32_t *)RESTART_ADDR) = (val))

void softReset()
{
  // 0000101111110100000000000000100
  // Assert [2]SYSRESETREQ
  WRITE_RESTART(0x5FA0004);
}

And pasted it strategically near the top of the first page of code and when performing first-run for remote control seems to work in that the board reboots but EEprom is not fully set up.

First run button procedure for hardware control produces same outcome.

Headscratching.

The reset button on the T3.2 and the Teensy code above seem to produce the same outcome.

The reset button on the Mega and it's softReset code above set up EEprom correctly.

Questions:-

Does the reset button the Teensy do different stuff than on the Mega? Like are we doing a "cold" restart when we need to a "warm" restart?

Does the last code example (above) cause T3.2 to "warm" or "cold" restart? Then if "cold", how to do "Warm"?


Gratitude in advance for enlightenment.
 
Status
Not open for further replies.
Back
Top