How to develop an embedded product from scratch?
First of all, if you are fortunate enough to see this article, don’t try to finish it in 2 hours. Even if you finish reading in 2 hours, I believe that you will not understand the essence of the explanation. I believe that you should This article, slowly taste, this is definitely a need to taste 2 to 3 days, combined with their past experience, plus their own thinking, I believe that you will not only technical ability, but even the overall way of thinking There will be a very big improvement.
The purpose of this article is to present a complete product and project development blueprint. It summarized some lessons and shared it with you with experience.
So start our journey of knowledge. The most important point is that in the development of a product or project, if there is no clear goal, then success will not be discussed. The first step in doing anything must be clear. .
As with most transactions in everyday life, the process of designing an embedded product must also begin with a defined goal and clearly define the product being produced. The definition of the product is mainly to describe what the product is and what function it can. Secondly, in our entire development process, we should write some development documents. The approximate framework is as follows:
1) Product Requirements Document: Describe the characteristics of the product
2) Functional Requirements Document: Describe the features that the product must have
3) Engineering documentation: describes the method of system implementation and means to meet the needs
4) Hardware documentation: Describe the hardware
5) Software or firmware documentation: A method for designing microprograms and firmware under a specific processor
6) Test documentation: Describe the items that must be tested and how to verify that the system is functioning properly
1. Definition of requirements
The requirement definition is used to describe the basic functions of the product. For the company, the demand is generally determined by the company’s marketing department or the company’s main customers; for small companies or enthusiasts (like fans in ouravr) The technician can be responsible for defining the requirements and writing the documents. For the STM32 Shenzhou series development board, the main interface is to provide various interfaces for the development of the products!
The usual definition of requirements is based on several factors:
1) The purpose of the system (defining the various functions that need to be implemented by the system)
2) How is the actual input and output implemented (for the selection of components)
3) Does the system require an operation interface (involving the selection of the software layer operating system)
In fact, for small embedded products, defining requirements is very important, because the requirements are clear, you can avoid the need for subsequent processing such as insufficient random access memory (RAM) capacity or the selected CPU speed can not meet the processing needs. A series of questions.
————————————————– ————————————————– ——
Here is a simple practical example for your reference:
System Description: Water pump water exchange system for Conghua Hot Springs (simulated by STM32 Shenzhou III development board)
Power input: use 9V~12V DC from the transformer
Pump power: 375W
1) Using a single-phase AC motor, controlled by mechanical and electrical
2) If the hot spring pool is at a low water level, enter the switch closure signal to prohibit the pump from continuing to run.
3) The user can freely set the length of time the pump runs or is turned off.
4) In addition to automatic setting control, it is also necessary to provide a manual device to allow maintenance personnel to flexibly control the pump for maintenance.
5) The pump on/off/manual intervention time can be adjusted in 30 minutes, ranging from 30 minutes to 23 hours.
6) The display device can indicate the switch status of the water pump, the remaining time, and whether the pump is in manual intervention mode.
7) It has the function of monitoring low water level and is displayed on the screen.
If commercial requirements are required, in addition to the functional requirements given above, the design documentation also includes electromagnetic interference (EMI) and electromagnetic compatibility (EMC) certification, safety certification, and the use environment (including ambient temperature, humidity, salt spray corrosion). Etc. etc. needs.
In fact, after the above requirements are determined, the next step is to consider choosing a suitable CPU to meet and implement the functions of the system. Then we need to translate the requirements that can be understood by the above 7 users into the needs of our professional fields. As follows, you can refer to it:
a. How fast does it take to process or update the input and output signals?
Explanation: At present, the main frequency of embedded processors generally ranges from tens of megabytes to hundreds of megabytes. The main frequency of single-chip microcomputers is usually several tens of megabytes. The CPUs of STM32 Shenzhou series development boards are all 72MHZ, and some ARM9 and ARM11 processing. It can be up to several hundred megabytes; we mainly look at whether this product needs to process a large amount of data, or whether it needs to operate the buffer frequently, whether there is a similar work to occupy the CPU data, which determines that we have to choose a A suitable processor to get the best performance from the product.
b. Can I use a monolithic integrated circuit (dedicated IC) or FPGA to complete the data processing?
Explain: If you can, you don’t have to choose a processor to do it. You can replace it with these professional chips.
c. Does the system have a large number of user input and output operations (such as frequent operation of switches and display devices)?
Explanation: If you have any, consider these factors when selecting the processor and choose a CPU that meets the above requirements.
d. What interface is required between the system and other external devices?
Explanation: This is also a key issue for evaluating processors. Choosing a processor with these interfaces will facilitate our circuit design and software programming.
e. Is it possible to make changes after the design is completed, or is the system requirements likely to change during the design process? Can our design adapt to changes in system requirements?
Explanation: To avoid the choice of the processor just meet the current requirements, so that when the transaction requirements are gradually improved, if there is still room for the processor performance, then the current product can be reused; the second is to choose not to be discontinued. Chips, many processors are very widely used, and there are many materials that can be borrowed, but it is very likely that this chip has been popular in the market for a long time. Chip manufacturers have already introduced replacements, if you choose this The chip, it is very likely that this processor chip will not be available after 1 or 2 years, resulting in having to re-select a new processor and redesign the product, which is time consuming, costly, more labor intensive, and delays the market. .
2. Processor selection
2.1. Number of I/O pins to use
Most processors use memory and external pins to control the input and output devices. Usually, the processor has built-in ROM and RAM. If the built-in memory is sufficient, the processor can save the reference to the external memory signal. Pin, so the processor can provide more device pins for input and output (some processors support the use of external RAM or ROM, but when accessing external memory, the processor generally needs 8 to 10 I/ O pin).
Also, some processors have a dedicated internal timing clock. These clocks also require a port pin for some timing functions. Some processors also have a drain output and high current output capability. Drive relays or solenoid coils directly without the need for additional drive hardware support.
When counting processor I/O pins, we must take into account certain pins that are restricted when using internal functions of the processor (such as serial interfaces and timers), like the STM32 Shenzhou III at hand. The processor chip is 144-pin (103ZET), and the Shenzhou IV processor chip is 100-pin (107VCT).
2.2. Number of interfaces to use
The main function of the embedded processor is to interact with the hardware in the application environment. This requires not only the external hardware to have real-time processing capability for the interface, but also the processor must effectively process the interface data quickly enough.
For example, the CPU of the STM32 Shenzhou series development board is an industrial-grade microprocessor produced by ST. It is based on the core of CORTEX M3 and can handle up to 72MHZ. The processor is equipped with USB, SPI, IIC, etc. Interfaces, such as the STM32 Shenzhou IV 107 processor also supports Ethernet and other output interfaces, the purpose is to more easily use these interfaces to develop embedded products.
It should be noted that since many processors have limitations that are not adequately stated in the processor’s technical literature, be sure to read the processor’s specifications. For example, during the process of reading the data, it may be found that the serial interface can work at the highest baud rate, but when you study the metric data of the processor carefully, you may find that all operating modes of the serial interface are not. Both can be run at the maximum baud rate.
In-depth understanding and clear method of interface requirements: You can write some programs yourself to actually test the interface to confirm whether a certain processor can meet the requirements of the application; because it is not a confirmation whether a processor can meet the interface requirements. A simple task.
2.3. Memory capacity to be used
Determining the size of memory capacity is a basic step in the design process of embedded products. If the estimated memory capacity is too high, then we may choose a higher cost solution; otherwise, if the required memory capacity is underestimated It is possible that the project will not be completed on time due to the need to redesign the system.
a. The difference between RAM and ROM: The memory is divided into two types: random access memory (RAM) and read only memory (ROM). The ROM is usually used to solidify and store some programs or data written by the manufacturer to start the computer and control the working mode of the computer. RAM is used to access various dynamic input and output data, intermediate calculation results, and data exchanged with external memory and temporary data. After the device is powered off, the data stored in the RAM is lost.
b. Random memory (RAM) selection: RAM capacity prediction is relatively straightforward, we only need to add the total number of variables to the capacity of all internal buffers and the first in first out (FIFO) queue length and stack length directly, The total number of RAM capacity required can be obtained.
If the required memory capacity exceeds the addressing range of such processors, then only the external RAM can be added to meet the demand; however, adding external RAM will occupy a certain number of I/O pins to find the extended memory. Address, this extension often affects the original intention of the processor to achieve the application.
One problem to be aware of is that some microprocessors limit the use of RAM. The purpose of this limitation is to borrow part of the memory memory for use as an internal register bank. In addition to the above factors, the development language used also has a certain impact on the required RAM capacity, and some less efficient compilers may take up a lot of valuable RAM space.
c. Choice of read-only memory (ROM): The size of the ROM required by the system should be the sum of the system program code and the capacity of all ROM-based data tables. The part that predicts the required ROM space capacity is the length of the prediction program code. The solution to this type of problem can only be to improve the prediction accuracy with the gradual accumulation of experience.
However, the most important thing is not to accurately calculate the code length of the program, but to clearly estimate the upper limit of the code length. As a rule of thumb, if 80% of the ROM space is occupied by code, it is too crowded. Unless you can ensure that there is no change in system requirements, you must at least reserve enough spare ROM space for possible changes.
In most cases, we can try to write a part of the program code in the ROM to observe the space occupied by the code. For a microprocessor system with internal ROM, the system program can only occupy a limited amount of program memory space. .
d. Experience: ROM and RAM usage are similar, and the program code length is related to the development language selected. For example, a program written in assembly language takes up much less space than a program written in C.
For small systems that are low-cost, high-level programming languages are generally not recommended; because high-level languages are easier to use, debug, and maintain, they also require more memory and A large number of processor clock cycles.
If the development language is not properly chosen, the consequence may be to turn a simple, low-cost microcontroller system into a 64-bit embedded processor system that requires a few megabytes of RAM.
2.4. Number of interrupts to use
The main purpose of the interrupt is to notify the central processor of certain types of special events that currently occur, such as timer timeout events, hardware-initiated events, and so on.
It should be emphasized that most system designers often use the interrupt function too much. In fact, the main function of the interrupt is to interrupt the execution of the current program. The interrupt is most suitable for events that must require the central processor to provide the service immediately.
In the case of design and use of interrupts, it is necessary to first confirm the actual number of interrupts required, and then must take into account the interrupt resources occupied by the system. If the interrupt resources to be used exceed the number of interrupts that the processor can receive, we should Use some special means to reduce the number of interrupt signals required.
2.5. Real-time processing considerations
Real-time processing is a wide-ranging topic, and its main content is closely related to the processing speed of the system. Real-time events are the main tasks that embedded microprocessors need to pay attention to.
For example, when the processor communicates with the serial port, it usually passes the upper layer software (to ensure real-time performance, the task switching time is short enough), and then the processor is used to perform the task of taking data from the serial port, and the speed of the processor is guaranteed. Faster than the serial port, the processor can react and process the relevant tasks of the serial port as quickly as possible, so that the maximum real-time performance can be achieved;
On the other hand, if the processor itself has a serial port controller, or a DMA, or LCD controller, it can ensure that the built-in interfaces of these processors can be used directly to control serial ports, LCD screens, etc. Real-time performance.
2.6. Does the vendor provide good development tools and environment?
Choosing a new processor is likely to use a new development tool and development environment, including the software compilation environment. For projects with tight schedules, developers often cannot take the time to research. Familiar with new development tools, so that you can’t fully grasp the skills of using development tools.
Moreover, some development tools are also expensive, and they are likely to be purchased only from manufacturers, and simulation tools are also paid for. These are the costs that we should consider when choosing a processor. factor.
2.7. Processor speed considerations
Mainly consider a few details:
1) Relationship between processor speed and processor clock
Example: Microcontroller 8031 is an example. The processor can adapt to the input clock of 12MHz frequency. So, can it be considered as a processor with a speed of 12MHz? No, in fact, since the internal logic of the processor requires a plurality of clock pulses of different frequencies for each instruction, the internal clock circuit of the processor is divided by 12 for the input 12 MHz clock; finally, only the processor provides 1MHz frequency.
Sometimes, an 80MHz processor (80MHz input clock, 80MHz execution speed) performs much faster than a 200MHz processor (200MHz input clock, 50MHz execution speed).
2) Processor instruction system
If you do not need to perform complex mathematics operations, the processor of the RISC instruction set is faster; if you perform more complex operations, the processor speed of the CISC instruction set is faster.
3) Chip structure system
Some chips now package multiple cores of different functions into one chip IC, and customize a specific function, such as DSP, including hardware multipliers and phase shifters for digital decoding and multiplication; however This type of processor is also limited by itself. It is often necessary to use additional instructions to put the data in the RAM into the internal registers before performing some normal operations. In contrast, the general processor only allows the RAM. Data is accessed directly.
2.8. Choice of read only memory (ROM)
Most engineering projects typically use rewritable programmable read only memory (EPROM) or flash memory during their development phase; the main advantage of such rewritable rewritable memory is that it can be used multiple times. Once the product is developed, the EPROM memory can be replaced by a write-once device (OTP). The appearance and package of the write-once device is almost the same as that of the EPROM. The only difference is that the surface does not have a window, and the price is It is much lower than EPROM.
However, in another case, if the product needs to be upgraded in the future, or online programming, then we should still choose a rewritable programmable memory.
Another type of non-volatile memory, such as a television set, may require the device to have the ability to remember the last channel viewed last time, even if the power is turned off, the channel information will not be lost.
Summary: Therefore, choosing different memories according to different products is also a very important study.
2.9. Power requirements
In some designs, there is no problem with the power supply. The only requirement for the power supply is that it can supply power to the circuit. In fact, there are three main issues to consider when selecting the power supply:
1) Pay attention to whether the power supply mode is limited in the design scheme, for example, whether it needs to be powered by the power socket on the inner wall like most household appliances, or powered by USB interface.
2) See if the system needs to use battery-powered mode. If so, we should consider the processor that does not require high drive current, and then choose the right battery for it.
3) Sleep current: Many microprocessors support low-power operation mode. In this mode, the system’s CPU processor will be in a sleep state, and all external devices’ power supply will be temporarily cut off to reduce system power consumption. Some microprocessors require very little holding current in this mode, but there are some microprocessors that don’t save much power in this way; however, we have to work on the system in node mode. An estimate to choose which battery to use for the specific situation.
In short, in either case, we must be aware of the total power required by the system.
2.10. Requirements for the working environment of the equipment
The main content of the environmental requirements is to consider temperature, humidity, etc.; if the system must operate in a wide temperature range, such as control systems for military equipment or automobiles, the range of processor options is much smaller;
And because equipment with a wide range of temperature variations is often expensive, it is no longer possible to budget based on the price of a typical industrial grade device during the design process.
2.11. Use cycle cost
If our product is stm32 Shenzhou development board, under normal circumstances, you can not have to consider the modification of the stm32 Shenzhou development board program at the user site, and do not need to worry about whether you can get equipment spare parts, this is because stm32 Shenzhou development board It is a learning consumer product, just a development board.
In other words, if our products are tens of thousands of pieces of industrial equipment and need to be constantly running all the year round, then we must be long-term in the product design process:
a. First, we need to choose a device that can be upgraded with a processor or storage architecture.
b. Considering the possibility of program upgrade, we also need to choose a larger memory
c. The last thing to note is whether the selected processor can be supplied for a long time, which is far more important than the price of the processor.
In addition to the above considerations, the use cycle cost is also a factor to consider at the beginning of the design. In general, the more parts that are produced, the more acceptable up-front development costs. If the product is mp3, we might choose a low-cost microprocessor and invest a lot of money to develop software that controls mp3.
However, if our products are expensive industrial equipment, then the sales volume of the equipment will be only a few hundred during the life of the product. There is no doubt that the most important thing to develop this product is to reduce development costs (reduced development). Cost, not hardware cost!!!); In addition, the cost of industrial products is not as sensitive as household appliances or consumer electronics. In summary, the development of industrial products must of course choose a processor that is easy to develop and helps to shorten the development process.
2.12. Is the processor related information rich?
If the processor is already widely used in the market, then we can get more relevant information, observe how people use the processor, and find a lot of relevant design information on the network. Related technical topics, which further reduce the technical threshold, ensure the use of the processor for product feasibility, reduce the risk; for example, the STM32 Shenzhou IV development board has a manual document for the board with more than 700 pages, if we If you choose STM32 chip to develop your product, it will be easy to develop with detailed information, and you can achieve twice the result with half the effort.
On the other hand, if it is a new processor introduced by the manufacturer, because there is no product to be borrowed in the market, we can only read from the full-chip manual of the English to understand the chip, so that the development cycle is not only long, but also unpredictable. The risks are also great.
3. Forecast and estimation of development costs
Most projects or products have dedicated personnel to predict the development cost of the entire process. For any project, the development cost mainly includes manpower and material costs.
Predicting development costs is largely based on experience, which is why large companies typically designate experienced senior engineers to accomplish this task. In addition to the overhead of manpower and materials, the following costs are summarized:
1) The cost of labor costs (developers, managers, sales staff, other administrative staff, etc.)
2) The cost of materials (hardware materials and losses, sometimes need to vote several times PCB version to stabilize the product)
3) The overhead of developing system and development tool software
4) The overhead of hardware tools (such as oscilloscopes, emulators, etc.)
For the entire project, the above expenses will directly lead to an increase in product costs, of which labor costs are the most critical, especially in China, huh, huh
4. Product development design document (need to include hardware and software)
4.1 Hardware Documentation Writing Ideas
1) First is the requirement definition or product specification:
If these are the ultimate goals of the product, then the hardware and software requirements of the product are the ultimate goal of the technical solution; the requirements for hardware and software begin with the definition of the user interface and system functions.
2) Secondly, according to the requirements, the specific definition of the hardware interface is given in the system definition document:
The most efficient way to define hardware is to start with the requirements. Since the hardware must support all the functions defined by the system, the hardware definition is inseparable from the system description;
For example, we design a timer (pre-requirement that the timer cannot be connected to a personal computer, so the CRT cannot be used to display the time). We only have two choices: one is to use a light-emitting diode (LED) and the other is to use a liquid crystal display. Device (LCD); although the LCD display is better, considering that the timer is to be outdoors all year round, and the early LCD display can not work at low temperatures, the LED device is finally selected (this whole process describes the selection of our hardware) One idea, this is closely related to demand)
3) Once the system’s overall documentation has been completed, the system design begins:
The first step is to refine the hardware description, including the design intent that engineers can understand, and the hardware information that software engineers need to use to program their hardware.
After completing the hardware board documentation, we will also add a preface to the documentation that describes the original requirements of the system, including the design ideas and methods for the solution, in addition to the software engineers. The various types of information required to control the hardware. This type of information mainly includes the following (information required for software engineering):
—–Memory and I/O port addresses (memory maps can be provided if needed)
—–Available memory capacity
—–The definition of each bit of the status register
—–Use of each port pin
—–How to drive external devices (for example, the clock frequency of the input timer circuit, etc.)
—– Other information that the software software personnel design program needs to know
For more complex systems, two separate parts are often used in the hardware documentation for description; the first part is used to describe the hardware indicators and working principle, and the second part is mainly to provide software personnel with the information needed for programming.
4.2 Software Document Writing Ideas
1) The software document is similar to the hardware document organization method. The main content of the software requirement document is to define the function to be implemented by the software; one is the software definition can also be used only for one kind of circuit board in the simple project design process. Give a description; for more complex projects, because the software personnel involved in the project are responsible for designing the code that drives the different hardware parts (the same board), each software person may specify different definitions for their own design code. Such software instructions need to provide the following:
—–Discuss the content required for implementation projects including requirements definition, engineering indicators, hardware parameters, etc.
—– Describe the communication protocol used between software, between processors or between the processor and its internal devices: its content should include specific descriptions of the buffer interface mechanism, command/response protocol, signal control and other protocols.
—– Using the flow chart, pseudo code or other possible methods to describe the software implementation method and process
2) Differences between software and hardware considerations (this experience is convenient for technical directors or other relevant managers, because no matter how high the technical manager is, whether it is hardware origin, software origin, or non-technical origin, Of course, there are also a few masters who are proficient in both hardware and software)
a. The flexibility of the software is far greater than the hardware. It is very difficult task for the software personnel to figure out the internal format of a certain software. The solution is to define in detail the specific content of the programming interface that other programmers need to understand, as well as other engineering personnel. Technical details required to implement the development project.
b. Software engineers are only likely to know how to operate the system hardware after receiving the hardware documentation; hardware personnel generally do not need to know the technical details of the software program.
c. Because the software is easy to change, the program content is often changed according to the requirements provided by the salesperson. In some cases, the contents of the software documentation do not reflect the latest changes in the program in a timely manner.
d. Software is often the last part of an engineering project, so its documentation is often incomplete due to lack of time. In fact, the software documentation is detailed and complete, and to some extent related to the company or customer requirements. For example, military or national engineering generally requires developers to provide comprehensive and detailed documentation of all of the software-implemented functions.
e. There is a hidden rule. The more complex the requirements of the software, the less likely it is that the requirements are correct. This is the experience. We need to make the standard of quasi-demand, instead of falling into individualism and software. Ask for your unrealistic imagination out of thin air.
f. We can design the hardware first and then build the software around the hardware. Although the actual system implementation process may be parallel development of software and hardware, software personnel are basically programmed around the hardware that has already been implemented; for more complex systems, the development process may be duplicated.
For example, a project’s hardware engineers and software engineers may sit down and decide to decide which hardware to use to implement a function; software personnel may ask for the need to buffer the memory capacity for the data buffer, or may require some kind of external Device interface to take advantage of the various driver code provided by off-the-shelf interface programs.
In general, there must be a trade-off between improving software development efficiency and the complexity and cost of hardware systems.
5. Embedded master’s understanding of technology
Many people think that the core factor of embedded system performance is software function. In fact, if this logic is used, the software design should be responsible for the problems in the system design. In fact, this view actually reflects the design of embedded products. How to consider the functions that should be implemented by dividing hardware and software, that is, whether this function is implemented by software or hardware (hardware implementation: hardware chips that need to purchase this function are needed to increase the cost; software implementation: no need to increase hardware cost , but it will take up processor and memory resources).
For example, the STM32-based Shenzhou II development board product we designed here, we can use professional decoding chip to be responsible for decoding and playing mp3 music files, or use another method to decode mp3 voice files, let ARM The processor uses the software control register to drive the earphone or the sound. After decoding the mp3 voice file, the processor sends the decoded data stream to the hardware interface of the audio output according to a certain protocol format for playing.
Advantages: This solution saves one device in terms of hardware, reduces the cost, and the function is also easy to debug (because it is implemented by software).
Disadvantages: From another point of view, although a piece of speech decoding chip is saved, it also increases the cost in three aspects.
First, add the code for the speech protocol decoding in the program;
Secondly, it may be necessary to add a ROM to store the protocol for voice decoding, which can increase the speed;
Finally, running the program will take up the processor’s time and resources.
In fact, then again, for this case, the above cost savings will not cause any problems, including the driver increase is only a small amount, we discuss the case of this mp3 product to explain how to software hardware The function is reasonably divided.
In general, the more functions that are handed over to the software, the lower the cost of the product. Of course, the processor must have enough processing speed and memory space to implement the design-specific functions. As the saying goes, the world There is no free lunch; assigning functions to software to achieve will increase the complexity of the software, development time, and debugging time of the program; however, as the processing power of the processor continues to increase, it is foreseeable that more and more The function will be implemented by software.
While implementing various functions in software increases development costs, porting functions to hardware increases the cost of the product, which is inevitable when constructing each system component. In a low-cost design, adding any additional hardware can have a significant impact on product cost, so software and hardware functional partitioning is a big issue that determines product cost. In cost-sensitive designs such as mass-marketing products, features that cannot be implemented in software are generally excluded.
[End of the text]