Dated Jul 28 2021 5 PM IST By- Dhruva Gole
- sinetone works fine at the expected freq of 440Hz
- passthrough works fine when I connected an AUX cable from my phone --> BELA IN and BELA OUT --> Earphones And it basically plays whatever I play on my phone to my earphones pretty clearly
- The serial logs of all this can be found here from "BELOW IS SERIAL LOGS WHEN SINTONE CODE is running, and also am getting the sine output"
IMPORTANT NOTE:
Don't forget to do sudo ./devmem2 0x4A005550 w 0x7000002
before running anything on BBAI+BELA
overlay loaded: BBAI-BELA...
git diff is done from folder: /home/debian/Bela-dhruva
whose most recent git log looks like:
/home/debian/Bela-dhruva
debian@beaglebone:~/Bela-dhruva$ git log
commit eb8373fdd6345645ef184c3d9f7bb07ef16166f2 (HEAD -> build_pru, origin/build_pru)
Author: Dhruva Gole <goledhruva@gmail.com>
Date: Mon Jul 26 12:52:38 2021 +0000
PRU ASM code runs without errors
new file: tempfolder/include_pru_asm.h
new file: tempfolder/template.pru1_1.out
commit f85dda0aca260d3ce08eb0b22b57df57b7d022e0
Author: Dhruva Gole <goledhruva@gmail.com>
Date: Sun Jul 25 13:20:17 2021 +0000
add modified pru_rtaudio_irq.p
modified: build_pru.sh
new file: pru_rtaudio_irq.p
Below is git diff
of the same
diff --git a/pru/pru_rtaudio.p b/pru/pru_rtaudio.p
index ac296d02..8c621301 100644
--- a/pru/pru_rtaudio.p
+++ b/pru/pru_rtaudio.p
@@ -11,8 +11,11 @@
#define CLOCK_SPI1 0x50
#define CLOCK_L4LS 0x60
-#define SPI0_BASE 0x48030100
-#define SPI1_BASE 0x481A0100
+#define SPI0_BASE 0x4809A100 // AI
+#define SPI1_BASE 0x480B8100 // AI
+
+// #define SPI0_BASE 0x48030100
+// #define SPI1_BASE 0x481A0100
#define SPI_BASE SPI0_BASE
#define SPI_SYSCONFIG 0x10
@@ -83,8 +86,8 @@
#define SHARED_COMM_MEM_BASE 0x00010000 // Location where comm flags are written
// General constants for McASP peripherals (used for audio codec)
-#define MCASP0_BASE 0x48038000
-#define MCASP1_BASE 0x4803C000
+// #define MCASP0_BASE 0x48038000
+#define MCASP0_BASE 0x48460000 // pg 6118 of AM57x Manual, it actually is MCASP1 but temporarily keeping as 0 for testing ease
#define MCASP_PWRIDLESYSCONFIG 0x04
#define MCASP_PFUNC 0x10
@@ -127,18 +130,31 @@
#define MCASP_SRCTL3 0x18C
#define MCASP_SRCTL4 0x190
#define MCASP_SRCTL5 0x194
+#define MCASP_SRCTL6 0x198
+#define MCASP_SRCTL7 0x19C
+#define MCASP_SRCTL8 0x1A0
+#define MCASP_SRCTL9 0x1A4
+#define MCASP_SRCTL10 0x1A8
+#define MCASP_SRCTL11 0x1AC
+#define MCASP_SRCTL12 0x1B0
+#define MCASP_SRCTL13 0x1B4
+#define MCASP_SRCTL14 0x1B8
+#define MCASP_SRCTL15 0x1BC
#define MCASP_XBUF0 0x200
#define MCASP_XBUF1 0x204
#define MCASP_XBUF2 0x208
#define MCASP_XBUF3 0x20C
#define MCASP_XBUF4 0x210
#define MCASP_XBUF5 0x214
+#define MCASP_XBUF10 0x228
+#define MCASP_XBUF11 0x22C
#define MCASP_RBUF0 0x280
#define MCASP_RBUF1 0x284
#define MCASP_RBUF2 0x288
#define MCASP_RBUF3 0x28C
#define MCASP_RBUF4 0x290
#define MCASP_RBUF5 0x294
+#define MCASP_RBUF10 0x2A8
#define MCASP_WFIFOCTL 0x1000
#define MCASP_WFIFOSTS 0x1004
#define MCASP_RFIFOCTL 0x1008
@@ -151,10 +167,10 @@
// Constants used for this particular audio setup
#define MCASP_BASE MCASP0_BASE
#ifdef DBOX_CAPE
-#define MCASP_SRCTL_X MCASP_SRCTL2 // Ser. 2 is transmitter
-#define MCASP_SRCTL_R MCASP_SRCTL0 // Ser. 0 is receiver
-#define MCASP_XBUF MCASP_XBUF2
-#define MCASP_RBUF MCASP_RBUF0
+#define MCASP_SRCTL_X MCASP_SRCTL11 // Ser. 2 is transmitter
+#define MCASP_SRCTL_R MCASP_SRCTL10 // Ser. 0 is receiver
+#define MCASP_XBUF MCASP_XBUF11
+#define MCASP_RBUF MCASP_RBUF10
#else
#define MCASP_SRCTL_X MCASP_SRCTL3 // Ser. 3 is transmitter
#define MCASP_SRCTL_R MCASP_SRCTL2 // Ser. 2 is receiver
@@ -168,7 +184,7 @@
#define MCASP_PIN_AMUTE (1 << 25) // Also, 0 to 3 are XFR0 to XFR3
#ifdef DBOX_CAPE
-#define MCASP_OUTPUT_PINS MCASP_PIN_AHCLKX | (1 << 2) // AHCLKX and AXR2 outputs
+#define MCASP_OUTPUT_PINS MCASP_PIN_AHCLKX | (1 << 11) // AHCLKX and AXR2 outputs
#else
#define MCASP_OUTPUT_PINS (1 << 3) // Which pins are outputs
#endif
@@ -870,12 +886,22 @@ SPI_INIT_DONE:
// Prepare McASP0 for audio
MCASP_REG_WRITE MCASP_GBLCTL, 0 // Disable McASP
- MCASP_REG_WRITE_EXT MCASP_SRCTL0, 0 // All serialisers off
+ MCASP_REG_WRITE_EXT MCASP_SRCTL0, 0 // All serialisers off
+ MCASP_REG_WRITE_EXT MCASP_SRCTL10, 0 // All serialisers off
MCASP_REG_WRITE_EXT MCASP_SRCTL1, 0
- MCASP_REG_WRITE_EXT MCASP_SRCTL2, 0
+ MCASP_REG_WRITE_EXT MCASP_SRCTL11, 0
MCASP_REG_WRITE_EXT MCASP_SRCTL3, 0
MCASP_REG_WRITE_EXT MCASP_SRCTL4, 0
MCASP_REG_WRITE_EXT MCASP_SRCTL5, 0
+ MCASP_REG_WRITE_EXT MCASP_SRCTL2, 0
+ MCASP_REG_WRITE_EXT MCASP_SRCTL6, 0
+ MCASP_REG_WRITE_EXT MCASP_SRCTL7, 0
+ MCASP_REG_WRITE_EXT MCASP_SRCTL8, 0
+ MCASP_REG_WRITE_EXT MCASP_SRCTL9, 0
+ MCASP_REG_WRITE_EXT MCASP_SRCTL12, 0
+ MCASP_REG_WRITE_EXT MCASP_SRCTL13, 0
+ MCASP_REG_WRITE_EXT MCASP_SRCTL14, 0
+ MCASP_REG_WRITE_EXT MCASP_SRCTL15, 0
MCASP_REG_WRITE MCASP_PWRIDLESYSCONFIG, 0x02 // Power on
MCASP_REG_WRITE MCASP_PFUNC, 0x00 // All pins are McASP
diff --git a/tempfolder/build_pru.sh b/tempfolder/build_pru.sh
old mode 100644
new mode 100755
index 3c1ef128..c7f1377f
--- a/tempfolder/build_pru.sh
+++ b/tempfolder/build_pru.sh
@@ -1,13 +1,13 @@
#!/bin/bash
set -xe
-[ -z "$1"] && echo "Pass one argument: .p file" >&2 && exit 1
+[ -z "$1" ] && echo "Pass one argument: .p file" >&2 && exit 1
PRU_FILE=$1
PRU_FILE_BIN=$(basename ${PRU_FILE%.*}.bin)
SOURCE=template.pru1_1
rm -rf $SOURCE.o* included_assembly.h
-pasm -V2 -b $PRU_FILE
+pasm -V2 -b -L $PRU_FILE
prudis $PRU_FILE_BIN | sed 's/^\(.*\)$/" \1\\n"/' > included_assembly.h
clpru -fe $SOURCE.o $SOURCE.c -v3 --endian=little --asm_listing --c_src_interlist --include_path=common --include_path=/usr/lib/ti/pru-software-support-package/include
lnkpru -o $SOURCE.out $SOURCE.o --stack_size=0x0 --heap_size=0x0 -m $SOURCE.map am57xx_pru.cmd
@@ -17,6 +17,6 @@ lnkpru -o $SOURCE.out $SOURCE.o --stack_size=0x0 --heap_size=0x0 -m $SOURCE.map
cp $SOURCE.out $SOURCE.out-bak
dd if=$PRU_FILE_BIN of=$SOURCE.out bs=1 obs=1 seek=52 conv=notrunc
# file is now ready to go.
+echo stop > /dev/remoteproc/pruss1-core1/state 2> /dev/null || true
# sudo cp $SOURCE.out /lib/firmware/am57xx-pru1_1-fw
-# echo stop > /dev/remoteproc/pruss1-core1/state 2> /dev/null || true
# echo start > /dev/remoteproc/pruss1-core1/state
diff --git a/tempfolder/pru_rtaudio_irq.p b/tempfolder/pru_rtaudio_irq.p
index b8d89a91..db4630de 100644
--- a/tempfolder/pru_rtaudio_irq.p
+++ b/tempfolder/pru_rtaudio_irq.p
@@ -1081,6 +1081,7 @@ DONE:
START:
+ HALT
// Initialize scratchpad 2 for test data
MOV r0, 0
MOV r1, 0
@@ -1125,7 +1126,7 @@ PRU_NUMBER_CHECK_DONE:
// Clear McSPI irq status bits
MOV r2, 0x7F
- SBBO r2, reg_spi_addr, SPI_IRQSTATUS, 4
+ // SBBO r2, reg_spi_addr, SPI_IRQSTATUS, 4
// Clear flags
MOV reg_flags, 0
To build the correct pru code (with the above mentioned changes in pru_rtaudio.p
) use:
./build_pru.sh ../pru/pru_rtaudio.p
from the tempfolder
The last two commit logs look like:
commit 3dcd25f0a5106d42cb5df040324c4c4a234874e2 (HEAD -> PruManager)
Author: root <root@beaglebone.localdomain>
Date: Mon Jul 26 16:05:57 2021 +0000
Revert "pru: use McaspIRQ code for all boards. pru/pru_rtaudio.p now becomes unused"
This reverts commit bf14f5172e25b0f3b1f9fc0b7ef573b8fa9d4786.
commit e79b1c8d9d1982f6dbfb081245fa906669eb7523 (origin/PruManager)
Author: Dhruva_Gole <goledhruva@gmail.com>
Date: Sun Jul 25 01:20:42 2021 +0530
PruManager: changed path from char to string
modified: core/PruManager.cpp
modified: include/PruManager.h
BELOW is git diff -a of the same:
diff --git a/Makefile b/Makefile
index 2cd03f4e..d043006a 100644
--- a/Makefile
+++ b/Makefile
@@ -310,7 +310,7 @@ else
ENABLE_PRU_RPROC = 0
endif
-DEFAULT_COMMON_FLAGS := $(DEFAULT_XENOMAI_CFLAGS) -O3 -g -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon -ftree-vectorize -ffast-math -DNDEBUG -D$(BELA_USE_DEFINE) -I$(BASE_DIR)/resources/$(DEBIAN_VERSION)/include -save-temps=obj $(IS_AM572x) -DENABLE_PRU_UIO=$(ENABLE_PRU_UIO) -DENABLE_PRU_RPROC=$(ENABLE_PRU_RPROC) -DfirmwareBelaRProc=\"$(firmwareBelaRProc)\"
+DEFAULT_COMMON_FLAGS := $(DEFAULT_XENOMAI_CFLAGS) -O0 -g -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon -ftree-vectorize -ffast-math -DNDEBUG -D$(BELA_USE_DEFINE) -I$(BASE_DIR)/resources/$(DEBIAN_VERSION)/include -save-temps=obj $(IS_AM572x) -DENABLE_PRU_UIO=$(ENABLE_PRU_UIO) -DENABLE_PRU_RPROC=$(ENABLE_PRU_RPROC) -DfirmwareBelaRProc=\"$(firmwareBelaRProc)\"
DEFAULT_CPPFLAGS := $(DEFAULT_COMMON_FLAGS) -std=c++11
DEFAULT_CFLAGS := $(DEFAULT_COMMON_FLAGS) -std=gnu11
BELA_LDFLAGS = -Llib/
diff --git a/core/Mcasp.cpp b/core/Mcasp.cpp
index 796d9cdc..90a9b2d1 100644
--- a/core/Mcasp.cpp
+++ b/core/Mcasp.cpp
@@ -8,7 +8,7 @@
McaspConfig::McaspConfig()
{
params = {0};
- params.auxClkIn = 24000000;
+ params.auxClkIn = 20000000;
}
double McaspConfig::getValidAhclk(double desiredClk, unsigned int* outDiv)
diff --git a/core/PRU.cpp b/core/PRU.cpp
index 5b38d1d3..d1cf78c7 100644
--- a/core/PRU.cpp
+++ b/core/PRU.cpp
@@ -803,6 +803,7 @@ int PRU::start(char * const filename, const McaspRegisters& mcaspRegisters)
#endif // ENABLE_PRU_UIO
#if ENABLE_PRU_RPROC == 1
+ pruManager->start(filename);
// do something else probably? Or simply not required.
#endif // ENABLE_PRU_RPROC
diff --git a/core/PruManager.cpp b/core/PruManager.cpp
index 04b335c6..246245d0 100644
--- a/core/PruManager.cpp
+++ b/core/PruManager.cpp
@@ -23,6 +23,7 @@ PruManagerRprocMmap::PruManagerRprocMmap(unsigned int pruNum, unsigned int v)
verbose = v;
unsigned int pruss = pru_num / 2 + 1;
unsigned int prucore = pru_num % 2;
+ std::cout << "PRUSS" << pruss << " PRU CORE = " << prucore << " pru num =" <<pru_num << "\n";
basePath = "/dev/remoteproc/pruss" + std::to_string(pruss) + "-core" + std::to_string(prucore) + "/";
statePath = basePath + "state";
@@ -37,6 +38,9 @@ PruManagerRprocMmap::PruManagerRprocMmap(unsigned int pruNum, unsigned int v)
// 2 : pru2-core 0 in AI -> 4b2b4000
// 3 : pru2-core 1 in AI -> 4b2b8000
//
+ //PRU ICSS 1 -> 0x4b20_0000
+ //PRU ICSS 2 -> 0x4B28_0000
+ //
// 1 : PRUSS address in AI for PRU 1
// 2 : PRUSS address in AI for PRU 2
//
@@ -44,13 +48,13 @@ PruManagerRprocMmap::PruManagerRprocMmap(unsigned int pruNum, unsigned int v)
// 1 : pru-core 1 in BBB -> 4a338000
# ifdef IS_AM572x // base addresses for BBAI
- pru_addr.insert(std::pair<unsigned int, unsigned int>(0,0x4b234000));
- pru_addr.insert(std::pair<unsigned int, unsigned int>(1,0x4b238000));
- pru_addr.insert(std::pair<unsigned int, unsigned int>(2,0x4b2b4000));
- pru_addr.insert(std::pair<unsigned int, unsigned int>(3,0x4b2b8000));
+ pru_addr.insert(std::pair<unsigned int, unsigned int>(0,0x4b200000));
+ pru_addr.insert(std::pair<unsigned int, unsigned int>(1,0x4b202000));
+ pru_addr.insert(std::pair<unsigned int, unsigned int>(2,0x4b280000));
+ pru_addr.insert(std::pair<unsigned int, unsigned int>(3,0x4b282000));
- pruss_addr.insert(std::pair<unsigned int, unsigned int>(1,0x4b200000));
- pruss_addr.insert(std::pair<unsigned int, unsigned int>(2,0x4b280000));
+ pruss_addr.insert(std::pair<unsigned int, unsigned int>(1,0x4b210000));
+ pruss_addr.insert(std::pair<unsigned int, unsigned int>(2,0x4b290000));
# else // base addresses for BBB
pru_addr.insert(std::pair<unsigned int, unsigned int>(0,0x4a334000));
pru_addr.insert(std::pair<unsigned int, unsigned int>(1,0x4a338000));
@@ -60,7 +64,7 @@ PruManagerRprocMmap::PruManagerRprocMmap(unsigned int pruNum, unsigned int v)
void PruManagerRprocMmap::stop()
{ // performs echo stop > state
if(verbose)
- std::cout << "Stopping the PRU" << std::to_string(pruss) + "_" + std::to_string(prucore) << "\n";
+ std::cout << "Stopping the PRU" << pruss + "_" + prucore << "\n";
IoUtils::writeTextFile(statePath, "stop");
}
diff --git a/include/PruManager.h b/include/PruManager.h
index 2c9259f5..7d03007c 100644
--- a/include/PruManager.h
+++ b/include/PruManager.h
@@ -47,10 +47,10 @@ private:
std::string firmwarePath;
std::string firmware;
std::string firmwareCopyCommand;
- unsigned int pru_num;
- unsigned int verbose;
- unsigned int pruss;
- unsigned int prucore;
+ unsigned int pru_num=1;
+ unsigned int verbose=1;
+ unsigned int pruss=1;
+ unsigned int prucore=1;
Mmap ownMemory;
Mmap sharedMemory;
};
diff --git a/include/bela_hw_settings.h b/include/bela_hw_settings.h
index 12d68a5e..2c0421e1 100644
--- a/include/bela_hw_settings.h
+++ b/include/bela_hw_settings.h
@@ -1,5 +1,5 @@
#pragma once
-const unsigned int codecI2cBus = 2; // Bus for TLV320AIC3104 codec
+const unsigned int codecI2cBus = 3; // Bus for TLV320AIC3104 codec
const unsigned int codecI2cAddress = 0x18; // Address of TLV320AIC3104 codec
const unsigned int kBelaCapeButtonPin = 115; //P9.27 / P2.34 connected to The Button
const unsigned int kAmplifierMutePin = 61; // P8.26 controls amplifier mute
no need to initialise these parameters here. Relying on this may lead to hard to track bugs later on.
commit this for good.