Skip to content

Commit afd9b18

Browse files
authored
Merge pull request #1481 from cr1901/msp430-misopt-fix
msp430x5xx: Add fix for possible bug in msp430-elf-gcc 9.3.0.
2 parents b6a8d0d + 731ac3d commit afd9b18

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/portable/ti/msp430x5xx/dcd_msp430x5xx.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,18 @@ void dcd_int_handler(uint8_t rhport)
631631
handle_setup_packet();
632632
}
633633

634-
uint16_t curr_vector = USBVECINT;
634+
// Workaround possible bug in MSP430 GCC 9.3.0 where volatile variable
635+
// USBVECINT is read from twice when only once is intended. The second
636+
// (garbage) read seems to be triggered by certain switch statement
637+
// configurations.
638+
uint16_t curr_vector;
639+
#if __GNUC__ > 9 || (__GNUC__ == 9 && __GNUC_MINOR__ > 2)
640+
asm volatile ("mov %1, %0"
641+
: "=r" (curr_vector)
642+
: "m" (USBVECINT));
643+
#else
644+
curr_vector = USBVECINT;
645+
#endif
635646

636647
switch(curr_vector)
637648
{

0 commit comments

Comments
 (0)