發表文章

目前顯示的是有「embedded」標籤的文章

STM32F103 "Hello World" Part3

圖片
Purpose 本篇實際操作STM32CubeMX去生成initialization code Development board在Part1介紹 預計demo功能為USART, GPIO, HSE USART dump "Hello World", GPIO toggle LED, 使用Oscillator -> PLL -> 72MHz, 為system clock STM32CubeMX Version 4.25 Pin assignment USART1 : RX(PA_10), TX(PA_9) LED : PC_13 External Oscillator : OSC_IN(PD_0) & OSC_OUT(PD_1) 2-Wire Serial Debug : SWDIO(PA_13) & SWCLK(PA_14) Step by step Step 1. click New Project Step 2. 選擇MCU型號, 可透過下方Filter Search挑選MCU, 或直接 Part Number Search 輸入型號, 找到後連點兩次進去主畫面 Step 3. 主畫面 在Pinout分頁中可設定開啟或關閉各項Peripherals, 右邊為Chip View, 檢查Pin使用情況 Step 4. 設定各Peripherals, 如下圖左 RCC config 選擇 High Speed Clock (HSE) 為 Crystal/Ceramic Resonator SYS config 選擇 Debug 為 Serial Wire USART1 config 選擇 Mode 為 Asynchronous GPIO config 於Chip View選擇 PC13 為 GPIO Output 設定好後, 右邊Chip View顯示相對應的Pin assignment 被設定過的Peripherals與Pin會以不同顏色表示 於官方TRM (UM1718)有詳細定義, 下方列出常見define Step 5. 切換至 Clock Configuration ...

STM32F103 "Hello World" Part2

圖片
Block Diagram STM32F103xx series 內部為Cortex-M3 32-bit RISC架構, 最快系統時脈72MHz,  Ibus (Instruction Bus)為ARM core從Internal Flash提取指令bus,  Flash放置code與自定義資料etc. Dbus (Data Bus)為ARM core存取Internal SRAM的bus, SRAM內存放register variable System bus為MCU周邊控制器存取通道  Bus Matrix為調度ARM core與周邊的管理 AHB, APB為AMBA規範下的protocol, 常見於SoC, AMBA為通用協定, 提供core與peripherals間的bus AMBA(Advanced Micro-controller Bus Architecture) AHB(Advanced High performance Bus) APB(Advanced Peripheral Bus) STM32F103xx series AHB Fmax = 72MHz, APB2 Fmax = 72MHz, APB1 Fmax = 36MHz, 使用上需注意peripherals放置在哪一bus上, 影響到該peripherals Fmax Clock Tree SYSCLK source: HSI RC (8MHz) HSE PLL (MUL x2-16) *when the HSI is used as a PLL clock input, the maximum system clock frequency that can be achieved is 64MHz. *for the USB function to be available, both HSE and PLL must be enable, with USBCLK running at 48MHz. *to have an ADC conv. time of 1us, APB2 must be at 14MHz, 28MHz or 56MHz. RTC source: L...

STM32F103 "Hello World" Part1

圖片
近期買了塊STM32F103 minimum development board 開發板上主要功能 1. Boot Select 2. Reset Button 3. MicroUSB Interface 4. External 8MHz Crystal for system 5. External 32768Hz Crystal for RTC 6. Power LED, and State LED connect to PC13 7. SWD Interface MCU為STM32F103C8T6 of ARM 32-bit Cortex-M3 CPU Core, LQFP-48 Package Key Features Pin assignment (Arduino風格的說明圖, STM32F103C8也可用Arduino環境開發) Development env.: STM32CubeMX + Keil 目前可用STM32CubeMX GUI生成MCU initialization code, 並藉由STM32CubeF1提供HAL & LL API直接開發 之前作法為使用STM32 stdperiph library, 開發上較為繁雜 Part2預計研究STM32F103 block diagram & clock, STM32CubeMX生成Keil project Resources Details of STM32F103C8 http://www.st.com/zh/microcontrollers/stm32f103c8.html Download STM32CubeMX: http://www.st.com/en/development-tools/stm32cubemx.html Details of STM32CubeF1: http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-mcu-packages/stm32cubef1.html ...