embeded/Cortex-M3 STM2025. 12. 9. 23:03

하드웨어로 구현된거라 소프트웨어로 루프돌리는것 보다 빠르다는게 장점인데 대충(?) 60배 빠르다고 한다.

[링크 : https://www.st.com/resource/en/application_note/an4187-using-the-crc-peripheral-on-stm32-microcontrollers-stmicroelectronics.pdf]

 

hcrc 라는 핸들이 선언되어 있고

HAL_CRC_Calcuate() 함수를 이용해서 바로 리턴을 받는 구조인 듯.

/* Private variables ---------------------------------------------------------*/
CRC_HandleTypeDef hcrc;

uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
{
  uint32_t index;      /* CRC input data buffer index */
  uint32_t temp = 0U;  /* CRC output (read from hcrc->Instance->DR register) */

  /* Change CRC peripheral state */
  hcrc->State = HAL_CRC_STATE_BUSY;

  /* Reset CRC Calculation Unit (hcrc->Instance->INIT is
  *  written in hcrc->Instance->DR) */
  __HAL_CRC_DR_RESET(hcrc);

  /* Enter 32-bit input data to the CRC calculator */
  for (index = 0U; index < BufferLength; index++)
  {
    hcrc->Instance->DR = pBuffer[index];
  }
  temp = hcrc->Instance->DR;

  /* Change CRC peripheral state */
  hcrc->State = HAL_CRC_STATE_READY;

  /* Return the CRC computed value */
  return temp;
}

[링크 : https://cpattern.tistory.com/218]

[링크 : https://m.blog.naver.com/sheld2/222346016827] crc32 와 동일하게 나오게 하려면 수정 필요

[링크 : https://blog.naver.com/eziya76/221507312819]

 

[링크 : https://community.st.com/t5/stm32-mcus/crc-computation-in-stm32-mcus-and-post-build-creation/ta-p/49710]

 

CRC calculation unit, 96-bit unique ID

2.3.3 CRC (cyclic redundancy check) calculation unit
The CRC (cyclic redundancy check) calculation unit is used to get a CRC code from a 32-bit data word and a fixed generator polynomial.
Among other applications, CRC-based techniques are used to verify data transmission or storage integrity. In the scope of the EN/IEC 60335-1 standard, they offer a means of verifying the Flash memory integrity. The CRC calculation unit helps compute a signature of the software during runtime, to be compared with a reference signature generated at linktime and stored at a given memory location.

[링크 : https://www.st.com/resource/en/datasheet/stm32f103rc.pdf]

'embeded > Cortex-M3 STM' 카테고리의 다른 글

stm32f103ret middleware - usb  (0) 2025.12.09
stm32f103ret connectivity - usb  (0) 2025.12.09
STSW-STM32084 / usb demo  (0) 2025.12.09
stlink v2 클론 도착!  (0) 2025.11.26
stm32 cubeide git commit hash  (0) 2025.11.24
Posted by 구차니
embeded/Cortex-M3 STM2025. 12. 9. 17:02

쭈욱 눌러보는데 저 FS가 Full Speed(12Mbps) 였군..

아무튼 지원가능한 클래스는 6가지이다. DFU로도 쓰면서 HID로 쓰고.. 이런식의 구성은 안될 것 같다.

 

Audio Deivce Class

 

샘플링 주파수는 250 ~ 48000 sample/s  이 가능하다. 내장  ADC를 어떻게 잘(?) 굴리면 48k 까지 가능하려나?

 

Communication Device Class (Virtual Port)

그래도 가상 com port인데 baudrate이 없네?

 

Download Firmware Update Class (DFU)

펍웨어 업로드 할때 쓰기 좋은 DFU 클래스.

USBD_DFU_MEDIA interface 는 무슨 의미이려나? Kg 써있으니 몸무게 같네

@Internal Flash   /0x08000000/03*016Ka,01*016Kg,01*064Kg,07*128Kg,04*016Kg,01*064Kg,07*128Kg

 

Human Interface Device Class (HID)

가상 키보드, 마우스, 조이스틱 만들기 좋은 HID 클래스

 

Custom Human Interface Device Class

HID랑 머가 다르려나? class parameter에 IN ENDPOINT, OUT ENDPOINT가 추가 되긴하는데..

송수신이 가능한 HID인가?

 

Mass Storage Class

microSD hat 붙이면 SD 플래시 메모리 만들수 있겠군

 

'embeded > Cortex-M3 STM' 카테고리의 다른 글

stm32f103ret crc  (0) 2025.12.09
stm32f103ret connectivity - usb  (0) 2025.12.09
STSW-STM32084 / usb demo  (0) 2025.12.09
stlink v2 클론 도착!  (0) 2025.11.26
stm32 cubeide git commit hash  (0) 2025.11.24
Posted by 구차니
embeded/Cortex-M3 STM2025. 12. 9. 16:45

23새 프로젝트 생성해서 이것저것 눌러보고 있는 중인데 USB는 무조건 48MHz가 들어가야 하나보다.

 

 

그 와중에 APB1 클럭은 10~36Mhz는 들어가야 하는 제약이라니

 

그 와중에  PLL source는 HSE만 허용한다고.. 왜 활성화 안되냐고!

 

먼가 꼬였었는지 RCC 설정이 없었는데 다시 ioc 파일 열고 외부 클럭 하니 이제야 된다.

USB를 쓰려면 PLL 클럭이 있어야 하고 그러려면 외부 클럭이 있어야 한다.

 

USB FS 활성화 하니 PA11 / PA12 가 설정된다.

 

Full Speed 12MB/s 만 선택지에 있고(USB FS - Full Speed)

Link Power Management를 활성화 하려면 Low Power를 Enable 해주어야 한다.

Battery Charging은 멀 하던 Enable 할 수 없네

 

NVIC Settings 제외하면 딱히 설정할 내용이 없긴한다.

 

'embeded > Cortex-M3 STM' 카테고리의 다른 글

stm32f103ret crc  (0) 2025.12.09
stm32f103ret middleware - usb  (0) 2025.12.09
STSW-STM32084 / usb demo  (0) 2025.12.09
stlink v2 클론 도착!  (0) 2025.11.26
stm32 cubeide git commit hash  (0) 2025.11.24
Posted by 구차니
embeded/Cortex-M3 STM2025. 12. 9. 16:43

 

[링크 : https://www.st.com/en/microcontrollers-microprocessors/stm32f103re.html]

 

받아보니 윈도우용.. OTL

[링크 : https://www.st.com/en/development-tools/stsw-stm32084.html#overview]

 

STM32F103RET 인데 USB Prescaler / To USB 가 있었네?

 

핀을 쓰고 있어서 활성화는 안되는데 Device (FS) 만 보인다.

File system인줄 알았는데 Fast Speed (12Mbps) 인 듯.

 

[링크 : https://blog.naver.com/eziya76/220945711310]

'embeded > Cortex-M3 STM' 카테고리의 다른 글

stm32f103ret middleware - usb  (0) 2025.12.09
stm32f103ret connectivity - usb  (0) 2025.12.09
stlink v2 클론 도착!  (0) 2025.11.26
stm32 cubeide git commit hash  (0) 2025.11.24
stm32f103c8t6 blue pill board  (0) 2025.11.22
Posted by 구차니
embeded/Cortex-M4 STM2025. 11. 28. 15:50

대충 21페이지에서 발견

3.8 CORDIC
The CORDIC provides hardware acceleration of certain mathematical functions, notably
trigonometric, commonly used in motor control, metering, signal processing and many other
applications.
It speeds up the calculation of these functions compared to a software implementation,
allowing a lower operating frequency, or freeing up processor cycles in order to perform
other tasks.
Cordic features
• 24-bit CORDIC rotation engine
• Circular and Hyperbolic modes
• Rotation and Vectoring modes
• Functions: Sine, Cosine, Sinh, Cosh, Atan, Atan2, Atanh, Modulus, Square root,
Natural logarithm
• Programmable precision up to 20-bit
• Fast convergence: 4 bits per clock cycle
• Supports 16-bit and 32-bit fixed point input and output formats
• Low latency AHB slave interface
• Results can be read as soon as ready without polling or interrupt
• DMA read and write channels

 

3.9 Filter mathematical accelerator (FMAC)
The filter mathematical accelerator unit performs arithmetic operations on vectors. It
comprises a multiplier/accumulator (MAC) unit, together with address generation logic,
which allows it to index vector elements held in local memory.
The unit includes support for circular buffers on input and output, which allows digital filters
to be implemented. Both finite and infinite impulse response filters can be realized.
The unit allows frequent or lengthy filtering operations to be offloaded from the CPU, freeing
up the processor for other tasks. In many cases it can accelerate such calculations
compared to a software implementation, resulting in a speed-up of time critical tasks.
FMAC features
• 16 x 16-bit multiplier
• 24+2-bit accumulator with addition and subtraction
• 16-bit input and output data
• 256 x 16-bit local memory
• Up to three areas can be defined in memory for data buffers (two input, one output),
defined by programmable base address pointers and associated size registers
• Input and output sample buffers can be circular
• Buffer “watermark” feature reduces overhead in interrupt mode
• Filter functions: FIR, IIR (direct form 1)
• AHB slave interface
• DMA read and write data channels

[링크 : https://www.st.com/resource/en/datasheet/stm32g473cb.pdf]

 

함수 3회 호출할 만큼 부하를 상쇄할 만큼 하드웨어 계산이 빠른거겠지?

1. Configure the CORDIC:
LL_CORDIC_Config(
    CORDIC,
    LL_CORDIC_FUNCTION_COSINE, /* cosine function */

    LL_CORDIC_PRECISION_6CYCLES, /* max precision for q1.31 cosine */
    LL_CORDIC_SCALE_0, /* no scale */
    LL_CORDIC_NBWRITE_1, /* One input data: angle. Second input data (modulus) is 1 af ter cordic reset */
    LL_CORDIC_NBREAD_2, /* Two output data: cosine, then sine */
    LL_CORDIC_INSIZE_32BITS, /* q1.31 format for input data */
    LL_CORDIC_OUTSIZE_32BITS
); /* q1.31 format for output data */

If only this configuration is used, this step is done once at initialization. Otherwise, it must be repeated each
time one of the above parameters changes.
2. Write the input argument(s):
/* Write angle */
LL_CORDIC_WriteData(CORDIC, ANGLE_CORDIC);
In this case, there is only one argument, the angle (defined as a constant value π/8). The other argument is
the default modulus of 1, so does not need to be written.
As soon as the expected number of arguments is written, the calculation starts.
3. Read the result(s):
/* Read cosine */
cosOutput = (int32_t)LL_CORDIC_ReadData(CORDIC);
/* Read sine */
sinOutput = (int32_t)LL_CORDIC_ReadData(CORDIC);

[링크 : https://www.st.com/resource/en/application_note/an5325-how-to-use-the-cordic-to-perform-mathematical-functions-on-stm32-mcus-stmicroelectronics.pdf]

 

FMAC configuration
The FMAC can be configured using the HAL driver from the STM32CubeG4 MCU Package. Before accessing
any FMAC registers, the FMAC clock must be enabled:
__HAL_RCC_FMAC_CLK_ENABLE();
An area of system memory must be reserved for the coefficients:
/* Declare an array to hold the filter coefficients */
static int16_t aFilterCoeffB[51];
We must also declare a structure to contain the FMAC parameters:
FMAC_HandleTypeDef hfmac;
Now we can configure the FMAC using the HAL_FMAC_FilterConfig() function:
FMAC_FilterConfigTypeDef sFmacConfig; /* declare a filter configuration structure */
sFmacConfig.CoeffBaseAddress = 0; /* Set the coefficient buffer base address */
sFmacConfig.CoeffBufferSize = 51; /* Set the coefficient buffer size to the number of coeffs */
sFmacConfig.InputBaseAddress = 51; /* Set the Input buffer base address to the next free address */
sFmacConfig.InputBufferSize = 100; /* Set the input buffer size greater than the number of coeffs */
sFmacConfig.InputThreshold = 0; /* Set the input watermark to zero since we are using DMA */
sFmacConfig.OutputBaseAddress = 151; /* Set the Output buffer base address to the next free address */
sFmacConfig.OutputBufferSize = 100; /* Set the output buffer size */
sFmacConfig.OutputThreshold = 0; /* Set the output watermark to zero since we are using DMA */

/* No A coefficients since FIR */

sFmacConfig.pCoeffA = NULL;
sFmacConfig.CoeffASize = 0;
sFmacConfig.pCoeffB = aFilterCoeffB; /* Pointer to the coefficients in memory */
sFmacConfig.CoeffBSize = 51; /* Number of coefficients */
sFmacConfig.Filter = FMAC_FUNC_CONVO_FIR; /* Select FIR filter function */
sFmacConfig.InputAccess = FMAC_BUFFER_ACCESS_DMA; /* Enable DMA input transfer */
sFmacConfig.OutputAccess = FMAC_BUFFER_ACCESS_DMA; /* Enable DMA output transfer */
sFmacConfig.Clip = FMAC_CLIP_ENABLED; /* Enable clipping of the output at 0x7FFF and 0x8000 */
sFmacConfig.P = 51; /* P parameter contains number of coefficients */
sFmacConfig.Q = FILTER_PARAM_Q_NOT_USED; /* Q parameter is not used */
sFmacConfig.R = 0; /* R parameter contains the post-shift value (none) */
if (HAL_FMAC_FilterConfig(&hfmac, &sFmacConfig) != HAL_OK) /* Configure the FMAC */
Error_Handler(); /* Configuration Error */
The HAL_FMAC_FilterConfig() function programs the configuration and control registers, and loads the
coefficients into the FMAC local memory (X2 buffer).

[링크 : https://www.st.com/resource/en/application_note/an5305-digital-filter-implementation-with-the-fmac-using-stm32cubeg4-mcu-package-stmicroelectronics.pdf]

'embeded > Cortex-M4 STM' 카테고리의 다른 글

STM32CubeProgrammer / uart / parity  (0) 2025.11.28
stm32flash 0.5 0.7 버전과 stm32g473  (0) 2025.11.28
stm32g473 ADC calibration  (0) 2025.11.28
stm32f411 black fill board  (0) 2025.11.22
stm32g473 adc  (0) 2025.11.03
Posted by 구차니
embeded/Cortex-M4 STM2025. 11. 28. 15:41

아무생각없이 57600-None 으로 했더니 정체 불명의(?) NACK가 뜬다.

 

57600-Even 로 해주니 잘된다.

'embeded > Cortex-M4 STM' 카테고리의 다른 글

stm32g4 cordic fmac  (0) 2025.11.28
stm32flash 0.5 0.7 버전과 stm32g473  (0) 2025.11.28
stm32g473 ADC calibration  (0) 2025.11.28
stm32f411 black fill board  (0) 2025.11.22
stm32g473 adc  (0) 2025.11.03
Posted by 구차니
embeded/Cortex-M4 STM2025. 11. 28. 15:36

ubuntu 22.04 패키지로 설치된 건 0.5 버전인데

stm32g473을 boot0 핀을 이용해서 내장 부트로더로 올려보려고 하니 이런 에러가 발생한다.

0x469 장치 아이디 미지원.. 쩝..

$ stm32flash /dev/ttyUSB0
stm32flash 0.5

http://stm32flash.sourceforge.net/

Interface serial_posix: 57600 8E1
Unknown/unsupported device (Device ID: 0x469)

 

소스가 0.7 인데 받아서 빌드하고 해보니 잘된다.

$ ./stm32flash /dev/ttyUSB0
stm32flash 0.7

http://stm32flash.sourceforge.net/

Interface serial_posix: 57600 8E1
Version      : 0x31
Option 1     : 0x00
Option 2     : 0x00
Device ID    : 0x0469 (STM32G47xxx/48xxx)
- RAM        : Up to 96KiB  (16384b reserved by bootloader)
- Flash      : Up to 512KiB (size first sector: 1x2048)
- Option RAM : 48b
- System RAM : 28KiB

'embeded > Cortex-M4 STM' 카테고리의 다른 글

stm32g4 cordic fmac  (0) 2025.11.28
STM32CubeProgrammer / uart / parity  (0) 2025.11.28
stm32g473 ADC calibration  (0) 2025.11.28
stm32f411 black fill board  (0) 2025.11.22
stm32g473 adc  (0) 2025.11.03
Posted by 구차니
embeded/Cortex-M4 STM2025. 11. 28. 14:45

전압이 이상하게(?) 낮게 나와서 찾아 보는데 (대충 0.3v 정도?) gpt도 캘리브레이션 하라고 한다.

cubeide에 의해서 생성된 코드로 adc 가 초기화되고 나서

캘리브레이션 한 다음 약 2usec 이후에 HAL_ADC_GetValue(&hadc1); 하면 된다고 한다.

  MX_ADC1_Init();
  /* USER CODE BEGIN 2 */
  extern ADC_HandleTypeDef hadc1;
  HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED);
  HAL_Delay(2);
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {

  }

 

stm32g4 인데 캘리브레이션 하지 않으면 0.924 V가 나왔고

1148
0.924902 * 24 = 22.197655

 

캘리브레이션 이후에는 0.979 V가 나왔다.

1216
0.979688 * 24 = 23.512501

[링크 : https://jeonhj.tistory.com/22]

'embeded > Cortex-M4 STM' 카테고리의 다른 글

stm32g4 cordic fmac  (0) 2025.11.28
STM32CubeProgrammer / uart / parity  (0) 2025.11.28
stm32flash 0.5 0.7 버전과 stm32g473  (0) 2025.11.28
stm32f411 black fill board  (0) 2025.11.22
stm32g473 adc  (0) 2025.11.03
Posted by 구차니
embeded/Cortex-M3 STM2025. 11. 26. 17:43

좀 더 써봐야 알겠지만, STM32F103C8T6과 STLink v2 클론 SWD로 작동 확인완료!

그나저나 reset은 안해놔서 리셋이 될지 모르겠네

 

'embeded > Cortex-M3 STM' 카테고리의 다른 글

stm32f103ret connectivity - usb  (0) 2025.12.09
STSW-STM32084 / usb demo  (0) 2025.12.09
stm32 cubeide git commit hash  (0) 2025.11.24
stm32f103c8t6 blue pill board  (0) 2025.11.22
stm32f103 usb c 연결 + usb ttl 연결  (0) 2025.11.22
Posted by 구차니
embeded/Cortex-M3 STM2025. 11. 24. 19:08

pre-build steps 에서 명령을 주어 특정 파일을 행성해서 그 변수에 값을 넣어주는 방식

머.. 어짜피 이것도 makefile로 생성될테니 방법은 방법이지

 

 

git log --pretty=format:'#define GIT_INFO_PRESENT%n static const char* GIT_INFO = "Version Information=[%H,%d]\r\n";' -n 1 > ../Core/Inc/gitcommit.h

[링크 : https://community.st.com/t5/stm32-mcus-embedded-software/git-commit-hash-flashed-along-with-my-code/td-p/179180]

'embeded > Cortex-M3 STM' 카테고리의 다른 글

STSW-STM32084 / usb demo  (0) 2025.12.09
stlink v2 클론 도착!  (0) 2025.11.26
stm32f103c8t6 blue pill board  (0) 2025.11.22
stm32f103 usb c 연결 + usb ttl 연결  (0) 2025.11.22
stm32f103 dfu (Device Firmware Upgrade)  (0) 2025.11.19
Posted by 구차니