From: AceVest Date: Sun, 19 May 2019 16:09:27 +0000 (+0800) Subject: add stm32 X-Git-Url: http://zhaoyanbai.com/repos/Bv9ARM.pdf?a=commitdiff_plain;h=a98a74ca51425fe2a31fba286a99f9808d8c24cb;p=acecode.git add stm32 --- diff --git a/learn/doc/mac_bash_profile b/learn/doc/mac_bash_profile index 79bad16..3bec058 100644 --- a/learn/doc/mac_bash_profile +++ b/learn/doc/mac_bash_profile @@ -26,8 +26,8 @@ CLOSECOLOR="\[\033[00m\]" #PS1='\[\033[02;37m\]\t\[\033[00m\]\[\033[01;37m\]@\[\033[01;33m\]\W\[\033[00m\]\$ ' #PS1='\[\033[02;37m\]\t\[\033[00m\]\[\033[01;37m\]@\[\033[01;33m\]\W\[\033[00m\]\$ ' -PS1="$GRAY\t$CLOSECOLOR$WHITE@$PURPLE\h $CYAN\W$RED\$ $CLOSECOLOR" -alias ll='ls -lGh --time-style=long-iso' +PS1="[$GRAY\t$CLOSECOLOR]\u$WHITE@$PURPLE\h $CYAN\W$RED\$ $CLOSECOLOR" +alias ll='ls -lGh' alias ls='ls -Gh' alias rm='rm -rf' alias cls='clear' diff --git a/learn/stm32/GPIO.md b/learn/stm32/GPIO.md new file mode 100644 index 0000000..5b0aab2 --- /dev/null +++ b/learn/stm32/GPIO.md @@ -0,0 +1,52 @@ +# GPIO + + + + +GPIO是挂在APB2下的 + +``` +#define PERIPH_BASE 0x40000000 +#define APB2PERIPH_BASE (PERIPH_BASE+0x10000) +#define GPIOA_BASE (APB2PERIPH_BASE+0x0800) +#define GPIOB_BASE (APB2PERIPH_BASE+0x0C00) +#define GPIOC_BASE (APB2PERIPH_BASE+0x1000) +#define GPIOD_BASE (APB2PERIPH_BASE+0x1400) +#define GPIOE_BASE (APB2PERIPH_BASE+0x1800) +``` + +GPIO的时钟RCC是挂在AHB下的 + +``` +#define AHBPERIPH_BASE (PERIPH_BASE+0x20000) +#define RCC_BASE (AHBPERIPH_BASE+0x1000) +``` + + +假设将PB9设置为推挽输出,并不断写高低电平 + +``` +#define APB2ENR (*(unsigned int*)(RCC_BASE+0x18)) +#define GPIOB_CRH (*(unsigned int*)(GPIOB_BASE+0x04)) +#define GPIOB_ODR (*(unsigned int*)(GPIOB_BASE+0x0C)) +#define GPIOB_BSRR (*(unsigned int*)(GPIOB_BASE+0x10)) +#define GPIOB_BRR (*(unsigned int*)(GPIOB_BASE+0x14)) + +unsigned int pin = 9; + +// 使能时钟 +APB2ENR |= 1 << 3; // 使能PB的是第3个bit + +// 设置为推挽输出 +GPIOB_CRH &= ~(0xF<<((pin-8)*4)); // 清除CNF、MODE的比特位 +GPIOB_CRH |= 0x3<<((pin-8)*4); // 设置为推挽输出的值 + +// 写高 +GPIOB_BSRR = 1 << pin; + +// 写低 +GPIOB_BRR = 1 << pin; + +// 取反 +GPIOB_ODR ^= 1 << pin; +``` \ No newline at end of file diff --git a/learn/stm32/env.md b/learn/stm32/env.md new file mode 100644 index 0000000..6f450ba --- /dev/null +++ b/learn/stm32/env.md @@ -0,0 +1,9 @@ +# ENV + +``` +st-flash --format ihex write blink.hex +``` + +``` +https://github.com/texane/stlink +```