Skip to content

Commit 13be96c

Browse files
ArcaneNibbledlech
authored andcommitted
pbio/drv/pwm/pwm_ev3: Use linker script to define shared memory
1 parent 091af20 commit 13be96c

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

lib/pbio/drv/pwm/pwm_ev3.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,19 @@
2424
#include "../../drv/pwm/pwm_ev3.h"
2525
#include "../../drv/gpio/gpio_ev3.h"
2626

27-
// This is the second 64K of the on-chip RAM
28-
#define PRU1_SHARED_RAM_ADDR 0x80010000
29-
3027
// This needs to match the interface expected by the PRU firmware
3128
typedef struct shared_ram {
3229
uint8_t pwms[PBDRV_PWM_EV3_NUM_CHANNELS];
3330
} shared_ram;
34-
static volatile shared_ram *const pru1_shared_ram = (volatile shared_ram *)PRU1_SHARED_RAM_ADDR;
31+
static volatile shared_ram pru1_shared_ram __attribute__((section(".shared1")));
3532

3633
static pbio_error_t pbdrv_pwm_tiam1808_set_duty(pbdrv_pwm_dev_t *dev, uint32_t ch, uint32_t value) {
3734
// Blue not available.
3835
if (ch == PBDRV_LED_PWM_CHANNEL_INVALID) {
3936
return PBIO_SUCCESS;
4037
}
4138

42-
pru1_shared_ram->pwms[ch] = value;
39+
pru1_shared_ram.pwms[ch] = value;
4340
return PBIO_SUCCESS;
4441
}
4542

@@ -60,7 +57,7 @@ void pbdrv_pwm_tiam1808_init(pbdrv_pwm_dev_t *devs) {
6057
TimerEnable(SOC_TMR_0_REGS, TMR_TIMER34, TMR_ENABLE_CONT);
6158

6259
// Clear shared command memory
63-
memset((void *)pru1_shared_ram, 0, sizeof(shared_ram));
60+
memset((void *)&pru1_shared_ram, 0, sizeof(shared_ram));
6461

6562
// Enable PRU1 and load its firmware
6663
PSCModuleControl(SOC_PSC_0_REGS, HW_PSC_PRU, PSC_POWERDOMAIN_ALWAYS_ON, PSC_MDCTL_NEXT_ENABLE);
@@ -69,8 +66,8 @@ void pbdrv_pwm_tiam1808_init(pbdrv_pwm_dev_t *devs) {
6966
unsigned int *fw_start = (unsigned int *)&_pru1_start;
7067
uint32_t fw_sz = &_pru1_end - &_pru1_start;
7168
PRUSSDRVPruWriteMemory(PRUSS0_PRU1_IRAM, 0, fw_start, fw_sz);
72-
// Set constant table C30 to point to 0x80010000
73-
PRUSSDRVPruSetCTable(1, 30, (PRU1_SHARED_RAM_ADDR >> 8) & 0xffff);
69+
// Set constant table C30 to point to shared memory
70+
PRUSSDRVPruSetCTable(1, 30, (((uint32_t)&pru1_shared_ram) >> 8) & 0xffff);
7471
PRUSSDRVPruEnable(1);
7572

7673
devs[0].funcs = &pbdrv_pwm_tiam1808_funcs;

lib/pbio/platform/ev3/platform.ld

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ ENTRY(Entry)
55

66
MEMORY
77
{
8-
SRAM (rwx) : ORIGIN = 0x80000000, LENGTH = 128K
8+
SRAM_PRU0 (rw) : ORIGIN = 0x80000000, LENGTH = 64K
9+
SRAM_PRU1 (rw) : ORIGIN = 0x80010000, LENGTH = 64K
910
DDR_unused (rwx) : ORIGIN = 0xC0000000, LENGTH = 0x8000
1011
DDR (rwx) : ORIGIN = 0xC0008000, LENGTH = (64M - 0x8000)
1112
ARM_LRAM (rwx) : ORIGIN = 0xFFFF0000, LENGTH = 8K
@@ -83,4 +84,14 @@ SECTIONS
8384
. = . + _minimal_stack_size; /* will cause linker error if there is not enough space for stack. */
8485
. = ALIGN(4);
8586
} > DDR
87+
88+
/* Shared on-chip SRAM */
89+
.shared0 (NOLOAD) :
90+
{
91+
*(.shared0)
92+
} > SRAM_PRU0
93+
.shared1 (NOLOAD) :
94+
{
95+
*(.shared1)
96+
} > SRAM_PRU1
8697
}

0 commit comments

Comments
 (0)