Electoday 2025

ไมโครคอนโทรลเลอร์ => ARM Processors => Topic started by: tha on October 22, 2020, 08:07:25 AM

Title: STM32F1 Memory & Bus
Post by: tha on October 22, 2020, 08:07:25 AM
3.1 System architecture
ใน low-, medium-, high- and XL-density devices, the main system ประกอบด้วย :
• Four masters:
     – Cortex® -M3 core DCode bus (D-bus) และ System bus (S-bus)
     – GP-DMA1 & 2 (general-purpose(วัตถุประสงค์ทั่วไป) DMA)
• Four slaves:
     – Internal SRAM
     – Internal Flash memory
     – FSMC
     – AHB ไปยัง APBx (APB1 หรือ APB2), ซึ่งต่อ the APB peripherals ทั้งหมด
สิ่งเหล่านี้เชื่อมต่อกันโดยใช้ a multilayer AHB bus architecture ดังแสดงใน Figure 1:

(https://i.imgur.com/Ib5SkVg.png)
Title: Re: STM32F1 Memory & Bus
Post by: tha on October 22, 2020, 08:39:19 AM
ใน connectivity line devices the main system ประกอบด้วย :
• Five masters:
     – Cortex® -M3 core DCode bus (D-bus) and System bus (S-bus)
     – GP-DMA1 & 2 (general-purpose DMA)
     – Ethernet DMA
• Three slaves:
     – Internal SRAM
     – Internal Flash memory
     – AHB ไปยัง APB bridges (AHB ไปยัง APBx), ซึ่งต่อ the APB peripherals ทั้งหมด
สิ่งเหล่านี้เชื่อมต่อกันโดยใช้ a multilayer AHB bus architecture ดังแสดงใน Figure 2:

(https://i.imgur.com/3sQinGB.png)
Title: Re: STM32F1 Memory & Bus
Post by: tha on October 22, 2020, 08:56:58 AM
ICode bus
bus นี้ต่อ the Instruction bus ของ the Cortex®-M3 core ไปยัง the Flash memory instruction interface. Prefetching ถูกกระทำบน bus นี้.

DCode bus
bus นี้ต่อ the DCode bus (literal load และ debug access) ของ the Cortex®-M3 core ไปยัง the Flash memory Data interface.

System bus
bus นี้ต่อ the system bus ของ the Cortex®-M3 core (peripherals bus) ไปยัง a BusMatrix ซึ่งจัดการ the arbitration(การชี้ขาด) ระหว่าง the core และ the DMA.

DMA bus
bus นี้ต่อ the AHB master interface ของ the DMA ไปยัง the BusMatrix ซึ่งจัดการการเข้าถึงของ CPU DCode และ DMA ไปยัง SRAM, Flash memory และ peripherals.
Title: Re: STM32F1 Memory & Bus
Post by: tha on October 22, 2020, 09:44:46 AM
BusMatrix
The BusMatrix จัดการ the access arbitration(การตัดสินการเข้าถึง) ระหว่าง the core system bus และ the DMA master bus. The arbitration ใช้ a Round Robin algorithm. ใน connectivity line devices, the BusMatrix ประหอบด้วย 5 masters (CPU DCode, System bus, Ethernet DMA, DMA1 และ DMA2 bus) และ 3 slaves (FLITF, SRAM และ AHB2APB bridges). ใน mcu เบอร์อื่น, the BusMatrix ประกอบด้วย 4 masters (CPU DCode, System bus, DMA1 bus และ DMA2 bus) และ 4 slaves (FLITF, SRAM, FSMC and AHB2APB bridges).

AHB peripherals ถูกต่อบน system bus ผ่านทาง a BusMatrix เพื่อยอมให้ DMA access.

AHB/APB bridges (APB)
The two AHB/APB bridges จัดให้มี full synchronous connections ระหว่าง the AHB และ the 2 APB buses. APB1 ถูกจำกัดไว้ที่ 36 MHz, APB2 ทำงานที่ full speed (ขึ้นไปถึง 72 MHz ขึ้นอยู่กับเบอร์ mcu).

อ้างอิงถึง Table 3 สำหรับ the address mapping ของ the peripherals ต่อถึงแต่ละ bridge.

หลังจากแต่ละ mcu reset, peripheral clocks ทั้งหมดถูกปิดการใช้งาน (ยกเว้นสำหรับ the SRAM และ FLITF). ก่อนการใช้ a peripheral คุณต้องเปิดการใช้งาน clock ของมันใน the RCC_AHBENR, RCC_APB2ENR or RCC_APB1ENR register.

Note: เมื่อ a 16- or 8-bit access ถูกกระทำบน an APB register, การเข้าถึงถูกแปลงเป็น a 32-bit access: the bridge จะซ้ำ the 16- หรือ 8-bit data เพื่อป้อนเป็น the 32-bit vector.
Title: Re: STM32F1 Memory & Bus
Post by: tha on October 23, 2020, 08:27:30 AM
3.2 Memory organization
Program memory, data memory, registers and I/O ports ถูกจัดระเบียบไว้ใน the same linear 4-Gbyte address space.

The bytes เหล่านี้ถูกเข้าระหัสใน memory ใน Little Endian format. The lowest numbered byte ใน a word ถูกถือเป็น the word's least significant byte และ the highest numbered byte the most significant.

สำหรับ the detailed mapping of peripheral registers อ้างอิงถึง the related sections(ส่วนที่เกี่ยวข้อง).

The addressable memory space ถูกแบ่งออกเป็น 8 main blocks, แต่ละ main block มี 512 MB.

the memory areas ทั้งหมดที่ไม่ได้ถูกจัดสรรให้ on-chip memories และ peripherals ถูกถือเป็น "สงวนไว้"). อ้างอิงถึง the Memory map figure ใน the corresponding product datasheet.
Title: Re: STM32F1 Memory & Bus
Post by: tha on October 23, 2020, 08:53:44 AM
3.3 Memory map
ดู the datasheet ที่ตรงกับเบอร์ mcu ของคุณสำหรับแผนภาพที่ครอบคลุมของ the memory map. Table 3 ให้ the boundary addresses ของ the peripherals ที่มีให้ใช้ในทุก STM32F10xxx devices

(https://i.imgur.com/XupUEEB.png)

ปล. ไปถึงไหนกันแล้ว ทำโปรแกรม ผมจะไม่ทำโปรแกรมนะ จะแปลอย่างเดียว ให้ทีมงานทำโปรแกรมไปนะครับ
Title: Re: STM32F1 Memory & Bus
Post by: tha on October 23, 2020, 09:15:34 AM
(https://i.imgur.com/8OAmv3b.png)
Title: Re: STM32F1 Memory & Bus
Post by: tha on October 23, 2020, 09:23:05 AM
(https://i.imgur.com/PSuhvOb.png)

1. การแชร์ SRAM นี้สามารถถูกเข้าถึงอย่างเต็มที่เพียงใน low-, medium-, high- and XL-density devices, ไม่มีใน connectivity line devices.
Title: Re: STM32F1 Memory & Bus
Post by: tha on October 23, 2020, 10:41:33 AM
3.3.1 Embedded SRAM
The STM32F10xxx มีคุณสมบัติมากถึง 96 Kbytes ของ static SRAM. มันสามารถถูกเข้าถึงได้เป็นแบบ bytes, half-words (16 bits) หรือ full words (32 bits). The SRAM start address คือ 0x2000 0000.

3.3.2 Bit banding
The Cortex®-M3 memory map ประกอบด้วย two bit-band regions. regions เหล่านี้ map แต่ละ word ใน an alias region ของ memory ไปยัง a bit ใน a bit-band region ของ memory. การเขียนไปยัง a word ใน the alias region มีผลเดียวกันกับ a read-modify-write operation บน the targeted bit ใน the bit-band region.

ใน the STM32F10xxx ทั้ง peripheral registers และ SRAM ถูก mapped ใน a bit-band region. นี้ยอมให้ single bit-band write และ read operations ถูกปฏิบัติ. The operations นี้มีให้ใช้สำหรับเพียง Cortex®-M3 accesses เท่านั้น, ไม่มีจาก bus masters อื่นๆ (e.g. DMA).

A mapping formula แสดงวิธีการอ้างอิงแต่ละ word ใน the alias region ไปยังบิตที่ตรงกันใน the bit-band region. The mapping formula เป็นดังนี้ :

bit_word_addr = bit_band_base + (byte_offset x 32) + (bit_number × 4)

ที่:
bit_word_addr คือ the address ของ the word ใน the alias memory region ที่ maps ไปยัง the targeted bit.
bit_band_base คือ the starting address ของ the alias region
byte_offset คือจำนวนของ the byte ใน the bit-band region ที่บรรจุ the targeted bit
bit_number คือ the bit position (0-7) ของ the targeted bit.

Example:
ตัวอย่างดังต่อไปนี้แสดงวิธีทำแผนที่ถึงกัน(map) bit 2 ของ the byte ตำแหน่งอยู่ที่ SRAM address 0x20000300 ใน the alias region:

0x22006008 = 0x22000000 + (0x300*32) + (2*4).

การเขียนไปยัง address 0x22006008 มีผลเดียวกันกับ a read-modify-write operation บน bit 2 ของ the byte ที่ SRAM address 0x20000300.

การอ่าน address 0x22006008 คืนค่า (0x01 หรือ 0x00) ของ bit 2 ของ the byte ที่ SRAM address 0x20000300 (0x01: bit set; 0x00: bit reset).

สำหรับข้อมูลที่มากขึ้นบน Bit-Banding อ้างอิงถึง the Cortex®-M3 Technical Reference Manual.
Title: Re: STM32F1 Memory & Bus
Post by: tha on October 23, 2020, 11:24:21 AM
อันนี้มีรูปให้ดูด้วย พอจะเข้าใจดีขึ้นหรือเปล่า https://os.mbed.com/cookbook/bit-banding (https://os.mbed.com/cookbook/bit-banding)
Title: Re: STM32F1 Memory & Bus
Post by: tha on October 24, 2020, 10:19:54 AM
3.3.3 Embedded Flash memory
The high-performance Flash memory module มีคุณสมบัติหลักดังต่อไปนี้:
• สำหรับ XL-density devices: ความหนาแน่นขึ้นไปถึง 1 Mbyte พร้อมด้วย dual bank architecture สำหรับความสามารถ read-while-write (RWW) :
     – bank 1: ขนาดคงที่ 512 Kbytes
     – bank 2: ขึ้นไปถึง 512 Kbytes
• สำหรับ mcu เบอร์อื่นๆ : ความหนาแน่นขึ้นไปถึง 512 Kbytes
• Memory organization: the Flash memory ถูกจัดระเบียบเป็น a main block และ an information block:
     – Main memory block มีขนาด :
        ขึ้นไปถึง 128 Kbytes × 64 bits แบ่งออกเป็น 512 หน้าๆละ 2 Kbytes (ดู Table 8 ) สำหรับ XL-density devices
        ขึ้นไปถึง 4 Kb × 64 bits แบ่งออกเป็น 32 หน้าๆละ 1 Kbyte สำหรับ low-density devices (ดู Table 4)
        ขึ้นไปถึง 16 Kb × 64 bits แบ่งออกเป็น 128 หน้าๆละ 1 Kbyte สำหรับ medium-density devices (ดู Table 5)
        ขึ้นไปถึง 64 Kb × 64 bits แบ่งออกเป็น 256 หน้าๆละ 2 Kbytes (ดู Table 6) สำหรับ high-density devices
        ขึ้นไปถึง 32 Kbit × 64 bits แบ่งออกเป็น 128 หน้าๆละ 2 Kbytes (ดู Table 7) สำหรับ connectivity line devices
     – Information block of size:
        770 × 64 bits for XL-density devices (see Table 8 )
        2360 × 64 bits for connectivity line devices (see Table 7)
        258 × 64 bits for other devices (see Table 4, Table 5 and Table 6)

The Flash memory interface (FLITF) features:
• Read interface with prefetch buffer (2x64-bit words)
• Option byte Loader
• Flash Program / Erase operation
• Read / Write protection
Title: Re: STM32F1 Memory & Bus
Post by: tha on October 25, 2020, 09:27:40 AM
(https://i.imgur.com/zOsFrKj.png)

(https://i.imgur.com/vjKYkGG.png)
Title: Re: STM32F1 Memory & Bus
Post by: tha on October 25, 2020, 10:08:46 AM
(https://i.imgur.com/EIPd826.png)
Title: Re: STM32F1 Memory & Bus
Post by: tha on October 25, 2020, 10:11:31 AM
(https://i.imgur.com/g19DFgi.png)
Title: Re: STM32F1 Memory & Bus
Post by: tha on October 25, 2020, 10:15:41 AM
(https://i.imgur.com/ANXunxN.png)

(https://i.imgur.com/nC3N02r.png)
Title: Re: STM32F1 Memory & Bus
Post by: tha on October 25, 2020, 10:21:59 AM
(https://i.imgur.com/dtGgJs5.png)

(https://i.imgur.com/KTFREYK.png)

Note: สำหรับข้อมูลเพิ่มเติมเกี่ยวกับ the Flash memory interface registers, อ้างอิงถึง the:"STM32F10xxx XL-density Flash programming manual" (PM0068) สำหรับ XL-density devices, "STM32F10xxx Flash programming manual" (PM0075) สำหรับ mcu เบอร์อื่นๆ.
Title: Re: STM32F1 Memory & Bus
Post by: tha on October 26, 2020, 08:02:55 AM
Reading the Flash memory
Flash memory instructions(คำสั่ง) และ data access ถูกกระทำผ่านทาง the AHB bus. The prefetch block ถูกใช้สำหรับ instruction fetches ผ่านทาง the ICode bus. Arbitration(การชี้ขาด) ถูกกระทำใน the Flash memory interface, และลำดับความสำคัญจะถูกกำหนดให้กับ data access บน the DCode bus.

Read accesses สามารถถูกดำเนินการได้ด้วยตัวเลือกการกำหนดค่าต่อไปนี้ :
• Latency: จำนวนของ wait states สำหรับ a read operation ที่โปรแกรมได้ทันที
• Prefetch buffer (2 x 64-bit blocks): มันถูกเปิดการใช้งานหลังจาก reset; a whole(ทั้ง) block สามารถถูกแทนที่ด้วย a single
   read จาก the Flash memory เนื่องจากขนาดของ the block เท่ากันกับ the bandwidth ของ the Flash memory. ขอบคุณ the
   prefetch buffer, faster CPU execution เป็นไปได้เนื่องจาก the CPU fetches(ดึง) one word ในเวลาเดียวกันที่ the next word
   พร้อมมีให้ใช้งานใน the prefetch buffer
• Half cycle: สำหรับ power optimization

Note:  ตัวเลือกเหล่านี้ต้องถูกใช้ให้สอดคล้องกับ the Flash memory access time. The wait states แสดงถึงอัตราส่วนของ the SYSCLK (system clock) period ต่อ the Flash memory access
time:
- 0 wait states, if 0 < SYSCLK ≤ 24 MHz
- 1 wait state, if 24 MHz < SYSCLK ≤ 48 MHz
- 2 wait states, if 48 MHz < SYSCLK ≤ 72 MHz

Half cycle configuration ไม่มีให้ใช้ร่วมกันกับ a prescaler บน the AHB. The system clock (SYSCLK) ควรเท่ากันกับ the HCLK clock. คุณสมบัตินี้จึงสามารถถูกใช้ได้กับเพียง a low-frequency clock ของ 8 MHz หรือน้อยกว่า. มันสามารถถูกสร้างจาก the HSI หรือ the HSE แต่ไม่ใช่จาก the PLL.

The prefetch buffer ต้องถูกเก็บเมื่อใช้ a prescaler แตกต่างไปจาก 1 บน the AHB clock.

The prefetch buffer ต้องถูก switched on/off เพียงเมื่อ SYSCLK ต่ำกว่า 24 MHz และไม่มี prescaler ถูกใช้งานบน the AHB clock (SYSCLK ต้องเท่ากับ HCLK). The prefetch buffer โดยปกติ switched on/off ในระหว่างขั้นตอนการเริ่มต้น(the initialization routine), ขณะที่ the microcontroller กำลังรันบน the internal 8 MHz RC (HSI) oscillator.

การใช้ DMA: DMA เข้าถึง Flash memory บน the DCode bus และมีลำดับความสำคัญเหนือกว่า ICode instructions. The DMA จัดให้มี one free cycle หลังจากแต่ละ transfer. บางคำสั่งสามารถถูกดำเนินการพร้อมกันกับ DMA transfer.

Programming and erasing the Flash memory (การโปรแกรมและการลบ the Flash memory)

The Flash memory สามารถถูกโปรแกรม 16 bits (half words) ในแต่ละครั้ง

สำหรับ write และ erase operations บน the Flash memory (write/erase), the internal RC oscillator (HSI) ต้องถูก ON.

The Flash memory erase operation สามารถถูกดำเนินการที่ page level หรือบน the whole Flash area (mass-erase). The mass-erase ไม่มีผลต่อ the information blocks

เพื่อให้แน่ใจว่าจะไม่มี over-programming, the Flash Programming และ Erase Controller blocks ถูกให้นาฬิกาโดย a fixed clock.

การสิ้นสุดของ write operation (programming or erasing) สามารถทริก an interrupt. interrupt นี้สามารถถูกใช้เพื่อออกจาก WFI mode, ได้เพียงถ้า the FLITF clock ถูกเปิดการใช้งาน. มิฉะนั้น, the interrupt นี้ถูกให้บริการเพียงหลังจากออกจาก WFI เท่านั้น.

The FLASH_ACR register ถูกใช้เพื่อ enable/disable prefetch และ half cycle access, และเพื่อควบคุม the Flash memory access time ให้สอดคล้องกับ the CPU frequency. ตารางข้างล่างนี้จัดให้มี the bit map และ bit descriptions สำหรับ register นี้.

สำหรับ information ที่สมบูรณ์ของ Flash memory operations and register configurations, อ้างอิงถึง the STM32F10xxx Flash programming manual (PM0075) or to the XL STM32F10xxx Flash programming manual (PM0068).
Title: Re: STM32F1 Memory & Bus
Post by: tha on October 26, 2020, 08:56:03 AM
(https://i.imgur.com/KkDD8Au.png)

Bits 31:6 Reserved, must be kept at reset value.
Bit 5 PRFTBS: Prefetch buffer status
บิตนี้จัดให้มีสถานะของ the prefetch buffer.
     0: Prefetch buffer ถูกปิดการใช้งาน
     1: Prefetch buffer ถูกเปิดการใช้งาน

Bit 4 PRFTBE: Prefetch buffer enable
     0: Prefetch ถูกปิดการใช้งาน
     1: Prefetch ถูกเปิดการใช้งาน

Bit 3 HLFCYA: Flash half cycle access enable
     0: Half cycle ถูกปิดการใช้งาน
     1: Half cycle ถูกเปิดการใช้งาน

Bits 2:0 LATENCY: Latency
บิตเหล่านี้แสดงอัตราส่วนของ the SYSCLK (system clock) period ต่อ the Flash access time.
     000 Zero wait state, if 0 < SYSCLK≤ 24 MHz
     001 One wait state, if 24 MHz < SYSCLK ≤ 48 MHz
     010 Two wait states, if 48 MHz < SYSCLK ≤ 72 MHz
Title: Re: STM32F1 Memory & Bus
Post by: tha on October 27, 2020, 07:13:45 AM
3.4 Boot configuration
ใน the STM32F10xxx, 3 different boot modes สามารถถูกเลือกผ่านทาง BOOT[1:0] pins ดังแสดงใน Table 9.

(https://i.imgur.com/hsIMpLg.png)

ค่าบน the BOOT pins ถูกลงกลอน(latched) บน the 4th rising edge ของ SYSCLK หลังจาก a reset. มันขึ้นอยู่กับผู้ใช้ที่จะเซ็ต the BOOT1 และ BOOT0 pins หลังจาก Reset เพื่อเลือก the required boot mode.

The BOOT pins ยังถูกสุ่มอีกครั้ง(re-sampled) เมื่อออกจาก Standby mode. ด้วยเหตุนี้พวกมันต้องถูกเก็บไว้ใน the required Boot mode ที่กำหนดค่าใน Standby mode. หลังจาก startup delay นี้ผ่านไป, the CPU ดึงข้อมูล(fetches) the top-of-stack value จาก address 0x0000 0000, จากนั้นเริ่ม code execution จาก the boot memory ที่เริ่มจาก 0x0000 0004.

เนื่องจาก fixed memory map ของมัน, the code area เริ่มจาก address 0x0000 0000 (เข้าถึงผ่านทาง the ICode/DCode buses) ขณะที่ the data area (SRAM) เริ่มจาก address 0x2000 0000 (เข้าถึงผ่านทาง the system bus). The Cortex®-M3 CPU ดึงข้อมูล(fetches) the reset vector บน the ICode bus เสมอ, ซึ่งหมายความว่ามี the boot space มีให้ใช้ใน the code area (โดยทั่วไป, Flash memory)เท่านั้น. STM32F10xxx microcontrollers จัดให้มีกลไกพิเศษเพื่อสามารถ boot จาก SRAM ได้อีกด้วยและไม่เพียงจาก main Flash memory และ System memory เท่านั้น.

ขึ้นอยู่กับ the selected boot mode, main Flash memory, system memory หรือ SRAM สามารถเข้าถึงได้ดังต่อไปนี้ :

• Boot จาก main Flash memory: the main Flash memory ถูกนามแฝง(aliased) ใน the boot memory space (0x0000
   0000), แต่ยังคงเข้าถึงได้จาก original memory space (0x800 0000) ของมัน. กล่าวอีกนัยหนึ่ง, the Flash memory contents
   สามารถถูกเข้าถึงเริ่มจาก 0x0000 0000 หรือ 0x800 0000.

• Boot จาก system memory: the system memory ถูกนามแฝง(aliased) ใน the boot memory space (0x0000 0000), แต่
   ยังคงเข้าถึงได้จาก original memory space ของมัน (0x1FFF B000 ใน connectivity line devices, 0x1FFF F000 ใน mcu
   เบอร์อื่น).

• Boot จาก the embedded SRAM: SRAM เข้าถึงได้เพียงที่ address 0x2000 0000 เท่านั้น

Note: เมื่อ booting จาก SRAM, ใน the application initialization code, คุณต้องย้ายที่ the vector table ใน SRAM โดย
    ใช้ the NVIC exception table และ offset register.

สำหรับ XL-density devices, เมื่อ booting จาก the main Flash memory, คุณมีทางเลือกที่จะ boot จากหนึ่งใน two memory banks. โดบค่าเริ่มต้น, boot จาก Flash memory bank 1 ถูกเลือก. คุณสามารถเลือกที่จะ boot จาก Flash memory bank 2 โดยการเคลียร์ the BFB2 bit ใน the user option bytes. เมื่อบิตนี้ถูกเคลียร์และ the boot pins อยู่ใน the boot จาก main Flash
memory configuration, the device บู๊ท(boots) จาก system memory, และ the boot loader กระโดดไปปฏิบัติงาน the user application ที่โปรแกรมใน Flash memory bank 2. สำหรับรายละเอียดที่มากขึ้นอ้างอิงถึง AN2606.

Note: เมื่อ booting จาก Bank2 ใน the applications initialization code, ย้ายที่ the vector table ไปยัง the Bank2
     base address. (0x0808 0000) โดยใช้ the NVIC exception table and offset register.
Title: Re: STM32F1 Memory & Bus
Post by: tha on October 27, 2020, 08:32:10 AM
Embedded boot loader
The embedded boot loader ถูกตำแหน่งอยู่ใน the System memory, โปรแกรมโดย ST ในระหว่างการผลิต. มันถูกใช้เพื่อโปรแกรมใหม่ the Flash memory ด้วยหนึ่งของ the available serial interfaces:
• ใน low-, medium- and high-density devices the bootoader ถูกทำให้ทำงานผ่านทาง the USART1 interface.
• ใน XL-density devices the boot loader ถูกทำให้ทำงานผ่านทาง the following interfaces: USART1 or USART2
   (remapped).
• ใน connectivity line devices the boot loader สามารถถูกทำให้ทำงานผ่านทางหนึ่งของ the following interfaces: USART1,
   USART2 (remapped), CAN2 (remapped) or USB OTG FS ใน Device mode (DFU: device firmware upgrade).

The USART peripheral ทำงานด้วย the internal 8 MHz oscillator (HSI). The CAN และ USB OTG FS, อย่างไรก็ตาม, สามารถทำงานได้ก็ต่อเมื่อ an external 8 MHz, 14.7456 MHz หรือ 25 MHz clock (HSE) มีอยู่เท่านั้น.

Note: สำหรับรายละเอียดที่มากขึ้นอ้างอิงถึง AN2606.