2023年10月24日 星期二

 

How to take USB traces with Bushound


  1. Open Bus Hound program and go to "Devices" page

      a. Check the device and clear any other checked items.

      b.  Check the vendor ID and product ID (VID/PID) is your test device. 

      c. If you want to quick select test device . Please  clear any other checked items and select "Auto select hot plugged devices" and power off/on your device. You will see your device has been selected like right picture.



  1. Go to Settings page

  a. Set Limits as your requirement

    • Capture Capacity: Captures megabytes of I/O at a time. The capture depth can be set starting from 1K up to available system RAM in 1K increments.
    • Max Record Length:  The capture depth of each individual I/O phase can be configured from 1 byte up to 2GB in 1-byte increments. For instance, if the capture depth is set to 8 bytes, only the first 8 bytes of each packet will be captured.

  b. Phases to Capture: The USB relate item. Usually check CTL, IN and OUT.

   CTL   USB control transfer       
   IN    Data in transfer           
   OUT   Data out transfer

  c. Columns to Display: What information you want to display the log window. 

2019年12月20日 星期五

Installing PyBluez in Windows10

PyBluez can be installed on GNU/Linux, Windows and macOS systems and is compatible with Python 2.7 and 3.

GNU/Linux Dependencies
  • Python 2.7 or more recent version
  • Python distutils (standard in most Python distros, separate package python-dev in Debian)
  • BlueZ libraries and header files

Windows Dependencies
  • Windows 7/8/8.1/10
  • Python 3.5 or more recent version
  • PyBluez requires a C++ compiler installed on your system to build CPython modules.
  • For Python 3.5 or higher
  • Microsoft Visual C++ 14.0 standalone: Build Tools for Visual Studio 2017 (x86, x64, ARM, ARM64)
  • Microsoft Visual C++ 14.0 with Visual Studio 2017 (x86, x64, ARM, ARM64)
  • Microsoft Visual C++ 14.0 standalone: Visual C++ Build Tools 2015 (x86, x64, ARM)
  • Microsoft Visual C++ 14.0 with Visual Studio 2015 (x86, x64, ARM)

Installing PyBluez in Windows 10

Run PyBluez API discover_devices()
  • location \pybluez-master\examples\simple\inquiry.py


I try to used PyBluez SDK to get data that broadcast from the client devices. But currently, I can only find devices nearby. And used find_service()  to list their service. After searching for some information from google. The PyBluez seems to only support RFComm protocol in the Windows10. I will continue to try to complete this task in Windows10.

PyBluez seems can't get advertising data under Win10. But I found another python PyPI. This SDK can meet my needs. Below is the GitHub Link: https://github.com/hbldh/bleak 

2016年8月18日 星期四

IAR Error[Pa045] function "xxx" has no prototype

    在將Keil的project轉移至IAR上時遇到了Error[Pa045]的Error,只要將"Require prototypes"取消掉重新編譯即可解決。

STM32 Flash 之 .icf檔

    在使用Flash功能時,為了確保資料寫入ROM後,下一次燒code到機器時,寫入的資料不希望被清掉,可以修改*.icf檔,IAR會根據這份文件,來避開某段FLASH_SECTOR。

Flash模組的組成

    可由reference manual中找到自己平台的Flash module。


Step 1. 修改*.icf檔

    假設我們需要使用Sector3來存放我們不想被清掉的資料,那我們的*.icf檔的寫法如下。

/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x08000000;
define symbol __ICFEDIT_region_ROM_end__ = 0x0803FFFF;

define symbol __ICFEDIT_region_ROM1_start__ = 0x08000000;
define symbol __ICFEDIT_region_ROM1_end__ = 0x0800BFFF;
define symbol __ICFEDIT_region_ROM2_start__ = 0x08010000;
define symbol __ICFEDIT_region_ROM2_end__   = 0x0803FFFF;

...
define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__];


define region ROM_region   = mem:[from __ICFEDIT_region_ROM1_start__   to __ICFEDIT_region_ROM1_end__] | mem:[from __ICFEDIT_region_ROM2_start__   to __ICFEDIT_region_ROM2_end__];


    由於Sector3的位置在0x0800C000~0x0800FFFF之間,因此將ROM1_end_ 設定為 0x800C000-1,ROM2_start_設定為0x0800FFFF+1,最後在ROM_region將ROM1跟ROM2照原本的方式設定上去即可。

Step 2.在IDE中載入*.icf檔

1.在Project右鍵選擇【Options...】


2.切到【Linker】頁面,勾選Override default,並將選擇檔案存放路徑。


3.Check the linker map file,看是否有成功linker到載入的檔案。









2016年8月15日 星期一

2016年7月27日 星期三

Report Descriptor之ReportID功能

    在做MCU使用USB通信協定與PC端溝通的實驗時,發現在linux與windows上有了不同的狀況。在windows用Bus Hound與自己寫的程式,都能正常地抓到MCU端丟出來的資料,但在Linux上卻有狀況。
    最後追到了Report Descriptor描述表中的ReportID這個項目,發現MUC端在Report Descriptor中有定義ReportID的話,送出的Data必須在最前面加上ReportID,不然Linux端會抓不到資料,後來去翻了HID1_11的文件,終於搞清楚是怎麼一回事了。

在HID1_11文件5.6 Reports有提到Report ID的特性:
1.Report ID items are used to indicate which data fields are represented in each report structure.
2.A Report ID item tag assigns a 1-byte identification prefix to each report transfer.
3.If no Report ID item tags are present in the Report descriptor, it can be assumed that only one Input, Output, and Feature report structure.

這裡總結一下以上的描述,當你的Report Descriptor只有一個InputOutput, 或是 Feature的話,可以不用定義Report ID,但是有用到Report ID的話,必須在每一個report transfer最前面加入一個Byte的Report ID參數。

2016年7月24日 星期日

STM32F411xC 基礎教學 :Timer使用方式

STM32F411xC/E Timer可分為以下三組:
1. Advanced-control timer(TIM1)
2.General-purpose timers(TIM2 to TIM5)
3.General-purpose timers(TIM9 to TIM11)

ps. TIM8 在STM32F411xC/E中是不能用的。

這三組有各自相對應的block diagram,根據使用不同的AHB/APB2或AHB/APB1,也會對時間計算有不同的結果,細節可自行參考RM0383 Reference manual

STM32 Timer 每次進入中斷時間間隔計算方式:
((1+TIM_Prescaler) / 系統頻率)*(1+TIM_Period) =
((1+9599)/96Mhz) * (1+9999) = 1 sec。

main function:
int main(void)
{
  RCC_ClocksTypeDef RCC_Clocks;
  RCC_GetClocksFreq(&RCC_Clocks);

  debug_io_init();
  TIM2_Init();

  /* Infinite loop */
  while (1)

}


Debug GPIO(PC15) init:
void debug_io_init( void )
{
    GPIO_InitTypeDef GPIO_InitStructure;

    RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOC, ENABLE );
 
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
  GPIO_Init( GPIOC, &GPIO_InitStructure );

    GPIO_ResetBits(GPIOC, GPIO_Pin_15);
    GPIO_SetBits(GPIOC, GPIO_Pin_15);
}


TIM2 init:
void TIM2_Init(void)
{
   TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;

   NVIC_InitTypeDef NVIC_InitStructure;

   /* TIM2 clock enable */
   RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

   /* Enable the TIM2 gloabal Interrupt */
   NVIC_InitStructure.NVIC_IRQChannel                   = TIM2_IRQn;
   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
   NVIC_InitStructure.NVIC_IRQChannelSubPriority        = 1;
   NVIC_InitStructure.NVIC_IRQChannelCmd                = ENABLE;
   NVIC_Init(&NVIC_InitStructure);

   /* Time base configuration */
   TIM_TimeBaseStructure.TIM_Period            = 10000-1;
   TIM_TimeBaseStructure.TIM_Prescaler         = 9600-1;
   TIM_TimeBaseStructure.TIM_ClockDivision     = 0;
   TIM_TimeBaseStructure.TIM_CounterMode       = TIM_CounterMode_Up;
   TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
   TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

   TIM_ClearFlag(TIM2, TIM_FLAG_Update);
   TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
   TIM_Cmd(TIM2, ENABLE);
}


TIM2 IRQHandler:
void TIM2_IRQHandler(void)
{
  if (TIM_GetITStatus(TIM2, TIM_IT_Update) == SET)
  {
    GPIO_ResetBits(GPIOC, GPIO_Pin_15);
    GPIO_SetBits(GPIOC, GPIO_Pin_15);
 
    GPIO_ToggleBits(GPIOC, GPIO_Pin_0);
 
    TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
  }
}


驗證:
    下圖為邏輯分析儀測量的結果,由圖中可看出PC15每一秒鐘會觸發一次,符合我們所預期的時間。