Noggin01
Posts: 61
Joined: Tue Jan 07, 2014 1:38 pm

General Questions in Project Design and Development

Tue Jan 07, 2014 2:22 pm

For a living, I write code for PIC microcontrollers. If I need access to a pin or a peripheral related to that pin, I can pull up the datasheet and get all of the information regarding that pin that I want. I have a project I want to do with an RPi, but this development process is going to feel a bit foreign to me. I'd appreciate it if someone could shed some light on the development process for me.

The RPi, unlike the PIC MCUs, is a closed system. I can't get the datasheet for the processor, so I'm not sure how I could get down to the hardware level to manipulate GPIO. I know libraries exist, such as WiringPi, that I can use but since I'm learning I'd like to know how I could accomplish this on my own without relying on libraries. WiringPi is released under GPLv3, so I suppose that means I could get the source and dig into it that way. However, if I were to write my own GPIO library, it would be nice to be able to do that without staring at other libraries. Is that where the NDA with, I believe, Broadcom would come in? I'd sign the NDA and get the datasheet from them?

At a much higher level view of the project I want to do, I'm wondering what the design would look like. My project will involve using the following:
  • SPI enabled ADC chip for sensing temperatures
  • servo for controlling a valve that affects the temperatures
  • PID loop for controlling the servo
  • SQL database (maybe?) to log the temperatures
  • web interface to view the system and change the setpoints


If I were doing this in a PIC MCU, I'd have the following files (as well as a few others):
  • spi.c - For sending and receiving spi data
  • adc_ic.c - Would utilize spi.c to read and write data to and from the ADC IC
  • temperature.c - Would utilize adc_ic.c to obtain the temperatures of the analog probes
  • pwm.c - Would allow access to the PWM pins
  • servo.c - Would utilize pwm.c to properly drive the servo
  • pid.c - Would provide a PID loop to be used by the application
  • Microchip TCP/IP Library - Would provide a web interface
  • app.c - Would tie together temperature.c, pid.c, servo.c and the TCP/IP Library
All of the modules (from spi.c to app.c) would all be thrown into a single project for the PIC. Communication between each of the modules would be simple, so long as the design was properly thought out before hand. This would be a fairly simple application to write.

However, I've never used a Raspbery Pi, and the only thing I've done on a BeagleBoard is open an Ethernet port to receive data. I'm ready to start designing the overall system, but I'm not sure how segregated everything should be. This is what I've come up with so far, and I'm hoping that someone can advise me on if this is a good way to do it or not.

Note: I'm not asking for anyone to give in depth details of how to do the things I have listed below. The list below is only a brain-dump of general ideas
  • Install the Apache web server
  • Install SQL database. The database will contain temperature setpoints and targets (input via the web interface) and temperature logging (input via the C project below)
  • Create a web page that allows me to read and write entries to the SQL database
  • Create a C project that includes WiringPi (I believe this gives me GPIO, SPI, and hardware PWM access) to communicate with the ADC IC to obtain temperatures. Also implement a PID controller in this project to control the servo (via PWM through WiringPi). Also find a library that allows me to access the SQL database
This has gotten kind of long and I'm very hopeful that I can get a few responses. If you've made it this far, thank you for taking the time to read the whole post.

For what its worth, I'm planning on releasing the source code via GPLv3 and I created a GitHub for it last night (pretty much empty though): https://github.com/Noggin01/SmokinPi/

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23078
Joined: Sat Jul 30, 2011 7:41 pm

Re: General Questions in Project Design and Development

Tue Jan 07, 2014 2:27 pm

Your initial statement is false.

There is a datasheet for the ARM processor (and specifically the on on the Raspi SoC) and the ARM side of the Raspi is completely open. There's a lot of information available on using the GPIO's etc available. See the Wiki and the tech help section on this site

The only closed code is the GPU which you wouldn't be able to make much use of anyway (in fact non for the use case you indicate)

Why do you think the Raspi is closed system? I thought that rumour had been quashed years ago.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: General Questions in Project Design and Development

Tue Jan 07, 2014 2:47 pm

Programming on the Rpi is just like any other Unix/Linux box. All the same tools are there. The big difference between pic programming and Unix/Linux is that there is a real OS running. What you are likely going to have to learn is how to interface with that OS. The OS is the keeper of the hardware.

Sure the hardware is different between machines but there are libraries for that. What libraries aren't there, are easy to write.

For the most part, there is nothing about the hardware that you really need to know. That is why there are device drivers. Device drivers take care of all the low level stuff so you don't have to. That also means that if you want to port your stuff to a Dell 690 running Ubuntu for example, it should just compile and run with no change to the source code despite the fact the hardware is completely different.

I understand your desire to understand the hardware at a low level, but it is really unnecessary. If you are really compelled to understand it, I suggest reading through the device driver source code.

I have done some development on the Rpi and it's SPI bus. It is not hard. There are examples out there.

My dev cycle works like this:

Use a high level language like Python for proof of concept testing.
Write the c programs
compile (make)
run the executable and debug.

If you need more info, let us know.
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

Noggin01
Posts: 61
Joined: Tue Jan 07, 2014 1:38 pm

Re: General Questions in Project Design and Development

Tue Jan 07, 2014 3:03 pm

jamesh wrote:Your initial statement is false.
Awesome!
jamesh wrote:Why do you think the Raspi is closed system? I thought that rumour had been quashed years ago.
Rumors are hard to quash, unfortunately.

I was wanting to decide between the BeagleBone Black and the RPi Model B. This is the article I read comparing the two systems. I had already thought that the hardware was a closed system, so this quote confirmed it (incorrectly?) for me:
Makezine wrote:Projects that you may wish to commercialize – Since the Raspberry Pi is more of a closed-source environment, it is impossible to make your own minimal versions. The open nature of the BeagleBone would allow you to just take the most important features and directly port that into your own design.
I like the BeagleBone Black more than the RPi due to the extra hardware pins available and that I thought it was more open, but I like that the RPi has 1080p output. I tried to buy a BBB this past weekend, but everyone was sold out. Right after I received shipment notification of the RPi, I received an In-Stock alert from Adafruit on the BBB. Regardless, I do not regret my decision to purchase the RPi and I am looking forward to using it.

If the company I work for decides they want to do an embedded Linux project (though I think they'd decide to do Windows CE since it is a true RToS) are you saying that we could do one based on the RPi SoC? We've done a BeagleBoard project (Linux based) and were able to remove stuff we didn't need, add bluetooth and WiFi modules to the board, and replace the power supply ICs without much trouble.

User avatar
Burngate
Posts: 5932
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: General Questions in Project Design and Development

Tue Jan 07, 2014 5:03 pm

Noggin01 wrote:I can't get the datasheet for the processor, so I'm not sure how I could get down to the hardware level to manipulate GPIO. I know libraries exist, such as WiringPi, that I can use but since I'm learning I'd like to know how I could accomplish this on my own without relying on libraries. WiringPi is released under GPLv3, so I suppose that means I could get the source and dig into it that way. However, if I were to write my own GPIO library, it would be nice to be able to do that without staring at other libraries.
Of interest may be http://elinux.org/Rpi_Low-level_peripherals and http://www.raspberrypi.org/wp-content/u ... herals.pdf

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

Re: General Questions in Project Design and Development

Tue Jan 07, 2014 5:30 pm

Noggin01 wrote: If the company I work for decides they want to do an embedded Linux project (though I think they'd decide to do Windows CE since it is a true RToS) are you saying that we could do one based on the RPi SoC?
Firstly I'm not quite sure what you mean about realtime, but if you mean it can be run in single-user mode then surely the raspi can too (and any linux system, I think...?) Also some people have posted about disabling some of the linux services to get more immediate response for, say, music applications and the like. But I'm open to correction and I may misunderstand what you need.

Secondly you might be interested in the Bare Metal part of the forum, if you want to dump linux and do everything at lower level. If this covers what you need...

As far as using the raspi's SoC, you'd need to buy them, and the makers won't sell the chips in small numbers. But if you just want to buy the boards and modify them, then the raspi's makers are perfectly happy with you using it for commercial applications. They've stated so in the past. They only get annoyed about use of their trademarks, I think.

I think the only thing that's really closed source is the highly proprietary graphics part of the SoC, not the ARM bit.

ghans
Posts: 7868
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: General Questions in Project Design and Development

Tue Jan 07, 2014 5:33 pm

You should definitely have a look at the bare metal
subforum and decide for yourself - can you find a community
this big and knowledgeable elsewhere ?

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

User avatar
joan
Posts: 14079
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: General Questions in Project Design and Development

Tue Jan 07, 2014 5:39 pm

Public domain http://abyz.co.uk/rpi/pigpio/

Code: Select all

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org/>

Noggin01
Posts: 61
Joined: Tue Jan 07, 2014 1:38 pm

Re: General Questions in Project Design and Development

Tue Jan 07, 2014 7:01 pm

Ravenous wrote:Firstly I'm not quite sure what you mean about realtime,
Basically, in embedded Linux, response times to interrupts is not guaranteed...or at least the guaranteed response time is not as as low as that guaranteed by Windows CE. I believe that you can run another kernel in Linux (doesn't replace the kernel, the main Linux kernel runs on top of it or something like that) which allows for guaranteed timings, but that kernel can't talk to the OS directly.

That said, I don't know why I said that the company I work for would chose Windows CE because of it being a "true" RToS; it would actually be chosen because we have already written many communication libraries that are portable between desktop flavors of Windows as well as Win CE. Brain wiring was crossed I guess.

By the way, I'm not comfortable talking about this as I'm not very familiar with it. The majority of what I know is from conversations with people that do know what they're talking about, but the goal of those conversations wasn't really to educate me on the differences between soft vs hard RToS's and Embedded Linux vs Windows.
Secondly you might be interested in the Bare Metal part of the forum, if you want to dump linux and do everything at lower level. If this covers what you need...
I'm not really interested in dumping Linux, I just want to understand how the hardware works. Understanding the hardware, I feel, gives me insight to understanding what the software is doing. For example, I can easily find libraries where I can call a function "Read_Adc( channel );" that reads the analog voltage on the specified pin. That is great, and I'm glad that library exists, but I'd much rather write my own functions to initialize the ADC so I can set the fastest acceptable timing and sample rates, decide which pins are analog and which are digital, set up DMA to move the results to RAM so I can access them later etc. If I didn't know how to set up the ADC peripheral at the register level, then I feel like I could easily be crippled if I were working on a timing sensitive project.

That said, I understand that since this is Linux, and Linux runs on hundreds (thousands?) of different processors, it just really may not be feasible to have that level of control at the cost of portability. If I actually do this project, and an RPi Model C is released a few years down the road with a new SoC, on board flash, built in LCD, hardware MP3 decoding and a 4G LTE modem it'd be awesome if I could use my project on the new hardware without having to port every single friggin line!

Noggin01
Posts: 61
Joined: Tue Jan 07, 2014 1:38 pm

Re: General Questions in Project Design and Development

Tue Jan 07, 2014 7:07 pm

ghans wrote:You should definitely have a look at the bare metal
subforum and decide for yourself
I'll take a look at the bare metal forum...I feel so stupid. When I saw "bare metal" my thought was, "Huh? Never heard of that language." I realize what it is now.
can you find a community this big and knowledgeable elsewhere
I tried the http://raspberry_pi.reddit.com, but they only seem to be interested in making cases and using other people's work. Don't get me wrong, using other people's work is what makes the RPi community so great and supportive. Asking questions about development seems to be downvoted and ignored while the seventeeth "Hey I mounted my PIs on a block of wood!" post gets the most action.

Noggin01
Posts: 61
Joined: Tue Jan 07, 2014 1:38 pm

Re: General Questions in Project Design and Development

Tue Jan 07, 2014 7:11 pm

joan wrote:Public domain http://abyz.co.uk/rpi/pigpio/
Nice! I'll take a look at it. I'm surprised that it advertises servo pulses on any of the pins as only one pin has PWM output. I know you can bit-bang it, but I suspect that might cause glitches. Or perhaps a server just isn't that sensitive to the jitter that would be present on big-banging the pin? I dunno, I should have my Pi available this weekend and I'll be able to start testing on it.

I'm excited!

User avatar
joan
Posts: 14079
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: General Questions in Project Design and Development

Tue Jan 07, 2014 8:48 pm

Noggin01 wrote:
joan wrote:Public domain http://abyz.co.uk/rpi/pigpio/
Nice! I'll take a look at it. I'm surprised that it advertises servo pulses on any of the pins as only one pin has PWM output. I know you can bit-bang it, but I suspect that might cause glitches. Or perhaps a server just isn't that sensitive to the jitter that would be present on big-banging the pin? I dunno, I should have my Pi available this weekend and I'll be able to start testing on it.

I'm excited!
No jitter, or your money back.

In class inheritance (gert -> richard hirst -> joan)

ghans
Posts: 7868
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: General Questions in Project Design and Development

Wed Jan 08, 2014 11:44 am

@Noggin01

There is already a Windows 7 CE BSP floating around :
http://www.raspberrypi.org/phpBB3/viewt ... 56&t=58259

The USB system isn't completely working though (for now), so
no Keyboard , Mouse and Internet !

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23078
Joined: Sat Jul 30, 2011 7:41 pm

Re: General Questions in Project Design and Development

Wed Jan 08, 2014 11:58 am

Noggin01 wrote:
ghans wrote:You should definitely have a look at the bare metal
subforum and decide for yourself
I'll take a look at the bare metal forum...I feel so stupid. When I saw "bare metal" my thought was, "Huh? Never heard of that language." I realize what it is now.
can you find a community this big and knowledgeable elsewhere
I tried the http://raspberry_pi.reddit.com, but they only seem to be interested in making cases and using other people's work. Don't get me wrong, using other people's work is what makes the RPi community so great and supportive. Asking questions about development seems to be downvoted and ignored while the seventeeth "Hey I mounted my PIs on a block of wood!" post gets the most action.
As with anything, you need to find the right place to ask questions. And here is the best place. As you might expect, it's the biggest forum, with the both Foundation and Broadcom (SoC manufacturer) people posting, including the people who've done the real development work.

Just out of interest, why did you try Reddit before coming here?
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

Noggin01
Posts: 61
Joined: Tue Jan 07, 2014 1:38 pm

Re: General Questions in Project Design and Development

Wed Jan 08, 2014 1:38 pm

Just out of interest, why did you try Reddit before coming here?
Only because I am already fairly active on Reddit. Reddit is nearly a 1-stop place for anything and everything. However, within the last few months I've started to find that Reddit is too generalized for more specific questions. I get better discussions about smoking meat at smokingmeatforums.com, better discussions about MCHP PICs at the Microchip.com forums, and it looks like I'll be getting better discussions about the Pi here :)

User avatar
Redrobes
Posts: 80
Joined: Mon Dec 26, 2011 9:19 pm
Location: S.W. UK
Contact: Website

Re: General Questions in Project Design and Development

Thu Jan 09, 2014 6:09 pm

I looked at the spec and wrote a GPIO driver and use it to toggle pins and do stuff. So its not that big a deal. I also program PICs and I have used it to interface the raspi to some 12F629's to send some data to them.

http://www.raspberrypi.org/phpBB3/viewt ... 33&t=32152

Heater
Posts: 12969
Joined: Tue Jul 17, 2012 3:02 pm

Re: General Questions in Project Design and Development

Thu Jan 09, 2014 8:18 pm

"Open", "Closed" always an interesting debate.

Seems that the ARM side is open and documented enough. You can drive those peripheral registers from a Linux device driver or even by mapping real memory (register) address space into user space and letting your program hit the registers directly. There is GPIO code in C available that shows how to do that. For some kind of "real-time" performance under Linux you can always assign a high priority to your process/thread.

If Linux is not real-time enough then you have to go the "bare metal" route,

However, the Raspi cannot even boot up without the GPU and it's firmware. Which of course is very closed. Basically the GPU owns the machine from boot time.

Some will worry about that. So far I do not. Until such time I get an idea the NSA has coerced Broadcom into backdooring the GPU.

Return to “C/C++”