2

I'm trying to setup the BOD33 for Samd51 MCU in th .ino file as a first thing, even before the #include lines in the .ino

// Define the base address for t_SUPC
#define T_SUPC_BASE 0x40001800UL

// Define the offsets for t_BOD33 and t_STATUS #define T_BOD33_OFFSET 0x10 #define T_STATUS_OFFSET 0x0C

// Set the t_SUPC register volatile uint32_t t_SUPC = (volatile uint32_t )T_SUPC_BASE;

// Set the t_BOD33 register volatile uint32_t t_BOD33 = (volatile uint32_t )(T_SUPC_BASE + T_BOD33_OFFSET);

// Set the t_STATUS register volatile uint32_t t_STATUS = (volatile uint32_t )(T_SUPC_BASE + T_STATUS_OFFSET);

// Clear bit 1 in t_BOD33 and then set it to 1 *t_BOD33 &= ~(1u << 1); // Clear bit 1

// Check bit 0 in t_STATUS and loop while it is 0 while ((*t_STATUS & 0x01) == 0) { }

*t_BOD33 &= (0x7D0300u << 1);

t_BOD33 |= (1u << 1); // Set bit 1 to 1 while ((t_STATUS & 0x01) == 0) { }

while ((*t_STATUS & 0x02) != 0) { }

// Clear bit 1 in t_BOD33 and then set it to 1 t_BOD33 &= ~(1u << 1); // Clear bit 1 while ((t_STATUS & 0x01) == 0) { } t_BOD33 |= (1u << 2); t_BOD33 &= ~(1u << 3); *t_BOD33 |= (1u << 1); // Set bit 1 to 1

but I'm getting a compile problem and VScode is throwing those error, which I have no clue why since I never encountered it before the errors are :

""

0_2.ino:28:10: error: expected constructor, destructor, or type conversion before '&=' token
   28 | *t_BOD33 &= ~(1u << 1); // Clear bit 1
      |          ^~
0_2.ino:31:1: error: expected unqualified-id before 'while'
   31 | while ((*t_STATUS & 0x01) == 0)
      | ^~~~~
0_2.ino:35:10: error: expected constructor, destructor, or type conversion before '&=' token
   35 | *t_BOD33 &= (0x7D0300u << 1);
      |          ^~
0_2.ino:37:10: error: expected constructor, destructor, or type conversion before '|=' token
   37 | *t_BOD33 |= (1u << 1); // Set bit 1 to 1
      |          ^~
0_2.ino:38:1: error: expected unqualified-id before 'while'
   38 | while ((*t_STATUS & 0x01) == 0)
      | ^~~~~
0_2.ino:42:1: error: expected unqualified-id before 'while'
   42 | while ((*t_STATUS & 0x02) != 0)
      | ^~~~~
0_2.ino:47:10: error: expected constructor, destructor, or type conversion before '&=' token
   47 | *t_BOD33 &= ~(1u << 1); // Clear bit 1
      |          ^~
0_2.ino:48:1: error: expected unqualified-id before 'while'
   48 | while ((*t_STATUS & 0x01) == 0)
      | ^~~~~
0_2.ino:51:10: error: expected constructor, destructor, or type conversion before '|=' token
   51 | *t_BOD33 |= (1u << 2);
      |          ^~
0_2.ino:52:10: error: expected constructor, destructor, or type conversion before '&=' token
   52 | *t_BOD33 &= ~(1u << 3);
      |          ^~
0_2.ino:53:10: error: expected constructor, destructor, or type conversion before '|=' token
   53 | *t_BOD33 |= (1u << 1); // Set bit 1 to 1
      |          ^~

thank you in advance.

Dan Neb
  • 21
  • 1

1 Answers1

3

The line where the error starts should go to a function e.g. setup(). You can compile the code below.

// Define the base address for t_SUPC
#define T_SUPC_BASE 0x40001800UL
// Define the offsets for t_BOD33 and t_STATUS
#define T_BOD33_OFFSET 0x10
#define T_STATUS_OFFSET 0x0C

// Set the t_SUPC register volatile uint32_t t_SUPC = (volatile uint32_t )T_SUPC_BASE; // Set the t_BOD33 register volatile uint32_t t_BOD33 = (volatile uint32_t )(T_SUPC_BASE + T_BOD33_OFFSET); // Set the t_STATUS register volatile uint32_t t_STATUS = (volatile uint32_t )(T_SUPC_BASE + T_STATUS_OFFSET);

void setup() { // Clear bit 1 in t_BOD33 and then set it to 1 *t_BOD33 &= ~(1u << 1); // Clear bit 1

// Check bit 0 in t_STATUS and loop while it is 0
while ((*t_STATUS &amp; 0x01) == 0)
{
}

*t_BOD33 &amp;= (0x7D0300u &lt;&lt; 1);

*t_BOD33 |= (1u &lt;&lt; 1); // Set bit 1 to 1
while ((*t_STATUS &amp; 0x01) == 0)
{
}

while ((*t_STATUS &amp; 0x02) != 0)
{
}

// Clear bit 1 in t_BOD33 and then set it to 1
*t_BOD33 &amp;= ~(1u &lt;&lt; 1); // Clear bit 1
while ((*t_STATUS &amp; 0x01) == 0)
{
}
*t_BOD33 |= (1u &lt;&lt; 2);
*t_BOD33 &amp;= ~(1u &lt;&lt; 3);
*t_BOD33 |= (1u &lt;&lt; 1); // Set bit 1 to 1

}

Fahad
  • 544
  • 2
  • 10