How to Develop an embedded product from scratch (20 years of embedded experience)
Source: www.armjishu.com
Author: Jesse
Reprinted please indicate the source
First of all, if you are lucky enough to see this article, do not try to finish reading it within two hours. Even if you finish reading it within two hours, I believe you will not understand the essence of this article, I believe that you should try this article slowly. This is definitely an article that needs to be tasted 2 ~ Three days later, combined with your past experience and thoughts, I believe that you will be greatly improved not only in terms of technical capabilities, but even in terms of the overall way of thinking.
I wrote this article to present a complete product and project development blueprint with my 20 years of embedded experience, I have summed up some lessons from my years of experience and shared them with you. I hope that you will be able to stand on your shoulders in the future to avoid detours, make more contributions to the company, and to the individual, my wish has been fulfilled, and I hope to see your feedback and replies, leave a footprint, leave your insights and wisdom, and lay a solid foundation for future generations, thank you.
From this point on, let's start a journey full of knowledge. The most important thing is that if there is no clear goal in the development of a product or project, success will be impossible, the first step in doing anything must be clear.
Like most transactions in daily life, the process of designing an embedded product must also be clearly defined starting from the goal. Defining a product mainly describes what the product is and what functions it can provide. Secondly, we should write some development documents throughout the development process. The general framework is as follows:
1) Product Requirement document: describes product features
2) Functional Requirements document: describes the features required by the product
3) Engineering Description: describes the system implementation methods and methods to meet requirements.
4) Hardware Description: describes the hardware.
5) software or firmware Description: describes how to design Microprograms and firmware for a specific processor.
6) Test Description: describes the items to be tested and the methods to verify the normal operation of the system.
1. requirement definition
The requirement definition is used to describe the basic functions of the product. For the company, the requirement is generally determined by the marketing department of the company or the main customers of the company; for small companies or enthusiasts (just like those in armjishu.com), technicians can define their own requirements and write them into documents.
Requirements are usually defined based on the following factors:
1) Purpose of the system (define various functions that need to be implemented by the system)
2) How to Implement the actual input and output (for reference of component selection)
3) whether the system requires an operation interface (involving software-Layer Operating System Selection)
In fact, for small embedded products, the definition requirements are very critical, because the requirements are clear, it can avoid the subsequent development process such as random memory (RAM) insufficient capacity or the selected CPU speed cannot meet the processing needs.
Bytes ----------------------------------------------------------------------------------------------------------
The following is a simple example for your reference:
System description: Water Pump swap System for Conghua Hot Spring
Power Input: Use 9v ~ From the transformer ~ 12 V DC
Pump Power: 375 W
1) use single-phase AC motor, controlled by Mechanical and Electrical
2) If the hot spring pool is in a low water level, enter the switch closing signal to prevent the pump from continuing to run.
3) users can freely set the duration of pump operation or shutdown
4) In addition to automatic control, a manual device is also required to allow maintenance personnel to flexibly control the water pump for maintenance.
5) the water pump can be turned on/off/manually intervened in 30 minutes, and adjusted in the range of 30 minutes to 23 hours.
6) The display device can indicate the switch status, remaining time, and whether the pump is in manual intervention mode.
7) Monitor the low water level and display it on the screen
For commercial use, in addition to the functional requirements described above, the design documents also include electromagnetic interference (EMI) and electromagnetic compatibility (EMC) certification, security certification, and use environment (including environmental temperature, humidity, salt spray corrosion, etc.) requirements.
In fact, after the above requirements are determined, the next step is to consider selecting a suitable CPU to meet and implement system functions, then, we need to convert the above seven points of user understanding into our professional needs, as shown below, for your reference:
A. How fast does it take to process or update input/output signals?
Explanation: currently, the frequency of embedded processors generally ranges from dozens to hundreds of megabytes. The frequency of single-chip processors is generally dozens of megabytes, And the ARM processor can reach hundreds of megabytes; we mainly look at whether this product needs to process a large amount of data, whether it needs to perform frequent operations on the buffer zone, and whether there is similar CPU usage work to be done, this determines that we should select a proper processor to achieve the best performance of the product.
B. Can I use a single-chip integrated circuit (dedicated ic) or FPGA for data processing?
Explanation: If you can, you don't have to choose a processor. Instead, you can use these professional chips.
C. Is there a large number of user input and output operations (such as frequent operations on switches and display devices) in the system )?
Explanation: If so, consider these factors when selecting a processor. Select a CPU that meets the preceding requirements.
D. What interfaces should be used between the system and other external devices?
Explanation: this is also a key issue to evaluate the processor. Selecting a processor with these interface functions will facilitate our circuit design and software programming.
E. Is it possible to make changes after the design is completed or the system requirements may change during the design process? Can our design adapt to the changes in system requirements?
Explanation: avoid selecting a processor to meet the current requirements. In this way, when the transaction requirements are gradually improved, and if there is still room for processor performance, the current product can be reused; the second option is to choose a chip that will not be discontinued soon. Many processors are widely used and many materials can be used for reference. However, it is likely that this chip has been popular in the market for a long time, chip manufacturers have already released replacements. If you choose this chip, it is likely that you will not be able to buy it in two or two years. As a result, you have to select a new processor, re-design the product, such as time-consuming, money-consuming, labor-consuming, and delaying the market.
2. processor Selection
2. 1. Number of I/O pins to be used
Most processors use the memory and external pins to control the input and output devices. Generally, the processor has built-in ROM and ram. If the built-in memory is enough, the processor can save the pins that generate signals that reference external memory, so that the processor can provide more device pins for the input and output (some processors support the use of external Ram or ROM, however, when accessing external memory, the processor usually needs to occupy 8 to 10 I/O pins ).
In addition, some processors have dedicated Internal timer clocks, which also require a Port Pin to implement some timer functions. Some processors also have drain output and high current output capabilities, you can easily directly drive relays or solenoid coils without the support of additional drive hardware.
When counting the processor I/O pins, we must take into account some pins that are used in a time-limited manner using the processor's internal functions (such as serial interfaces and timers.
2. Number of interfaces to be used
The main function of the embedded processor is to interact with the hardware in the application environment, which requires not only the external hardware to have real-time processing capabilities for interfaces, in addition, the processor must efficiently process interface data at a sufficient speed.
For example, at91rm9200 is an industrial arm9microprocessor produced by ATMEL. It is based on the ARM920T core and can process up to 200 MIPS, at the same time, the processor is configured with USB, Ethernet, infrared serial port supporting RS485, IIC, SPI, SSC, and other output interfaces, which are used to develop embedded products more conveniently.
Note that because many processors have limitations and are not described in the processor technical materials, you must carefully read the processor metric description. For example, when reading the data, the data may indicate that the serial interface can work at the highest baud rate, but when carefully studying the metric data of the processor, it may be found that not all operation modes of the serial port interface can be run at the maximum baud rate.
In-depth understanding and clear interface requirements: You can write some programs to test the interface, to confirm whether a processor can meet the application requirements; because, it is not a simple task to confirm whether a processor can meet the interface requirements.
. Memory capacity to be used
Determining the size of memory capacity is a basic step in the design of embedded products. If we estimate the size of the required memory capacity too high, we may choose a high-cost solution. Otherwise, if the required memory capacity is underestimated, the project may fail to be completed on time because the system needs to be re-designed.
A. Differences between RAM and Rom: memory is divided into random memory (RAM) and read-only memory (ROM. Rom is usually used to solidify and store the program or data written by some manufacturers, and is used to start and control the computer. Ram is used to access various dynamic input and output data, intermediate computing results, data exchanged with external storage, and temporary data. After a device is powered off, data stored in Ram is lost.
B. instant memory (RAM) Selection: the prediction of Ram capacity is more intuitive. We only need to compare the number of all variables with the capacity of all internal buffers and the first-in-first-out (FIFO) the queue length and stack length are directly added to obtain the total number of required Ram capacity.
If the required memory capacity exceeds the addressing range of such processors, you can only add external Ram to meet your needs. However, when external Ram is added, a certain amount of I/O pins will be used to address the extended memory. Such expansion will often affect the processor's original intention to implement the application.
One issue that needs to be noted is that some microprocessors restrict the use of RAM, which is intended to borrow some memory for use as an internal register group. In addition to the above factors, the development language also has a certain impact on the required Ram capacity, some less efficient compilation programs may occupy a large amount of valuable Ram space.
C. Select 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 hard part of the RoM space capacity required for prediction is the length of the prediction program code. The solution to this problem can only improve the prediction accuracy with the gradual accumulation of experience.
However, the most important thing is not to accurately calculate the code length of a program, but to clearly estimate the upper limit of the code length. According to experience, if 80% of the RoM space is occupied by code, it will be too crowded unless it can ensure that the system requirements will not change, otherwise, at least reserve enough spare Rom space for possible changes.
In most cases, we can try to write some program code in the Rom to observe the space occupied by the Code. For a microprocessor system with an internal ROM, system programs can only occupy limited program memory space.
D. Experience: Rom is similar to RAM usage, and the program code length is related to the selected development language. For example, compiled programs in assembly language occupy much less space than those compiled in C language.
For small systems that are pursuing low costs, it is generally not recommended to use advanced programming languages. Although advanced languages are easier to use, debug, and maintain, at the same time, these languages require more memory space and a large number of CPU clock cycles.
If the development language is improperly selected, the consequence may be that a simple and low-cost single-chip microcomputer system is changed to a 64-bit embedded processor system that requires the configuration of several megabytes of RAM space.
. Number of interruptions to be used
The main purpose of an interruption is to notify the central processor of a specific type of special event, such as a timer timeout event and a hardware event.
It should be emphasized that most system designers often use interrupt functions too frequently. In fact, the main function of interruption is to interrupt the execution of the current program, interruptions are most suitable for events that require the central processor to provide services immediately.
In the case of design and use interruptions, you must first confirm the actual number of interruptions required, and then take into account the interrupted resources occupied by the system, if the number of interrupt resources needed exceeds the number of interrupts that the processor can receive, we should reduce the number of Interrupt signals needed by some special means.
. Considerations for real-time processing
Real-time processing is a wide range of questions. Its main content is closely related to the processing speed of the system. Real-time events are the main tasks that need attention of embedded microprocessor.
For example, when a processor communicates with a serial port, it usually uses upper-layer software (to ensure real-time performance, the task switching time is short enough), and then uses the processor to execute the task of getting data from the serial port, in addition, to ensure that the processor speed is faster than the serial port speed, the processor can respond to and process serial port related tasks as quickly as possible, so as to achieve maximum real-time performance;
On the other hand, if the processor itself has a built-in serial controller, or DMA, or LCD controller, then it can ensure that the built-in interfaces of these processors can be used directly to control serial ports, LCD screens, and other objects, to achieve maximum real-time performance.
. Does the vendor provide good development tools and environments?
To select a new processor, you may need to use a new development tool and development environment, including the software compilation environment. For projects with tight development schedules, developers often cannot take special time to study and familiarize themselves with new development tools. As a result, they cannot fully master the use skills of development tools.
In addition, some development tools are expensive and may only be purchased from the manufacturer. simulation tools also require payment, is the cost factor that should be taken into account.
. Processor speed considerations
Several details are considered:
1) Relationship between processor speed and processor clock
For example, if the single-chip microcomputer 8031 is used as an example, the processor can adapt to the input clock at 12 MHz frequency, so can it be considered as a 12 MHz processor? No, in fact, because the logic circuit of the processor needs multiple clock pulses of different frequencies to execute each command, the internal clock circuit of the processor needs to process the input 12 MHz clock at a frequency; in the end, only 1 MHz clock speed is provided for the processor.
Sometimes, the 80 MHz clock speed processor (80 MHz input clock, 80 MHz execution speed) is much faster than the MHz clock speed processor (MHz input clock, 50 MHz execution speed.
2) processor Command System
If you do not need to execute complex mathematical operations, the processor of the RISC instruction set is faster. If you want to perform complex operations, the processor of the CISC instruction set is faster.
3) chip Structure System
Some chips Package Multiple cores with different functions into one chip IC to customize a specific function, such as DSP, these include hardware multiplier and Phase Shifters used for digital decoding and multiplication. However, these processors are also limited by themselves, before executing some common operations, you must use additional commands to put the data in Ram into an internal register. In contrast, the general processor only allows direct access to the data in Ram.
. Read-only memory (ROM) Selection
Most engineering projects generally use erasable programmable read-only memory (EPROM) or quick memory (flash memory) in their development stages. The primary advantage of this kind of Erasable write-able memory is that it can be used multiple times. Once the product is developed, you can replace the EPROM memory with one write device (OTP). The appearance and encapsulation of the one-time write device are almost the same as that of the EPROM, the only difference is that there is no window to erase and the price is much lower than EPROM.
However, in another case, if the product requires firmware upgrade or online programming in the future, we should still choose to erase programmable memory.
There is also a non-Loss memory. For example, if you create a TV set, you may need the device to have the ability to remember the last channel you watched last time, even after you cut off the power supply, the channel information will not be lost.
Conclusion: Therefore, choosing different storage devices based on different products is also a very learning topic.
. Power supply requirements
In some design schemes, there is no problem with the power supply. The only requirement on the power supply is that the power supply can be normally supplied to the circuit. In fact, three problems should be considered when selecting the power supply:
1) Pay attention to whether the power supply method is limited in the design scheme. For example, do you need to use the power outlet on the wall of the house as most household appliances, or use a USB interface for power supply?
2) check whether the system needs battery power supply. If so, we need to choose a processor that does not have high requirements on the drive current, and then select a suitable battery for it.
3) sleep current: Many microprocessors support low-power operating mode. In this mode, the CPU processor of the system is in sleep state, at the same time, the power supply of all external devices is temporarily cut off to reduce the power consumption of the system. In this way, some microprocessor need to maintain a very small current, however, some microprocessors cannot save much power in this way. In any case, we need to estimate the operating time of the system in node mode, select the battery to use.
In short, in either case, we need to be aware of the total power supply required by the system.
2. 10. Requirements for the working environment of the device
The main environmental requirements include temperature and humidity. If the system must run in a large temperature range, such as a control system for military equipment or automobiles, the range of processors is much smaller;
In addition, equipment with a wide range of temperature changes is usually expensive, so during the design process, the budget cannot be made based on the price of General Industrial-level devices.
. Use Cycle Cost
If our product is MP3, you do not have to worry about modifying the MP3 program at the user's site, or worry about getting spare parts for the equipment, this is because MP3 is a consumption product;
In other words, if our products are tens of thousands of pieces of industrial equipment that need to run continuously all the year round, then we must make a long discussion in the product design process:
A. First, we need to select a device that can be upgraded with either a processor or a storage architecture.
B. Considering the possibility of program upgrade, We need to select a large memory size.
C. The last thing to note is whether the selected processor can be supplied for a long time, which is much more important than the price of the processor.
In addition to the above considerations, the use cycle cost is also a factor to be considered at the beginning of the design. In general, the more components produced, the higher the cost of development at the early stage. If the product is MP3, we may choose a low-cost microprocessor, and invest a lot of money to develop the software to control MP3.
However, if our product is an expensive industrial device, the sales volume of this device will be only several hundred units during the service period, the most important thing to develop such products is to reduce development costs (reduce development costs rather than hardware costs !!!); In addition, the cost of industrial products is not as sensitive as household appliances or consumer electronic products. In conclusion, to develop industrial products, You must select a processor that facilitates development and helps shorten the development process.
. Is there a wealth of processor-related information?
If the processor has been widely used in the market, we can get more information and observe how the processor is used by other products, we can also find a lot of related design materials and related technical topics on the network, which further lowers the technical threshold, ensures the feasibility of using this processor for products, and reduces risks;
On the contrary, if it is a new processor launched by the manufacturer, because there are no products available for reference in the market, we can only read the chip manual in full English to understand this chip, in this way, the development cycle is not only longer, but also unpredictable risks.
Development cost prediction and Estimation
Most projects or products have dedicated personnel responsible for predicting the development costs of the entire process. For any project, the development costs mainly include manpower and material costs.
The cost of development prediction is largely based on experience, which is why large companies generally designate experienced senior engineers to complete this task, in addition to human and material overhead, to sum up, there are also the following Overhead:
1) labor costs (developers, managers, sales staff, other administrative staff)
2) overhead of materials (hardware materials and losses, sometimes it is necessary to invest a few PCB versions to stabilize the product)
3) overhead for developing systems and tools and software
4) hardware tool overhead (for example, oscilloscope and simulator)
For the entire project, the above overhead may directly lead to an increase in product costs, of which labor costs are the most critical, especially in China.
. Product development and design documents (including hardware and software)
4.1 hardware document writing ideas
1) requirement definition or product specification:
If these are the final goals of the product, the requirements of the product for hardware and software are the final goals of the technical solution. The requirements for hardware and software start with defining the user interface and system functions.
2) Secondly, according to the requirements, the detailed definition of the hardware interface is provided in the overall definition document of the system:
The most effective way to define hardware is to describe from the requirement. Because hardware must support all the functions defined by the system, the hardware definition is inseparable from the system description;
For example, if we design a timer (the timer cannot be connected to a PC, so the CRT display time cannot be used), we only have two options: one is the use of light emitting diode (LED), the other is the use of LCD; although the LCD display is better, but considering that the timer is always outdoors, in addition, early LCD monitors could not work at low temperatures, and eventually led devices were selected (this process described our idea of hardware selection, which is closely linked to requirements)
3) once the system's overall instructions are completed, the system design will begin:
First, we need to refine the hardware description, including adding design intent that can be understood by engineers, and hardware information that software engineers need to use when performing program design on hardware.
After completing the hardware circuit board instructions, we also add a preface to this document to describe the original requirements of the system, including the design ideas and methods of the solution. In addition, the information required by software engineers to control hardware is also attached, which mainly includes the following (information required for Software Engineering ):
----- Memory and I/O port addresses (if needed, you can also provide a memory ing diagram)
----- Available memory capacity
----- Definition of each bit of the Status Register
----- Purpose of each port pin
----- Driving Method of an external device (for example, indicating the clock frequency of the input timer circuit)
----- Other information required by the owner software engineer for programming
For complex systems, two independent parts are often used in the hardware documentation. The first part describes hardware metrics and working principles, the second part mainly provides the information required by the program design for the software personnel.
4.2 software document writing ideas
1) The software documents are organized in a similar way as the hardware documents. The main content of the software requirements documents is to define the functions to be implemented by the software, software can also be defined to describe only the software used by one type of circuit board. For more complex projects, since the software personnel involved in such a project are responsible for designing the code that drives different hardware parts (the same circuit board), each software engineer 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 requirement definition, engineering indicators, and hardware parameters
----- Describe the communication protocols between software, processors, or between the processor and its internal devices: the content of the protocols such as the Buffer Interface Mechanism, command/response protocol, and signal control.
----- Use flowcharts, pseudocode, or other possible methods to describe the software implementation methods and processes
2) differences between software and hardware (this experience is convenient for the technical director or other related managers, because no matter how profound the technical manager is, or the hardware is born, either software or non-technical)
A. software flexibility is far greater than hardware. It is very difficult for software personnel to understand the internal format of a software. Solution: define the specific content of programming interfaces that other programmers need to know in detail, and the technical details required by other engineers during the implementation of the development project.
B. software engineers may only know how to operate the system hardware after receiving the hardware instruction documents. hardware engineers generally do not need to understand the technical details of software programs.
C. Because the software is easy to change, the program content is often changed according to the requirements provided by the sales staff. In some cases, the content of the software document cannot reflect the latest changes of the program in a timely manner.
D. Software is often the final part of the project, so its documents are often incomplete due to lack of time. In fact, whether the software documentation is detailed and complete is related to the requirements of the company or the customer to some extent. For example, military or national engineering generally requires developers to provide comprehensive and detailed documentation on the functions implemented by all their software.
E. there is a potential rule. The more complex the requirements for software, the less likely the requirement is to be correct. This is an experience. We need to take the criterion of accurate requirements as an example, instead of taking yourself into consideration as a matter of individualism and software requirements, you can use your imagination out of thin air.
F. We can first design the hardware and then compile the software around the hardware. Although the implementation process of the actual system may be parallel development of hardware and software, software engineers basically design programs around the implemented hardware. For more complex systems, the development process may be repeated.
For example, hardware engineers and software engineers of a project may sit down for a meeting to jointly decide which hardware is used to implement a certain function. software engineers may propose the need to dump memory capacity for the data buffer port, an external device interface may also be required to take full advantage of the various driver code provided by the ready-made interface program.
In general, we must weigh the complexity and cost between improving software development efficiency and hardware system.
. Understanding of technologies by embedded experts (excellent experience over the years)
Many people think that the core factor of embedded system performance is the software function. In fact, if such logic is followed, the software personnel should be responsible for the problems existing in system design; in fact, this point of view actually reflects how to consider the division of hardware and software functions when designing embedded products, that is, whether this function is software implementation or hardware implementation (hardware implementation: you need to purchase hardware chips that process this function to increase costs. Software Implementation: there is no need to increase hardware costs, but it will occupy CPU and memory resources ).
For example, we have designed an arm-Based MP3 embedded product here. We can use professional decoding chips to decode and play MP3 music files, you can also use another method to decode MP3 audio files so that arm processors can use software control registers to drive headphones or audios, after decoding the MP3 audio file, the processor sends the decoded data stream to the audio output hardware interface for playing in a certain protocol format.
Advantage: This solution saves one device in hardware, reduces costs, and facilitates debugging (because it is implemented by software ).
Disadvantages: from another point of view, although a speech decoding chip is saved, the cost must be increased in three aspects.
First, you need to add the speech protocol decoding code in the program;
Second, you may need to add the Rom to store the audio decoding protocol, which can increase the speed;
Finally, running the program will take up the time and resources of the processor.
In fact, in this case, the above cost saving will not cause any problems, including a small amount of driver increase, the purpose of this mp3 product case is to explain how to rationally divide the functions of software and hardware.
In general, the more features provided to the software, the lower the cost of the product. Of course, this requires the processor to have enough processing speed and memory space to implement the specified functions; normally, there is no free lunch in the world. Assigning functions to the software increases the complexity of the software, the development time, And the debugging time of the program. However, as the processing capability of the processor continues to improve, it is foreseeable that more and more functions will be implemented by software.
Although implementing various functions in the software will increase the development cost, porting the functions to the hardware will increase the product cost, such overhead is unavoidable when constructing each system component. In a low-cost design scheme, adding any additional hardware will have a significant impact on the product cost. Therefore, the division of software and hardware functions is a big problem that determines the product cost. In cost-sensitive design solutions such as mass consumer products, functions that cannot be implemented through software are usually excluded.