Skip to content

Commit

Permalink
#358 USART options for STM8L High Density devices
Browse files Browse the repository at this point in the history
  • Loading branch information
TG9541 committed Oct 10, 2020
1 parent 2b5173c commit 729bf88
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
36 changes: 33 additions & 3 deletions STM8L152R8/boardcore.inc
Expand Up @@ -13,11 +13,41 @@

BOARDINIT:
; Board I/O initialization
MOV CLK_PCKENR1,#0x21 ; Enable USART1[5] and TIM2[0]
MOV SYSCFG_RMPCR1,#0x10 ; Map USART1 to PA2[TX] and PA3[RX]
BSET CLK_PCKENR1,#0 ; TIM2[0]

.ifne USE_UART2
BSET CLK_PCKENR3,#3 ; USART2
BSET PE_DDR,#4 ; Setup PE4[USART2_TX] as output
BSET PE_CR1,#4 ; Setup PE4[USART2_TX] as push-pull output
.else
.ifne USE_UART3
BSET CLK_PCKENR3,#4 ; USART3
.ifne ALT_USART_STM8L
BSET SYSCFG_RMPCR3,#1 ; Map USART3 to PF0[TX] and PF1[RX]
BSET PF_DDR,#0 ; Setup PF0[USART3_TX] as output
BSET PF_CR1,#0 ; Setup PF0[USART3_TX] as push-pull output
.else
BSET PG_DDR,#1 ; Setup PG1[USART3_TX] as output
BSET PG_CR1,#1 ; Setup PG1[USART3_TX] as push-pull output
.endif
.else
BSET CLK_PCKENR1,#5 ; Enable USART1[5]
.ifeq (ALT_USART_STM8L-1)
BSET SYSCFG_RMPCR1,#4 ; Map USART1 to PA2[TX] and PA3[RX]
BSET PA_DDR,#2 ; Setup PA2[USART1_TX] as output
BSET PA_CR1,#2 ; Setup PA2[USART1_TX] as push-pull output

.else
.ifeq (ALT_USART_STM8L-2)
BSET SYSCFG_RMPCR1,#5 ; Map USART1 to PC5[TX] and PC6[RX]
BSET PC_DDR,#5 ; Setup PC5[USART1_TX] as output
BSET PC_CR1,#5 ; Setup PC5[USART1_TX] as push-pull output
.else
BSET PC_DDR,#3 ; Setup PC3[USART1_TX] as output
BSET PC_CR1,#3 ; Setup PC3[USART1_TX] as push-pull output
.endif
.endif
.endif
.endif

.ifne HAS_OUTPUTS
; Leds init
Expand Down
3 changes: 2 additions & 1 deletion STM8L152R8/globconf.inc
Expand Up @@ -2,11 +2,12 @@
; Config for STM8L152R8
; Clock: HSI (no crystal)

ALT_USART_STM8L = 1 ; Alternative STM8L USART GPIO mapping (e.g. PA3/PA2 instead of PC2/PC3)
HALF_DUPLEX = 0 ; Use UART in half duplex mode
HAS_TXUART = 1 ; No UART TXD, word TX!
HAS_RXUART = 1 ; No UART RXD, word ?RX
USE_UART2 = 0 ; Use USART2 instead of USART1 for the console
USE_UART3 = 0 ; Use USART3 instead of USART1 for the console
USE_UART3 = 1 ; Use USART3 instead of USART1 for the console
HAS_TXSIM = 0 ; Enable TxD via GPIO/TIM4, word TXGP!
HAS_RXSIM = 0 ; Enable RxD via GPIO/TIM4, word ?RXGP
PNRX = 0 ; Port GPIO# for HAS_RXDSIM
Expand Down
1 change: 1 addition & 0 deletions inc/defconf.inc
Expand Up @@ -11,6 +11,7 @@
HALF_DUPLEX = 0 ; Use the STM8S Low Density UART in half duplex mode (1: PD5, 2: PA3)
USE_UART2 = 0 ; Use the 2nd UART for the console (STM8S207: optional, STM8S105: default, STM8L152: optional)
USE_UART3 = 0 ; Use the 3rd UART for the console (STM8L152: optional)
ALT_USART_STM8L = 0 ; Alternative STM8L USART GPIO mapping (e.g. PA3/PA2 instead of PC2/PC3)
CUARTBRR = 0x6803 ; default value for UARTBRR 9600 baud (refer to mcu/UART_DIV)
HAS_RXUART = 1 ; Enable UART RXD, word ?RX
HAS_TXUART = 1 ; Enable UART TXD, word TX!
Expand Down

0 comments on commit 729bf88

Please sign in to comment.