embeded/Cortex-M4 STM2026. 1. 5. 17:46

'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
stm32g473 ADC calibration  (0) 2025.11.28
stm32f411 black fill board  (0) 2025.11.22
Posted by 구차니
embeded/Cortex-M3 STM2026. 1. 5. 16:51

대~~충 프로젝트 하나 파고 외부 8MHz로 해서 PLL 사용해 USB에는 48MHz를 넣어준다.

 

USB Fast Speed 를 지원하도록 하고 CDC(VCP) 를 지원하도록 하면

 

 

PA11 / PA12에 USB_DP / USB_DM 이라고 표기된다.

그런데.. D는 D+ 니까 Positive 같은데 왜 D-는 DM이지? negative DN 이어야 하지 않나?

(ai 답변. data minus.. -_-)

 

아무튼 미들웨어 추가하면, 미들웨어와 USB_DEVICE 라는 디렉토리가 추가된다.

 

함수 쓰는건 귀찮으니 대충 끌어옴.

int main(void)
{

/* USER CODE BEGIN 1 */
#define BUF_SIZE 30
uint8_t usb_buf[BUF_SIZE];
uint32_t count = 0;
/* USER CODE END 1 */

/* MCU Configuration--------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

/* USER CODE BEGIN Init */

/* USER CODE END Init */

/* Configure the system clock */
SystemClock_Config();

/* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USB_DEVICE_Init();
/* USER CODE BEGIN 2 */

/* USER CODE END 2 */

/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
sprintf((char*)usb_buf, "USB CDC TEST %ld\r\n", count);
CDC_Transmit_FS(usb_buf, BUF_SIZE);
HAL_Delay(1000);
memset(usb_buf,0,BUF_SIZE);
count++;

/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}

[링크 : https://eteo.tistory.com/194]

 

꽂으니 아래처럼 인식한다.

$ sudo demsg -w
[25664.443438] usb 1-2: new full-speed USB device number 26 using xhci_hcd
[25664.574720] usb 1-2: New USB device found, idVendor=0483, idProduct=5740, bcdDevice= 2.00
[25664.574741] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[25664.574748] usb 1-2: Product: STM32 Virtual ComPort
[25664.574754] usb 1-2: Manufacturer: STMicroelectronics
[25664.579419] cdc_acm 1-2:1.0: ttyACM0: USB ACM device

 

$ lsusb -t -v
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/12p, 480M
    ID 1d6b:0002 Linux Foundation 2.0 root hub
    |__ Port 2: Dev 26, If 0, Class=Communications, Driver=cdc_acm, 12M
        ID 0483:5740 STMicroelectronics Virtual COM Port
    |__ Port 2: Dev 26, If 1, Class=CDC Data, Driver=cdc_acm, 12M
        ID 0483:5740 STMicroelectronics Virtual COM Port

minicom은 9600으로 하던 115200 으로 하던 동일하게 값이 잘 들어온다. 신기하네

다만 많은 데이터가 있을때는 어떻게 될 진 미지수. 나중에 테스트 해봐야지

 

 

1회 굽기는 되는데 그 이후로 rebooting이 안될 때

step 1. reset 누르고 connect 누르고 reset 뗀다음 full chip erase

 

step 2. cubeide에서 swd 핀 할당해주기

 

"no debug" 로 두면 PA13/PA14가 주황색으로 되는데, 그러면 계속 retry 뜨니까 Serial Wire로 변경해준다.(SWO)

이건 실패시



STMicroelectronics ST-LINK GDB server. Version 7.8.0
Copyright (c) 2024, STMicroelectronics. All rights reserved.

Starting server with the following options:
        Persistent Mode            : Disabled
        Logging Level              : 1
        Listen Port Number         : 61234
        Status Refresh Delay       : 15s
        Verbose Mode               : Disabled
        SWD Debug                  : Enabled

Waiting for debugger connection...
Debugger connected
Waiting for debugger connection...
Debugger connected
Waiting for debugger connection...
      -------------------------------------------------------------------
                        STM32CubeProgrammer v2.17.0                  
      -------------------------------------------------------------------



Log output file:   /tmp/STM32CubeProgrammer_RFILwX.log
ST-LINK SN  : 31000D000D2D343632525544
ST-LINK FW  : V2J45S7
Board       : --
Voltage     : 3.21V
SWD freq    : 4000 KHz
Connect mode: Under Reset
Reset mode  : Hardware reset
Device ID   : 0x410
Revision ID : Rev X
Device name : STM32F101/F102/F103 Medium-density
Flash size  : 128 KBytes
Device type : MCU
Device CPU  : Cortex-M3
BL Version  : --



Memory Programming ...
Opening and parsing file: ST-LINK_GDB_server_byIESj.srec
  File          : ST-LINK_GDB_server_byIESj.srec
  Size          : 31.65 KB 
  Address       : 0x08000000 


Erasing memory corresponding to segment 0:
Erasing internal memory sectors [0 31]
Download in Progress:


File download complete
Time elapsed during download operation: 00:00:01.365



Verifying ...




Download verified successfully 


Shutting down...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...

 

이건 설정해주고 잘 될 때

STMicroelectronics ST-LINK GDB server. Version 7.8.0
Copyright (c) 2024, STMicroelectronics. All rights reserved.

Starting server with the following options:
        Persistent Mode            : Disabled
        Logging Level              : 1
        Listen Port Number         : 61234
        Status Refresh Delay       : 15s
        Verbose Mode               : Disabled
        SWD Debug                  : Enabled

Waiting for debugger connection...
Debugger connected
Waiting for debugger connection...
Debugger connected
Waiting for debugger connection...
      -------------------------------------------------------------------
                        STM32CubeProgrammer v2.17.0                  
      -------------------------------------------------------------------



Log output file:   /tmp/STM32CubeProgrammer_0DypHa.log
ST-LINK SN  : 31000D000D2D343632525544
ST-LINK FW  : V2J45S7
Board       : --
Voltage     : 3.21V
SWD freq    : 4000 KHz
Connect mode: Under Reset
Reset mode  : Hardware reset
Device ID   : 0x410
Revision ID : Rev X
Device name : STM32F101/F102/F103 Medium-density
Flash size  : 128 KBytes
Device type : MCU
Device CPU  : Cortex-M3
BL Version  : --



Memory Programming ...
Opening and parsing file: ST-LINK_GDB_server_a2ozrR.srec
  File          : ST-LINK_GDB_server_a2ozrR.srec
  Size          : 31.65 KB 
  Address       : 0x08000000 


Erasing memory corresponding to segment 0:
Erasing internal memory sectors [0 31]
Download in Progress:


File download complete
Time elapsed during download operation: 00:00:01.371



Verifying ...




Download verified successfully 


Shutting down...
Exit.

[링크 : https://blog.naver.com/crucian2k3/221533654464]

 

stlink/v2 에서는 3v3 핀을 제거하고 usb를 연결해주면 깔끔하게 전원이랑 문제없이 연결된다.

 

+

2026.01.06

되긴한데.. 먼가 잘되진 않는 느낌. 소스코드 하나 붙여넣고 그러면 정상적으로 나오지 않고

usb 연결한채로 프로그램을 다시 구으면 usb 뽑았다 꽂기 전에는 재기동이 정상적으로 이루어지지 않는다.

클럭을 올려도 (72MHz) 안되는걸 보면 다른게 문제인데... 멀까?

// main.c
void USB_CDC_RxHandler(uint8_t* Buf, uint32_t Len)
{
  for(int idx = 0; idx < Len;idx++)
  if(Buf[idx] == 0x0D) Buf[idx] = 0x0A;
CDC_Transmit_FS(Buf, Len);
}

// usbd_cdc_if.c
static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
{
  /* USER CODE BEGIN 6 */
  USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
  USBD_CDC_ReceivePacket(&hUsbDeviceFS);

  USB_CDC_RxHandler(UserRxBufferFS, *Len);
  memset(UserRxBufferFS, '\0', *Len);

  return (USBD_OK);
  /* USER CODE END 6 */
}

 

[링크 : https://deepbluembedded.com/stm32-usb-cdc-virtual-com-port-vcp-examples/#stm32-usb-cdc-transmit-example]

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

stm32f103 bluepill 회로도, usb 풀업  (1) 2026.01.05
bluepill 보드를 stlink v2로 만들기  (0) 2025.12.16
stm32f103ret crc  (0) 2025.12.09
stm32f103ret middleware - usb  (0) 2025.12.09
stm32f103ret connectivity - usb  (0) 2025.12.09
Posted by 구차니
embeded/Cortex-M3 STM2026. 1. 5. 14:25

PA1이 high로 되어있어야 한다는데

D+가  high로 되어있어야지 usb로 인식되려나?

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

 

그래서 stm32f103c8t6 blue pill 회로도 찾아보니 d+ 라인에 5v pull up이 걸려있다.

내가 가진건 정확한 모델을 알 수 없는 클론이라 머.. 이대로 되어있을거라고 생각해도 되려나?

[링크 : https://stm32-base.org/assets/pdf/boards/original-schematic-STM32F103C8T6-Blue_Pill.pdf]

 

Full speed 에서는 D+에 1.5k 의 pull up을

Low speed 에서는 D-에 1.5k 의 pull down을 규격으로 내세우고 있다.

[링크 : https://wcours.gel.ulaval.ca/GIF1001/old/h20/docs/USB_20.pdf]

[링크 : https://www.varofla.com/8c2ccda5-dc69-47a7-bd69-dd90aa64e5b1]

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

stm32f103c9t6(bluepill) + stlinkv2 + cdc(vcp)  (0) 2026.01.05
bluepill 보드를 stlink v2로 만들기  (0) 2025.12.16
stm32f103ret crc  (0) 2025.12.09
stm32f103ret middleware - usb  (0) 2025.12.09
stm32f103ret connectivity - usb  (0) 2025.12.09
Posted by 구차니
embeded/Cortex-M3 STM2025. 12. 16. 16:10

discovery 보드에서 jtag 부분에 stm32f103c8t6을 사용하고 있길래

[링크 : https://www.st.com/en/evaluation-tools/b-l072z-lrwan1.html]

 

저번에 구매했던 bluepill 보드를 어떻게 하면 jtag으로 개조할 수 있을까 하고 찾아보는데..

합법적이고 공식적인 방법은 없는듯.

[링크 : https://blog.naver.com/chandong83/222586172793]

 

[링크 : https://www.st.com/en/development-tools/stsw-link007.html] << 펌웨어 업로더

[링크 : https://www.st.com/en/development-tools/stsw-link004.html] << 펌웨어 업로더

[링크 : https://github.com/Krakenw/Stlink-Bootloaders] << 누군가 덤프해둔 stlink 펌웨어

 

This Firmware is not open source. But it may be delivered in a few cases after request to an FAE or a marketing agent.

[링크 : https://community.st.com/t5/stm32-mcus-boards-and-hardware/st-link-source-code/td-p/711010]

 

반대로.. jtag을 싸게 팔면 그걸 사서 bluepill 처럼 써버리는것도 방법이려나?

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

stm32f103c9t6(bluepill) + stlinkv2 + cdc(vcp)  (0) 2026.01.05
stm32f103 bluepill 회로도, usb 풀업  (1) 2026.01.05
stm32f103ret crc  (0) 2025.12.09
stm32f103ret middleware - usb  (0) 2025.12.09
stm32f103ret connectivity - usb  (0) 2025.12.09
Posted by 구차니
embeded/Cortex-M0 STM2025. 12. 10. 18:02

UCPD는 별도로 판매하는 건가...?

cortex-m0 기반의 개발보드인데.. 정체를 모르겠다..

m0인데 왜 액정이 달려있고 HDMI 나 DP가 달린거지...

 

[링크 : https://www.st.com/en/evaluation-tools/stm32g081b-eval.html#overview]

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

STM32G071B-DISCO  (0) 2025.12.10
stm32g081b-eval / mb1352-c02  (0) 2025.12.10
Posted by 구차니
embeded/Cortex-M0 STM2025. 12. 10. 18:01

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

STM32G081B-EVAL  (0) 2025.12.10
stm32g081b-eval / mb1352-c02  (0) 2025.12.10
Posted by 구차니
embeded/Cortex-M0 STM2025. 12. 10. 17:02

cortex-m0+ 엥? stm32G면 m4 아니었어?

[링크 : https://www.st.com/en/evaluation-tools/stm32g081b-eval.html#overview]

 

찾아보니 stm32g0 g4 식으로 라인업이 존재한다

[링크 : https://www.st.com/ko/stm32/stm32/stm32intro/stm32g0-series.html]

[링크 : https://www.st.com/ko/stm32/stm32/stm32intro/stm32g4-series.html]

 

M4도 F/L/G에 다 있군..

[링크 : https://www.st.com/content/st_com/en/arm-32-bit-microcontrollers/arm-cortex-m4.html?icmp=tt18613_gl_lnkon_nov2020]

 

그나저나 DP는 왜 있는겨 -_-?

HPD source 라고 해서 High Definition Display 라고 google ai에서 나오는데 공식적인 링크는 못 찾겠다.

[링크 : https://www.st.com/resource/en/schematic_pack/mb1352-c02_schematic.pdf]

  [링크 : https://www.stmcu.jp/design/hwdevelop/other/63465/]

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

STM32G081B-EVAL  (0) 2025.12.10
STM32G071B-DISCO  (0) 2025.12.10
Posted by 구차니
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' 카테고리의 다른 글

stm32f103 bluepill 회로도, usb 풀업  (1) 2026.01.05
bluepill 보드를 stlink v2로 만들기  (0) 2025.12.16
stm32f103ret middleware - usb  (0) 2025.12.09
stm32f103ret connectivity - usb  (0) 2025.12.09
STSW-STM32084 / usb demo  (0) 2025.12.09
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' 카테고리의 다른 글

bluepill 보드를 stlink v2로 만들기  (0) 2025.12.16
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
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 구차니