helpme
Posts: 118
Joined: Thu May 16, 2013 2:20 am

What are situations to use bare metal when python is so much easier?

Wed Aug 23, 2017 12:28 am

Python code is readable and there are lots of ready libraries to use without reinventing the wheel. What are applications or situations to use bare metal code when python is so much easier?

User avatar
rpdom
Posts: 11381
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: What are situations to use bare metal when python is so much easier?

Wed Aug 23, 2017 5:50 am

Reasons:

Speed. Python is an script language and relatively slow (but better than some). Raw code works at full speed.

Boot time. No OS to load means boot times are a few seconds.

Minimal code means less to cause issues - it is only your code that is running, so you know what it is (should be) doing.

No OS = more secure (mostly)

Also, just because we can ;-)

helpme
Posts: 118
Joined: Thu May 16, 2013 2:20 am

Re: What are situations to use bare metal when python is so much easier?

Wed Aug 23, 2017 5:55 am

rpdom wrote:
Wed Aug 23, 2017 5:50 am
Reasons:

Speed. Python is an script language and relatively slow (but better than some). Raw code works at full speed.

Boot time. No OS to load means boot times are a few seconds.

Minimal code means less to cause issues - it is only your code that is running, so you know what it is (should be) doing.

No OS = more secure (mostly)

Also, just because we can ;-)
Thanks for the answer. I understand your point about speed. I get the impression that bare metal is more meant for microcontrollers and not "mini-computers". RPi is almost like a computer. It's equivalent to a computer >10 years ago. It sounds pretty over-kill to me to use RPi for bare metal. Having said that, I will respect any engineer who is able to do that for fun ;)

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

Re: What are situations to use bare metal when python is so much easier?

Wed Aug 23, 2017 5:59 am

People who write bare-metal often want to meet precise timing requirements. Raspbian is a pre-emptive multitasking desktop system and CPython employs automatic garbage-collection so you don't get any realtime guarantees with both.

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

helpme
Posts: 118
Joined: Thu May 16, 2013 2:20 am

Re: What are situations to use bare metal when python is so much easier?

Wed Aug 23, 2017 6:03 am

ghans wrote:
Wed Aug 23, 2017 5:59 am
People who write bare-metal often want to meet precise timing requirements. Raspbian is a pre-emptive multitasking desktop system and CPython employs automatic garbage-collection so you don't get any realtime guarantees with both.

ghans
Wouldn't it make more sense to use a cheaper 32-bit MCU like STM32 for real-time guarantees?

User avatar
rpdom
Posts: 11381
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: What are situations to use bare metal when python is so much easier?

Wed Aug 23, 2017 6:09 am

helpme wrote:
Wed Aug 23, 2017 6:03 am
Wouldn't it make more sense to use a cheaper 32-bit MCU like STM32 for real-time guarantees?
Possibly, but how many 32-bit MCU's have 1080p HDMI output and 512MB of RAM for under £10 including tax and postage? (Pi Zero)

Driving the video output via framebuffer in bare metal is pretty simple.

helpme
Posts: 118
Joined: Thu May 16, 2013 2:20 am

Re: What are situations to use bare metal when python is so much easier?

Wed Aug 23, 2017 6:13 am

rpdom wrote:
Wed Aug 23, 2017 6:09 am
helpme wrote:
Wed Aug 23, 2017 6:03 am
Wouldn't it make more sense to use a cheaper 32-bit MCU like STM32 for real-time guarantees?
Possibly, but how many 32-bit MCU's have 1080p HDMI output and 512MB of RAM for under £10 including tax and postage? (Pi Zero)

Driving the video output via framebuffer in bare metal is pretty simple.
Ahh... that makes sense. That would be a suitable situation to use bare-metal. RPi

hippy
Posts: 2169
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: What are situations to use bare metal when python is so much easier?

Wed Aug 23, 2017 9:37 am

rpdom wrote:
Wed Aug 23, 2017 5:50 am
No OS = more secure (mostly)
And fewer licensing issues.

And, as you ( the OP ) mentioned Python; while that has the advantages you mention, it's not so easy to keep one's source code secret. There's no perfect solution to achieving that - and solutions don't necessitate going bare metal - it is more a reason why Python isn't better in all cases.

It is also possible to boot directly to some versions of Python which is closer to bare metal than closer to a full OS. Unfortunately that is not currently supported by the Pi, though one can do it for Pascal using Ultibo.

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

Re: What are situations to use bare metal when python is so much easier?

Wed Aug 23, 2017 9:54 am

Its an odd comparison. Python is a computer language, bare metal is method of using the processor. They don't really compare.

More relevant questions might be...

Why use Python when C is so much faster? Why use C when Python is so much easier?

Why use bare metal when you can use Linux? Why use as OS when you can write time sensitive code in bare metal?

It's all down to the requirements, get those solid, then decide what is the best way to achieve them.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.

jahboater
Posts: 1667
Joined: Wed Feb 04, 2015 6:38 pm

Re: What are situations to use bare metal when python is so much easier?

Wed Aug 23, 2017 10:45 am

hippy wrote:
Wed Aug 23, 2017 9:37 am
It is also possible to boot directly to some versions of Python which is closer to bare metal than closer to a full OS. Unfortunately that is not currently supported by the Pi, though one can do it for Pascal using Ultibo.
Can you not just add "init=/usr/bin/python" to /boot/cmdline.txt ??
I am sure this worked for me in the past on Raspbian, but I don't have a spare monitor handy to try it now.

hippy
Posts: 2169
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: What are situations to use bare metal when python is so much easier?

Wed Aug 23, 2017 10:54 am

jahboater wrote:
Wed Aug 23, 2017 10:45 am
Can you not just add "init=/usr/bin/python" to /boot/cmdline.txt ??
Possibly but I believe that still loads the OS anyway, rather than just needing a Python interpreter as kernel.img

jahboater
Posts: 1667
Joined: Wed Feb 04, 2015 6:38 pm

Re: What are situations to use bare metal when python is so much easier?

Wed Aug 23, 2017 10:59 am

hippy wrote:
Wed Aug 23, 2017 10:54 am
jahboater wrote:
Wed Aug 23, 2017 10:45 am
Can you not just add "init=/usr/bin/python" to /boot/cmdline.txt ??
Possibly but I believe that still loads the OS anyway, rather than just needing a Python interpreter as kernel.img
Yes thats right, the kernel still runs as normal. Python would replace init (or systemd now I presume). It does mean you can boot straight into a Python prompt, which perhaps is what the OP was looking for.

LdB
Posts: 516
Joined: Wed Dec 07, 2016 2:29 pm

Re: What are situations to use bare metal when python is so much easier?

Wed Aug 23, 2017 12:09 pm

That has to be the weirdest comparison ever, it's actually hard to find common ground to even compare anything :-)

Anywhere you can run python you certainly won't be baremetal programming.
Last edited by LdB on Wed Aug 23, 2017 12:23 pm, edited 1 time in total.

helpme
Posts: 118
Joined: Thu May 16, 2013 2:20 am

Re: What are situations to use bare metal when python is so much easier?

Wed Aug 23, 2017 12:51 pm

LdB wrote:
Wed Aug 23, 2017 12:09 pm
That has to be the weirdest comparison ever, it's actually hard to find common ground to even compare anything :-)

Anywhere you can run python you certainly won't be baremetal programming.
You can run python on Raspberry Pi, yet this is a forum for discussing baremetal programming on Raspberry Pi.

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

Re: What are situations to use bare metal when python is so much easier?

Wed Aug 23, 2017 3:06 pm

helpme wrote:
Wed Aug 23, 2017 12:51 pm
LdB wrote:
Wed Aug 23, 2017 12:09 pm
That has to be the weirdest comparison ever, it's actually hard to find common ground to even compare anything :-)

Anywhere you can run python you certainly won't be baremetal programming.
You can run python on Raspberry Pi, yet this is a forum for discussing baremetal programming on Raspberry Pi.
What is your actual question? Why do baremetal at all?
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.

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

Re: What are situations to use bare metal when python is so much easier?

Wed Aug 23, 2017 5:13 pm

Maybe I'm in a minority (or maybe I'm just weird) but I tend to think of Python - or any interpreted language for that matter - as just a virtual machine with a set of instructions, just like an Arm or an Intel x86.
It's a lot slower than a real machine, but it's got a lot of sophisticated instructions so you can get a lot done with a short script. If plus-or-minus half a second is good enough timing, then a Python "machine" is ace.
And because other things can be running in the background, the Python "machine" can be thought of as having multiple cores.

But if speed or timing is of the essence, and instructions such as BNE loop1 or ORRNE R11,R11,#(1<<GaC%) are good enough for the job, then an Arm is the thing to use.

And it's not an either / or situation - you don't have to choose one or the other.
Start Linux on three of the Pi's cores, and use the fourth for your bare-metal Arm code.
I eventually managed that with a 32 x 16 LED panel, with the Arm code running full-tilt driving the pwm to the panel to provide the 24-bit-per-pixel colour information, and the Linux side (actually Risc Os in my case) feeding the"frame store" with images when needed.

LdB
Posts: 516
Joined: Wed Dec 07, 2016 2:29 pm

Re: What are situations to use bare metal when python is so much easier?

Wed Aug 23, 2017 5:26 pm

"@helpme": We can't fathom what you are discussing because the two things don't share any common ground and there is hardly anything we do on baremetal that would be allowed under linux much less python.

Most of us playing around with Baremetal on the Pi are either learning ARM SOC platforms (the Pi is one of the easier SOC platforms), writing their own O/S or looking at commercial products. Very few even have an O/S that python could sit on and I suspect most wouldn't use it even if they could because there are other much faster and more preferable languages available.

So there is pretty much zero interest in discussing python on a baremetal forum as it has no role.
Last edited by LdB on Wed Aug 23, 2017 7:41 pm, edited 1 time in total.

beta-tester
Posts: 1052
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: What are situations to use bare metal when python is so much easier?

Wed Aug 23, 2017 7:15 pm

helpme wrote:
Wed Aug 23, 2017 5:55 am
It sounds pretty over-kill to me to use RPi for bare metal.
it is also an overkill to have a full opperating system running that is able to do multiple things, but you are only running a python script on it.

why bare metal? becaus you can!
testing out the limits of a device, how tiny can your code be, how quick can your code be or how far can you go, how can you tweak the system... its like sport / olympic games.
when you have a RPi in your shelf, why not using it
its not always a matter of logic or economic.
(make it snese to bring a ball from one side of a playfield to the other side - no ! but for some people it makes a lot of fun)
{ I only give negative feedback }
RPi Model B (rev1, 256MB) & B (rev2, 512MB) & B+, RPi2B (1GB), 64GB microSDXC1 class 10, HDMI 1920x1080, keyboard-mouse-combo (wireless), PiCamera, ethernet-cable, 5V/1.2A power supply, Wifi dongle (rt5370)

helpme
Posts: 118
Joined: Thu May 16, 2013 2:20 am

Re: What are situations to use bare metal when python is so much easier?

Wed Aug 23, 2017 11:54 pm

jamesh wrote:
Wed Aug 23, 2017 3:06 pm
helpme wrote:
Wed Aug 23, 2017 12:51 pm
LdB wrote:
Wed Aug 23, 2017 12:09 pm
That has to be the weirdest comparison ever, it's actually hard to find common ground to even compare anything :-)

Anywhere you can run python you certainly won't be baremetal programming.
You can run python on Raspberry Pi, yet this is a forum for discussing baremetal programming on Raspberry Pi.
What is your actual question? Why do baremetal at all?
Hi LdB and jamesh,

I guess the question is not well phrased. If there is a problem that can be solved by using python, it makes zero sense to use bare metal. I should have asked "What are things that bare metal can do that python cannot on Rpi? What are some applications that are best suited to be done by bare metal instead of python on Rpi?"

I am ignorant about using bare metal on Rpi. I am asking to get a sense if it is worth acquiring knowledge in Rpi bare metal.

dwelch67
Posts: 817
Joined: Sat May 26, 2012 5:32 pm

Re: What are situations to use bare metal when python is so much easier?

Thu Aug 24, 2017 1:20 am

It is an improperly phrased question. A language vs an environment. The why use C when you can use Python or why use _fill in the blank_ when you can use Python. Which of course really have no answer.

it is like asking why fix your brakes yourself when your mechanic can do it. How does the mechanic learn how to do it? Only on broken cars? probably not they probably have some percentage in the shop class and some percentage they keep taking the same wheel off or brakes apart and putting them back together.

How can you have Python if there is nobody that knows how to write a compiler/interpreter? How can you have the python virtual machine if nobody knows how to do basically bare metal to make that machine work or translate that into another machine (yes, python and javas virtual machines are simply just another instruction set that is run on an emulator/simulator/virtual machine, there is nothing special beyond that other than the instrucitons are massivly CISC, almost need a new word to describe some of them as they are beyond even CISC like instructions (others are cisc/risc like but mostly stack machines so very simple)). How can someone write an operating system if they only know how to run them and (just drive a car) rather than dig in and find out how they work (be a mechanic or fix it themselves). For every lets say 100,000 programmers or maybe even more you have someone that knows the internals and can work on a compiler or driver or other. In my case and some small percentage of others, you need folks at this level to even be able to create chips or motherboards, not only know bare metal but build tests and debug processors in development or broken processors, etc. as well as all the above.

Take a product company say apple and the iphone, you really only need a very small number say one to a few to do the low level work for that whole product line. Some companies may have between zero and a few folks, everyone else is writhing C++ or JAVA or python or whatever, well a few are writing drivers for the operating system and some are porting the operating system (believe it or not porting linux to a new platform takes a fair amount of experience, millions of lines of other peoples code, infinte number of crashes getting it running, etc). 99% of your folks are non-bare-metal, non-driver. A lot of times companies take the bsp from some other company (the chip company) and just compile it without the desire to even look under the hood, if it doesnt just work they file a support ticket. Same goes for a large percentage of microcontroller developers they take the bsp/libraries from the chip company and just make calls, no different than making C or operating system calls to make a gui program. File tickets or go to stackoverflow if something breaks rather than reading the documentation for the chip. Why is the arduino so popular? I just answered that question. So we could be on an stm32 forum and someone would be asking the same question, why are you writing bare metal programs to manage the spi peripheral when st has already written some and you think they would know their own stuff (my answer to that is have you looked at these chip vendors libraries? The A-Team doesnt write them, the interns and junior engineers write them with minimal mentoring from the senior folks if you even have any at a company like that, just like looking at the guts of linux or gcc these libraries are downright scary in places, but without the right experience you wouldnt know that).

Just like the avr freaks, the arduino thing, why did the raspberry pi end up with a baremetal forum that is actually useful, why isnt there one as good as this for other boards/chips? dont know just happened this way, is very interesting. The platform is strange in that if you are paying full price when it came out the pi was cheaper or priced along with an arduino, a zillion times more everything for the same money, and you can program it high level or low level, whatever you want, sold. Now you can pay full price for an stm32 discovery or nucleo around $10 or $15 or get a pi zero for less (and add shipping to either). both are fun and interesting both have the why are you doing bare metal, but the pi has a lot more bang for the buck, and is actually easier to program than a microcontroller, despite the poor documentation (well the peripherals are, the core is getting way more complicated).

Some folks want education, this is a designed for education platform, and I am happy to see it is a very good choice for that for those folks (I want to write my own operating system kind of thing). Baremetal can be used to turn this platform into a very reliable product, like or not the fewer lines of code the less risk, linux is neither a performer nor low risk, you can get better performance and significantly lower risk if you put in a little NRE. Great platform for someone who wants to port linux on their own, wants to port bsd, you name it. The inability to brick it puts it on par with microcontrollers instead of competing boards. you brick your pi you simply remove the sd card and re-write it. you brick something else you have to pull out your jtag equipment you bought, even if it was only $10, you have to know how to use and configure it where are you going to find that (sometimes easy sometimes very hard) and sometimes soldering is required, sometimes very delicate soldering is required. With the pi you just remove the sd card and re-write it and try again, so long as you didnt let any smoke out but that a risk in general for most platforms.

compilers, gcc for example IMO have gotten worse over the last few major releases (from 3.x.x to the present). There are too many languages and the skills needed at the low level are just not there, some schools are bringing back some of the skills in the form of assembly bomb programs and some folks are using it to hack for good or bad reasons, but the pool of folks with the skills vs the pool of folks is eroding fast IMO. Ever see the Wall-E movie? Can any of those humans plant their own food, make their own clothes or clothes for other people, etc? You might look down your nose at your mechanic but if you cant fix your car yourself or build a car yourself should you be driving one if all you can do us pump gas and work the key, brake and gas pedal? If the mechanics all gave up because it is easier to drive a car than to build/fix one, where would we be? Just like assembly language knowledge makes you a better C or Python or any other programmer (IMO), understanding how things work deep down make you a better user and programmer as well.

Think of the myriad of programmers that dont realize the same source code does not compile to the same machine code every time. Different compilers produce different output, the same compiler produces different output with different command line options. You see regularly on stackoverflow folks learning this...Dont know never looked...dont know what I am looking at anyway, assembly language is a dead language nobobody programs in it, etc etc (not realizing most compilers certainly "tool chains" thus the name compile from say C to assembly language then assemble that to an object then link those to a binary which is a misleading term as there are tons of ways to take the same machine code and put it in a file format called a "binary" all of this of course buried behind the C compiler program name like "gcc" that spawns all the other programs (at times like gcc actually spawns other programs just to do the compile part)).

These are not skills that a robot is going to take away, not efficiently at least, like the quality of some of the compilers or even for example using JAVA or Python, you are throwing away so much, you are spending several times as much money to perform the same task. could have a 1ghz processor with half the ram that costs you way less than half out perform a 4ghz processor simply by switching from Python to C or JAVA to C, or name several other languages to C. Then unbloat the operating system and it all scales up. More up front work to have the runtime better, is it worth it? you have to balance that but if you never knew how or nobody else you know knows how how will the Nth compiler ever get better? For much of my life the processors get better every year, but the software cannot keep up, not sure how the chip folks dont go insane. We take some hot new processor then run a binary compiled for the lowest common denominator even if C or some other efficient language, you are still throwing away half of the hardware you bought if not much more.

/ rant off /
/ soapbox off /

I have excuses, I do this for fun. I find it challenging to figure this stuff out even if after I figure it out I never ever make anything with what I learned. I do this as my day job, but in my day job I cannot pick or choose the things I want to dig into or debug or figure out or test because its not fun, I have to do it fun or not. Here I can just not try the things that dont look fun and not think twice about it.

Someone wise once told me there are lego people and there are G.I.Joe(/Barbie) people. Some want to build something just to build it and then immediately tear it down and build something else, but never really play with the thing they built. And there are folks that want to just play with the thing and not have to build it first. Nothing wrong with either type, but you really need both types, some that do one and some that do the other. You cannot have python on raspberry pi without say 2 to a dozen folks that can build a chip that works, port an operating system (write an operating system) make a language/compiler etc (Okay beyond a dozen folks now), so that the masses can write cool programs that solve real problems in whatever language they choose, including Python. The person that cures cancer is very likely not going to be someone who can build a microscope or know how to make the glass from raw materials and form a test tube, but are very likely to have a large lab full of tools someone else made and couldnt have cured cancer without it. And of course many of the lego folks can play with barbies too, can write a bootloader and write an application, might not be proficient in 17 different programming languages and pick and choose between them, but can still make both sides functional.

(I hope I dont regret writing this...I wonder if I can delete it)...

dwelch67
Posts: 817
Joined: Sat May 26, 2012 5:32 pm

Re: What are situations to use bare metal when python is so much easier?

Thu Aug 24, 2017 2:04 am

What are situations? These are very real things, be it a $50,000 car or a $5 raspberry pi. Microcontrollers since you are asking or cpld/fpgas. Every penny counts when mass producing a product. If I put an RTOS on a microcontroller so that I can program in JAVA or Python or just be lazy, that _might_ require a larger microcontroller or one running at a higher clock rate or both. It might be a $2 part instead of a $1 part. Might be $2 vs $1.75. The higher clock rate may require more power, might get 10 months from one battery instead of 12 in your remote control. And maybe customers notice that or maybe not. They do notice that one remote only needs one battery and another needs two or three or four.

The balance is a business decision as well as technical. need to know and fully understand the 80/20 rule. If you pay another $50,000 to the employee or contractor to ultimately save 5 cents per product, if you dont sell more than what is it 1,000,000 units then you lost out on that savings. Baremetal sometimes comes in to play here, sometimes not, you can cut your flash size down which is a big chunk of the cost of a microcontroller/other (tablet, etc) by just having less and more efficient code. And I would argue and can demonstrate sometimes it takes the same amount of time to write that application in bare metal as it does making api calls. Sometimes the other way, but not automatically one way or the other.

I once had a manager that said the project wont be finished shoot the engineer (along the lines of it aint over till the fat lady sings). Meaning the engineers will just keep working on it to make it faster/better/cheaper forever, eventually you have to just tell them to stop its good enough move on. Doesnt work that way in every business, but again that is basic management skills as to how much freedom and control to give the developers and then when to tell them to stop or how to drive milestones and keep them on track, rather than let them perfect the paint and polish on a button for a product where the button doesnt do anything yet because they didnt work on that they were having too much fun making the perfect button.

You can see this in a lot of folks can take an arduino, play in the arduino sandbox, buy shields and make a robot thing for hundreds of dollars plus their time. But someone else can sell the same thing on amazon and with profit included it costs $10. Step one make the board smaller and cheaper, well I dont know how to make a board I just buy them at Adafruit or Sparkfun. Absolutely nothing wrong with making something from arduino parts with sandboxed apis. fun and easy and quick. Like building your rubics cube solving robot out of legos instead of machining rods and gears and such from chunks of metal. (or like writing a program in Python instead of C). And maybe you can do both but for fun you do the arduino thing but at work do the make a product thing. You prototype in Python or make adhoc tools, but sometimes if it needs to be productized you re-write it in C or C++ for various reasons (size, performance, security, etc).

No it is not wise to take a raspberry pi and use baremetal to make a product out of it that is better than some linux based product with that pi. (if you are making a product around a pi then someone else can probably make a replacement product cheaper and will take your market away if there is a real market). But the skills you learn from baremetal on a pi can be used to make other products faster, cheaper, more reliable. Or even lets say to replace or create drivers for linux on a pi that makes that pi perform better but on an operating system. If you are not able to isolate the peripheral in some way from the operating system (baremetal or not) to understand the peripheral how are you going to then be able to use the peripheral on that operating system? Sometimes the skills translate that way.

DDR init, you now what kind of nightmare it is to bring up dram and make it work reliably? All of those skills come into play, long before you can port the operating system someone has to get the dram up, there is no doubt some on chip sram that is used for this (by the GPU), the old days you could run from flash/eeprom directly and rely on the processors general purpose registers in assembly language and maybe get by, but DDR init is a big one that requires these skills and you cant do it with python unless you have a lot of on chip sram. I have looked over someone elses shoulder on this for a couple of chip generations where I work and he quit so next year I get to do this with new ddr IP on a new chip on new boards...10 months of fun...or pain...will see...the extra fun comes from it being new silicon as well, does it not work because I programmed the controller wrong or because the chips broke or the board is noisy, the balls are not soldered down right, the processor is buggy, etc...

User avatar
Gavinmc42
Posts: 1375
Joined: Wed Aug 28, 2013 3:31 am

Re: What are situations to use bare metal when python is so much easier?

Thu Aug 24, 2017 3:18 am

Python is easier, which is why people use it.
I started on Pi's with Python code ported from a Micro PC running Linux and Python/Pygame.
Big PC code can be made to run on tiny Pi's, that is massive progress.

I still have this old model A out in the field monitoring solar panels and batteries etc.
Not fast sensor sampling, every 10secs or so. It is running graphics display on two monitors showing a power in, power out.
This was done on Raspbian with Python using Pygame, background image, overlay images, texts and lines and animations.

Backing up requires taking an image of the 8GB SD card. Do a few projects and soon your harddisk is filled with backup SD card images.
Last time it failed a few python library files got corrupted on the SD card. Took quite some time to resurrect it.

Baremetal Ultibo now has nearly to the same capability as Raspbian + Python + Pygame.
But in this case all that is needed on the SD card is bootcode.bin, start.elf, fixup.dat and the Ultibo Free Pascal code code compiled to a single kernel.img. Backing up is just backing up a few 10k's of source files, I can recompile these in a few minutes.

From a security point of view it is easier to check a single Ultibo kernel.img than Raspbian OS + lots of other stuff that comes on it.
Ultibo coding is similar to microcontroller coding, just a really fancy Arduino, boots faster than Linux but still takes two seconds.
Linux and the multitude of languages and other methods I used before finding Ultibo really pushed my capacity to learn to the limit.

Try driving HDMI displays from a microcontroller.
I could upgrade the model A with a $5 Zero. The Zero could do the same thing and runs a little faster and has twice the memory as the old A.
$5, Zero , $10 Zero W, not exactly a low power solutions but very hard to beat the capability for the price plus they have proven to be very reliable hardware.

I have a middle solution using piCore and micropython, piCore Linux OS looks after the SD card a bit better and this is usually less than 100MB. Much smaller backup images.
If I need a realtime control type output then I just add a tiny microcontroller controlled from the Pi via i2c.

The Pi could be called using a sledge hammer to drive nail, but we do have a family of various sized hammers now, don't always needed a Pi3. Cannot do the project in baremetal on a Pi? Just swap the SD card and pick an OS and language or library ....

Would I make a mass produced product with a Pi in it? Probably not.
It depends on what qty "mass" is, Qty 1- reach for Pi, qty 10 ok use Pi, qty 100 Pi?, 1000 maybe not a Pi.

You want reliable software with less Zero day exploits, go baremetal?
Things like GoKrazy are offering a sort of interim middle ground, Linux Kernel plus single file application
Pi's just offer you more software solutions, it would take the rest of your life learning them and testing every solution :lol:
A microcontroller has less options. This is being stretched as bigger/better Arduino's get made.

Microcontroller/Microcomputer? the lines are getting blurry between them these days.
All the good microcontrollers tend to be 32bit now and some of these you can get for <$1.
But you can get a complete Zero Microcomputer for $5, that's just crazy, turn the world upside down pricing.

There is a triangle model for product development , Quality, Time, Cost - pick two.
With Pi's now there is a chance to get all three into a product.
Python fits in the Time point of this triangle. Somethings I found like i2c comms is more reliable in Ultibo, that's the Quality point of the triangle. Cost? er Pi's are cheap because they are made in serious volume for a unique purpose, teaching me to code :lol:
Attachments
GTSE_sm.jpg
GTSE_sm.jpg (59.05 KiB) Viewed 1050 times
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

dwelch67
Posts: 817
Joined: Sat May 26, 2012 5:32 pm

Re: What are situations to use bare metal when python is so much easier?

Thu Aug 24, 2017 8:38 pm

for example the cortex-m4 the cortex-m7 and I just saw there is an armv8m for the cortex-m22 and cortex-m23. it is very hard to call the m4 and m7 a microcontroller with a straight face, 100 to 200 mhz, floating point unit, seperate i cache and d cache, something that resembles an mmu, granted these are all fairly large parts that have been made from them (well the m7 at least) and are not 1$ parts. But I think ti has settled on the m4 for a lot of things and is making various sized ones...(they bought luminary micro which was the first company to come out with a cortex-m, the stellaris line).

There was talk of an armv8 based 32 bit only not sure why that isnt just called an armv7 but whatever. it is like their microcontroller cores and their full sized cores are merging toward each other on one end and of course the full sized are also growing the other direction too.

I can solder no problem but would have rather or also seen a pi-zero not W with headers installed, and a reset button. I think at least headers would help the folks that cant/wont solder. or do the staggered holes thing so that they hold the pins without necessarily needing solder, that would be a somewhat trivial change to the pcb.

I know these are computers not platforms for making robots or other hobby projects...

I didnt mention in my prior statement, although the pi-zero is very price competitive to say an stm32 discovery or nucleo board ($10 up), you can go on ebay and find whole stm32f103 or other stm32 board for $2 give or take from asia, cheaper than most of us can buy the microcontroller itself in large quantities, have to call direct and negotiate to get the one part that cheap and these have a pcb, crystal, usb connector, pins, etc...but they are very slow, dont have video, etc. which you get for a few bucks more...

User avatar
Gavinmc42
Posts: 1375
Joined: Wed Aug 28, 2013 3:31 am

Re: What are situations to use bare metal when python is so much easier?

Fri Aug 25, 2017 12:41 am

Some of these "little" pcb/cpu's can now run micropython or Lua or JS.
The ESP8266 changed the WiFi connectivity sensor world, not exactly a powerful cpu but good enough, just.
Next gen versions like the ESP32 etc can do even more, but still not HDMI.

Micropython, Lua, Javascript do make these easier to use/program than embedded C.
but is Micropython baremetal?
These higher level languages are all about getting similar functions at a faster development speed.
And most importantly at a lower user skill level.
Yep Cortex M4 is a beast and the M7 is near microcomputer performance.
But what is a microcomputer these days, these chips are way past my first 12MHz 80286 PC.

Use what ever is the easiest to do the job required?
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

LdB
Posts: 516
Joined: Wed Dec 07, 2016 2:29 pm

Re: What are situations to use bare metal when python is so much easier?

Fri Aug 25, 2017 4:22 am

MicroPython still can't compile itself (it requires a C compiler for that) a status FreePascal like you use on Ultibo reached rather fast.

It also has not been ported to the Pi but it is on Github
https://github.com/micropython/micropython

The startpoint is given if he wants to try
minimal/ -- a minimal MicroPython port. Start with this if you want to port MicroPython to another microcontroller

Then he will find out why the baremetal section exists and what it is for and the penny will drop, as you just gave an example to him :-)

Return to “Bare metal”

Who is online

Users browsing this forum: No registered users and 7 guests