Is the programming protocol of the SWD interface of STM32 public?

Publisher:梦想学院Latest update time:2016-06-12 Source: eefocusKeywords:stm32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
You need a good oscilloscope to capture it so that you have enough memory depth to ensure that you can filter out that damn 50clock.

According to the Arm manual, each conversion on the sender side requires a TNR, but when I look at the JLINK waveform, there is no damn TNR.

The manual says that asynchronous SWD requires it and synchronous does not - or vice versa, but I didn't find a description of synchronous vs asynchronous.

For now, just ignore the TNR and read the damn IDR.

In addition, the reset timing of JLINK is very strange, roughly

70clk High, 0xe79e (note, SWD is LSB First),

70clk High, 0xedb6 (weird here, can't find a description),

70clkHigh, 16clkLow, 0xa5,

Note that this should be the TNR bit according to the protocol - but this bit is not actually observed.

0b100 (ACK-OK), 0xba01477…

In actual testing, the IDR can be read as usual without adding the strange 0xedb6.

Also note that the data on the device side should be read at the falling edge of CLK, or after a delay of 1/2 bit after the rising edge.

If you want to go deeper, you can go to sourceforge.net to download SWD Lib and openOCD. It will be very convenient to compare the two.

It is very comfortable to write programs using bitband, especially when processing SWD bit streams. An int32 pointer jumps very smoothly, and it is an LSB First structure.

There are absolutely no obstacles.

In addition, it is found that after reading IDR, after the ACK of other read and write commands, SWDIO will have a slowly rising waveform of two bits.

And they are pulled down by Target at the falling edge of clk. If the format is followed rigidly, these two bits should be ignored.

No explanation for these two positions has been found so far.

Sometimes, it can be seen that when JLink reads the last bit of information, it will pull down the parity that should have been sent by the Target and ignore it.

It is also important to note that, except for reading the IDR, CTRL, and ABOUT registers, reading other registers has a data frame delay.

For example, if you initiate the first read, the data read is meaningless.

The second read frame reads the data corresponding to the first address, and so on.

In terms of hardware, the pull-up of SWDIO must be strong enough, otherwise the rising edge may not be steep enough. I am currently using 2.2k, which is okay.

I saw that the source code of SWD LIB is based on 8-bit reading and writing and 32-bit reading and writing.

In other words, as long as SWCLK is controlled well and no SWDIO bit information is lost, SPI can also be used to simulate the SWD timing.

This part refers to the LibSwd project of SourceForge. The project is open source, written very rigorously, and the code style is also very good. I strongly recommend you to take a look.

The original code has four functions, read, write, 8, 32. I reduced it to two functions, using the bitband structure so the entry is simpler, just the buffer and the number of bits.

int iLibSwdMosi(unsigned int* pBits,unsigned int iLen)
{
        unsigned int i;
        
        for(i=0;i

What do you think when you see return(0)?

Hey, originally I used a timer to control clk, so I needed to consider the return code when the program ran into an error.

Later I realized that this was stupid, so I just waited until death.

In this way, there is no need to return exception information, but in order to maintain the consistency of form, the function still has the appearance of a return value.

Here is the delay function, the capitalized quantity is the macro definition

int iLibSwdDelay(unsigned int iDly)
{
        unsigned int i,k;
        
        for(i=0;i

Here is the function that switches to SWD mode and reads the IDR.

int iLibSwdSwitch2SWD(void)
{
        unsigned int i;
        
        for(i=0;i

 

If the read is successful, a pointer will be returned. The buffer corresponding to this pointer is pre-allocated. Since the program has not been modified, it is not very nice here. You can use your own ideas.

The part shielded by /**/ is the weird part in JLINK waveform. There seems to be no difference between shielding and not shielding when reading IDR.

I don't know what JLINK is used for. Does anyone know?

Sometimes, in order to distinguish whether the bit is sent by the host or the target, some adjustments can be made to the timing.

Target always sends data on the rising edge of Clk, and Host can send data a little before the rising edge.

In this way, you can use an oscilloscope to distinguish whether it is the Target or the Host that sends the 0

In addition, the manual mentions that several extra clk cycles are appended to each data frame.

The JLink waveform does show this, but it doesn't seem to appear all the time.

I haven't found any impact on this yet, maybe it's for universal considerations.

Keywords:stm32 Reference address:Is the programming protocol of the SWD interface of STM32 public?

Previous article:Entering the world of STM32: Hex program burning
Next article:STM32 11 days to burn Chinese character library and display it on LCD

Recommended ReadingLatest update time:2024-11-16 17:42

STM32 combination device realizes USB to dual serial port
Serial port and interrupt initialization void USART1Init(void) {   GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructu
[Microcontroller]
STM32 Study Notes 8 - Serial Port Output Data Loss Problem
The project uses STM32F103 and AD7260 for data collection. After data collection, we want to output the data point by point to the host computer through the serial port, and then check whether the data is correct. AD7260 uses external interrupts for data collection. When the BUSY output of AD7260 falls, the external i
[Microcontroller]
STM32 ADC and serial port
If you simply use USART, the configuration is quite simple. You only need to configure the baud rate, data length, stop bit length, and check bit. Then set the pins of the serial port, the input is up-and-back input, and the output is push-pull output. In this way, the serial port is configured. If you use the library
[Microcontroller]
NVIC_PriorityGroupConfig() Description
There are two concepts of priority in STM32 (Cortex-M3) - preemptive priority and response priority. Some people call response priority "sub-priority" or "sub-priority". Each interrupt source needs to be assigned these two priorities. An interrupt with a high preemptive priority can be responded to during the processi
[Microcontroller]
Design of Rubik's Cube Solving Robot Based on STM32
Solution Design The servo is used as the driving motor of the Rubik's Cube. From the driving principle of the servo, it can be seen that the speed of the servo is not related to the main frequency, so there is no difference in the control effect between using a servo with a lower main frequency and using a serv
[robot]
stm32 timer output comparison function different frequency
Output comparison: Turn on a TIMx counter, and then turn on one or several output comparators of TIMx (4 in total). After all are configured, the counter starts counting. When the value in the counter is equal to the value in the comparison register, an output comparison interrupt is generated. In the interrupt, the v
[Microcontroller]
Design of digital encryption recording pen based on STM32
  With the widespread application of digital signal processing technology in electronic products, the confidentiality of voice information has also become an important research direction in the field of information processing. The digitization process of analog audio signals includes sampling, quantization and encodin
[Microcontroller]
Design of digital encryption recording pen based on STM32
Problems with setting Systick priority in STM32 V3.5 library
The previous old version of the library uses the following function to set the priority of Systick. However, the new V3.5 library does not contain this function. I searched for a long time before I got the answer. I found that many of the answers on the Internet are wrong and misleading. NVIC_SystemHandlerPriorityConf
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号