Skip to main content
58 votes
Accepted

Why do we need a bootloader separate from our application program in microcontrollers?

A bootloader on a microcontroller is responsible for updating the main firmware over a communication channel other than the programming header. This is useful for updating firmware in the field over ...
CurtisHx's user avatar
  • 997
55 votes

MCU programming - C++ O2 optimization breaks while loop

The code optimizer has analyzed the code and from what it can see the value of choice will never change. And since it will never change, there's no point in ...
Ignacio Vazquez-Abrams's user avatar
54 votes
Accepted

Why do microcontrollers need a programmer device?

That's what the programmer does. It takes the binary output from the compiler and stores it in the MCU's Flash EPROM, usually over a serial bus. Flash EPROM requires a programming algorithm to store ...
TonyM's user avatar
  • 23.5k
43 votes
Accepted

Create Circuit Simulation

I wrote the simulation engine that powers CircuitLab from scratch: from the sparse matrix library up through component models and simulation modes. My co-founder wrote the front-end. It ended up being ...
compumike's user avatar
  • 3,684
35 votes
Accepted

Why is a register initialised through bitwise operations instead of a binary string?

0b00001000 vs 1<<3 The binary notation is not standards-compliant C. That might just rule it out. If it doesn't rule it ...
Marcus Müller's user avatar
32 votes

Why do microcontrollers need a programmer device?

A programmer is the implementation of " via specific bus,". Some devices have inbuilt bootloaders (may be hardware or software or firmware) that allow the use of a port of some sort to load ...
Russell McMahon's user avatar
  • 151k
31 votes

Is it possible to draw circuits through code?

If you are familiar with \$\LaTeX\$, you can use circuitikz to draw nice circuits by writing code. Example. More Examples
nidhin's user avatar
  • 8,332
27 votes

Why do we need a bootloader separate from our application program in microcontrollers?

So that the loading process can recover from errors. Suppose there is a communication error or power disconnects during an upgrade. If the boot loader were part of the application you were upgrading ...
user4574's user avatar
  • 12.4k
22 votes

How can I estimate the speed of this code section for this microcontroller?

Since the code snippet you're interested in isn't big, you could disassemble your compiled code, look at all the assembly instructions and count how many cycles they need. You can find the number of ...
Swedgin's user avatar
  • 753
21 votes

Why do microcontrollers need a programmer device?

transfer it to specific place in flash memory via specific bus This is exactly what flash programmer devices do. They just don't use something slow and archaic like RS232, but instead nowadays ...
Lundin's user avatar
  • 21.1k
19 votes
Accepted

What does a function mean that doesn't have "void", "int", etc in front of it mean?

The functions are interrupt handlers, defined using the ISR(vector, attributes) macro. The macro generates a proper platform-specific function signature, including ...
Kuba hasn't forgotten Monica's user avatar
18 votes
Accepted

Do you typically need to program-in a USB communication protocol?

Like any protocol stack, USB incorporates components representing various layers. High-level drivers and libraries provide higher-layer functionality on top of lower layers, effectively abstracting ...
nanofarad's user avatar
  • 20.2k
17 votes
Accepted

How does one go about learning to program a new micro controller?

Generally speaking you won't find all the information in a single document on newer 32-bit MCUs. The "data sheet" is more like a light overview of capabilities with electrical ...
Spehro Pefhany's user avatar
17 votes

What's a good way to assert in embedded microcontroller code?

It depends. On an ARM platform there are very low level error handlers which indicate that some kind of low level problem has occurred (e.g. illegal memory access) and these need to have specific ...
danmcb's user avatar
  • 7,288
16 votes

Is it possible to draw circuits through code?

Check out SKiDL (https://github.com/xesscorp/skidl), this is along the lines you're thinking. Edit (as req'd): SKiDL allows procedural description of all circuits (rather than just digital), instead ...
awjlogan's user avatar
  • 7,959
16 votes

Is it possible to drive a 2 X 16 LCD display using logic gates? (Without computer)

It is possible to make a circuit out of logic gates that would be able to initialize and display characters onto a 16x2 LCD character mode module. It is also possible to make a circuit out of logic ...
Michael Karas's user avatar
16 votes
Accepted

What's a good way to assert in embedded microcontroller code?

The assert function as such is problematic, as you've probably noticed since you asked this question. No, using it is not good practice. Do not mix up "lots of ...
Lundin's user avatar
  • 21.1k
15 votes
Accepted

MCU programming - C++ O2 optimization breaks while loop

(Cross site duplicate on SO about the thread case, rather than interrupt/signal-handler case). Also related: When to use volatile with multi threading? A data race on a non-...
Peter Cordes's user avatar
  • 1,366
15 votes

How does one go about learning to program a new micro controller?

ST Microelectronics separates things into Datasheets and User Reference Manuals. The datasheet has part specific information while the reference manual has the information common between parts of a ...
DKNguyen's user avatar
  • 56.9k
14 votes

How can I estimate the speed of this code section for this microcontroller?

Let's do it! Say we have the code ...
yar's user avatar
  • 330
13 votes

Is it possible to draw circuits through code?

Many programs can draw a schematic. None that I know of can draw a good schematic: One that emphasizes the most important information, and arranges the circuit in a clear and easy to understand way. ...
The Photon's user avatar
  • 131k
13 votes

PIC12F675 GP4 doesn't work

You have configured the PIC to output the internal clock signal on GP4 using #pragma config FOSC = INTRCCLK Replace INTRCCLK with INTRCIO.
Spehro Pefhany's user avatar
13 votes

Why is a register initialised through bitwise operations instead of a binary string?

Well, the example is very poor, as for initializating the whole port after reset, either one can be used. The point is that later on, you might want to control one bit only, and keep the state of the ...
Justme's user avatar
  • 158k
12 votes

FPGA - DIY Programming

Yes, it would work just fine. Actually, the development tools for most FPGAs allow you to program the external flash directly through the FPGA's own JTAG connection, eliminating the need for a ...
Dave Tweed's user avatar
  • 175k
12 votes
Accepted

PIC12F675 GP4 doesn't work

Just to add to Spehro's correct answer: Since the microcontroller you are using has only 8 pins, they necessarily must share functionality to provide the various features that the device is capable ...
JYelton's user avatar
  • 34.3k
12 votes

Use of VCC and GND pins on programming headers

Well, you certainly must connect the GND pin so that the programmer and the mcu share a common ground. The 3V3 pin is not necessarily there to power the MCU. Some programmers (eg. Segger's J-Link) ...
Elliot Alderson's user avatar
11 votes

Why do we need a bootloader separate from our application program in microcontrollers?

They're generally there to allow you to update your main application program. You need some code which knows how to erase and reprogram some of the internal flash, that can't be the main program as ...
Colin's user avatar
  • 4,547
11 votes

How can I estimate the speed of this code section for this microcontroller?

I normally use the built-in simulator of Atmel Studio which has a cycle counter in the processor status window. This is a combined screenshot from stepping though the code: ] As you can see, the ...
Oldfart's user avatar
  • 14.5k
10 votes

How to make a PCB based on ATtiny easily updatable by end users?

Take a look a the micronucleus bootloader... https://github.com/micronucleus/micronucleus It allows an ATTINY to accept a code download over a (slightly hackey) USB connection. It is widely used and ...
bigjosh's user avatar
  • 10.2k
10 votes

How can I flash a castellated ESP32?

You need to connect it as shown in Fig 4 of your datasheet, at least to power, reset and serial. A usb-serial chip as in the development kit (soldered, not socketed, module) would allow programming ...
Spehro Pefhany's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible