关于 STM32 UART4 的一些小问题

为什么80%的码农都做不了架构师?>>>   hot3.png

不知为什么,STM32的中、小容量启动文件中没有发现UART4,UART5的中断处理函数,也就是在HD以下的版本中是没有UART4、UART5中断的喽?但查了下,中等容量的STM32F103RCT6是有UART4、UART5的,并且支持部份中断,以下摘自库函数(@version  V3.5.0)说明:

/**
  * @brief  Enables or disables the specified USART interrupts.
  * @param  USARTx: Select the USART or the UART peripheral.
  *   This parameter can be one of the following values:
  *   USART1, USART2, USART3, UART4 or UART5.
  * @param  USART_IT: specifies the USART interrupt sources to be enabled or disabled.
  *   This parameter can be one of the following values:
  *     @arg  USART_IT_CTS:  CTS change interrupt (not available for UART4 and UART5)
  *     @arg USART_IT_LBD:  LIN Break detection interrupt
  *     @arg USART_IT_TXE:  Tansmit Data Register empty interrupt
  *     @arg USART_IT_TC:   Transmission complete interrupt
  *     @arg USART_IT_RXNE: Receive Data register not empty interrupt
  *     @arg USART_IT_IDLE: Idle line detection interrupt
  *     @arg USART_IT_PE:   Parity Error interrupt
  *     @arg USART_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)
  * @param  NewState: new state of the specified USARTx interrupts.
  *   This parameter can be: ENABLE or DISABLE.
  * @retval None
  */

很明显,UART4、UART5是具备产生中断的能力的。那么为何没有相应的中断呢?此点暂不得而知。解决办法也是有的,最简单采用startup_stm32f10x_hd.s即可,不过涉及到内存分配,此处不予讨论。也可在对就容量的启动文件中添加代码:

IMPORT  UART4_IRQHandler
IMPORT  UART5_IRQHandler

DCD  UART4_IRQHandler
DCD  UART5_IRQHandler

自此算是基本解决了。

----------------------------------------------------------------------------------------------------------------------

感谢@mcloud ,此处有一个重大的问题我一直没有注意到!那就是对于STM32启动文件的理解。以下贴上STM32启动文件的相关内容:

小容量产品是指闪存存储器容量在16K至32K字节之间的STM32F101xx、STM32F102xx和STM32F103xx微控制器。

中容量产品是指闪存存储器容量在64K至128K字节之间的STM32F101xx、STM32F102xx和STM32F103xx微控制器。

大容量产品是指闪存存储器容量在256K至512K字节之间的STM32F101xx和STM32F103xx微控制器。

互联型产品是指STM32F105xx和STM32F107xx微控制器。

 

- startup_stm32f10x_ld_vl.s: for STM32 Low density Value line devices 
- startup_stm32f10x_ld.s: for STM32 Low density devices 
- startup_stm32f10x_md_vl.s: for STM32 Medium density Value line devices 
- startup_stm32f10x_md.s: for STM32 Medium density devices 
- startup_stm32f10x_hd.s: for STM32 High density devices 
- startup_stm32f10x_xl.s: for STM32 XL density devices 
- startup_stm32f10x_cl.s: for STM32 Connectivity line devices 

cl:互联型产品,stm32f105/107系列 
vl:超值型产品,stm32f100系列 
xl:超高密度产品,stm32f101/103系列
ld:低密度产品,FLASH小于64K 
md:中等密度产品,FLASH=64 or 128 
hd:高密度产品,FLASH大于128

 

● Low-density devices: STM32F101xx, STM32F102xx and STM32F103xx
  microcontrollers where the Flash memory density ranges between 16 and 32 Kbytes.
● Medium-density devices: STM32F101xx, STM32F102xx and STM32F103xx
  microcontrollers where the Flash memory density ranges between 64 and 128 Kbytes.
● High-density devices: STM32F101xx and STM32F103xx microcontrollers where the
  Flash memory density ranges between 256 and 512 Kbytes.
● XL-density devices: STM32F101xx and STM32F103xx microcontrollers where the
  Flash memory density ranges between 512 and 1024 Kbytes.
● Medium-density Low-Power devices: STM32L15xx microcontrollers where the Flash
  memory density ranges between 64 and 128 Kbytes.
● Low Power Medium-density Plus devices:STM32L15xx and STM32L162xx
  microcontrollers where the Flash memory density is 256 Kbytes.
● Low Power High-density devices: STM32L15xx and STM32L162xx microcontrollers
  where the Flash memory density is 384 Kbytes.

那么问题来了,我之所以会有如题的疑惑,乃是因为用着STM32F103RCT6这款芯片,却用的是startup_stm32f10x_md.s的启动文件,那自然是没UART4、UART5的。而STM32F103RCT6实则是256K内存,属于 hd:高密度产品,FLASH大于128 。难怪在看芯片文档时,该芯片是有UART4、UART5的。

转载于:https://my.oschina.net/truel/blog/368156

你可能感兴趣的:(关于 STM32 UART4 的一些小问题)