Author Topic: STM32 USB libraries  (Read 6062 times)

0 Members and 1 Guest are viewing this topic.

Offline lawrence11Topic starter

  • Frequent Contributor
  • **
  • Posts: 321
  • Country: ca
STM32 USB libraries
« on: January 17, 2020, 02:34:52 pm »
So I now realise that my C language understanding sucks when trying to read or even follow a tutorial.

Whats this ugly thing called? This unnamed ( or named at the end of the block) typedef struct wich holds functions?




 
The following users thanked this post: bogdant

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1198
  • Country: fi
Re: STM32 USB libraries
« Reply #1 on: January 17, 2020, 02:55:39 pm »
Code: [Select]
uint8_t *(*GetDeviceDescriptor)(...)is a pointer to a function that returns a pointer to uint8_t. The tag is optional in a structure declaration. That is basically one implementation of classes and virtual functions in C.

Offline lawrence11Topic starter

  • Frequent Contributor
  • **
  • Posts: 321
  • Country: ca
Re: STM32 USB libraries
« Reply #2 on: January 17, 2020, 03:06:37 pm »
Say that again in universally googleable terms? I wanna know reasons, use cases and technique.

Yeah I was talking about these

Code: [Select]
typedef
struct
{
uint8_t *(*GetDeviceDescriptor )( USBD_SpeedTypeDef speed , uint16_t *length);
uint8_t *(*GetLangIDStrDescriptor )( USBD_SpeedTypeDef speed , uint16_t *length);
uint8_t *(*GetManufacturerStrDescriptor )( USBD_SpeedTypeDef speed , uint16_t *length);
uint8_t *(*GetProductStrDescriptor )( USBD_SpeedTypeDef speed , uint16_t *length);
uint8_t *(*GetSerialStrDescriptor )( USBD_SpeedTypeDef speed , uint16_t *length);
uint8_t *(*GetConfigurationStrDescriptor )( USBD_SpeedTypeDef speed , uint16_t *length);
uint8_t *(*GetInterfaceStrDescriptor )( USBD_SpeedTypeDef speed , uint16_t *length);
#if
(USBD_LPM_ENABLED == 1)
uint8_t  *(*GetBOSDescriptor )( USBD_SpeedTypeDef speed , uint16_t *length);
#
endif
}
USBD_DescriptorsTypeDef
« Last Edit: January 17, 2020, 03:16:13 pm by lawrence11 »
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: STM32 USB libraries
« Reply #3 on: January 17, 2020, 03:19:48 pm »
Yeah I was talking about these
This is array of pointers to a functions that returns a pointer to uint8_t.
 

Offline lawrence11Topic starter

  • Frequent Contributor
  • **
  • Posts: 321
  • Country: ca
Re: STM32 USB libraries
« Reply #4 on: January 17, 2020, 03:31:25 pm »
What do you mean an array? Technically there is not an array.

There is a multitude of pointers to a functions that returns a pointer to uint8_t, on each line, yes.
 

Offline lawrence11Topic starter

  • Frequent Contributor
  • **
  • Posts: 321
  • Country: ca
Re: STM32 USB libraries
« Reply #5 on: January 17, 2020, 03:41:26 pm »
like this?
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: STM32 USB libraries
« Reply #6 on: January 17, 2020, 03:42:00 pm »
Right. Bunch of function pointers in the structure :)
 

Offline lawrence11Topic starter

  • Frequent Contributor
  • **
  • Posts: 321
  • Country: ca
Re: STM32 USB libraries
« Reply #7 on: January 17, 2020, 03:48:32 pm »
and there would be no difference in the code if I moved  USBD_DescriptorsTypeDef  right next to typedef struct

instead of

typedef struct
{

}
USBD_DescriptorsTypeDef

correct? I dont like this style, it should follow a convention.
 

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1198
  • Country: fi
Re: STM32 USB libraries
« Reply #8 on: January 17, 2020, 05:55:42 pm »
and there would be no difference in the code if I moved  USBD_DescriptorsTypeDef  right next to typedef struct
Yes there would, because that is the name of the type alias that is being defined. Moving it would generate a syntax error. You can add a tag to the struct if you insist, there's an example in the first picture.

Offline lawrence11Topic starter

  • Frequent Contributor
  • **
  • Posts: 321
  • Country: ca
Re: STM32 USB libraries
« Reply #9 on: January 17, 2020, 06:08:39 pm »
No ides what you just said, whats the role of the name underneaht the unnamed typedef struct

USBD_DescriptorsTypeDef
 

Offline Kilrah

  • Supporter
  • ****
  • Posts: 1852
  • Country: ch
Re: STM32 USB libraries
« Reply #10 on: January 17, 2020, 06:27:24 pm »
When you do

Code: [Select]
struct blah
{
};

you then declare a variable as
Code: [Select]
struct blah myVar;
But if you wrap that with a typedef you can then omit the struct in the declaration, so with
Code: [Select]
typedef struct blah
{
}blah;

you can instead declare your variable with
Code: [Select]
blah myVar;
Which is shorter and people prefer.

But when you typedef there is no need to give the struct a name anymore, so people omit it since it's pointless to have it twice, so it becomes

Code: [Select]
typedef struct
{
}blah;

« Last Edit: January 17, 2020, 06:29:24 pm by Kilrah »
 

Offline lawrence11Topic starter

  • Frequent Contributor
  • **
  • Posts: 321
  • Country: ca
Re: STM32 USB libraries
« Reply #11 on: January 23, 2020, 11:24:54 pm »
So I notice this uncomfortable feeling of not knowing WTF is going on when I single step through ALL the config, trying to make sense of all this BS stepping to setup the registers. Since most of this stuff I soon wont care about exept their 1 or 2 functions, but the USB I need to study a bit, yet when it gets to this peripheral, it sets it up in a Handler, and I cant see the relationship going between setup page and SFR's, wich I like to do.

How do people know where to check for Handlers. Now theres a handler but its lost somewhere...

I wanna see where this Interrupt is enabled for the USB clock in the first place, I know that as soon as the CLK bit is set it trips, but thats because its enabled.

I wanna practice and watch over the INTERRUPT ENABLE registers for such and such peripherals, is there there a "tree like" diagram for all the possible interrupt names and their peripherals for each family??

BTW, I dont see why people complain about this IDE its quite fast and stable with hardware reset and setup with "connect on reset". using ST-link V3

« Last Edit: January 23, 2020, 11:27:57 pm by lawrence11 »
 

Offline lawrence11Topic starter

  • Frequent Contributor
  • **
  • Posts: 321
  • Country: ca
Re: STM32 USB libraries
« Reply #12 on: January 24, 2020, 01:17:48 am »
http://blog.atollic.com/what-you-need-to-know-about-debugging-interrupts-and-exceptions-on-cortex-m-devices

So I wanna know to to trace exeption event but lol, I dont see where he teaches me this??
 

Offline Kilrah

  • Supporter
  • ****
  • Posts: 1852
  • Country: ch
Re: STM32 USB libraries
« Reply #13 on: January 24, 2020, 04:45:04 am »
As mentioned it's about gathering stats about interrupts in a running application, where halting isn't possible because it would cause everything to break.
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: STM32 USB libraries
« Reply #14 on: January 24, 2020, 05:25:54 am »
Memory read/write breakpoints are very useful when you debug HAL/driver code. Knowing your MCU and debugger helps as well. Take some time to learn more about ARM, debugger and probe. When you know what is available - it is much more easier to find right approach. Info just about breakpoint features. It's IAR, but other debuggers in general do not differ much.
 

Offline lawrence11Topic starter

  • Frequent Contributor
  • **
  • Posts: 321
  • Country: ca
Re: STM32 USB libraries
« Reply #15 on: January 24, 2020, 11:59:43 am »
Yeah I know about breakpoints, its just the blue dots on the left that can be all deleted in a view and you get 5 maximum.

I would put one in the exeption handler but I dont where it is.
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: STM32 USB libraries
« Reply #16 on: January 24, 2020, 12:05:50 pm »
just the blue dots on the left that can be all deleted in a view and you get 5 maximum.
Those are not memory breakpoints. Before you jump into conclusion that you know everything about breakpoints - make sure that you are not mistaken ;)
 

Offline lawrence11Topic starter

  • Frequent Contributor
  • **
  • Posts: 321
  • Country: ca
Re: STM32 USB libraries
« Reply #17 on: January 24, 2020, 12:20:37 pm »
I thought these were breakpoints?  As it says breakpoints in the tab.

So they are just software? Not written into memory of the cortex, I see.

So they are more like watchpoints.
 

Offline lawrence11Topic starter

  • Frequent Contributor
  • **
  • Posts: 321
  • Country: ca
Re: STM32 USB libraries
« Reply #18 on: January 24, 2020, 12:29:10 pm »
I see now, you can change them.
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: STM32 USB libraries
« Reply #19 on: January 24, 2020, 12:40:54 pm »
There are code breakpoints and then there are memory access breakpoint. Those you show are all related to code. Maybe read IAR article I linked to see that breakpoints differ?  :-//
 

Offline lawrence11Topic starter

  • Frequent Contributor
  • **
  • Posts: 321
  • Country: ca
Re: STM32 USB libraries
« Reply #20 on: January 24, 2020, 01:29:12 pm »
And what do you think I am trying to do?

Heres a register I wanna watch, theres 4 things I can do in terms of debugging..

1: Watch by breakpoints by installing blue dots in the text editor manually, then tediously setting them as Hardware since there seems to be no quick Hardware breakoints, these cannot be set on address directly as I would  just *USB peripheral address. in a field of some sort, there is no field for direct address.

2: Expressions, these seem to give the right value but only after the exeption is fully done and nothing seems stopped by Hardware breakpoint and I cant see nothing still, thus I have no sense of comprehension.

3: Live expressions, same as #2, seems useless.

4: The useless stuff on the bottom with having to do with ITM ports, these only log and dont stop, same problem.

So now I wonder if this capability is not found by a special code in the edit watch expression window to make this a hardware breakpoint on address write?
« Last Edit: January 24, 2020, 01:35:04 pm by lawrence11 »
 

Offline kamtar

  • Regular Contributor
  • *
  • Posts: 62
Re: STM32 USB libraries
« Reply #21 on: January 24, 2020, 01:50:07 pm »
this is what you want
 

Offline lawrence11Topic starter

  • Frequent Contributor
  • **
  • Posts: 321
  • Country: ca
Re: STM32 USB libraries
« Reply #22 on: January 24, 2020, 02:15:48 pm »
WOW I was looking for that thing, well hidden.

But it seems its type cannot be specified to hardware, and shows nothing. Hardware breakpoints seem to only be possible on blue dots that you specify.

No idea how to step on an unknown exeption handlers still...All the SFR fields instantly appear on a Step over.
 

Offline lawrence11Topic starter

  • Frequent Contributor
  • **
  • Posts: 321
  • Country: ca
Re: STM32 USB libraries
« Reply #23 on: January 24, 2020, 02:34:13 pm »
https://community.nxp.com/thread/389027

Well it seems like in my case I cant configure it to stop on a write or read.

Perhaps I am in  this category?


Watchpoints can be configured to halt on a Read (or Load), Write (or Store), or both. Since watchpoints 'watch' accesses to memory, they are suitable for tracking accesses to global or static variables, and any data accesses to memory including those to memory mapped peripherals.

 

Note: Due to the way watchpoints are implemented, any monitored access will be performed by the CPU before a halts occurs (unlike instruction breakpoints - which halt the CPU before the underlying instruction executes). When a watchpoint is hit you will see some 'skid' beyond the instruction that performed the watched data access. If the instruction after the data access changes program flow (e.g. a branch or function return), then the IDE may not show the instruction or statement that caused the CPU to halt.
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: STM32 USB libraries
« Reply #24 on: January 24, 2020, 03:30:18 pm »
Perhaps I am in  this category?
Why don't you just try?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf