Based on the automatic code generation software--Targetlink supplied by dSPACE Company, and combined with MATLAB/Simulink simulation platform the software development and automatic generated production code of embedded control system were achieved. Depending on the standard design of the control models, optimization and automatic code generation of Targetlink, as well as various simulation tests and final experimental validation on sample ECU, the control software of the electronic controlled diesel injection system was developed. Compared with the manually written codes, the automatic produced codes realize the same functions, while the additional execution time and memory consumption are acceptable. For electronic control system development, the automatic code generation by Targetlink is better than conventional manual mode, which saves development period, improves code upgrade efficiency and the quality.