Ardiuno DUE not work with example on software

Hi,

I have bought 1 board ardiuno DUE and learned more from it.
I used examples on the IDE (version 1.5.6-r2 BETA) to run it, first time it run very good and have no issue about hardware or software.

I run my application about internal flash memory (write, read, erase) for a long time by using the IDE (studio) with my style as following example:

#include <stdio.h>
#include <string.h>
#include "sam.h"

////////////////////////////////////////debug code area///////////////////////////////////////////////////////////////////////
/* Clock Definitions */
#define BAUD(b) ((SystemCoreClock + 8*b)/(16*b))

void SER_Init (unsigned long baud_rate) {

  PMC->PMC_WPMR = 0x504D4300;             /* Disable write protect            */

  PMC->PMC_PCER0 = ((1UL << ID_PIOA) |    /* enable PIOA clock                */
                    (1UL << ID_UART)  );  /* enable UART clock                */

  /* Configure UART for 115200 baud. */
  PIOA->PIO_IDR    =
    PIOA->PIO_PUDR   =
      PIOA->PIO_PDR    =  (PIO_PA8A_URXD | PIO_PA9A_UTXD);
  PIOA->PIO_ABSR  &= ~(PIO_PA8A_URXD | PIO_PA9A_UTXD);

  UART->UART_CR    = UART_CR_RSTRX   | UART_CR_RSTTX;
  UART->UART_IDR   = 0xFFFFFFFF;
  UART->UART_BRGR  = BAUD(baud_rate);
  UART->UART_MR    = (0x4 <<  9);         /* (UART) No Parity                 */
  UART->UART_PTCR  = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS;
  UART->UART_CR    = UART_CR_RXEN     | UART_CR_TXEN;
  PMC->PMC_WPMR = 0x504D4301;             /* Enable write protect             */
}

/*----------------------------------------------------------------------------
  Write character to Serial Port
 *----------------------------------------------------------------------------*/
int SER_PutChar (int c) {

  while (!(UART->UART_SR  & UART_SR_TXRDY));
  UART->UART_THR = c;
  return (c);
}

/*----------------------------------------------------------------------------
  Read character from Serial Port   (blocking read)
 *----------------------------------------------------------------------------*/
int SER_GetChar (void) {

  while (!(UART->UART_SR  & UART_SR_RXRDY));
  return (UART->UART_RHR);
}

int main(void){

  WDT->WDT_MR = WDT_MR_WDDIS; //config for watchdog timer
  
  SER_Init(9600);

  while(1){
      SER_PutChar(SER_GetChar());
  };
}

All of above code has written on IDE version 1.5.6-r2 BETA and run fine on the board.

But recently, I come back with coding as your style also on IDE version 1.5.6-r2 BETA, the board did not work? all of example codes as followings are same issue

void setup() {
  Serial.begin(9600);
}

void loop() {
  int sensorValue = analogRead(A0);
  float voltage = sensorValue * (5.0 / 1023.0);
  Serial.println(voltage);
}

After that, I come back with my code, the board work fine.
Currently, It have just run with my code (as my style) without all of example codes from IDE

Could you please tell me why have this issue?
How to fix it?

Thanks,
GiaoLong from VietNam

Hi GiaoLong,

It's a bit difficult to help you if we don't know what errors you are getting. Could you post the verbose output during the compilation of the code that doesn't work? Go to File -> Preferences and do click on compilation. Regards!

p

Hi Palliser,

The log file which you want as attached file

And here is capture of my code in IDE:

My issue is: the board did not work again with any example code from IDE after I used my code.

nclude <stdio.h>
#include <string.h>
#include "sam.h"

////////////////////////////////////////debug code area///////////////////////////////////////////////////////////////////////
/* Clock Definitions */
#define BAUD(b) ((SystemCoreClock + 8*b)/(16*b))

void SER_Init (unsigned long baud_rate) {

  PMC->PMC_WPMR = 0x504D4300;             /* Disable write protect            */

  PMC->PMC_PCER0 = ((1UL << ID_PIOA) |    /* enable PIOA clock                */
                    (1UL << ID_UART)  );  /* enable UART clock                */

  /* Configure UART for 115200 baud. */
  PIOA->PIO_IDR    =
    PIOA->PIO_PUDR   =
      PIOA->PIO_PDR    =  (PIO_PA8A_URXD | PIO_PA9A_UTXD);
  PIOA->PIO_ABSR  &= ~(PIO_PA8A_URXD | PIO_PA9A_UTXD);

  UART->UART_CR    = UART_CR_RSTRX   | UART_CR_RSTTX;
  UART->UART_IDR   = 0xFFFFFFFF;
  UART->UART_BRGR  = BAUD(baud_rate);
  UART->UART_MR    = (0x4 <<  9);         /* (UART) No Parity                 */
  UART->UART_PTCR  = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS;
  UART->UART_CR    = UART_CR_RXEN     | UART_CR_TXEN;
  PMC->PMC_WPMR = 0x504D4301;             /* Enable write protect             */
}

/*----------------------------------------------------------------------------
  Write character to Serial Port
 *----------------------------------------------------------------------------*/
int SER_PutChar (int c) {

  while (!(UART->UART_SR  & UART_SR_TXRDY));
  UART->UART_THR = c;
  return (c);
}

/*----------------------------------------------------------------------------
  Read character from Serial Port   (blocking read)
 *----------------------------------------------------------------------------*/
int SER_GetChar (void) {

  while (!(UART->UART_SR  & UART_SR_RXRDY));
  return (UART->UART_RHR);
}

int main(void){

  WDT->WDT_MR = WDT_MR_WDDIS; //config for watchdog timer
  
  SER_Init(9600);

  while(1){
      SER_PutChar(SER_GetChar());
  };
}

log_file.txt (35.5 KB)

Did you try with a non beta Arduino IDE? a beta software might be very buggy sometimes

GiaoLong,

Are you getting errors when you are trying to upload your sketch? Your attached file only shows the compilation of your code (verify). Try pressing CRTL+R.

p

Thanks for your answer eugenio412,

But I can not use another IDE version, because Ardiuno DUE board just been supported by this version.
Could you please help me find another?

Palliser:
GiaoLong,

Are you getting errors when you are trying to upload your sketch? Your attached file only shows the compilation of your code (verify). Try pressing CRTL+R.

p

Thanks for your feedback Palliser, I can not show to you about error, because, all of things are fine: verify code, upload code to board. But just 1 problem: software does not work with board.

log file of upload as attached file.

May be my code impact on internal flash of the chip, so start address of flash is modified??
Unfortunately, the start address of flash used in startup code of IDE has been erased when my code run?

logfile_upload.txt (10.9 KB)

GiaoLong:
Thanks for your answer eugenio412,

But I can not use another IDE version, because Ardiuno DUE board just been supported by this version.
Could you please help me find another?

actually i have a Due and I use the last IDE available, the 1.6.4, i'm sure it's working, try with that

eugenio412:
actually i have a Due and I use the last IDE available, the 1.6.4, i'm sure it's working, try with that

Thanks for your suggestion, I will test again with it. and then feedback here.

eugenio412:
actually i have a Due and I use the last IDE available, the 1.6.4, i'm sure it's working, try with that

HI eugenio412,

How are you get Ardiuno DUE board from IDE 1.6.4?
I dont see it on this.

Thanks,
GiaoLong

GiaoLong:
How are you get Ardiuno DUE board from IDE 1.6.4?
I dont see it on this.

You need to use the Tools->Boards Manager in order to load the Arduino Due package.

p

Hi Palliser,

I have tested it with IDE 1.6.4
But nothing is not big change,
I think when i work with flash memory code, it make change internal memory address,

Unfortunately, commands of IDE (when using example code from IDE) have used these memory areas,
but it can not write, so it can not run.

Do you think so?

regard,
Vui Nguyen

Hi Vui,

In the past, when I had issues with the flash memory (corrupted or locked) of the Due, the only way to solved them was using official tools like a hardware probe (an ICE like SAMICE or Segger) together with jlink commander and Atmel Studio 6. May be it is not related to your problem but I have learned that the gpnvm bit should stays in boot from flash instead of booting from rom, which is needed for arduino/bossac. Good luck.

p