6 years, 7 months ago.

Can not define own IO protocol

Hi All,

Below is my header define. The environment what I use that include NUCLEO-F746ZG, FTDI232 module, logic analyzer, Tera Term, mbed CLI and STM32 ST-LINK Utility.

swd.h

#include "mbed.h"

class SWD{
public:
	SWD(PinName,PinName,uint32_t);
	void JTAG_to_SWD();
	
private:
     uint32_t delay_loop;
     DigitalInOut *swdio_;
     DigitalOut   *swclk_;
     void SystemDelay();
};

And this is my cpp define.

swd.cpp

#include "mbed.h"
#include "swd.h"
#define Test_Bit(value,x)  (value & (1<<x))  
#define Set_Bit(value,x)   (value |= (1<<x))
#define Clr_Bit(value,x)   (value &= (0<<x))

void SWD::SystemDelay(){
	uint32_t i;
        for( i = 0; i<=delay_loop ; i++);
	}

SWD::SWD(PinName _IO_port, PinName _Clk, uint32_t delay_count){
	DigitalInOut _SWDIO(_IO_port);
	DigitalOut   _SWCKL(_Clk);
	
	swdio_ = &_SWDIO;
	swclk_ = &_SWCKL;
	delay_loop = delay_count;
}

/**********************************
JTAG_to_SWD sequence
**********************************/
void SWD::JTAG_to_SWD(){
	
	 int i;
	 swdio_->output();
	 *swdio_ = 1;
	 
	 //wait_us(2); 
	 SystemDelay();
     for(i=0; i<=55; i++)           
		{                              
			*swclk_ = 1;                  
			SystemDelay();			
			*swclk_ = 0;                 
			SystemDelay();			
	
		}     
		
        /**** issue code ****/
	 /*** If I do not mark here, PG_0 and PG_1 can not work. the swclk will disappear and swdio still work
	  int data = 0x79;
	  for(i=0; i <8; i++)
		{
			*swdio_ = ( Test_Bit(data,7)?1:0);
			data <<= 1;
			SystemDelay();
			*swclk_ = 1;
			SystemDelay();
			*swclk_ = 0;
			SystemDelay();
		}  
	*/
	}

Main code

main.cpp

#include "mbed.h"
#include "swd.h"

Serial pc(PB_10,PB_11);

int main() 
{
    pc.baud(921600);
    
    pc.printf("Get start\n\r");
    pc.printf("Hello World!\n\r");

	
    SWD swd1(PG_0,PG_1,400);

    swd1.JTAG_to_SWD();
		
    pc.printf("End!\n\r");
    return 0;
}

My question is, the code can be done always. Because I can get message "End!". But if I do not mask issue code(in swd.cpp) swclk clocks will disappear and swdio still work. Dose anyone may tell me what trap do I meet?

Mask situation. http://i.imgur.com/UlezQBh.png No mask issue code, swclk gone,swdio still work. http://i.imgur.com/x26kCvR.png

Be the first to answer this question.