Skip to content

Commit 7a4935a

Browse files
committed
pbio/drv/pwm/pwm_ev3: Use linker script to define shared memory
1 parent ab51df5 commit 7a4935a

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

lib/pbio/drv/pwm/pwm_ev3.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@
3131
typedef struct shared_ram {
3232
uint8_t pwms[PBDRV_PWM_EV3_NUM_CHANNELS];
3333
} shared_ram;
34-
static volatile shared_ram *const pru1_shared_ram = (volatile shared_ram *)PRU1_SHARED_RAM_ADDR;
34+
static volatile shared_ram pru1_shared_ram __attribute__((section(".shared1")));
3535

3636
static pbio_error_t pbdrv_pwm_tiam1808_set_duty(pbdrv_pwm_dev_t *dev, uint32_t ch, uint32_t value) {
3737
// Blue not available.
3838
if (ch == PBDRV_LED_PWM_CHANNEL_INVALID) {
3939
return PBIO_SUCCESS;
4040
}
4141

42-
pru1_shared_ram->pwms[ch] = value;
42+
pru1_shared_ram.pwms[ch] = value;
4343
return PBIO_SUCCESS;
4444
}
4545

@@ -60,7 +60,7 @@ void pbdrv_pwm_tiam1808_init(pbdrv_pwm_dev_t *devs) {
6060
TimerEnable(SOC_TMR_0_REGS, TMR_TIMER34, TMR_ENABLE_CONT);
6161

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

6565
// Enable PRU1 and load its firmware
6666
PSCModuleControl(SOC_PSC_0_REGS, HW_PSC_PRU, PSC_POWERDOMAIN_ALWAYS_ON, PSC_MDCTL_NEXT_ENABLE);
@@ -69,8 +69,8 @@ void pbdrv_pwm_tiam1808_init(pbdrv_pwm_dev_t *devs) {
6969
unsigned int *fw_start = (unsigned int *)&_pru1_start;
7070
uint32_t fw_sz = &_pru1_end - &_pru1_start;
7171
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);
72+
// Set constant table C30 to point to shared memory
73+
PRUSSDRVPruSetCTable(1, 30, (((uint32_t)&pru1_shared_ram) >> 8) & 0xffff);
7474
PRUSSDRVPruEnable(1);
7575

7676
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)