Skip to content

Commit 797a9b5

Browse files
committed
boards/arm64/bcm2711/raspberrypi-4b: Fix GPIO
* Fix GPIO unspecified behavior on some GPIO ports. * Fix GPIO undefined behavior caused by uncleared set or reset bits. Signed-off-by: Saurav Pal <resyfer.dev@gmail.com>
1 parent a09dfcd commit 797a9b5

2 files changed

Lines changed: 8 additions & 13 deletions

File tree

arch/arm64/include/bcm2711/chip.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575

7676
#if defined(CONFIG_RPI4B_RAM_4GB) || defined(CONFIG_RPI4B_RAM_8GB)
7777
#define CONFIG_RAMBANK1_SIZE GB(4) - MB(64)
78+
#elif defined(CONFIG_RPI4B_RAM_2GB)
79+
#define CONFIG_RAMBANK1_SIZE GB(2) - MB(64)
7880
#endif /* defined(CONFIG_RPI4B_RAM_4GB) || defined(CONFIG_RPI4B_RAM_8GB) */
7981

8082
/* The 8GB version begins to use a second RAM bank.

arch/arm64/src/bcm2711/bcm2711_gpio.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -380,22 +380,22 @@ void bcm2711_gpio_set_func(uint32_t gpio, enum bcm2711_gpio_func_e func)
380380
value = (g_fsel_map[func] << ((gpio - 10) * 3));
381381
modreg32(value, value, BCM_GPIO_GPFSEL1);
382382
}
383-
else if (gpio <= 29 && gpio > 20)
383+
else if (gpio <= 29 && gpio > 19)
384384
{
385385
value = (g_fsel_map[func] << ((gpio - 20) * 3));
386386
modreg32(value, value, BCM_GPIO_GPFSEL2);
387387
}
388-
else if (gpio <= 39 && gpio > 30)
388+
else if (gpio <= 39 && gpio > 29)
389389
{
390390
value = (g_fsel_map[func] << ((gpio - 30) * 3));
391391
modreg32(value, value, BCM_GPIO_GPFSEL3);
392392
}
393-
else if (gpio <= 49 && gpio > 40)
393+
else if (gpio <= 49 && gpio > 39)
394394
{
395395
value = (g_fsel_map[func] << ((gpio - 40) * 3));
396396
modreg32(value, value, BCM_GPIO_GPFSEL4);
397397
}
398-
else if (gpio <= 57 && gpio > 50)
398+
else if (gpio <= 57 && gpio > 49)
399399
{
400400
value = (g_fsel_map[func] << ((gpio - 50) * 3));
401401
modreg32(value, value, BCM_GPIO_GPFSEL5);
@@ -418,15 +418,8 @@ void bcm2711_gpio_set_func(uint32_t gpio, enum bcm2711_gpio_func_e func)
418418
void bcm2711_gpio_pin_set(uint32_t gpio, bool set)
419419
{
420420
DEBUGASSERT(gpio < BCM_GPIO_NUM);
421-
422-
if (set)
423-
{
424-
bcm2711_gpio_help_set(gpio, BCM_GPIO_GPSET0, BCM_GPIO_GPSET0, true);
425-
}
426-
else
427-
{
428-
bcm2711_gpio_help_set(gpio, BCM_GPIO_GPCLR0, BCM_GPIO_GPCLR0, true);
429-
}
421+
bcm2711_gpio_help_set(gpio, BCM_GPIO_GPSET0, BCM_GPIO_GPSET1, set);
422+
bcm2711_gpio_help_set(gpio, BCM_GPIO_GPCLR0, BCM_GPIO_GPCLR1, !set);
430423
}
431424

432425
/****************************************************************************

0 commit comments

Comments
 (0)