Cerb40: MF4.3 Pins Mystery initialization

Hello
I use for more months Cerb40 with MF4.2 and GHI SDK 2014-R1 without problem for Analog and Digital inputs, all run very well.
My MF4.2 code is here:

     m_pinADC0 = new AnalogInput(Cpu.AnalogChannel.ANALOG_3);  // Pin PC0
m_pinADC1 = new AnalogInput(Cpu.AnalogChannel.ANALOG_4);  // Pin PC1
m_pinADC2 = new AnalogInput(Cpu.AnalogChannel.ANALOG_6);  // Pin PC2
m_pinADC3 = new AnalogInput(Cpu.AnalogChannel.ANALOG_7);  // Pin PC3
m_pinIN0 = new InputPort(GHI.Hardware.FEZCerb.Pin.PA0, true, Port.ResistorMode.Disabled);  // Pin PA0
m_pinIN1 = new InputPort(GHI.Hardware.FEZCerb.Pin.PA1, true, Port.ResistorMode.Disabled);  // Pin PA1
m_pinIN2 = new InputPort(GHI.Hardware.FEZCerb.Pin.PA2, true, Port.ResistorMode.Disabled);  // Pin PA2
m_pinIN3 = new InputPort(GHI.Hardware.FEZCerb.Pin.PA3, true, Port.ResistorMode.Disabled);  // Pin PA3
m_pinIN4 = new InputPort(GHI.Hardware.FEZCerb.Pin.PB6, true, Port.ResistorMode.Disabled);  // Pin PB6
m_pinIN5 = new InputPort(GHI.Hardware.FEZCerb.Pin.PB7, true, Port.ResistorMode.Disabled);  // Pin PB7
m_pinIN6 = new InputPort(GHI.Hardware.FEZCerb.Pin.PB8, true, Port.ResistorMode.Disabled);  // Pin PB8
m_pinIN7 = new InputPort(GHI.Hardware.FEZCerb.Pin.PC12, true, Port.ResistorMode.Disabled);  // Pin PC12

Now I have migrate on MF4.3 and GHI SDK 2014-R5.
I have just adapted my code with new GHI namespaces.
Here my MF4.3 code:

m_pinADC0 = new AnalogInput(Cpu.AnalogChannel.ANALOG_3);  // Pin PC0
m_pinADC1 = new AnalogInput(Cpu.AnalogChannel.ANALOG_4);  // Pin PC1
m_pinADC2 = new AnalogInput(Cpu.AnalogChannel.ANALOG_6);  // Pin PC2
m_pinADC3 = new AnalogInput(Cpu.AnalogChannel.ANALOG_7);  // Pin PC3
// New syntax for MF4.3 and GHI SDK 2014-R5
m_pinIN0 = new InputPort(GHI.Pins.Generic.GetPin('A', 0), true, Port.ResistorMode.Disabled);  // Pin PA0
m_pinIN1 = new InputPort(GHI.Pins.Generic.GetPin('A', 1), true, Port.ResistorMode.Disabled);  // Pin PA1
m_pinIN2 = new InputPort(GHI.Pins.Generic.GetPin('A', 2), true, Port.ResistorMode.Disabled);  // Pin PA2
m_pinIN3 = new InputPort(GHI.Pins.Generic.GetPin('A', 3), true, Port.ResistorMode.Disabled);  // Pin PA3
m_pinIN4 = new InputPort(GHI.Pins.Generic.GetPin('B', 6), true, Port.ResistorMode.Disabled);  // Pin PB6
m_pinIN5 = new InputPort(GHI.Pins.Generic.GetPin('B', 7), true, Port.ResistorMode.Disabled);  // Pin PB7
m_pinIN6 = new InputPort(GHI.Pins.Generic.GetPin('B', 8), true, Port.ResistorMode.Disabled);  // Pin PB8
m_pinIN7 = new InputPort(GHI.Pins.Generic.GetPin('C',12), true, Port.ResistorMode.Disabled);  // Pin PC12

At the execution, I have an exception ‘System.InvalidOperationException’ in Microsoft.SPOT.Hardware.dll" for the lines:
m_pinADC2 = new AnalogInput(Cpu.AnalogChannel.ANALOG_6); // Pin PC2
and
m_pinIN2 = new InputPort(GHI.Pins.Generic.GetPin(‘A’, 2), true, Port.ResistorMode.Disabled); // Pin PA2
All other lines are corrects.
I do not understand why I have theses errors.
Reference : https://www.ghielectronics.com/docs/44/fez-cerb40-developer

@ ChristianJack - I was not able to reproduce that issue. All of those inputs were created fine and I was able to read from two problem ones you mentioned. Is there any other code in your project?

@ John - Here my initialization code, there is no special code - I will update another Cerb40 and try with it.

using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using System.IO.Ports;
using System.Text;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Microsoft.SPOT.Hardware;
using GHI.Pins;

namespace Cerb40Scope
{
    public partial class Program
    {
        /// <summary>Serial port to communicate with the PC</summary>
        private SerialPort m_serialPort;

        /// <summary>Analogic inputs ports</summary>
        private AnalogInput m_pinADC0;  
        private AnalogInput m_pinADC1;
        private AnalogInput m_pinADC2;
        private AnalogInput m_pinADC3;

        /// <summary>Digital inputs ports</summary>
        private InputPort m_pinIN0;
        private InputPort m_pinIN1;
        private InputPort m_pinIN2;
        private InputPort m_pinIN3;
        private InputPort m_pinIN4;
        private InputPort m_pinIN5;
        private InputPort m_pinIN6;
        private InputPort m_pinIN7;

        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            m_pinADC0 = new AnalogInput(Cpu.AnalogChannel.ANALOG_3);  // Pin PC0
            m_pinADC1 = new AnalogInput(Cpu.AnalogChannel.ANALOG_4);  // Pin PC1
            m_pinADC2 = new AnalogInput(Cpu.AnalogChannel.ANALOG_6);  // Pin PC2  problem
            m_pinADC3 = new AnalogInput(Cpu.AnalogChannel.ANALOG_7);  // Pin PC3
  
            // New syntax for MF4.3 SDK 2014-R4
            m_pinIN0 = new InputPort(GHI.Pins.Generic.GetPin('A', 0), true, Port.ResistorMode.Disabled);  // Pin PA0
            m_pinIN1 = new InputPort(GHI.Pins.Generic.GetPin('A', 1), true, Port.ResistorMode.Disabled);  // Pin PA1
            m_pinIN2 = new InputPort(GHI.Pins.Generic.GetPin('A', 2), true, Port.ResistorMode.Disabled);  // Pin PA2 problem
            m_pinIN3 = new InputPort(GHI.Pins.Generic.GetPin('A', 3), true, Port.ResistorMode.Disabled);  // Pin PA3
            m_pinIN4 = new InputPort(GHI.Pins.Generic.GetPin('B', 6), true, Port.ResistorMode.Disabled);  // Pin PB6
            m_pinIN5 = new InputPort(GHI.Pins.Generic.GetPin('B', 7), true, Port.ResistorMode.Disabled);  // Pin PB7
            m_pinIN6 = new InputPort(GHI.Pins.Generic.GetPin('B', 8), true, Port.ResistorMode.Disabled);  // Pin PB8
            m_pinIN7 = new InputPort(GHI.Pins.Generic.GetPin('C',12), true, Port.ResistorMode.Disabled);  // Pin PC12
            // Remark : PB5 is high by default

            m_serialPort = new SerialPort("COM3", 57600);
            m_serialPort.DataReceived += new SerialDataReceivedEventHandler(On_Serial_DataReceived);
            m_serialPort.Open();
        }

@ ChristianJack - It looks like you are using Gadgeteer. What mainboard are you using? The Cerb40 is not a Gadgeteer mainboard.

@ John - I have updated a second Cerb40 to GHI SDK 2014-R5 (Loader and Firmware).
I have the same problem on the initialization of PC2 pin as Analog input and PA2 pin as digital input.

Une exception non gérée du type ‘System.InvalidOperationException’ s’est produite dans Microsoft.SPOT.Hardware.dll

@ ChristianJack - Do you have anything connected to any pins on the Cerb40? I’ve tried a second one and still have not been able to reproduce the issue.

@ John - I have no connection on the Cerb40.
I have made a breakboard to update the Cerb40 with only the supply (regulator 3,3v from external supply 9v), reset button and loader switch.

I have used this breakboard previously to update more times the Cerb40.

I use a new computer with Windows7 SP1 and VS2012 Premium French. MF4.3 and SDK 2014-R5.
Previously I use XP computer with VS2010 Premium French, MF4.2 and SDK 2014-R1.
I have opened my running MF4.2 project under VS2012 and updated to MF4.3 (change GHI namespaces and reference to MF4.3) and run debug to test.

My Cerb40 are version 1 not 2.

@ John - I have make a new project MF4.3 from scratch on VS2012, add references and my lines of code. I have the same initialization errors for PC2 and PA2.

I have downgraded one of my Cerb40 to MF4.2 and SDK 2014-R1
Loader : 4.2.6.1
Firmware : 4.2.6.2

With my Cerb40 on my breakboard, I have launched my MF4.2 software.
All the pins initialization are corrects, no initialization errors for pins PC2 and PA2. I retrieve the previous state.

The problem comes with the migration to MF4.3

@ ChristianJack - I am also using a Cerb40, not Cerb40 II. I tried again and it still worked. Can you try this in a non Gadgeteer project? The Cerb40 is not a Gadgeteer mainboard.

@ John - I made a new MF4.3 project (Not a Gadgeteer project) and now the pins initialization are OK.

Last year, with MF4.2, I have made 3 Gadgeteer projects for the Cerb40 and all my programs run very well.
It was by chance and luck :slight_smile:
Thank you very much John for yor help.

@ ChristianJack - Happy to help, glad you got it working.