You seem to have code that was written for an AVR micro like an UNO or a Mega and want it to run as is on a SAM board like a Due. Ain't gonna happen. You need to scrap this whole code and look for something specific to the Due.
How does that make you incapable of using a basic search engine? Google "generate square wave from Due" or something like that. I'm positive that this has been solved several times over. Come back when you have some specific question that is better than, " I've got nothing, I've done nothing, you explain the whole entire thing to me here."
No. This isn't a free code writing service. This is where you get help fixing the code you write. If you want someone to write it for you then there are folks that will do that for hire in the Gigs and Collaborations section. Just be very very specific about the requirements and how much you are willing to pay.
The following code uses the Due's PWM controller to output a 2MHz square wave on pin DAC1:
// Output a 2MHz PWM waveform at a resolution of 5-bits on pin DAC1 (PWML0)
void setup() {
// PWM Set-up on pin: DAC1
REG_PMC_PCER1 |= PMC_PCER1_PID36; // Enable PWM
REG_PIOB_ABSR |= PIO_ABSR_P16; // Set PWM pin perhipheral type A or B, in this case B
REG_PIOB_PDR |= PIO_PDR_P16; // Set PWM pin to an output
REG_PWM_CLK = PWM_CLK_PREA(0) | PWM_CLK_DIVA(1); // Set the PWM clock rate to 84MHz (84MHz/1)
REG_PWM_CMR0 = PWM_CMR_CPRE_CLKA; // Enable single slope PWM and set the clock source as CLKA
REG_PWM_CPRD0 = 42; // Set the PWM frequency 84MHz/2MHz = 42
REG_PWM_CDTY0 = 21; // Set the PWM duty cycle 50%
REG_PWM_ENA = PWM_ENA_CHID0; // Enable the PWM channel
}
void loop() {}
If you need to alter the duty cycle to a value other than 50% during operation then change the REG_PWM_CDTYUPD0 (duty cycle update register for channel 0) to a value between 0 and 42, (the value in the period register (REG_PWM_CPRD0).