Page 1 of 1

Playing with Weact STM32H562RGT6

Posted: Thu Jan 02, 2025 7:56 pm
by ag123
Playing with Weact STM32H562RGT6
https://github.com/WeActStudio/WeActStu ... _CoreBoard
this board is a little pricy, I'd guess it is due to the new chip which is a Cortex M33
https://www.aliexpress.com/item/1005007502799023.html

this board works nicely out of the box in Arduino IDE 2.x (I'm using Arduino IDE 2.3.4)
and using stm32duino version 2.9.0 - current version
https://github.com/stm32duino/Arduino_Core_STM32

Weact installed a default sketch in the chip which is basically a blinky. One can backup the flash like the 1st 1MB (actually 64k would do for now after I examined the exported bin) of flash if one wants to keep it.

flashing the sketch using USB DFU works just fine. Initially, it didn't work for me, I originally mistook it to be related to those secure boot stuff (new in these new soc). It turns out incorrect, simply flip the usb c cable over and it works !
updating using dfu-util can be done via
https://dfu-util.sourceforge.net/

Code: Select all

dfu-util -a 0 -s 0x8000000 -D sketch.bin
it may be necessary to compile dfu-util from source if that distributed with the core doesn't work.

the sketch can be exported using Sketch > export compiled binary, and it'd be in the sketch folder in the build directory.
then one can use the usual tools or with STM32Cube programmer that'd be integrated in the ide.
it is necessary to press the boot and reset buttons as usual
- press both boot0 and reset
- hold boot0 release reset
- release boot0 1 secs later

if compiled with -O2 optimizations, this is a pretty fast chip, the Wheatstone benchmark looks like this
Hello stm32h562
Beginning Whetstone benchmark at default speed ...

Loops:10000, Iterations:1, Duration:3075.36 millisec
C Converted Single Precision Whetstones:325.17 Mflops
Hello stm32h562
Beginning Whetstone benchmark at default speed ...

Loops:10000, Iterations:1, Duration:3075.36 millisec
C Converted Single Precision Whetstones:325.17 Mflops
spec sheets says it is 250 Mhz
https://www.st.com/en/microcontrollers- ... 562rg.html
I think the apparent high floating point speeds > 1 fp per clock is due to vector SIMD computations

This chip has a lot of sram and flash !
I'd guess one can just go ahead and make fat binaries -O2 etc :lol:
it can probably run pretty big RTOS and can use things like malloc() to do memory management, I'd guess.
select usb-cdc-serial for the built

Re: Playing with Weact STM32H562RGT6

Posted: Thu Jan 02, 2025 10:54 pm
by GonzoG
I've played with it few month back. It's a nice little and quite powerful board.
But there's one issue with G4, H5, and probably few more series. ADC initialization is very slow and analogRead() is 2-3 times slower than on F411.

Re: Playing with Weact STM32H562RGT6

Posted: Fri Jan 03, 2025 1:56 pm
by ag123
reading the data sheets
https://www.st.com/resource/en/datashee ... h562rg.pdf
and ref manuals
https://www.st.com/resource/en/referenc ... ronics.pdf

it certainly feel quite different from the 'older' F4 families, this soc like the high dense f4xx and h7xx is cram packed with features and pheriperials.
quite notable is the FMC and the octo-spi psram feature, I'd guess it may be possible to use spi psram with this and that expands memory significantly.

the smaller features are like the Digital temperature sensor that converts the temperature into a square wave, whose
frequency is proportional to the temperature. The plain old analog temperature sensor is there too.

tried playing with the digital temperature sensor

Code: Select all

void setup() {
  // clock the DTS
  __HAL_RCC_DTS_CLK_ENABLE();
  // pclk is running at 250 Mhz, internal freq must be < 1 Mhz for calibration
  // set HSREF_CLK_DIV to 0x7f (127)
  DTS->CFGR1 |= DTS_CFGR1_HSREF_CLK_DIV_Msk;
  // enable digital temperature sensor  
  DTS->CFGR1 |= DTS_CFGR1_TS1_EN;
  // improve accuracy by using 5 periods
  DTS->CFGR1 |= 5 << DTS_CFGR1_TS1_SMP_TIME_Pos;

}

float readtemp() {
  // wait for TS1_RDY
  while(! DTS->SR & DTS_SR_TS1_RDY) delay(1);
  // clear data register
  DTS->DR = 0;
  // start measuremennt
  DTS->CFGR1 |= DTS_CFGR1_TS1_START;
  // wait for TS1_RDY
  while(! DTS->SR & DTS_SR_TS1_RDY) delay(1);
  // read the measurement value
  int32_t ts1_mfreq = DTS->DR & 0xfffful;
  
  /* from ref manual rm0481
  T = T_0 + (( F_PCLK ⁄ TS1_MFREQ ) * TS1_SMP_TIME - 100 * TS1_FMT0 ) / TS1_RAMP_COEFF
  */
  float t0 = 30.0;
  float f_pclk = 250e6;
  int32_t ts1_fmt0 = DTS->T0VALR1 & 0xfffful;
  int32_t ts1_ramp_coeff = DTS->RAMPVALR & 0xfffful;
  int16_t ts1_smp_time = 5;

  Serial.print("ts1_mfreq ");
  Serial.println(ts1_mfreq);

  Serial.print("ts1_fmt0 ");
  Serial.println(ts1_fmt0);

  Serial.print("ts1_ramp_coeff ");
  Serial.println(ts1_ramp_coeff);

  float t = t0 + (( f_pclk / ts1_mfreq) * ts1_smp_time - 100 * ts1_fmt0) / ts1_ramp_coeff;

  return t;
}

void loop() {
	float t = readtemp();
	Serial print("temp: ");
	Serial.println(t);
	delay(10000);
}
the build works just well no errors.
but no luck, I'm getting zeros for all the DTS register reads, (edit: see below)
apparently there are 2 banks of registers secure and non-secure
the DTS symbol points to the non secure bank of DTS registers in the include file stm32h562xx.h.
i'm not too sure if it is due to pclk being too fast as ref manual states that during calibration the internal frequency of the DTS sensor needs to be less than 1 Mhz, pclk = sysclk = 250 Mhz !, so i set the prescaler to 127 which is the largest divisor possible.

other things that I did not check could be that some peripherals are not clocked, oh well, I'd take a break for now :)

footnote: an interesting thing I noted is the APB1,2,3 runs at 250 Mhz ! it is probably among the fastest APB speeds seen vs the 'older' stm32 chips e.g. F103, F4 etc. these speeds are interesting, but that a long enough wire off a pin would literally make that an antenna, this is running at vhf frequencies higher than typical FM radio bands.

---
edit: ok found it

Code: Select all

__HAL_RCC_DTS_CLK_ENABLE();
now it works pretty well !
Loops:10000, Iterations:1, Duration:3078.15 millisec
C Converted Single Precision Whetstones:324.87 Mflops
ts1_mfreq 346
ts1_fmt0 7075
ts1_ramp_coeff 1895
Temp: 37.94
Hello stm32h562
Beginning Whetstone benchmark at default speed ...

Loops:10000, Iterations:1, Duration:3078.16 millisec
C Converted Single Precision Whetstones:324.87 Mflops
ts1_mfreq 347
ts1_fmt0 7075
ts1_ramp_coeff 1895
Temp: 36.84
Hello stm32h562
Beginning Whetstone benchmark at default speed ...

Loops:10000, Iterations:1, Duration:3078.16 millisec
C Converted Single Precision Whetstones:324.87 Mflops
ts1_mfreq 346
ts1_fmt0 7075
ts1_ramp_coeff 1895
Temp: 37.94
pause
higher temperatures as it is on the die and that after all I'm running a whetstone benchmark

I've attached the updated sketch with DTS codes, enhanced it a little so that you can pause / resume the scrolling by sending any keystrokes in the console. select usb-cdc-serial for the built. Bin file is included in the zip file.