Skip to content

Commit

Permalink
Initial class hierarchy for STM32 device support
Browse files Browse the repository at this point in the history
  • Loading branch information
azonenberg committed Jul 10, 2018
1 parent d7a7461 commit 5601a0d
Show file tree
Hide file tree
Showing 15 changed files with 625 additions and 6 deletions.
28 changes: 23 additions & 5 deletions ARMCortexA9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,34 @@ void ARMCortexA9::PrintInfo()

//Pins of interest are MIO bank 1, pins 50/51

//Read PSS_IDCODE
//Read MCTRL

//Read PSS_IDCODE from the zynq
//uint32_t pss_idcode = ReadMemory(0xF8000530);
//uint32_t pss_idcode = m_ap->ReadWord(0xF8000530);
//LogDebug("pss_idcode = %08x\n", pss_idcode);

//Read MCTRL
uint32_t mctrl = ReadMemory(0xF8007080);
LogDebug("mctrl = %08x\n", mctrl);

//Set MIO7 (MIO LED) to output
m_ap->GetDebugPort()->WriteMemory(0xf800071c, 0x00000600); //sclr.MIO_PIN_07
m_ap->GetDebugPort()->WriteMemory(0xe000a204, 0x00000080); //gpio.XGPIOPS_DIRM_OFFSET
m_ap->GetDebugPort()->WriteMemory(0xe000a208, 0x00000080); //gpio.XGPIOPS_OUTEN_OFFSET
for(int i=0; i<10; i++)
{
LogDebug("toggle\n");
m_ap->GetDebugPort()->WriteMemory(0xe000a040, 0x00000080); //gpio.XGPIOPS_DATA_OFFSET
usleep(500 * 1000);
m_ap->GetDebugPort()->WriteMemory(0xe000a040, 0x00000000); //gpio.XGPIOPS_DATA_OFFSET
usleep(500 * 1000);
}

//MIO LED @ MIO7
//MIO inputs at MIO50, 51
//GPIO controller is at 0xe0000000
//Read DIRM to see what
//Read DATA_RO?
//GPIO controller is at 0xe000a000
//Input data (DATA_RO) is at +0x60 - 6c
//

//Read L0_SEL

Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ set(JTAGHAL_SOURCES
MicrochipMicrocontroller.cpp
MicrochipPIC32Device.cpp

STMicroDevice.cpp
STMicroMicrocontroller.cpp
STM32Device.cpp

XilinxDevice.cpp
XilinxCPLD.cpp
XilinxCoolRunnerIIDevice.cpp
Expand Down
1 change: 1 addition & 0 deletions JEDECVendorID_enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ enum JEDECVendorID {
VENDOR_ID_ARM = 0x23b,
VENDOR_ID_MICROCHIP = 0x029,
VENDOR_ID_PHILIPS = 0x015,
VENDOR_ID_STMICRO = 0x020,
VENDOR_ID_XILINX = 0x049,
};

Expand Down
1 change: 1 addition & 0 deletions JEDECVendorIDs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ JEDECVendorID:
VENDOR_ID_ARM: 23B
VENDOR_ID_MICROCHIP: 29
VENDOR_ID_PHILIPS: 15
VENDOR_ID_STMICRO: 20
VENDOR_ID_XILINX: 49
3 changes: 3 additions & 0 deletions JtagDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ JtagDevice* JtagDevice::CreateDevice(unsigned int idcode, JtagInterface* iface,
case VENDOR_ID_MICROCHIP:
return MicrochipDevice::CreateDevice(idcode, iface, pos);

case VENDOR_ID_STMICRO:
return STMicroDevice::CreateDevice(idcode, iface, pos);

case VENDOR_ID_XILINX:
return XilinxDevice::CreateDevice(idcode, iface, pos);

Expand Down
2 changes: 1 addition & 1 deletion MicrochipPIC32Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ struct MicrochipPIC32DeviceInfo
};

/**
@brief A Xilinx CoolRunner-II device
@brief A Microchip PIC32 microcontroller (MX, MZ, MM, etc)
\ingroup libjtaghal
*/
Expand Down
143 changes: 143 additions & 0 deletions STM32Device.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/***********************************************************************************************************************
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2018 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
* following conditions are met: *
* *
* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other materials provided with the distribution. *
* *
* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
***********************************************************************************************************************/

/**
@file
@author Andrew D. Zonenberg
@brief Implementation of STM32Device
*/

#include "jtaghal.h"
#include "STM32Device.h"
#include "STMicroDeviceID_enum.h"
#include "memory.h"

using namespace std;

STM32Device::STM32Device(
unsigned int devid, unsigned int stepping,
unsigned int idcode, JtagInterface* iface, size_t pos)
: STMicroMicrocontroller(devid, stepping, idcode, iface, pos)
, JtagDevice(idcode, iface, pos)
{
m_irlength = 5;

//Look up properties
switch(devid)
{
case STM32F411E:
m_flashKB = 512;
m_ramKB = 128;
break;

default:
m_flashKB = 0;
m_ramKB = 0;
}

if(pos == 0)
{
throw JtagExceptionWrapper(
"STM32Device boundary scan TAP must not be the first device in the scan chain. Where's the ARM DAP?",
"");
}

//Get a pointer to our ARM DAP. This should always be one scan chain position before us.
m_dap = dynamic_cast<ARMDebugPort*>(iface->GetDevice(pos-1));
if(m_dap == NULL)
{
throw JtagExceptionWrapper(
"STM32Device expects an ARM DAP one chain position prior",
"");
}

//What now?
}

/**
@brief Destructor
*/
STM32Device::~STM32Device()
{
}

JtagDevice* STM32Device::CreateDevice(
unsigned int devid, unsigned int stepping, unsigned int idcode, JtagInterface* iface, size_t pos)
{
//TODO: Sanity checks
return new STM32Device(devid, stepping, idcode, iface, pos);
}

string STM32Device::GetDescription()
{
string name = "(unknown STM32";
switch(m_devicetype)
{
case STM32F411E:
name = "STM32F411E";
break;
}

char srev[256];
snprintf(srev, sizeof(srev), "ST %s (%u KB SRAM, %u KB flash, stepping %u)",
name.c_str(),
m_ramKB,
m_flashKB,
m_stepping);

return string(srev);
}

bool STM32Device::HasRPCInterface()
{
return false;
}

bool STM32Device::HasDMAInterface()
{
return false;
}

bool STM32Device::IsProgrammed()
{
LogWarning("STM32Device::IsProgrammed() not implemented\n");
return true;
}

void STM32Device::Erase()
{
LogWarning("STM32Device::Erase() not implemented\n");
}

void STM32Device::Program(FirmwareImage* /*image*/)
{
throw JtagExceptionWrapper(
"Not implemented",
"");
}
103 changes: 103 additions & 0 deletions STM32Device.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/***********************************************************************************************************************
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2018 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
* following conditions are met: *
* *
* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other materials provided with the distribution. *
* *
* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
***********************************************************************************************************************/

/**
@file
@author Andrew D. Zonenberg
@brief Declaration of STM32Device
*/

#ifndef STM32Device_h
#define STM32Device_h

#include "STMicroMicrocontroller.h"

#include <list>
#include <string>

/**
@brief A STM32 microcontroller
\ingroup libjtaghal
*/
class STM32Device
: public STMicroMicrocontroller
, public JtagDevice
{
public:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Construction / destruction
STM32Device(
unsigned int devid,
unsigned int stepping,
unsigned int idcode,
JtagInterface* iface,
size_t pos);
virtual ~STM32Device();

static JtagDevice* CreateDevice(
unsigned int devid,
unsigned int stepping,
unsigned int idcode,
JtagInterface* iface,
size_t pos);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// General device info

virtual std::string GetDescription();

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// MCU stuff

virtual bool IsProgrammed();
virtual void Erase();

virtual void Program(FirmwareImage* image);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// No NoC interfaces

virtual bool HasRPCInterface();
virtual bool HasDMAInterface();

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Helpers for chain manipulation
public:
void SetIR(unsigned char irval)
{ JtagDevice::SetIR(&irval, m_irlength); }

unsigned int m_flashKB;
unsigned int m_ramKB;

protected:
ARMDebugPort* m_dap;
};

#endif
Loading

0 comments on commit 5601a0d

Please sign in to comment.