Building an Embedded Asterisk PBX Part 1

Over the last few days I have been bringing some telephony hardware to life. I have finally obtained all the parts I need and am assembling, testing, and blogging as I go!

This work is part of a project to develop and build “open” IP-PBX hardware. Now by building I mean really building. Like designing the circuits and Printed Circuit Boards (PCBs) and then hand-loading the PCBs with a soldering iron. The PBX is an embedded Asterisk design running on a Blackfin STAMP platform. This work is part of the Free Telephony Project.

Now the first priority is to start with a clean, tidy, professional work area:

Mmmmmmmmm. Oh well, I will tidy it up one day.

Lets start with the 4fx board. The 4fx board interfaces the Blackfin STAMP to the FXS & FXO modules. It has a little Xilinx XC9536 programmable logic chip (or CPLD). I had previously designed and simulated the Verilog code for this CPLD so all I had to do was program the chip using a JTAG cable that connects between my PC and a header on the 4fx card:

It actually took me a few hours of head scratching to get the chip to program. The problem was I has accidentally selected the wrong chip type when I synthesised the CPLD code. DOH! Anyway once I worked that out it programmed straight away which was a relief – you never know with a new design if you have messed up something fundamental like connecting power in reverse. So the first “sign of life” you get from a new board is always a big relief.

I then poked around with the scope while running a unit test program on the Blackfin that put the CPLD through a few tests. Just like software, it is very important to make sure the components of a hardware design a working before integrating the components into a larger design. The typical trap is that we get excited and try to move forward too fast, for example testing several new and unknown parts of the design all at once. Simple errors compound to tough bugs when combined with other untested hardware and software.

So I always try to test thoroughly at the earliest possible stage. In fact I often organise my designs so they can be broken apart into little chunks and tested, rather than thinking about testing as an after thought. In the case of the CPLD I ran many simulations using the Icarus Verilog simulation tools before even going near the hardware. Experience (OK plenty of screw-ups) has taught me that it takes much less effort to test carefully earlier than to debug later.

Anyway, back to the story. On the CPLD I messed up one pin’s position in the pin-locking file (easily fixed by recompiling the CPLD image), but apart from that the CPLD appears to be working fine. All the chip select signals are being generated in response to the commands from my test software.

OK, the next step is to see if I can make some LEDs on the board light under software control. The LEDs are connected to the CPLD and will be used to show the status of each telephony port. So if we can make the LEDs do their thing this will prove another chunk of the CPLD code is OK.

I modified the unit test program to write to the register that controls the LEDS:
bfsi_spi_init(baud, (1<<NCS_A) | (1<<NCS_B));

for(i=0; i<tests; i ) {
bfsi_spi_write_8_bits(NCS_B, select);
bfsi_spi_write_8_bits(NCS_A, data);

In the for loop, the first write sets the “destination” of the data (which SPI device we wish to write to). The second write sets the actual value. The way the LED is wired up if we write a 01 (binary) we should get the LED to glow red, and 10 (binary) to make it glow green. The for loop makes it repeat many times, just so I can see what is going on with my ancient analog scope. Only one write is actually neeeded.

I peer at the LED. It stares back, blank and just daring me to try:

I hit the magic command line:
root:~> insmod tspi_4fx.ko data=0x1

Hey – it worked! Thats not meant to happen! Not first time! WHOO-HOO! OK, lets try making it green:
root:~> insmod tspi_4fx.ko data=0x2


It is hard to explain feeling of achievement you can get from just making a LED light. You never really understand how much complex technology is between the vision and reality of making a simple LED come on – until you start to build chunks of that technology, solder the LED yourself, write the driver etc. Then you realise, and a simple LED turning on when you tell it to seems like an unlikely miracle! Anyone who has ever worked on making computers talk to hardware will understand what I mean.

Especially if you have had your share of times when that LED wouldn’t turn on. For like days or weeks.

OK so the next step was to test the FXO and FXS modules. Here they are all soldered and ready to smoke up, errr I mean test. The large, ugly resistors hanging off them are because I couldn’t easily source some very high (15M) and very low (0.5 ohm) resistors I needed in 0603/0805 packages. Can anyone send me a few please?

First I wanted to test the FXO module. I connected it directly to the Blackfin STAMP card, rather than using the 4fx card just yet. Golden rule – always test the minimum possible:

I already had some Asterisk software for the Blackfin running and tested (using other hardware). That meant I had tested and working software to test the unknown hardware. So it was just a matter of firing that up and seeing if it detected the card:
Welcome to:
____ _ _
/ __| ||_| _ _
_ _| | | | _ ____ _ _ \ \/ /
| | | | | | || | _ \| | | | \ /
| |_| | |__| || | | | | |_| | / \
| ___\____|_||_|_| |_|\____|/_/\_\

For further information see:

BusyBox v1.00 (2006.08.25-23:13 0000) Built-in shell (msh)
Enter 'help' for a list of built-in commands.

root:~> eth0: link up, 100Mbps, full-duplex, lpa 0x45E1
Zapata Telephony Interface Registered on major 196
Registered Span 1 ('WCTDM/0') with 1 channels
Span ('WCTDM/0') is new master
iRxBuffer1 = 0xff800000
iTxBuffer1 = 0xff800080
ISR installed OK
Testing for ProSLIC
ProSLIC not loaded...
Testing for DAA...
VoiceDAA System: 04
ISO-Cap is now up, line side: 03 rev 06
Module 0: Installed -- AUTO FXO (FCC mode)
Found: Blackfin STAMP (1 modules)
Registered tone zone 0 (United States / North America)
4294895942 Polarity reversed (0 -> 1)

root:~> /var/tmp/asterisk -vc

Thats a pretty good result – the FXO port was detected OK. So then I started Asterisk and put a few calls through it. I placed a call into the PBX (using another Asterisk PBX running on an x86 box) and it detected the ring signal and went off hook OK:
*CLI> RING on 1/1!
NO RING on 1/1!
RING on 1/1!
NO RING on 1/1!
Jan 1 02:51:59 NOTICE[96]: chan_zap.c:5406 ss_thread: Got event 2 (Ring/Answer)

However the audio had lots of sharp clicks and pops. Crack-Crack-Crack every few seconds. Damn.

I spent half a day chasing this bug. I puzzled me a bit as I knew the circuit was straight out of the Silicon Labs data sheet and that I (and a few others) had carefully checked it. So I figured it must have been an assembly error like a wrong component or bad solder joint. Actually I wasn’t quite that logical: in the real world bugs tend to get your emotions involved. You really want it to work so you get a little stressed and start doing and thinking stupid things. So you end up checking a bunch of things you don’t need to (like the schematic five times) and perhaps missing some other more sensible checks – you don’t always think straight when your emotions are in play. Such is the psychology of bug hunts.

I started checking signals on the header and had trouble getting a good contact with my scope probe. I looked at the pin and there was some flux residue stuck to it. So I gave that part of the board a scrub with a fine brush and some solvent and then fired it up again to check that signal. Huh – now the audio is OK – clicks gone! WTF? I am still now sure what happened here – perhaps the brush dislodged a small short or the flux was conducting a little.

So anyway the FXO module (fxomod) seems to work OK now.

I then tried the FXS module and it worked on the first try. I was really happy about that – I was placing calls over it 5 minutes after the first time I applied power. Hardware development isn’t meant to work like that! Anyway I guess I will get my fair share of bugs later (it’s the conservation of bugs law), there is still plenty of development to go.

My next step is to integrate the FXS and FXO modules with the 4fx board. More on that in a later post.

This is what the whole thing looks like when put together with the STAMP, 4fx, and (for now) a single FXO module:

The idea is that you can stack more 4fx boards to get multiples of 4 ports. You could also stack other cards, for example BRI-ISDN, E1/T1, or cards that give you additional DSP horsepower.

You might have also noticed the SD-card. The driver for that was developed by Hans Eklund and the team at Rubico. They have done a fantastic job. I compiled the latest uClinux version with SD/MMC card support and it worked perfectly first time. It is really cool to read and write files to a SD card on the Blackfin, then transfer the card to a PC and find the files all there and readable. Such a simple hardware interface too (just a few wires).

Geekiness is contagious. Just last week I convinced my wife Rosemary to help me with some board stuffing. I started here off on a simple thru-hole kit to teach here soldering. A few days later here she is soldering tiny 0603 resistors and doing a fine job:

Thats all for now. I’ll might blog some more later as I work through the steps to bring up the rest of the board.


  1. Building an Embedded Asterisk PBX Part 2
  2. Building an Embedded Asterisk PBX Part 3
  3. More information on the Free Telephony Project here.
  4. Blackfin MMC/SD card how-to.
  5. More information on the design I am building here.
  6. Here is the (current) 4fx schematic in PDF form. It will probably change as the bugs are found and fixed.
  7. You can download source files for the schematics, PCB design, CPLD code here. Grab the latest hardware-x.y.tar.gz file. In the cpld directory there is a README that explains the CPLD code as well as “test benches” – Verilog code that tests other Verilog code.

mortgage calculator rate loan 2ndremortgage http home advice uk loanloan abacuspayday loans 30 dayhour faxing loans no 1loan physician bank america$3000 loan credit with badloan education acsa bad loan with personal creditloan 1003 applicationdaphne pornporn daphnyporn vain star darienangel bio dark pornbbs porn darkporn collection dark bbsporn dark girlporn dark portal Map

47 thoughts on “Building an Embedded Asterisk PBX Part 1”

  1. Good Day!
    I have interest in constructing one I modulate of the hardware to work with asterisk (pbx IP) of tamnho reduced for residential use, would like to know which the steps and ways I must use for the same.


    Fabricio Vilela

  2. Farbrico – I have a lot of information on my web site. Please let me know where you require further information.

    Dome – sure, I will have some kits available in early October.

  3. Hi Dave,
    wonderful project: I hope I’ll be able to give my 2 cents somewhere sooner or later.

    Just one little thing you probably already know: Si3220 (Dual ProSLIC) has the same (better: compatible) SPI protocol as Si3050 DAA and (should be) interchangeable on the same SPI bus.

    Good Luck,

  4. hi Dave

    i also intersing purchaseing some of development kit from you. could you send me a email??



  5. hi Dave

    i also intersing purchaseing some of development kit from you. could you send me a email??



  6. Hi Dave

    I have a bf537-stamp. I am intersting to test 4 port fxo/fxs daughter card on bf537-stamp .

    Now I have some questions.

    1. Are you sure the SPORT0 of bf533_stamp is same as
    the SPORT0 of bf537_stamp?
    I mean can I use the daughter card on bf537 without modify
    2. Is the sch (4fx_0.33.pdf) the newest stable version?
    3.Maybe the component c5,c6,fb2,fb1,r25,r24 in the board
    shoud be moved to module since It is not suitable for fxs moudule .


  7. Hi WangXiang,

    1. The SPORTs are very similar, but for the BF537 u need to program a bunch of mux registers as the SPORT pins have several different functions. The latest driver takes care of all this. In fact, I am using the BF537 STAMP for most of my testing at the moment. Actually due to the physical layout of the STAMP boards, I use SPORT1 on the 537, and SPORT0 on the 533.

    2. Yes V0.33 is the latest, but I would consider it Beta rather than stable.

    3. The idea of placing the components close to the RJ11 jack is to minimise EMI. If placed on the module you would have greater amount of EMI injected into the RJ11 cable. They will also reduce EMI on the FXS ports but otherwise not affect the FXS signal.

    – David

  8. Hello David..nice this will encorage everybody to build their own system…do you have the part list and supplyers?

    take care

  9. Very good device! I am a hardward desinger in China, I made X100p using motorola chipset successed. But now I had some problem in CPLD in TDM400P. Does you CPLD programm is same as TDM400P, if you help me in this xilinx CPLD, I can made tdm400p in low price(100usd), so I can sell it to more people in China install astersik. You can send the Xilinx 9572 CPLD code to my private e-mail.

    I had a small shop in china.
    You can see my X100P using motorola chipset sell only 20USD.
    Let’s help more people play asterisk.
    Thank you!

  10. Hi Eric,

    The 9536 CPLD I use is different from the one on TDM400P, although I guess it performs some of the same functions. The Verilog source is freely available from the harwdare-x.y tar ball in the downloads section of this site.

    Eric, you may also be interested in making complete Asterisk embedded IP-PBXes using the BlackfinOne and 4fx designs. We could use a low cost supplier.



  11. Hi David,

    I would like to know if you think that this project could give a solution to us as well. We need small asterisk boxes to connect customer’s branch offices to their main office. We plan to use asterisk to asterisk IAX trunking to do this, but we are not sure what would be the best hardware for us. Do you or anyone else provide these boxes with asterisk already preinstalled or do we always have to develop the whole system? We would only need SIP and IAX support, but no FXS or FXO is needed, because we would just route VoIP between SIP phones and other asterisk boxes. Please comment.



  12. Jarmo, if no analog phones are required, and its just a few SIP phones, the best solution is to run Asterisk on a WRT54G – Asterisk is available as part of the OpenWRT software.

  13. Hi David,

    I have been working with asterisk trunk 1.4 in order to have GSM connection. Know I want to migrate to an embedded system. The problem is that i do not have hardware so I decide to use the Skyeye simulator of a ARM7TDMI. So far, i just compiled the uClinux and a hello program. Now i wish i could run uCasterisk there. My question is, how could i provide GSM support to this device?

    I have been looking source code from Asterisk trunk and the uCasterisk1.8. They are totally different. Are you interested in that?


  14. Hi Iban,

    Asterisk comes with a software GSM codec. You could use that. uCasterisk 1.8 is different from Asterisk trunk as it is based on Asterisk 1.2. We are in the process of shifting our development efforts to which is based on Asterisk 1.4.

    – David

  15. Hi David,

    Probably my question was not clear enough. I know that in Asterisk 1.2 there is no GSM channel supported, I imagine that the code of GSM is pretty the same as in Asterisk 1.2 (correct me if that is not true). Anyway, I am talking about creating a channel for GSM in this embedded device, I was thinking about two options:
    1) From a GSM modem with a rs232 connection create a channel of GSM for asterisk
    2) Use bluetooth stack to control a mobile phone from an embedded system. It that particular option, Asterisk 1.4 has developed a patch called chan_cellphone which i tried and works fine, but as you said the uCasterisk 1.8 is based on Asterisk 1.2 which does not support chan_cellphone (I tested that).

    Which of this solutions do you think is more suitable?

    Thanks in advance.

  16. Hi Iban,

    OK, I understand – you meant a GSM channel driver for Asterisk. Well solution (1) is a bit easier at the moment – as we have a RS232 port. It might be possible to support Bluetooth through the USB port of the BlackfinOne. In either case I would suggest using (a Blackfin port of Asterisk 1.4).



  17. Hi David,

    The ADZS-BF537-STAMP does not have any usb connector, it just have rs232. About the BlackfinOne, which board is this one? I could not find it either in Analog Devices nor Digi-key.



  18. Hi David,

    Sorry about writing in twice.

    I have downloaded the astfin but obviously this is a work done just for blackfin architecture. Is there any chance to make that work in an ARM7TDMI? What forum could I acces to talk about that?

    thanks in advance.

  19. Hi Iban,

    Yes you could use a similar approach to astfin or uCasterisk to make Asterisk work for the ARM7. For example when I started this project no Asterisk port existed for the Blackfin and so I spent about 1 month working with and learning buildroot to get a basic Asterisk version running. I am not sure what forums could support this work, perhaps asterisk-dev?



  20. Hi Kanti,

    We are using the Asterisk 1.4 built-in GUI, however it is currently unstable on our platform. This shouldn’t be too hard to fix. We have investigated Trixbox however I understand it needs a fairly heavyweight web server and database (plus PHP I think) which is not easily ported to an embedded system running uClinux.



  21. Hi,David
    Thanks for your work,
    I tested to stack 4fxx +bf537 stamp, it seems to unstable,
    the test software is uImage.537.2fxo2fxs; it works well at the first time,
    and when I test it at the 2nd time, the 7th,8th fxs did not work.
    Is the newest cpld code in the hardware-0.33/cpld?
    I have built a cpu board( based bf537 stamp),and a 8 port board( based
    4fxx), and used 1 cpld in my 8port board,and expand your code supporting 8 port, when i test it ,1 4 port is OK, and others are not work。
    could you give me any suggestion? SI ?

    Wang Xiang

  22. Hi Wang,

    Sounds like an exciting project you have there – congratulations. I have a couple of suggestions:

    1/ Perhaps it is best to post the the Blackfin Asterisk forum, as there will be more people who can help you.

    2/ The image you are using is very old, I suggest you use Astfin.

    3/ 8 port operation is experimental, but some people are working on it, please join us on the Blackfin Asterisk forum and we can work together.

    – David

  23. Very cool! I wish I could get MY wife to solder SM components! (Or through-hole, or a copper pipe, or anything…)

    I notice that you use a SOAR ‘scope. (At least that’s the label on mine). I thought I was the only person in the world who had one!

    Try DigiKey for the resistors. They have the half-ohm in 0805, and the 15M in 0603, 0805, and 1206, in strips of 10, about 40 cents per resistor.



  24. hi, i have the question i want to know , if you have cards make and the elements for the modules fxo, fxs 4fx card, without soldering, if you can send me to El salvador to implement the system and to work in its development since to obtain to the elements and make pcb it is very difficult in my country
    in hope for your answer thanks

  25. Thanks Tommy – unfortunatley her geeky phase is now over, but it was fun while it lasted :-)

    Hi Juan,

    Sorry I don’t have any more stock of the fxs/fxo/4fx starter kits, but more IP04s will be available soon.

    – David

  26. Hi David, great project you have there. =) Just wondering if you have any documentations on the fxo/fxs modules?

    Thanks! =D

  27. Hello David,

    thanks for your work, very nice! Congratulation for all.
    I hope I can do it even a day!!!

    I’am particularly interested in zapata porting. I have a Intel IXP435 board with both FXS and FXO port. Intel release drivers for both HSS/PCM interface and slic (Si3210, Si3050) . I would be porting zaptel driver on this board. This blog is the fist that speak about “custom” zaptel driver without hardware PCI interface. Zaptel is not very simple to understand :-((
    Can you suggest me howto start ?



  28. Hi Antonello,

    A good place to start is to examine the wctdm.c module. You need to replace the PCI interface code for (i) SPI control and (ii) TDM data with routines to suit the Intel target. Start with the SPI side.

    – David

  29. Hello Every one:
    i m working on SLIC(si3210).i have a problem.i can’t get Proper PCM data.when i write(Direct register2=28,enable PCM and u-law)and (Direct register 8=2 ,its loop back).it generate random data at si3210’s DTX although no input on its tip/ring.
    can any one tell me how i get send/receive proper PCM data



  30. Hi Azhar,

    Iam also using Si 3210. I too have the same problem as you. Can you help me out of this please. I guess you would have solved it. Can you send me the register settings for si 3210.

  31. Hi!
    I’m working with KIXRP435 Intel Board, with SI3210! And i not undrestand how to connect Asterisk and si3210 SLIC? I’m try to compile wctdm Zaptel module, and it is not work. Maybe any one can help me with it problem.

  32. hi Sudhir:
    approx i have fix it.can you tell me which thing you have connect with si3210 i.e phone or fax.

  33. hi,

    We want to dev an asterisk based SIP IP Pbx with E1 (Qsig) support instead of analog FXS/FXO ports.

    I was wondering if there is any help / documentation to get started with that project.

  34. A 256MB SD card, wow, the times they are ‘a changing. I’ve got a 16GB card sitting here on my keyboard doing nothing of value.

    I think it was around the time of this blog post that I bought a 512MB USB thumbdrive for $120 CAD, noting the amazing deal that it was.

Comments are closed.