Hi, because we don’t have your test application to reproduce the issue, so we had to guess and made one.
The tca is ~ 500KB and firmware. Loaded from SDcard and put into RAM, with external RAM enabled,
We setup system do IFU every time I press the button. We have done > 20 times so far, and “Could not reproduce”.
This is why we keep asking for the simple application to reproduce the issue.
Below is our application test, you can try to see if you can reproduce. If not then look at your application to see anything else need to be checked. The different here is we load source from SD card, you load the src from network. But this does not matter because they are finally cached into RAM and any one byte different will cause exception. You can open the tca or fimware and modify them to see the error will be thrown.
using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.IO;
using GHIElectronics.TinyCLR.Native;
using GHIElectronics.TinyCLR.Pins;
using GHIElectronics.TinyCLR.Update;
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
namespace IFU_stop_after_few
{
internal class Program
{
const int LED1 = SC20260.GpioPin.PH11; // PH11
const int LDR1 = SC20260.GpioPin.PB7; // PB7;
static GpioPin led1;
static GpioPin ldr1;
static void Main()
{
var controller = GpioController.GetDefault();
led1 = controller.OpenPin(LED1);
ldr1 = controller.OpenPin(LDR1);
led1.SetDriveMode(GpioPinDriveMode.Output);
ldr1.SetDriveMode(GpioPinDriveMode.InputPullUp);
var gpioController = GpioController.GetDefault();
int cnt = 0;
while (ldr1.Read() == GpioPinValue.High)
{
led1.Write(led1.Read() == GpioPinValue.Low ? GpioPinValue.High : GpioPinValue.Low);
var dt = DateTime.Now;
Thread.Sleep(100);
cnt++;
if (cnt % 10 == 0)
{
GC.Collect();
Debug.WriteLine("I am IFU master: " + Memory.ManagedMemory.FreeBytes / 1024);
}
}
DoTestIFU_Memory();
}
static void DoTestIFU_Memory()
{
var media = GHIElectronics.TinyCLR.Devices.Storage.StorageController.FromName(SC20260.StorageController.SdCard);
const int SD_CLOCK_ADDRESS_REG = 0x00000004;
var clock_divider = 2;
// 1: 24 / 1 = 24
// 2: 24 / 2 = 12
// 3: 24 / 3 = 8
// 4: 24 / 4 = 6
// 5: 24 / 5 = 5
// Setting clock need to be before initialize/mount SDcard
Marshal.WriteInt32((IntPtr)SD_CLOCK_ADDRESS_REG, clock_divider);
var drive = FileSystem.Mount(media.Hdc);
DriveInfo driveInfo = new DriveInfo(drive.Name);
Debug.WriteLine("====This is IFU");
Debug.WriteLine("Free: " + driveInfo.TotalFreeSpace);
Debug.WriteLine("TotalSize: " + driveInfo.TotalSize);
Debug.WriteLine("VolumeLabel:" + driveInfo.VolumeLabel);
Debug.WriteLine("RootDirectory: " + driveInfo.RootDirectory);
Debug.WriteLine("DriveFormat: " + driveInfo.DriveFormat);
var appKey = new byte[] { 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 };
var indicatorPin = GpioController.GetDefault().OpenPin(SC20260.GpioPin.PB5);
InFieldUpdate updater;
updater = new InFieldUpdate()
{
ActivityPin = indicatorPin
};
var filestreamApp = new FileStream(@"A:\20_app_internal.tca", FileMode.Open);
var filestreamFw = new FileStream(@"A:\20_firmware.ghi", FileMode.Open);
var idxApp = 0;
var data = new byte[1024];
var countDebug = 0;
while (idxApp < filestreamApp.Length)
{
if (countDebug % 100 == 0)
Debug.WriteLine("Loading application. Idx = 0x" + idxApp.ToString("x8"));
var count = filestreamApp.Read(data, 0, data.Length);
idxApp += updater.LoadApplicationChunk(data, 0, count);
countDebug++;
}
updater.LoadApplicationKey(appKey);
Debug.WriteLine("Verify App.... ");
var ApplicationVersion = updater.VerifyApplication();
Debug.WriteLine("App Version: " + ApplicationVersion);
var idxFirmware = 0;
while (idxFirmware < filestreamFw.Length)
{
if (countDebug % 100 == 0)
Debug.WriteLine("Loading Firmware. Idx = 0x" + idxFirmware.ToString("x8"));
var count = filestreamFw.Read(data, 0, data.Length);
idxFirmware += updater.LoadFirmwareChunk(data, 0, count);
countDebug++;
}
Debug.WriteLine("VerifyFirmware.... ");
var firmwareVersion = updater.VerifyFirmware();
Debug.WriteLine("FW Version: " + firmwareVersion);
Thread.Sleep(1000);
Debug.WriteLine("Flashing.... ");
updater.FlashAndReset();
}
}
}