embeded/arduino(genuino)2025. 7. 29. 11:13

아니 쓰지도 못하고 재워두는거 왜 사는지 나도 이해가 안되지만 일단 지름 ㅋㅋㅋ

nRF24는 있어서 사려다가 패스

 

'embeded > arduino(genuino)' 카테고리의 다른 글

패시브 부저  (0) 2025.08.01
nRF24L01 복수 장치 통신  (0) 2025.07.29
1.8인치 TFT LCD with SDcard  (0) 2024.10.18
아두이노 FFB 휠 소스코드  (0) 2024.10.11
arducam esp8266 https post 예제  (0) 2024.01.31
Posted by 구차니
embeded/Cortex-M3 STM2025. 7. 28. 15:12

몇개 참조했는데 그냥 결국에는 맨땅에 헤딩해서 대충 구현.. -_ㅠ

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

 

1. HAL_Flash_Program() 호출 전에 해당 섹터는 HAL_FlashEx_Erase()를 불러서 지워져 있는 상태여야 함

STM32Cubeprogrammer로 보면 전부 0xFFFFFF 라서 그냥 바로 쓰면 되겠네? 싶어서

HAL_Flash_Unlock() 이후 바로  HAL_Flash_Program() 호출해서 쓰니 Hard Fault 발생 -_-

찾아봐도 별 도움되는건 없어서, 결국에는 지우고 새로 쓰니 문제 없이 되었는데

[링크 : https://community.st.com/t5/stm32-mcus-products/hal-flash-program-triggers-hardfault-exception/td-p/684669]

 

다시 안지우고 쓰려고 하면 아까처럼 hard fault는 안뜨고

HAL_Flash_Program() 의 리턴값이 HAL_ERROR(1)로 뜰 뿐 문제가 없다. 머지?

 

 

아래는 쓰는데 성공한 예제

 

2. 섹터 지우는건 빠른데, 쓰는건 느리다(word)

아래 코드에서 32MHz로 작동중인데,

Erase는 2msec 이내로 끝났고

Write는 2048 Byte, 1 섹터를 가득 채우는건데 65 msec 미만으로 소요되었다.

tick1 1
tick2 64

 

3. 16bit 32bit write 속도가 다르다.

함수 호출 횟수 차이인진 모르겠으나 WORD 에서 HALFWORD로 바꾸고 쓰기 횟수를 2배로 늘려주니

    ret = HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, addr, data);


무려(?) 3msec가 느려졌다.

tick1 1
tick2 67

 

3. HAL_FLASH_Unlock() / HAL_FLASH_Lock()

플래시를 unlock 하지 않고 erase / program 하면 실제로 써지거나 지워지지 않지만 HAL_OK로 리턴된다.

이게 머야 -_-

 

소스코드

void flash_test()
{
  HAL_StatusTypeDef ret;
  uint32_t addr = FLASH_BASE + 0x0007F800;
  int data = 0;

  HAL_FLASH_Unlock();

  FLASH_EraseInitTypeDef eraseDef;
eraseDef.TypeErase = FLASH_TYPEERASE_PAGES;
eraseDef.Banks = 1;
eraseDef.PageAddress = 0x807F800;
eraseDef.NbPages = 1;

  uint32_t ret_era = 0;
  uint32_t tick = HAL_GetTick();
  HAL_FLASHEx_Erase(&eraseDef, &ret_era);
  uint32_t tick2 = HAL_GetTick();

  printf("tick1 %d\r\n",tick2-tick);

  tick = HAL_GetTick();
  for(int idx = 0; idx < 512; idx++)
  {
    ret = HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, addr, data);
    if(ret != HAL_OK)
    {
      printf("ret[%x]\r\n", ret);
      break;
    }
    // else
    // {
    //   printf("%X [%X] ok\r\n", FLASH_BASE + addr * 4, data);
    // }

    addr += 4;
    data += 4;
  }
  tick2 = HAL_GetTick();
  printf("tick2 %d\r\n",tick2-tick);

  HAL_FLASH_Lock();
}

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

stm32 cpp  (0) 2025.08.08
stm32 eeprom emulation  (0) 2025.07.29
HAL_FLASH_Program  (0) 2025.07.21
stm32cubeide build analyzer  (0) 2025.07.21
stm32 wwdg, iwdg 차이  (0) 2025.06.30
Posted by 구차니
embeded/Cortex-M3 STM2025. 7. 21. 16:40

특이한 건 블럭단위가 아니라는 것과 program은 있어도 Erase나 Read 함수가 안보인다는 점.

// stm32f1xx_hal_flash.h
HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data);

HAL_StatusTypeDef HAL_FLASH_Unlock(void);
HAL_StatusTypeDef HAL_FLASH_Lock(void);
HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);

// stm32f1xx_hal_flash_ex.h
HAL_StatusTypeDef  HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError);
HAL_StatusTypeDef  HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit);

HAL_StatusTypeDef  HAL_FLASHEx_OBErase(void);
HAL_StatusTypeDef  HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit);
void               HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit);
uint32_t           HAL_FLASHEx_OBGetUserData(uint32_t DATAAdress);

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

[링크 : https://selpman.tistory.com/287]

 

음.. 플래시 영역은 0x0800 0000 으로 지정되어 있으니 거기서 부터 512KB (= 0x0008 0000)

인 0x0807 FFFF 까지 읽어보면 되려나

 

 

STM32F103RET 니까 아래 조건이려나

/* High Density */
#if (defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE))
#define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x200U) ? \
                                           ((ADDRESS) <= FLASH_BANK1_END) :  (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0x180U) ? \
                                           ((ADDRESS) <= 0x0805FFFFU) :  ((ADDRESS) <= 0x0803FFFFU))))

#endif /* STM32F100xE || STM32F101xE || STM32F103xE */

 

그런데 STM32CubeProgrammer로 확인해보니

512KB 맞고 sector는 0에서 255까지 256개 * 2KB

 

Write Protect는 0에서 31 까지 총 32개.. 8개 섹터당 1개의 write protect 인가

 

 



 

 

2.4.2 Write protection
In high-density and connectivity line devices, from page 0 to page 61, write protection is implemented with a granularity of two pages at a time. The remaining memory block (from page 62 to page 255 in high-density devices, and from page 62 to page 127 in connectivity line devices) is write-protected at once.

0~61 까지는 2개씩 해서 총 31개 write protect로 상세하게 제어되고

62~255까지 퉁쳐서 1개,

합계 32개의 write protect로 제어된다.

[링크 : https://www.st.com/resource/en/programming_manual/pm0075-stm32f10xxx-flash-memory-microcontrollers-stmicroelectronics.pdf]

 

Depending on the selected boot mode, main Flash memory, system memory or SRAM is accessible as follows:
 Boot from main Flash memory: the main Flash memory is aliased in the boot memory space (0x0000 0000), but still accessible from its original memory space (0x800 0000). In other words, the Flash memory contents can be accessed starting from address 0x0000 0000 or 0x800 0000.
 Boot from system memory: the system memory is aliased in the boot memory space (0x0000 0000), but still accessible from its original memory space (0x1FFF B000 in connectivity line devices, 0x1FFF F000 in other devices).
 Boot from the embedded SRAM: SRAM is accessible only at address 0x2000 0000.

Embedded boot loader
The embedded boot loader is located in the System memory, programmed by ST during production. It is used to reprogram the Flash memory with one of the available serial interfaces:
 In low-, medium- and high-density devices the bootoader is activated through the USART1 interface.
 In XL-density devices the boot loader is activated through the following interfaces: USART1 or USART2 (remapped).
 In connectivity line devices the boot loader can be activated through one of the following interfaces: USART1, USART2 (remapped), CAN2 (remapped) or USB OTG FS in Device mode (DFU: device firmware upgrade).

[링크 : https://www.st.com/resource/en/reference_manual/rm0008-stm32f101xx-stm32f102xx-stm32f103xx-stm32f105xx-and-stm32f107xx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf]

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

stm32 eeprom emulation  (0) 2025.07.29
stm32f103ret flash program / erase 테스트  (0) 2025.07.28
stm32cubeide build analyzer  (0) 2025.07.21
stm32 wwdg, iwdg 차이  (0) 2025.06.30
stm32f wwdg iwdg 그리고 stop mode  (0) 2025.06.27
Posted by 구차니
embeded/Cortex-M3 STM2025. 7. 21. 15:35

크게 도움이 되는 기능은 아니지만 왜 안나오나 해서 찾아보니

windows - preference - STM32Cube - Build views settings 에서

on request 에서 auto로 바꾸어 주면 된다.

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

 

정책변경인진 모르겠지만 위 글을 참고하면 1.15.x~ 이후는 auto가 아니게 된 듯.

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

stm32f103ret flash program / erase 테스트  (0) 2025.07.28
HAL_FLASH_Program  (0) 2025.07.21
stm32 wwdg, iwdg 차이  (0) 2025.06.30
stm32f wwdg iwdg 그리고 stop mode  (0) 2025.06.27
stm32 cubeide ioc gen  (0) 2025.06.18
Posted by 구차니
embeded/전자회로2025. 7. 17. 11:06

웨비나 보다가 검색

보상도선을 쓰지 않으면 일반전선과 온도센서 접합점이 온도센서가 되어 오차가 발생 한다고

[링크 : https://m.blog.naver.com/jsrhim516/223414081150]

[ 링크 : https://setoo0922.tistory.com/353] 종류, 어댑터

 

열전대 용접기

[링크 : https://www.dhtc.co.kr/yc/shop/product.php?it_id=1568167478]

 

 

'embeded > 전자회로' 카테고리의 다른 글

아 어쩐지 부품이 두개더라 -_-?  (0) 2025.10.08
buzzer - 액티브 패시브  (0) 2025.07.15
rheostat ?  (0) 2024.07.25
notch filter  (0) 2024.05.21
멀티미터 TR 테스트  (0) 2023.11.02
Posted by 구차니
embeded/전자회로2025. 7. 15. 16:46

indicator 혹은 active buzzer는 내부에 회로가 내장되어

전기만 공급되면 resonant frequency 로 소리를 발생시키는 부품이다.

transducer 라던가 passive buzzer가 pwm에 의해 주파수로 입력하면 원하는 소리가 나는 부품인듯.

 

[링크 : https://puiaudio.com/file/specs-AI-1223-TWT-3V-2-R.pdf]

'embeded > 전자회로' 카테고리의 다른 글

아 어쩐지 부품이 두개더라 -_-?  (0) 2025.10.08
열전대 써모커플러  (0) 2025.07.17
rheostat ?  (0) 2024.07.25
notch filter  (0) 2024.05.21
멀티미터 TR 테스트  (0) 2023.11.02
Posted by 구차니
embeded/risc-v2025. 7. 8. 11:56

'embeded > risc-v' 카테고리의 다른 글

risc-v sv39  (0) 2023.11.18
milk-v duo(risc-v)  (0) 2023.11.18
부품 도착! + 주문 취소!  (0) 2023.11.02
오늘의 지름  (0) 2023.11.01
risc-v 저가보드 / sipeed maix amigo  (0) 2023.11.01
Posted by 구차니
embeded/esp322025. 7. 8. 11:07

ESP32 / ESP32-S 만 xtensa 계열이고, 나머지는 RISC-V 계열이다.

특이하게 C5/C6/C61 에서는 802.11ax 까지 지원하고, C5만 802.11ac를 지원한다.

 

  ESP32-P4 ESP32-S3 ESP32-S2 ESP32-C5 ESP32-C6 ESP32-C61 ESP32-C3 ESP32-C2 ESP32-H4 ESP32-H2 ESP32
wifi   bgn bgn bgn/ac/ax bgn/ax bgn/ax bgn bgn     bgn
BLE   5.0   5.3 5.3 5.0 5.0 5.0 5.4 5.0 4.2/classic
arch RISC-V Xtensa Xtensa RISC-V RISC-V RISC-V RISC-V RISC-V RISC-V RISC-V Xtensa
core dual dual single single single single single single Dual Single Single/Dual
clock(MHZ) 400 240 240 240 160 160 160 120 96 96 240

[링크 https://products.espressif.com/static/Espressif%20SoC%20Product%20Portfolio.pdf]

'embeded > esp32' 카테고리의 다른 글

esp32devkitc v4  (0) 2025.01.06
esp32cam sdio wifi  (0) 2024.09.11
esp32 wifi/bt on linux  (0) 2024.08.13
esp32 at 소스 빌드(윈도우)  (0) 2023.12.19
esp32 at source 빌드(리눅스)  (0) 2023.12.19
Posted by 구차니
embeded/Cortex-M3 STM2025. 6. 30. 11:17

iwdg는 내부 rc 클럭으로 작동을 하는 부분으로 stop이나 standby 모드에서도 작동한다.

즉, 절전모드 하려면 iwdg는 조금은 더 주의 깊게 설정해야 한다는 의미인데...

 

wwdg 는 window 라서 특정 시간대에만 와치독을 리셋할 수 있게 한다.

너무 빠르게 리셋해도 전체 시스템이 리셋되고, 너무 늦어도 리셋된다.

작동 시간이 일정하다면 wwdg를 쓰면 될 것 같기한데...

 

Independent watchdog
The independent watchdog is based on a 12-bit downcounter and 8-bit prescaler. It is clocked from an independent 40 kHz internal RC and as it operates independently of the main clock, it can operate in Stop and Standby modes. It can be used either as a watchdog to reset the device when a problem occurs, or as a free-running timer for application timeout management. It is hardware- or software-configurable through the option bytes. The counter can be frozen in debug mode.

Window watchdog
The window watchdog is based on a 7-bit downcounter that can be set as free-running. It can be used as a watchdog to reset the device when a problem occurs. It is clocked from the main clock. It has an early warning interrupt capability and the counter can be frozen in debug mode.

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

 

 

 

[링크 : https://pineenergy.tistory.com/138]

[링크 : https://electronics.stackexchange.com/questions/123080/independent-watchdog-iwdg-or-window-watchdog-wwdg]

[링크 : https://community.st.com/t5/stm32-mcus-products/iwdg-vs-wwdg/td-p/451732]

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

HAL_FLASH_Program  (0) 2025.07.21
stm32cubeide build analyzer  (0) 2025.07.21
stm32f wwdg iwdg 그리고 stop mode  (0) 2025.06.27
stm32 cubeide ioc gen  (0) 2025.06.18
stm32 uart tx dma  (0) 2025.06.18
Posted by 구차니
embeded/Cortex-M3 STM2025. 6. 27. 17:27

iwdg가 wdg_sw 설정되는줄 알았는데.. iwdg가 software랑 hardware로 나눠지는 듯.. 찾아봐야겠네

 

Option Byte는 아래의 api를 통해 접근할수 있고

HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit)

 

UserConfig 변수내에 bit 단위로 설정되도록 되어있다.

typedef struct
{
uint32_t OptionType; /*!< OptionType: Option byte to be configured.
This parameter can be a value of @ref FLASHEx_OB_Type */

uint32_t WRPState; /*!< WRPState: Write protection activation or deactivation.
This parameter can be a value of @ref FLASHEx_OB_WRP_State */

uint32_t WRPPage; /*!< WRPPage: specifies the page(s) to be write protected
This parameter can be a value of @ref FLASHEx_OB_Write_Protection */

uint32_t Banks; /*!< Select banks for WRP activation/deactivation of all sectors.
This parameter must be a value of @ref FLASHEx_Banks */
 
uint8_t RDPLevel; /*!< RDPLevel: Set the read protection level..
This parameter can be a value of @ref FLASHEx_OB_Read_Protection */

#if defined(FLASH_BANK2_END)
uint8_t USERConfig; /*!< USERConfig: Program the FLASH User Option Byte:
IWDG / STOP / STDBY / BOOT1
This parameter can be a combination of @ref FLASHEx_OB_IWatchdog, @ref FLASHEx_OB_nRST_STOP,
@ref FLASHEx_OB_nRST_STDBY, @ref FLASHEx_OB_BOOT1 */
#else
uint8_t USERConfig; /*!< USERConfig: Program the FLASH User Option Byte:
IWDG / STOP / STDBY
This parameter can be a combination of @ref FLASHEx_OB_IWatchdog, @ref FLASHEx_OB_nRST_STOP,
@ref FLASHEx_OB_nRST_STDBY */
#endif /* FLASH_BANK2_END */

uint32_t DATAAddress; /*!< DATAAddress: Address of the option byte DATA to be programmed
This parameter can be a value of @ref FLASHEx_OB_Data_Address */
 
uint8_t DATAData; /*!< DATAData: Data to be stored in the option byte DATA
This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF */
} FLASH_OBProgramInitTypeDef;

 

STOP 모드 들어가면 리셋걸리지 않게 하려면 해당 OB로 설정해주어야 하나..

/** @defgroup FLASHEx_OB_IWatchdog Option Byte IWatchdog
* @{
*/
#define OB_IWDG_SW ((uint16_t)0x0001) /*!< Software IWDG selected */
#define OB_IWDG_HW ((uint16_t)0x0000) /*!< Hardware IWDG selected */
/**
* @}
*/

/** @defgroup FLASHEx_OB_nRST_STOP Option Byte nRST STOP
* @{
*/
#define OB_STOP_NO_RST ((uint16_t)0x0002) /*!< No reset generated when entering in STOP */
#define OB_STOP_RST ((uint16_t)0x0000) /*!< Reset generated when entering in STOP */
/**
* @}
*/

/** @defgroup FLASHEx_OB_nRST_STDBY Option Byte nRST STDBY
* @{
*/
#define OB_STDBY_NO_RST ((uint16_t)0x0004) /*!< No reset generated when entering in STANDBY */
#define OB_STDBY_RST ((uint16_t)0x0000) /*!< Reset generated when entering in STANDBY */

 

HAL_FLASHEx_OBGetConfig()
HAL_FLASH_OB_Unlock()
HAL_FLASH_Unlock()
HAL_FLASH_OB_Launch()

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

[링크 : https://community.st.com/t5/stm32-mcus/how-to-program-stm32-option-bytes-with-the-hal-api/ta-p/49660]

 

IWDG는 option byte에 설정 가능 - 설정하면 리부팅 필요 혹은 강제로 리부팅됨

[링크 : https://m.blog.naver.com/kim1417/221461254045]

[링크 : https://pineenergy.tistory.com/138]

 

The Independent watchdog can not be stopped in any processor mode. You have to wake up regularly to reload the watchdog. What you can do is change the prescaler to maximum so the watchdog is counting slowly.
IWDG will only be stopped if you disconnect the controller from the power supply.

[링크 : https://stackoverflow.com/questions/53334571/disabling-stm32-hal-iwdg-or-wwdg-watchdog-before-stop-mode]

 

stm32g 의 경우인데 f에 없는 플래그가 존재한다.

[링크 : https://community.st.com/t5/stm32-mcus-products/iwdg-disable-during-sleep-stop/td-p/95106]

 

+

2025.07.31

stm32f1xx_hal.h 에서 찾은 건데..

FREEZE 로 된걸 해주면 stp 모드에서 동결되려나? 그런데 debug mode 래서 언제 쓸수 있는지 찾아봐야 할 듯.

/**
* @brief WWDG Peripherals Debug mode
*/
#define __HAL_DBGMCU_FREEZE_WWDG() SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_WWDG_STOP)
#define __HAL_DBGMCU_UNFREEZE_WWDG() CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_WWDG_STOP)

/**
* @brief IWDG Peripherals Debug mode
*/
#define __HAL_DBGMCU_FREEZE_IWDG() SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_IWDG_STOP)
#define __HAL_DBGMCU_UNFREEZE_IWDG() CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_IWDG_STOP)

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

stm32cubeide build analyzer  (0) 2025.07.21
stm32 wwdg, iwdg 차이  (0) 2025.06.30
stm32 cubeide ioc gen  (0) 2025.06.18
stm32 uart tx dma  (0) 2025.06.18
stm32 pwm 주파수 계산  (0) 2025.06.05
Posted by 구차니