Skip to content

Conversation

@ramielkhatibPQS
Copy link

@ramielkhatibPQS ramielkhatibPQS commented Apr 12, 2025

These changes perform the following:

  • Remove multiple definitions for device name (no more warning)
  • Fix frequency reading so UART can select the correct divider for different Baud rate.
  • Allow initial baud rate for UART to be modifiable using macro UART_INITBAUD
  • Change STM32F2 to use STM32F215RGT6 since this is the one currently sold (might need to update wiki + online listing since they list an older model)
  • Add RNG for STM32F2
  • Cleanup the STM32F2 and STM32F4 so they match each other with minor changes
  • Fix PLL values (M, N, Q) so they output 48MHz for the default HSE oscillator frequency (7.3728MHz). This is important for the RNG to produce correct output.
  • Allow PLL values to be generated in the makefile (through a one line python script) for any HSE oscillator frequency F_CPU. This allows the PLL values (M, N, Q) to always produce 48 MHz.

For the last one, the python script does the following:

  • It loops through all allowed values of M, N, and Q (checked using STM32CubeMx)
  • Skip values that don't produce output at each stage within the acceptable range (Main PLL characteristics table in target datasheet)
  • Find the value that produces an output closest to 48 MHz

@ramielkhatibPQS ramielkhatibPQS force-pushed the main branch 2 times, most recently from 5d405da to a3b3568 Compare April 12, 2025 08:21
@ramielkhatibPQS
Copy link
Author

Fixed PLL_TIMEOUT_VALUE for STM32F2. It was set to 100 tick. It should be 2*10^6 ticks similar to the STM32F4. Otherwise, the PLL will not have enough time to lock.

@alex-dewar
Copy link
Collaborator

Hi, sorry about the late response on this PR. Getting the following error when building for the F2:

Compiling:
arm-none-eabi-gcc -c -mcpu=cortex-m3 -I. -x assembler-with-cpp -mthumb -mfloat-abi=soft -fmessage-length=0 -ffunction-sections -DF_CPU=7372800 -Wa,-gstabs,-adhlns=objdir-CW308_STM32F2/stm32f2_startup.lst -I.././simpleserial/ -I.././hal/chipwhisperer-fw-extra -I.././hal/ -I.././hal/chipwhisperer-fw-extra/stm32f2 -I.././hal/chipwhisperer-fw-extra/stm32f2/CMSIS -I.././hal/chipwhisperer-fw-extra/stm32f2/CMSIS/core -I.././hal/chipwhisperer-fw-extra/stm32f2/CMSIS/device -I.././hal/chipwhisperer-fw-extra/stm32f2/Legacy -I.././simpleserial/ -I.././crypto/ -I.././crypto/tiny-AES128-C .././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_startup.S -o objdir-CW308_STM32F2/stm32f2_startup.o
    .././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.c ...    .././hal/hal.c ...    .././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_sysmem.c ...    .././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal.c ...    .././hal/chipwhisperer-fw-extra/stm32f2/stm32f2xx_hal_rng.c ...    .././crypto/tiny-AES128-C/aes.c ...    .././simpleserial/simpleserial.c ...    simpleserial-aes.c ...    .././crypto/aes-independant.c ...In file included from .././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.c:39:
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.h:182:4: error: #error "HSE_PLLM_VALUE not supported"
  182 |   #error "HSE_PLLM_VALUE not supported"
      |    ^~~~~
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.h:185:4: error: #error "HSE_PLLN_VALUE not supported"
  185 |   #error "HSE_PLLN_VALUE not supported"
      |    ^~~~~
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.h:191:4: error: #error "HSE_PLLQ_VALUE not supported"
  191 |   #error "HSE_PLLQ_VALUE not supported"
      |    ^~~~~
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.c: In function 'HAL_RCC_GetPCLK1Freq':
<command-line>: error: 'U' undeclared (first use in this function)
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.h:161:26: note: in expansion of macro 'HSE_VALUE'
  161 |     #define SYSCLK_FREQ (HSE_VALUE)
      |                          ^~~~~~~~~
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.h:164:21: note: in expansion of macro 'SYSCLK_FREQ'
  164 | #define HCLK_FREQ  (SYSCLK_FREQ / HSE_AHBCLKDIV_VALUE)
      |                     ^~~~~~~~~~~
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.h:165:21: note: in expansion of macro 'HCLK_FREQ'
  165 | #define PCLK1_FREQ (HCLK_FREQ / HSE_APB1CLKDIV_VALUE)
      |                     ^~~~~~~~~
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.c:552:20: note: in expansion of macro 'PCLK1_FREQ'
  552 |   return (uint32_t)PCLK1_FREQ;
      |                    ^~~~~~~~~~
<command-line>: note: each undeclared identifier is reported only once for each function it appears in
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.h:161:26: note: in expansion of macro 'HSE_VALUE'
  161 |     #define SYSCLK_FREQ (HSE_VALUE)
      |                          ^~~~~~~~~
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.h:164:21: note: in expansion of macro 'SYSCLK_FREQ'
  164 | #define HCLK_FREQ  (SYSCLK_FREQ / HSE_AHBCLKDIV_VALUE)
      |                     ^~~~~~~~~~~
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.h:165:21: note: in expansion of macro 'HCLK_FREQ'
  165 | #define PCLK1_FREQ (HCLK_FREQ / HSE_APB1CLKDIV_VALUE)
      |                     ^~~~~~~~~
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.c:552:20: note: in expansion of macro 'PCLK1_FREQ'
  552 |   return (uint32_t)PCLK1_FREQ;
      |                    ^~~~~~~~~~
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.c: In function 'HAL_RCC_GetPCLK2Freq':
<command-line>: error: 'U' undeclared (first use in this function)
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.h:161:26: note: in expansion of macro 'HSE_VALUE'
  161 |     #define SYSCLK_FREQ (HSE_VALUE)
      |                          ^~~~~~~~~
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.h:164:21: note: in expansion of macro 'SYSCLK_FREQ'
  164 | #define HCLK_FREQ  (SYSCLK_FREQ / HSE_AHBCLKDIV_VALUE)
      |                     ^~~~~~~~~~~
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.h:166:21: note: in expansion of macro 'HCLK_FREQ'
  166 | #define PCLK2_FREQ (HCLK_FREQ / HSE_APB2CLKDIV_VALUE)
      |                     ^~~~~~~~~
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.c:565:20: note: in expansion of macro 'PCLK2_FREQ'
  565 |   return (uint32_t)PCLK2_FREQ;
      |                    ^~~~~~~~~~
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2xx_hal_rng.c: In function 'HAL_RNG_GenerateRandomNumber':
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2xx_hal_rng.c:260:17: warning: implicit declaration of function 'HAL_GetTick' [-Wimplicit-function-declaration]
  260 |     tickstart = HAL_GetTick();
      |                 ^~~~~~~~~~~
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.c: In function 'HAL_RCC_GetPCLK1Freq':
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.c:553:1: warning: control reaches end of non-void function [-Wreturn-type]
  553 | }
      | ^
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.c: In function 'HAL_RCC_GetPCLK2Freq':
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.c:566:1: warning: control reaches end of non-void function [-Wreturn-type]
  566 | }
      | ^
make: *** [.././Makefile.inc:505: objdir-CW308_STM32F2/stm32f2_hal_lowlevel.o] Error 1
make: *** Waiting for unfinished jobs....
In file included from .././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal.c:3:
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.h:182:4: error: #error "HSE_PLLM_VALUE not supported"
  182 |   #error "HSE_PLLM_VALUE not supported"
      |    ^~~~~
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.h:185:4: error: #error "HSE_PLLN_VALUE not supported"
  185 |   #error "HSE_PLLN_VALUE not supported"
      |    ^~~~~
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal_lowlevel.h:191:4: error: #error "HSE_PLLQ_VALUE not supported"
  191 |   #error "HSE_PLLQ_VALUE not supported"
      |    ^~~~~
Done!
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal.c: In function 'platform_init':
<command-line>: error: 'U' undeclared (first use in this function)
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal.c:70:37: note: in expansion of macro 'HSE_PLLM_VALUE'
   70 |  RCC_OscInitStruct.PLL.PLLM       = HSE_PLLM_VALUE;
      |                                     ^~~~~~~~~~~~~~
<command-line>: note: each undeclared identifier is reported only once for each function it appears in
.././hal/chipwhisperer-fw-extra/stm32f2/stm32f2_hal.c:70:37: note: in expansion of macro 'HSE_PLLM_VALUE'
   70 |  RCC_OscInitStruct.PLL.PLLM       = HSE_PLLM_VALUE;
      |                                     ^~~~~~~~~~~~~~
make: *** [.././Makefile.inc:505: objdir-CW308_STM32F2/stm32f2_hal.o] Error 1

- Updated STM32F2 to STM32F215RG board
- Added RNG to STM32F2
- Cleaned up STM32F2 and STM32F4 so they are mostly matching
- Fixed PLL values in STM32F2 and STM32F4 to output 48 MHz for RNG at the default frequency of 7.37MHz
@ramielkhatibPQS
Copy link
Author

@alex-dewar I was able to reproduce your error. You are using python < 3.8, while the python script uses walrus operator which is a 3.8 feature. I assumed that python 3.9 or later would be installed since older versions are no longer maintained.

I made a change so the PLL values fallback to the default values if python is not installed or is installed and the version is < 3.8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants