Author Topic: Help me understand this code  (Read 11381 times)

0 Members and 1 Guest are viewing this topic.

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12500
  • Country: us
    • Personal site
Re: Help me understand this code
« Reply #25 on: November 17, 2020, 02:45:58 am »
It is not about that function. It is about the puthex code that I proposed that would actually print the numbers you want (in hex).

You can use itoa() or sprintf() or whatever you like to turn your number into a string and then output that string on the port.
« Last Edit: November 17, 2020, 02:47:49 am by ataradov »
Alex
 

Offline LootMasterTopic starter

  • Regular Contributor
  • *
  • !
  • Posts: 192
  • Country: ca
Re: Help me understand this code
« Reply #26 on: November 17, 2020, 02:48:08 am »
Thats what I meant...  :phew:
 

Offline LootMasterTopic starter

  • Regular Contributor
  • *
  • !
  • Posts: 192
  • Country: ca
Re: Help me understand this code
« Reply #27 on: November 17, 2020, 04:42:56 am »
I finally got this whole thing to work.

I think the host of the video, the ST employee, simply is a bit ....  :palm:

What is the point of ITM_Port32(31)=1; and ITM_Port32(31)=2; besides causing unnecessary confusion for beginners since send ITM_SendChar will send to port 0 anyways this making those lines useless number pushing



 \brief   ITM Send Character
  \details Transmits a character via the ITM channel 0, and
           \li Just returns when no debugger is connected that has booked the output.
           \li Is blocking when a debugger is connected, but the previous character sent has not been transmitted.
  \param [in]     ch  Character to transmit.
  \returns            Character to transmit.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12500
  • Country: us
    • Personal site
Re: Help me understand this code
« Reply #28 on: November 17, 2020, 04:45:36 am »
Those two things are not related to each other. You should chill accusing other people if you just learned about the thing and don't really understand it.

You can write your own ITM_SendChar() that sends on whatever channel you like. The default one sends on 0.

He is showing the basic functionality that ITM_SendChar() is based on.
Alex
 

Offline LootMasterTopic starter

  • Regular Contributor
  • *
  • !
  • Posts: 192
  • Country: ca
Re: Help me understand this code
« Reply #29 on: November 17, 2020, 04:53:31 am »
I'm sorry, its just his voice...  :palm:
 

Offline LootMasterTopic starter

  • Regular Contributor
  • *
  • !
  • Posts: 192
  • Country: ca
Re: Help me understand this code
« Reply #30 on: November 17, 2020, 07:00:20 pm »
Most of the parentheses are just parentheses, used to group an expression so its evaluated before the outer operator gets it.  The outer pair are so that adjacent operators when/where the #defined name is used don't affect evaluation within it.  The (n) after the name makes the name a function-like macro, with parameter n.  The pair immediately round volatile unsigned long * are a cast operator, in this case casting an integer to that pointer type.

There's no particular 'magic', this is just 'vanilla' C, constructing a pointer to a port (using an architecture and processor dependent integer base address) and dereferencing it for access.

Arguably, the parameter n should have parentheses round where its used, as if an expression not wrapped in parentheses containing any operator with lower precedence than multiplication is used for n, the result will be incorrect and probably cause a misaligned pointer error.   Here's the fixed version:
Code: [Select]
#define ITM_Port32(n) (*((volatile unsigned long *)(0xE0000000+4*(n))))

ITM_Port32(31)=1;

So essentially, he made an expression to to find a memory location that he can write too?

A "pointer" to an offsetted array by 0xE0000000 and distanced by 4 bytes according to n.

What bothers me is that there is no limit to that number that is set for n, isnt that dangerous to not declare a limit as you #define it? At least the compiler might warn you..

so when he puts ITM_Port32(31)=1;

the processor goes to a memory location pointer ITM_port... wich applies a formula go(0xE0000000+4*(31)) and write 1.

Am I correct? What is the correct terminology for this sort of mind tricks, honestly these boklets I read never contained such hardcore parentheses examples.

I was just confused as o why he would want to do that....ITM_Port32(31)=1

If all the action happens with ITM_Port32(0)=1 or w/e...Since this is a queued slow process anyways... Whats the benefit writing to those "ghost town" stimulus ports? If there was better data organization and faster with the eclipse interpretation I could understand.

Just poor clarity on the matter.. nd the guy just lost me with his goofy attitude...I  want SERIOUS videos made by pros.

« Last Edit: November 17, 2020, 07:08:57 pm by LootMaster »
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12500
  • Country: us
    • Personal site
Re: Help me understand this code
« Reply #31 on: November 17, 2020, 07:12:22 pm »
So essentially, he made an expression to to find a memory location that he can write too?
Yes, this is how memory mapped I/O works.

What bothers me is that there is no limit to that number that is set for n, isnt that dangerous to not declare a limit as you #define it? At least the compiler might warn you..
You are working with a low level language. Of course it is dangerous if you don't know what you are doing.

If there is ever a change that n can be taken in run-time from the user, then you need to verify it, of course. Any user inputs need to be verified.

Am I correct? What is the correct terminology for this sort of mind tricks, honestly these boklets I read never contained such hardcore parentheses examples.
Correct. This is called memory mapped I/O.

I was just confused as o why he would want to do that....ITM_Port32(31)=1
To show you that it is possible and multiple channels are implemented on this device.

If all the action happens with ITM_Port32(0)=1 or w/e...Since this is a queued slow process anyways.
The action happens where you make it happen.
Alex
 

Offline LootMasterTopic starter

  • Regular Contributor
  • *
  • !
  • Posts: 192
  • Country: ca
Re: Help me understand this code
« Reply #32 on: November 17, 2020, 07:28:04 pm »
"The action happens where you make it happen."

I can see a "very occasionnal use" for this if I had a situation where multiple data is changed back to back and I just want to dump each individual data into seperate channels, then for a "long long while", let the data flow to computer... But dont I already have tht sort f thing when I put 4 variables on the "swo comparator for channel 0 ???..It will utilize 100% of the BW of the SWO albeit with 4 variables only?, wich in my case with ST-Link V3 is 2MHz

A sort of "burst situation"... If I dont wanna deal with conditionnal constraints of port 0 and I am in a rush...I just dont see the need for this often.

But I would need a new ITM_Sendchar function,where now I change the 0.32 to [n].32 in the CMSIS thing, another argument is needed.

« Last Edit: November 17, 2020, 07:33:30 pm by LootMaster »
 

Offline LootMasterTopic starter

  • Regular Contributor
  • *
  • !
  • Posts: 192
  • Country: ca
Re: Help me understand this code
« Reply #33 on: November 18, 2020, 07:07:30 am »
So I discovered something... All that was needed was to observe this in the SWV Trace log...Tickbox port 31...When in this mode it interprets the raw binary correctly and I cna see the numbers on screen. 1 and 2

MX_GPIO_Init();

 
  MX_TIM2_Init();
  MX_TIM8_Init();
  /* USER CODE BEGIN 2 */
  ITM_Port(31)=1;
  HAL_Delay(100);
  ITM_Port(31)=2;

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {

//printf("I'm in the ain loop =%ld\n", data0); not using

HAL_Delay(500); // boring code....

  }



Another question

Why does AXI-> not propose me any auto complete? There are a few AXI registers that have some writeable bit fields ( most are read only). Same for Flash->

I can have autocomplete work with JPEG-> and I dont have anything related to that I dont understand...
« Last Edit: November 18, 2020, 07:11:12 am by LootMaster »
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12500
  • Country: us
    • Personal site
Re: Help me understand this code
« Reply #34 on: November 18, 2020, 07:14:59 am »
Why does AXI-> not propose me any auto complete?
That I don't know. I don't use IDEs and auto complete.

Most likely it takes autocomplete data from the header files, but the structure of the registers on the top comes from the SVD file. They may not match generally.

It is also possible that some files that have those definitions for AXI are not included in the project, so the IDE does not see them.
Alex
 

Offline LootMasterTopic starter

  • Regular Contributor
  • *
  • !
  • Posts: 192
  • Country: ca
Re: Help me understand this code
« Reply #35 on: November 18, 2020, 07:19:35 am »
Dam , it sucks that its not universally true that anything that I see in the SFR register view

X-> was always observeable and followed the datasheet by me in a monkey see monkey do fashion.

Guess there are exeptions. Could this be on purpose for limiting damage?
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12500
  • Country: us
    • Personal site
Re: Help me understand this code
« Reply #36 on: November 18, 2020, 07:24:47 am »
Guess there are exeptions. Could this be on purpose for limiting damage?
What damage? There is nothing permanently damaging you can do. And nobody is going to be babysitting you here, it is embedded development.

Just look in your header files and see where this structure is defined and how it is named. AXI may have conflicted with something else, so it was renamed to accommodate that conflict, who knows.

May be whoever generated those header files just forgot to include that structure, or they were generated based on some older SVD file that dud not have it.

Or may be Eclipse just fails to parse something in that file and silently fails to update the completion list.

The only way to tell is to look in the header file.
Alex
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->