MATLAB / Simulink on BeagleBone Black

3,446 views
Skip to first unread message

kevind

unread,
Dec 30, 2013, 11:30:51 PM12/30/13
to beagl...@googlegroups.com

I have MATLAB / Simulink working with BeagleBone Black.  I'm posting the instructions here in case anyone else might find it useful.

I'm using it with the audio cape, so these instructions include how to make the alsa sound Simulink blocks work. I haven't tried using HDMI audio; if you want to do that it might require a different alsa configuration.

BeagleBone Black Configuration:

You'll need to boot your BeagleBone to Ubuntu with a current image, anything prior to kernel 3.8.13-bone31 won't work with the Audio Cape. 

I used this one for uSD card:
and this one for eMMC:

decompress with 7zip, and write to uSD card with Win32 Disk Imager:

Boot to the SD card (requires holding down the button near the uSD card slot while applying power).
If you use the eMMC flasher, wait 10 minutes until LEDs all come on steady, then reboot without the uSD card.

# create a swap file (I used 512MB for booting from internal eMMC, use larger if booting from uSD card)
sudo su
mkdir -p /var/cache/swap/
dd if=/dev/zero of=/var/cache/swap/swapfile bs=1M count=512
chmod 0600 /var/cache/swap/swapfile
mkswap /var/cache/swap/swapfile
swapon /var/cache/swap/swapfile
# set the swap file to load on boot by adding an entry to /etc/fstab:
nano /etc/fstab

/var/cache/swap/swapfile    none    swap    sw    0   0

# install required packages
apt-get update
apt-get install build-essential libsdl1.2-dev mplayer espeak alsa-utils
wget -P /var/lib/alsa http://beagleboardtoys.info/files/BeagleBoneAudio/asound.state

# set up build environment
mv /usr/include/sys/asoundlib.h /usr/include/arm-linux-gnueabihf/sys
rmdir /usr/include/sys
ln -s /usr/include/arm-linux-gnueabihf/sys /usr/include/sys
ln -s /usr/include/arm-linux-gnueabihf/asm /usr/include/asm
ln -s /usr/include/arm-linux-gnueabihf/bits /usr/include/bits
ln -s /usr/include/arm-linux-gnueabihf/gnu /usr/include/gnu

# test sound output if using the audio cape
# run alsamixer, and crank up the levels on "PCM" and "HP DAC", or you won't hear anything
alsamixer
# test that sound comes out, run 2X because sound ramp-up is delayed
aplay /usr/share/sounds/alsa/Front_Left.wav
aplay /usr/share/sounds/alsa/Front_Right.wav
# test with mp3 file if you have one
mplayer xxxxxxxx.mp3


MATLAB Configuration:

1) install the BeagleBoard target.  For R2012A/B, run "targetinstaller".

2) run "xmakefilesetup" 

For R2012B, set "Template" to "gmake_remotebuild" & "Configuration" to "LinuxRemoteBuild"
For R2012A, set "Template" to "beagleboardgmake" and "Configuration" to "BeagleBoard"

On the "Compiler" tab, set "Arguments" to "-c -mfloat-abi=hard"

3) in your Simulink model, select "Tools -> Run On Target Hardware -> Options"

Select "Run On Target Hardware", then:

"Target Hardware" is "BeagleBoard"

"Enable External mode" should be checked, and port set to "17725"

For "Host name", enter the IP address of your BeagleBone
For "User name", enter "Ubuntu"
For "Password", enter "temppwd" (or current password if you changed it)
For "Build Directory", enter "/home/Ubuntu"

3) In your Simulink model, if you use the ALSA audio blocks, leave the device name set to 'default'


4) Run your model using "Tools -> Run On Target Hardware -> Run"

MATLAB will generate C code from your Simulink model, send it to the BeagleBone, build the code on the BeagleBone, then run the code on the BeagleBone.  You can adjust parameters in your model while it runs (i.e. move a slider or type in a new value), and the new values will be sent to the BeagleBone.




Tux Leonard

unread,
Dec 31, 2013, 8:26:46 AM12/31/13
to beagl...@googlegroups.com
Thank you for this great post. I am also interested in using Matlab/Simulink or Scilab/Sicos on BBB.

Perhaps you could give me some additional information.

-What tool boxes do I need beside Matlab/Simulink? Some code generation tools?
-Are there some simulink blocks for GPIO, PWM, analog input, I2c...?
-Can you use the compiled application on BBB in a "stand alone" mode? I mean without a matlab/Simulink connection.
-Do you have any experiences with Scilab/Sicos

Thanks

Roy





2013/12/31 kevind <ke...@doren.org>

--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

kevind

unread,
Dec 31, 2013, 2:05:19 PM12/31/13
to beagl...@googlegroups.com
For Simulink models, you need MATLAB, Embedded Coder, Simulink, and Simulink Coder.  The DSP System Toolbox or other toolboxes might be helpful depending on your application.  No other tools are necessary because the models are built on the BeagleBone.  They generate a standalone executable that can be run without MATLAB / Simulink.

It's also possible to target the BeagleBone from MATLAB code without Simulink, although I haven't done that.  For that I believe you need MATLAB, MATLAB Coder and Embedded Coder, plus some free tools: Eclipse C/C++ IDE (plus GNU ARM and Remote System Explorer plugins) and  Sourcery CodeBench Lite.

There's a good book about using MATLAB / Simulink with BeagleBoard.  It and all Packt Publishing eBooks sare on sale for only $5 until Jan 3, 2014.  Most of this book should also apply to BeagleBone using the configuration instructions I posted.


The Simulink BeagleBoard target includes blocks for ALSA Audio Capture & Playback, SDL Video Display, V4L2 Video Capture, and UDP Send & Receive.

I've never used Scilab/Sicos.

-Kevin

kevind

unread,
Jan 1, 2014, 8:58:01 PM1/1/14
to beagl...@googlegroups.com
Errata: In the "MATLAB Configuration section", "ubuntu" should be lower case:  Username: "ubuntu", and Build Directory "/home/ubuntu".

The Google groups spell checker capitalized them on me even though I typed them in lower case.  And there's no option to edit the original post, all I can do is reply to it.

-Kevin 

stewar...@gmail.com

unread,
May 22, 2018, 5:41:16 PM5/22/18
to BeagleBoard
Debian 7.9 will work, although I am not sure about the audio cape
Reply all
Reply to author
Forward
0 new messages