AT32F403A anyone?

Anything not related to STM32
webjorn
Posts: 43
Joined: Sat Jul 09, 2022 8:49 pm

F_CPU is a constant, but should reflect speed

Post by webjorn »

It seems F_CPU is NOT calculated, but is a constant of 80.000.000.....

Reading the CRM_CFG register, the PLL mult factor should be the input parameter...

Gullik
webjorn
Posts: 43
Joined: Sat Jul 09, 2022 8:49 pm

Board libraries for this MCU

Post by webjorn »

Hi,

Some progress, DFU upload did not work until I edited /etc/udev/rules.d/50-usb-conf.rules
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="df11", GROUP="users", MODE="0666"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2e3c", ATTRS{idProduct}=="df11", GROUP="users", MODE="0666"
The last line is the one allowing the WeAct board to be programmed with the default and only upload tool.

Note that just connecting the board to a live usb disables the serial upload. Using a power bank serial upload is OK.

Now I just need to add libraries, these do not come in automatically when installing the board. There IS a library, AT32F403A_407_Firmware_Library_V2.0.9.zip, I do not understand if that is what arduino wants....
I tried to install it as a ZIP, but it does not seem to do anything.....

Also, there is no option to include usb support (so that prints can forward to a /dev/ttyACM0...
But, board installs and blink works and setting clock to 240 Mhz also seems ok, even though F_CPU always says 80 Mhz.

Gullik
webjorn
Posts: 43
Joined: Sat Jul 09, 2022 8:49 pm

Ports A and C but not B enabled

Post by webjorn »

Trying a small sketch I found GPIOB not being enabled. Dumping the CRM_APB2 register shows no clock at GPIOB. I enabled that oring 0x8 to
the register, and the port gives reasonable values.

The reason for A and C being already enabled is of course the use of PC13 for the led and PA9-PA10 for serial.

Not to try to read a port at max speed and see what that gives....

Gullik
webjorn
Posts: 43
Joined: Sat Jul 09, 2022 8:49 pm

Re: AT32F403A anyone?

Post by webjorn »

I have made a small sketch that just sends the contents of an array to PORTB. This indicates about 2 Mhz toggling. the code is extremely simple, just

for (i=0;i<maxarray;i++) {
GPIOB = maxarray;
}

Why so slow? How do I display the generated assembly code? I am running the CPU at 240 Mhz.

240/2 , 120 instructions per iteration?? Puzzled!!!

Gullik
ozcar
Posts: 143
Joined: Wed Apr 29, 2020 9:07 pm
Answers: 5

Re: AT32F403A anyone?

Post by ozcar »

webjorn wrote: Mon Sep 05, 2022 9:57 pm How do I display the generated assembly code?
If you were using an ide which allows debugging, it would probably allow you to just select assembly view.

Otherwise use

Code: Select all

arm-none-eabi-objdump.exe -D your.ino.elf
Setting the compile options to verbose in the Arduino ide preferences will help you locate both the objdump program and also your elf file.

However I have no idea how the code you showed is supposed to do what you said you want.
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: AT32F403A anyone?

Post by GonzoG »

@webjorn
You will get 120MHz output only if MCU supports this speed for GPIO and only if you put code that doesn't use conditional jumps or loops (if, for, while, etc).
Each condition, each jump in code needs from one to few MCU cycles.

Also there is a GPIO clock, that defines it's speed.
webjorn
Posts: 43
Joined: Sat Jul 09, 2022 8:49 pm

Re: AT32F403A anyone?

Post by webjorn »

Thanks guys,

I am now using this little loop for testing.

Code: Select all

  // write alternate all zeros and all ones into datarray so I can scope on all pins.
   
   for(k=0;k<maxdata;k++) {
      if(( k & 1) == 0)
        datarray[k] = 0x0;
      else
        datarray[k] = 0xffff;
      }
      t1 = millis();
        for(i=0;i<maxdata;i++) {
//          datarray[i] = (*(uint16_t *) 0x40010c08); // read instead of write
        (*(uint16_t *) 0x40010c0c ) = datarray[i];
        }
and this is generated code....

Code: Select all

800042e:	462a      	mov	r2, r5
 8000430:	2300      	movs	r3, #0
 8000432:	f343 0100 	sbfx	r1, r3, #0, #1
 8000436:	3301      	adds	r3, #1
 8000438:	f5b3 5f80 	cmp.w	r3, #4096	; 0x1000
 800043c:	f822 1b02 	strh.w	r1, [r2], #2
 8000440:	d1f7      	bne.n	8000432 <_Z4loopv+0x216>
 8000442:	f000 f9cd 	bl	80007e0 <millis>
 8000446:	2300      	movs	r3, #0
 8000448:	4604      	mov	r4, r0
 800044a:	3301      	adds	r3, #1
 800044c:	f835 2b02 	ldrh.w	r2, [r5], #2
 8000450:	81b2      	strh	r2, [r6, #12]
 8000452:	f5b3 5f80 	cmp.w	r3, #4096	; 0x1000
 8000456:	d1f8      	bne.n	800044a <_Z4loopv+0x22e>
The result is a square wave on the pins, 30nS high and 30nS low, which equates to 16.67 Mhz, i.e. each sample 33 Mhz. It seems the cpu takes
5 instructions to write a word to GPIO. CPU clock is 240 Mhz as I have configured it. I would have hoped for a bit more than that but
this is as simple as it gets.

Regards,

Gullik
webjorn
Posts: 43
Joined: Sat Jul 09, 2022 8:49 pm

Re: AT32F403A anyone?

Post by webjorn »

i did write
.....= datarray; but the index disappeared....
webjorn
Posts: 43
Joined: Sat Jul 09, 2022 8:49 pm

Re: AT32F403A anyone?

Post by webjorn »

GPIO clock is 120 Mhz if I understand the setup. That would be a period of 8.33 nS.
And publishing square bracket left index square bracket right semicolon drops the index on preview or publish
using an index i does not work, but index k does work
left is index i, right is index k [k]
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: AT32F403A anyone?

Post by fpiSTM »

webjorn wrote: Tue Sep 06, 2022 3:05 pm GPIO clock is 120 Mhz if I understand the setup. That would be a period of 8.33 nS.
And publishing square bracket left index square bracket right semicolon drops the index on preview or publish
using an index i does not work, but index k does work
left is index i, right is index k [k]


Simply use code snippet to avoid this. Else your code is interpreted like a BB code....

Code: Select all

[i] left is index i, right is index k [k]
Post Reply

Return to “Off topic”