3257 views|6 replies

9717

Posts

24

Resources
The OP
 

Just to tell you a joke, I spent the whole afternoon trying to write a for loop properly. [Copy link]

This post was last edited by littleshrimp on 2021-7-15 09:00

It's probably like this. I want to add a piece of data in a row of the two-dimensional array rx_data to the specified position of key

memcopy(key,0,rx_data[0],5,3);
memcopy(key,3,rx_data[1],2,6);
memcopy(key,9,rx_data[2],2,6);
memcopy(key,15,rx_data[3],2,1);

Because I couldn't find a suitable function, I wrote a 2B function like this:

The key is a 16-byte data, and the data output each time is incorrect. Because I originally used vscode to debug gd32vf103, and I haven't found the online simulation function (I haven't found a good method yet), I can only compile and download again and again and view the data through the serial port.

After a while of trying to find the cause, I decided to use NucleiStudi's online debugging function. After installing NucleiStudi, I found that the eclic_irq_enable function was not available when I moved the GD32 official CAN routine to the project.

After searching all the files in nuclei_sdk, I found only one matching place, MD. The official also commented on the use of this function. Without calling this function, CAN cannot trigger an interrupt when receiving data. Later, I moved the official GD32 code little by little into the project before it could be compiled normally.

After entering the debugging mode, I finally found the problem using the debugging speed as slow as a cow. It was the following sentence:

for(uint32_t i = sIndex;i<len;i++)

After changing to the following, it is normal

for(uint32_t i = sIndex;i<sIndex+len;i++)

This post is from Talking

Latest reply

Without a good environment, logical errors are indeed difficult to adjust.   Details Published on 2021-7-19 17:54
Personal signature虾扯蛋,蛋扯虾,虾扯蛋扯虾
 
 

2870

Posts

4

Resources
2
 

The statement for(uint32_t i = sIndex;i<sIndex+len;i++) is really bad.

1. Variables such as i are only used for loops and should not be involved in program logic during loops.

2. The types of the variable and address of the i loop are often different. If i is uint16 or uint8, this may easily lead to overflow. Be more careful if you are on a 64 system.

This post is from Talking

Comments

Should the first question be written like this? for(uint32_t i=0;iDetails Published on 2021-7-15 08:56
 
 
 

9717

Posts

24

Resources
3
 
bigbat posted on 2021-7-15 08:08 for(uint32_t i = sIndex;i
第一个问题应该这样写吗?
for(uint32_t i=0;i<len;i++)
{
	d[index++] = s[sIndex+i];
}

This post is from Talking

Comments

There’s nothing wrong with writing this way!  Details Published on 2021-7-15 13:12
There’s nothing wrong with writing this way!  Details Published on 2021-7-15 09:09
Personal signature虾扯蛋,蛋扯虾,虾扯蛋扯虾
 
 
 

1942

Posts

2

Resources
4
 
littleshrimp posted on 2021-7-15 08:56 Should the first question be written like this? for(uint32_t i=0;i

There’s nothing wrong with writing this way!

This post is from Talking
 
 
 

2870

Posts

4

Resources
5
 
littleshrimp posted on 2021-7-15 08:56 Should the first question be written like this? for(uint32_t i=0;i

Yeah, I think this is better.

This post is from Talking

Comments

It is indeed not easy to make mistakes this way. I don't quite understand your second question.  Details Published on 2021-7-15 14:12
 
 
 

9717

Posts

24

Resources
6
 
bigbat posted on 2021-7-15 13:12 Yes, I think this is better

It is indeed not easy to make mistakes this way.
I don't quite understand your second question.

This post is from Talking
 
 
 

7454

Posts

2

Resources
7
 

Without a good environment, logical errors are indeed difficult to adjust.

This post is from Talking
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 
 

Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list