Topmetal control and readout using STM32 and its internal ADC
- Pixel clock:
PC6
- ADC sampling trigger:
PC8
- Reset:
PD12
- Speak:
PD13
- USB VCP (on OTG port) could be opened with
python -m serial.tools.miniterm /dev/cu.usbmodemFD131 115200
- D-Cache could cause DMA issues
- Examples are very valuable.
- Power domains
- D1 domain containing some peripherals and the Cortex-M7 core. AXI bus; AHB3; APB3
- D2 domain containing a large part of the peripherals. AHB1,2; APB1,2; SRAM1,2,3; DMA1,2
- D3 domain containing some peripherals and the system control. AHB4; APB4; SRAM4; BDMA
- PB1 (on CN12) is ADC12_INP5, which is a fast channel.
- t_conv = 4.5 CLK (8bit) ~ 8.5 CLK (16bit), 1 CLK for every 2 bits.
- t_samp >= 1.5 CLK.
- 16-bit mode max sample rate is 3.6 Msps.
- ADC1 and ADC2 are in AHB1/D2 (domain 2).
- Fadc = 72MHz / 2 / a select factor. Max is 36MHz (BOOST=1), 20MHz (BOOST=0).
- The extra /2 factor is introduced in silicon revision V.
- BOOST should be automatically handled by
HAL_ADC_Init()
. - In code, manually setting
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
seems to work.
- DAC1_OUT1 is routed out to PA4 (CN11 pin 32). If ADC channel and DAC channel are selected on the same GPIO, connection is done internally in GPIO pad, user has nothing to connect.
- DAC is on APB1 (120MHz max), 12-bit. TIM6 and TIM7 are usually used for triggering DAC.
- TIM8 set to asymmetric PWM mode to generate chip clock and ADC sampling trigger with precise phase offset control.
- CH1 (Pin PC6) is clock output.
- CH3 (Pin PC8) is ADC trigger output.
- TIM4 is set to be the slave of TIM8.
- In one-pulse mode, slave GATED mode. Effectively the trigger from TIM8 becomes its clock.
- Ch1 and Ch2 in PWM mode.
- Software starts counter
TIM4->CR1 |= (TIM_CR1_CEN);
.
- TIM6 triggers the DAC.
- Routing
PD13
back toPC7
to trigger the start of ADC/DMA acquisition will miss the beginning of the 1st frame by several CLKs.
STM32CubeMX
is used to configure the pin function/clock and setup the basic software skeleton.- Make sure SYS->Debug = Serial Wire is selected. Otherwise future flash writing will be disabled.
- Choose
Makefile
underToolchain/IDE
for GNU-RM compatible skeleton. - Choose HAL set all free pins as analog and Enable full assert.
- Choose copy all used libraries into the project folder so that
make
won't rely on independently installed Cube FW package (SDK). - Make minimal modification to the generated code. Place the majority of user code in separate files one level up to the generated code directory.
- It seems asking the software to update the already generated files is not reliable. Better delete all generated files and re-generate.
- After copying the files over, run
cleanCube.sh
to clean up the file permissions and add additional information intoMakefile
. Newmakefile
is generated andmake
will pick up the new one automatically. ModifycleanCube.sh
accordingly when new.c
files are added. - A new
main.c
is generated as well. This way, no manual intervention to any of the STM32CubeMX generated files is needed.
readelf -a xxx.elf
orobjdump -h xxx.elf
to see the built image size. Add up the size of all the loadable sections, such as.text
and.data
. Look for theLOAD
flag in the output fromobjdump
. Ignore non-loadable sections such as.comment
,.debug
and.bss
.
- STM32CubeMX
- GNU
- Download and put into
~/Applications/arm
. ~/Applications/arm/env.sh
:
#!/bin/sh ARMROOT=$HOME/Applications/arm export PATH=$ARMROOT/bin:$ARMROOT/arm-none-eabi/bin:$PATH export LD_LIBRARY_PATH=$ARMROOT/lib:$LD_LIBRARY_PATH export MANPATH=$ARMROOT/share/man:$MANPATH
arm-none-eabi-objdump -d build/main.o
to see the assembly code generated bygcc
.- stlink stm32 discovery line linux programmer
- Install under
~/Applications/arm/
$ mkdir build && cd build $ cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/arm .. $ make -j5 $ make DESTDIR=~/Applications install
st-util
,st-flash
,st-info
to download image to/manipulate STM32 MCU.
- Download and put into
- In-Application Programming (IAP)
- Open source ARM Cortex-M microcontroller library libopencm3
- J-Link Debug Probes
- Black Magic Probe: In application debugger for ARM Cortex microcontrollers
- STM32CubeProgrammer
- Write firmware then start running:
~/Applications/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/bin/STM32_Programmer_CLI -c port=SWD -w build/STM32H743ZITxCubeMX.hex -s
- For NUCLEO (-H7 at least), remember to hold down reset (black button), start the command, then release the button.
- Enable Debug (SWD) in CubeMX project to solve this problem.
- Write firmware then start running: