Hello everyone, I’m playing with the new nano R4 board and I have a doubt about the use of Data Synchronization Barrier of the Arm Cortex-M4 processor … If I want to blink RGB leds with direct register operations:
| LEDR (P409) | LEDG (P411) | LEDB (P410) | Color |
|---|---|---|---|
| 0 | 1 | 1 | Red |
| 1 | 0 | 1 | Green |
| 1 | 1 | 0 | Blue |
It is enough using __DSB() or asm volatile("dsb") only one time inside the setup function like this:
#define PORTBASE 0x40040000 /* Port Base */
#define P400PFS 0x0900 // Port 4 Pin Function Select Register
#define PFS_P409PFS ((volatile unsigned int *)(PORTBASE + P400PFS + ( 9 * 4))) // LEDR
#define PFS_P410PFS ((volatile unsigned int *)(PORTBASE + P400PFS + (10 * 4))) // LEDB
#define PFS_P411PFS ((volatile unsigned int *)(PORTBASE + P400PFS + (11 * 4))) // LEDG
#define PFS_P409PFS_BY ((volatile unsigned char *)(PORTBASE + 0x0903 + (9 * 4))) // LEDR
#define PFS_P410PFS_BY ((volatile unsigned char *)(PORTBASE + 0x0903 + (10 * 4))) // LEDB
#define PFS_P411PFS_BY ((volatile unsigned char *)(PORTBASE + 0x0903 + (11 * 4))) // LEDG
void setup() {
__DSB();
}
void loop() {
// blink RED led
*PFS_P409PFS_BY = 0x04;
delay(1000);
*PFS_P409PFS_BY = 0x05;
delay(1000);
}
Or I need to call __DSB() instruction also inside the loop function?