1 McBSP (Multichannel Buffered Serial Port) serial port uses DMA in multi-frame communication interrupt processing
In actual communication applications, after a burst, the program must prepare for the next burst. Therefore, the DMA multi-frame method of the serial port is generally used. However, there are some issues to be discussed when the serial port transmits data in DMA mode. First, the transmission synchronization event of DMA should be set to the transmission event of McBSP, that is, XEVT, so that after one byte is transmitted, another byte will be automatically prepared (the rising edge of McBSP's READY triggers DMA transmission). When an interrupt occurs, it means that a block has been transmitted. At this time, the DMA enable is automatically turned off, and the READY of McBSP will remain in a high state. However, when the DMA is directly enabled for the next burst transmission, the transmission cannot be started (I believe that many of me will encounter such problems). This is because the READY rising edge required for McBSP to trigger the start cannot be generated. The solution is to turn off the McBSP transmission in the interrupt program first, so that READY="0", then send and enable DMA in the program, and then turn on the McBSP transmission. If you turn on the McBSP transmission first and then turn on DMA, it will not work. Because the READY of McBSP has changed from 0 to 1, the READY rising edge can no longer be generated.
2The difference between turning off DMA and turning off McBSP
In the field of communication, in order to make full use of the on-chip peripheral resources of DSP, DMA is often used to put the data from the serial port or the data to be sent into the buffer and then process it. For DMA, as long as its pointer in the data buffer points to the position where the interrupt should occur, an interrupt will be generated. However, at this time, the last data only enters the McBSP but is not actually sent out, so in the interrupt program at the end of the transmission, only DMA can be turned off but not McBSP. Because at this time there is still a word in the send register DXR of McBSP that has not been sent.
3 Key timing of McBSP serial port configuration
The main thing is to configure register SPCR2: configure other serial port control registers while keeping RRST, XRST, and FRST all at 0. Wait for at least 2 CLKR/T clocks to ensure the synchronization inside the DSP.
(1) You can load data into DXR or enable DMA.
(2) Enable GRST (GRST = 1) (if the DSP needs to generate a sampling clock internally).
(3) Enable RRST or XRST. Note that only this bit in the SPCR must be changed.
(4) Enable FRST (FRST = 1) (if frame synchronization is required within the DSP).
(5) After waiting for 2 R/T CLK clock cycles, the receiving or transmitting end will be valid.
4 Variables in assembly language programs
Common variables in assembly language programs should be defined in files, such as .def carry. Local variables used in assembly language programs do not need to be defined and can be declared directly, such as trn_num .word 00h. If there are two variables with the same name that are not defined in two asm files, the compiler will think that they are not the same variable. There should be a .mmregs macro statement at the beginning of the assembly program. On the one hand, it indicates the confirmation of the default definition (ah, bh, trn, etc.), and on the other hand, it can redefine the registers used. For example: .mmregs DMPREC .set 54h; define the DMA priority and enable register address at 54h DMSA .set 55h DMSDN .set 57h DXR10 .set 23h; define the send register address of serial port 1 at 23h
5 Effect of the CPL bit in the ST1 register
The CPL bit is the compilation mode control bit, which indicates which pointer is used for relative direct addressing. When CPL=0, the page pointer DP is used; when CPL=1, the stack pointer SP is used. There is no difference between the two in actual use, but the program using SP addressing is easier to read. CPL=1 is often used in the program.
6. Ambiguity of Instructions
6.1 Compare the following instruction STLM B, AR4; send the content of bl to register AR4 (×)
STLM B,*AR4; send the contents of bl to register AR4 (√)
The former actually sends the contents of bl to a buffer used by the system. The latter can also be used: MVDM BL, AR4; send the contents of bl to register AR4 (√)
Other sentences that may cause ambiguity include:
LD AR5, A; send the contents of AR5 to register A (×)
LDM AR5, A; send the contents of AR5 to register A (√)
ANDM #0x107e,AR4; add #107e to register AR4 (×)
ANDN #0x107e, *AR4; add #107e to register AR4 (√)
Instructions that are valid only on certain registers:
MVDD * AR2+, *AR3+; copy the content with AR2 as address to AR3. This type of instruction is particularly effective for data block movement, but it is only valid for AR2, AR3, AR4, and AR5.
The error-prone statements that are most harmful to program execution are:
ST #0, * (bsp0_out_sign); bsp0_out_sign is a variable name (√)
STM #0, bsp0_out_sign; This statement is compiled as STM #0, PMST or STM #0, IMR (×)
This statement can cause random failures in program execution and is extremely difficult to detect.
6.2 Flow Conflict
Analyze the following program:
STM to_dce_buff,AR4 LDM AR4,B ADD A,B ;B=AR4+AL MVDM BL,AR4 ;AR4=to-dce-buff+AL In fact, the above program cannot get the result of AR4=to-dce-buff+AL. This is because DSP generally adopts a pipeline structure with a depth of 3 to 6 levels, which produces an unsolvable conflict, so it cannot be executed correctly. The solution is to insert one or more other instructions or NOP statements between the assignment and the reference.
7 Key issues in mixed programming of assembly language and C language
7.1 Sharing of C program variables with assembly program variables To make the program easier to interface and maintain, you can reference variables shared with the C program in the assembly program: .ref_to_dce_num,_to_dte_num,_to_dce_buff,_to_dte_buff
Variables that can be directly defined in C programs and referenced in the assembly program:
unsigned char to_dte_buff[BUFF_SIZE]; //Data sent from DSP to PC
int to_dte_num; //The number of valid bytes stored in the buffer
int to_dte_store: //buffer storage pointer
int to_dte_read; //buffer read pointer
In this way, the correspondence can be completed through the link.
7.2 Program entry problem In C programs, the program entry is the main() function. In assembly programs, its entry is determined by the command in the *.cmd file, such as: -emain_start; the program entry address is main_start. In this way, the mixed assembly program cannot get the correct result. Because the assembly from C to ASM has a default entry c-int00, the program starting from this section prepares for the running of the C program. These tasks include initializing variables, setting stack pointers, etc., which is equivalent to the system shell cannot be crossed. At this time, you can remove the statement: -e main_start in the *.cmd file. If you still want to execute some assembly programs, you can execute them in the form of C functions, such as:
main_start(); //Contains other assembly routines
But the prerequisite is that _main_start is used as the starting address in the assembler, the program ends with rete (as a callable function) and _main_start is referenced in the assembler, that is, .ref _main_start.
7.3 Shift Problem When a variable is set to char type in C language, it is 8-bit, but in DSP assembly, this variable is still treated as 16-bit. Therefore, the shift result in the C program is different from the shift result in the assembly program. The solution is to "AND" the shift result with 0X00FF in the C program.
7.4 Stack Issues In assembly programs, there is little reliance on the stack, but in C programs, allocating local variables, initializing variables, passing function variables, saving function return addresses, and protecting temporary results are all done with the stack. The C compiler cannot check whether the stack will overflow when the program is running. Therefore, try to allocate as much space as possible for the stack. The default size of the C compiler is 1KB. When the program runs abnormally, you should check whether the stack overflows.
7.5 Program Runaway Problems Runaway of compiled C programs is usually caused by accessing non-existent storage areas. First, check the .MAP file and compare it with the memory map to see if it is out of range. If the program runs away in an interrupted program, focus on checking whether the registers used in the interrupt program are pushed onto the stack for protection. If a C program is called in an interrupt program, check whether the unprotected registers are used in the assembled C program and provide protection (registers such as A and B are not protected during the compilation of the C program).
8. Writing command files
When editing the *.cmd file, the compiler defaults to: page 0 is the ROM area, page 1 is the RAM area. The following sections must be placed in the ROM area.
.text load="PROG" PAGE 0 ; program segment
.const load="data" PAGE 0 ; constant section
.cinit load="data" PAGE 0 ; Initialization section
.switch load="data" PAGE 0 ; switch instruction constant table
It is worth noting that you should try not to use the FILL option. Once filling is performed, the generated .out file will increase in size and even exceed the internal storage space and cannot be bootloaded.
Previous article:Design of Micro Digital Storage System Based on FPGA
Next article:Application of TMS320VC5402 in Acceleration Wave Sensor
Recommended ReadingLatest update time:2024-11-16 17:33
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- [Fudan Micro FM33LG0 Series Development Board Evaluation] Development Board Hardware Evaluation, CMSIS-DAP Download Test
- 【Development Kit for nRF52840】+ Three Tools for Evaluation & Cloud Gateway Testing
- What is carrier bandwidth in wireless communications?
- [HC32F460 Development Board Review] 09. Implementing read and write operations on W25Q64 through hardware QSPI
- What is DC coupling & AC coupling?
- How to test power integrity?
- CC3200 kit OURS-SDK-WFB_Exploration 3 - FreeRTOS porting failed
- Participate to get gifts | Welcome to Tektronix High Speed Serial Knowledge Planet
- 【Fudan Micro FM33LC046N】A breathtaking clock
- What happened to ZTE? I saw an article and shared it with everyone