int main(void)
{
__IO uint8_t tmp8;
__IO uint32_t tmp32;
M0P_SYSCTRL->PERICLKEN0 = 0xffffffff;
M0P_SYSCTRL->PERICLKEN1 = 0xffffffff;
M0P_GPIOA->ADS = 0x00;
Swd_Bus_Reset();
while( 1 )
{
// Swd_Bus_Reset();
//
// Swd_Bus_SendByte( 0x9E );
// Swd_Bus_SendByte( 0xE7 );
// Swd_Bus_SendByte( 0x00 );
// Swd_Bus_SendByte( 0x00 );
//
Swd_Bus_Reset();
Swd_Bus_SendByte( 0x00 );
//--------------------------------------------------
//Read DP.IDR
Swd_Bus_SendByte( 0xa5 );
Swd_Bus_Turn();
tmp8 = Swd_Bus_RecvAck();
tmp32 = Swd_Bus_RecvWordAndParity();
Swd_Bus_Turn();
Swd_Bus_SendByte( 0x00 );
//--------------------------------------------------
//write ctrl/state
Swd_Bus_SendByte( 0xa9 );
Swd_Bus_Turn();
tmp8 = Swd_Bus_RecvAck();
Swd_Bus_Turn();
Swd_Bus_SendWordAndParity( 0x50000000 );
Swd_Bus_SendByte( 0x00 );
//--------------------------------------------------
//Read AP.IDR
Swd_Bus_SendByte( 0xb1 ); //write select AP BANK - 0F
Swd_Bus_Turn();
tmp8 = Swd_Bus_RecvAck();
Swd_Bus_Turn();
Swd_Bus_SendWordAndParity( 0x000000f0 );
Swd_Bus_SendByte( 0x00 );
Swd_Bus_SendByte( 0x9f ); //read DRW dummy
Swd_Bus_Turn();
tmp8 = Swd_Bus_RecvAck();
tmp32 = Swd_Bus_RecvWordAndParity();
Swd_Bus_Turn();
Swd_Bus_SendByte( 0x00 );
Swd_Bus_SendByte( 0xbd ); //read rdbuf
Swd_Bus_Turn();
tmp8 = Swd_Bus_RecvAck();
tmp32 = Swd_Bus_RecvWordAndParity();
Swd_Bus_Turn();
Swd_Bus_SendByte( 0x00 );
//--------------------------------------------------
//SET AP 位宽为32位
Swd_Bus_SendByte( 0xb1 ); //write select AP BANK - 00
Swd_Bus_Turn();
tmp8 = Swd_Bus_RecvAck();
Swd_Bus_Turn();
Swd_Bus_SendWordAndParity( 0x00000000 );
Swd_Bus_SendByte( 0x00 );
Swd_Bus_SendByte( 0xA3 ); //write CSW -
Swd_Bus_Turn();
tmp8 = Swd_Bus_RecvAck();
Swd_Bus_Turn();
Swd_Bus_SendWordAndParity( 0x23000002 ); //32bit 位宽,地址不自动增加
Swd_Bus_SendByte( 0x00 );
//--------------------------------------------------
//stop the cpu
Swd_Bus_SendByte( 0x8B ); //write TAR
Swd_Bus_Turn();
tmp8 = Swd_Bus_RecvAck();
Swd_Bus_Turn();
Swd_Bus_SendWordAndParity( 0xE000EDF0 ); //
Swd_Bus_SendByte( 0x00 );
Swd_Bus_SendByte( 0xBB ); //WRITE DRW
Swd_Bus_Turn();
tmp8 = Swd_Bus_RecvAck();
Swd_Bus_Turn();
Swd_Bus_SendWordAndParity( 0xA05F0303 );
Swd_Bus_SendByte( 0x00 );
//--------------------------------------------------
//Read User Memery @ 0x00100d90
Swd_Bus_SendByte( 0x8B ); //write TAR
Swd_Bus_Turn();
tmp8 = Swd_Bus_RecvAck();
Swd_Bus_Turn();
Swd_Bus_SendWordAndParity( 0x00100d90 );
Swd_Bus_SendByte( 0x00 );
Swd_Bus_SendByte( 0x9f ); //read DRW
Swd_Bus_Turn();
tmp8 = Swd_Bus_RecvAck();
tmp32 = Swd_Bus_RecvWordAndParity(); //dummy
Swd_Bus_Turn();
Swd_Bus_SendByte( 0x00 );
Swd_Bus_SendByte( 0xbd ); //read rdbuf
Swd_Bus_Turn();
tmp8 = Swd_Bus_RecvAck();
tmp32 = Swd_Bus_RecvWordAndParity(); //read
Swd_Bus_Turn();
Swd_Bus_SendByte( 0x00 );
//--------------------------------
//write and read reg @ 0x40020F04
Swd_Bus_SendByte( 0x8B ); //write TAR
Swd_Bus_Turn();
tmp8 = Swd_Bus_RecvAck();
Swd_Bus_Turn();
Swd_Bus_SendWordAndParity( 0x40020F04 );
Swd_Bus_SendByte( 0x00 );
Swd_Bus_SendByte( 0xBB ); //WRITE DRW
Swd_Bus_Turn();
tmp8 = Swd_Bus_RecvAck();
Swd_Bus_Turn();
Swd_Bus_SendWordAndParity( 0xffffffff );
Swd_Bus_SendByte( 0x00 );
Swd_Bus_SendByte( 0x9f ); //read DRW dummy
Swd_Bus_Turn();
tmp8 = Swd_Bus_RecvAck();
tmp32 = Swd_Bus_RecvWordAndParity();
Swd_Bus_Turn();
Swd_Bus_SendByte( 0x00 );
Swd_Bus_SendByte( 0xbd ); //read rdbuf
Swd_Bus_Turn();
tmp8 = Swd_Bus_RecvAck();
tmp32 = Swd_Bus_RecvWordAndParity();
Swd_Bus_Turn();
Swd_Bus_SendByte( 0x00 );
while( 1 );
}
}