Reputation: 115
I am trying to configure stm32g030 (SOP8) to using UART.
Below you can see the assembly code I have written until now.
Added LED is blinking, so the loop is working.
GDB shows correct values in registers.
But logic analyzer shows nothing, no data at all.
Pin is always HIGH.
@ Registers values
RCC_IOPENR = 0x00000003 @ GPIOA(UART) and GPIOB(LED)
RCC_APBENR2 = 0x00004000
GPIOA_AFRH = 0x00000010
GPIOA_MODER = 0xebfbffff
USART_BRR = 0x00000683
USART_CR1 = 0x00000009
USART_CR2 = 0x00000000
USART_CR3 = 0x00000000
USART_ISR = 0x002000c0
@ 30 seconds from logic analyzer
Chanel1 - blinking LED
Stm32 TX - should be row of 'A'
What am I doing wrong? Any help please!
.syntax unified
.cpu cortex-m0plus
.thumb
.word _StackEnd @ 0x20000100
.word Reset_Handler @ 0x00000004
.space 0xb4
.equ RCC, (0x40021000)
.equ RCC_IOPENR, (RCC + (0x34))
.equ RCC_APBENR2, (RCC + (0x40))
.equ SYSCFG, (0x40010000)
.equ SYSCFG_CFGR1, (SYSCFG + (0x00))
.equ GPIOB, (0x50000400)
.equ GPIOB_MODER, (GPIOB + (0x00))
.equ GPIOB_BSRR, (GPIOB + (0x18))
.equ GPIOA, (0x50000000)
.equ GPIOA_MODER, (GPIOA + (0x00))
.equ GPIOA_AFRH, (GPIOA + (0x24))
.equ USART1, (0x40013800)
.equ USART_CR1, (USART1 + (0x00))
.equ USART_CR2, (USART1 + (0x04))
.equ USART_CR3, (USART1 + (0x08))
.equ USART_BRR, (USART1 + (0x0c))
.equ USART_TDR, (USART1 + (0x28))
.equ USART_ISR, (USART1 + (0x1c))
@ UART config
.text
.type Reset_Handler, %function
Reset_Handler:
ldr r0, =RCC_IOPENR @ (0x40021034)
ldr r2, [r0]
movs r3, #0x1 @ 0x1 for GPIOA (UART1)
orrs r2, r2, r3
str r2, [r0]
ldr r0, =RCC_APBENR2 @ (0x40021040) UART clock enable
ldr r2, [r0]
ldr r3, =#0x4001 @
orrs r2, r2, r3
str r2, [r0]
ldr r0, =SYSCFG_CFGR1 @ (0x40010000)
ldr r2, [r0]
movs r3, #0x8
orrs r2, r2, r3
str r2, [r0]
ldr r0, =GPIOA_AFRH @ (0x50000024)
ldr r2, [r0]
ldr r3, =#0x10 @ define alternate AF1 for PA9 0x10
orrs r2, r2, r3
str r2, [r0]
ldr r0, =GPIOA_MODER @ (0x50000000)
ldr r2, [r0]
ldr r3, =#0xfffbffff @ turn on alternate for PA9
ands r2, r2, r3
str r2, [r0]
ldr r0, =USART_CR1 @ (0x40013800),
movs r3, #0x0 @
str r3, [r0]
ldr r0, =USART_BRR @ (0x4001380c)
ldr r3, =#0x683 @ 16Mhz and 9600
str r3, [r0]
ldr r0, =USART_CR2 @ (0x40013804),
movs r3, #0x0 @
str r3, [r0]
ldr r0, =USART_CR3 @ (0x40013808),
movs r3, #0x0 @
str r3, [r0]
ldr r0, =USART_CR1 @ (0x40013800),
ldr r2, [r0]
movs r3, #0x1 @ usart enabled
orrs r2, r2, r3
str r2, [r0]
ldr r0, =USART_CR1 @ (0x40013800)
ldr r2, [r0]
movs r3, #0x8 @ transmiter enabled
orrs r2, r2, r3
str r2, [r0]
teack_check:
ldr r0, =USART_ISR @ (0x4001381c)
ldr r2, [r0]
ldr r3, =#0x200000 @ waiting for TEACK
tst r2, r3
beq teack_check
@ END of UART config
@ GPIOB for LED
ldr r0, =RCC_IOPENR @ (0x40021034)
ldr r2, [r0]
movs r3, #0x2 @ 0x2 for GPIOB (LED)
orrs r2, r2, r3
str r2, [r0]
ldr r1, =GPIOB_MODER @ (0x50000400)
ldr r4, [r1]
ldr r6, =#0xffff7fff @ 0xffff7fff for PB7
ands r4, r4, r6
str r4, [r1]
blink_loop:
txe_check:
ldr r1, =USART_ISR @ (0x4001381c)
ldr r2, [r1]
ldr r3, =#0x80
tst r2, r3
beq txe_check
ldr r1, =USART_TDR @ (0x40013828)
movs r3, #0x41
uxtb r4, r3
str r4, [r1]
tc_check:
ldr r1, =USART_ISR @ (0x4001381c)
ldr r2, [r1]
ldr r3, =#0x40
tst r2, r3
beq tc_check
ldr r0, =GPIOB_BSRR @ 0x50000418
ldr r1, =#0x80 @ LED turn on
str r1, [r0]
ldr r2, =#10000000
wait_1:
subs r2, #1
bne wait_1
ldr r1, =#0x800000 @ LED turn off
str r1, [r0]
ldr r2, =#10000000
wait_2:
subs r2, #1
bne wait_2
b blink_loop
Upvotes: 0
Views: 261
Reputation: 1213
Pin 5 is PA11 by default; for PA9 you have to set SYSCFG_CFGR1.PA11_RMP.
Btw. don't forget to enable SYSCFG clock in RCC.
Upvotes: 1