Always check UART_FLAG_FE flag when using USART on STM32

If you are using HAL libraries, you may be not aware that framing error will stop current receiving operation. I discovered this problem while performing ESD test (electrostatic discharge). At first I thought that ESD spike somehow corrupted USART registers, so USART stopped to receive any data from PC.  Later I found out that this problem is related to UART_FLAG_FE (framing error flag). Framing errors are easy to encounter when using half-duplex RS-485 IC chip,  or some type of interference (ESD, relay switching, etc.). It is important to monitor error flags, especially UART_FLAG_FE, because it stops USART RX transfer in case of circular DMA buffer transfer.  Temporarily I have solved this problem using this code:

if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_FE)) { … restart usart dma rx transfer again …}

Truestudio 9.1.0: solving “undefined reference to” errors and _FPU_PRESENT errors for STM32F4

If you have “undefined reference to arm_sin_q31, arm_sin_q31,  arm_cfft_, etc.” errors, __FPU_PRESENT errors, CMSIS, _ARM_MATH_CMx errors, here is my solution:

1. go to project -> build settings

2. in left menu open C/C++ general –> Paths and Symbols

3. open “Symbols” tab, press ADD and add symbol: __FPU_PRESENT (double underscore symbol at the beginning), then press ADD and symbol _ARM_MATH_CM4

4. open “Libraries” tab, add arm_cortexM4lf_math. Note that this name does not have “lib” at the beginning (filename is libarm_cortexM4lf_math.a)!

5. open “Library Paths” tab, add path to libarm_cortexM4lf_math.a file: C:\Users\someusername\STM32Cube\Repository\STM32Cube_FW_F4_V1.21.0\Drivers\CMSIS\Lib\GCC\

TrueSTUDIO 9.0.1 Flash and run without debugging

  1. go to Run > External Tools > External Tools Configurations
  2. right-click on Program > click New
  3. set Location and Working directory to ST-LINK_CLI.exe
  4. for ST-LINK / ST-LINK v2, set Arguments to:
    -c SWD -P ${project_loc}\${config_name:${project_name}}\${project_name}.hex -Rst
    or with flash erase (-ME) and veryfy (-V), which is slower:
    -c SWD -ME -P ${project_loc}\${config_name:${project_name}}\${project_name}.hex -V -Rst
    for ST-LINK v2 with connect under reset (UR):
    -c SWD UR -P ${project_loc}\${config_name:${project_name}}\${project_name}.hex -Rst
    or with flash erase:
    -c SWD UR -ME -P ${project_loc}\${config_name:${project_name}}\${project_name}.hex -V -Rst

After configuration is done, Flash and run already may be used from Run > External Tools.

Next, open Run > Run Configurations…, right-click on Launch Group, click New..
Click “Add…” on the right side and choose external tool you’ve just created for ST-LINK_CLI.EXE:

Build-and-run may be done this way:
Press Ctrl+B to build your project, and then press Ctrl+F11 to flash and run.

 

TrueSTUDIO 9.0.1 + STM32CubeMX + PCM5102 I2S DAC example

Download stm32 + pcm5102 example source code here (937kb)

Just made a quick test to connect PCM5102 module to STM32F407VET6 board through I2S interface.

First, I downloaded and installed latest version of CubeMX. I changed default position of I2S pins as shown on the image below:

First, audioBuffer array is filled with two sinusoidal tones of 1KHz and 2KHz. Then HAL_I2S_Transmit_DMA is called to run DMA transfer in circular mode.

Although I2S configured as 32/32bit tranfer, I configured DMA transfer as halfword/halfword (16bit) to make it work correctly. It seems that there is a hint in STM’s Reference Manual:

The 24-bit and 32-bit data frames need two CPU read or write operations to/from the SPI_DR or two DMA operations if the DMA is preferred for the application. For 24-bit data frame specifically, the 8 nonsignificant bits are extended to 32 bits with 0-bits (by hardware)