From patchwork Thu Sep 19 13:10:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 829631 Delivered-To: patch@linaro.org Received: by 2002:adf:ebcc:0:b0:367:895a:4699 with SMTP id v12csp320426wrn; Thu, 19 Sep 2024 06:19:48 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUA162I+bDH82ZK0Oyi2lJOBeIftJNQ4btCwgMUPljvt9jJE4st6yI4cLeiDoDb/6v7TjdpMQ==@linaro.org X-Google-Smtp-Source: AGHT+IGpyqvNx9+zLzhE6iFnJ/MRIEE/xp0ffGHkNzH0ApWl3oVg5F69Fwj/atXhGamsqp7LnRZj X-Received: by 2002:a05:690c:6612:b0:6b3:a6ff:768e with SMTP id 00721157ae682-6dbcc000989mr209814187b3.0.1726751988333; Thu, 19 Sep 2024 06:19:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726751988; cv=none; d=google.com; s=arc-20240605; b=eeGVNftmxrh2g5/yEdueyKmvKO23AMw2zwPitE1ydV4CQyfiP8oY51egbM8TteKmLi fG+IqANKwMVTrZDgmBNnS2E4/Cq4BtvYuq9So3xVKPOrSDoVgWEg58wQ8DtneluOIHdg sPx8nsnBlR3L3i1osLJHCoVhj8/Th3rGBAgss3gHppWLY/gLJq0izYAvgZ747yarCQ8h xzkbSIhhpSYQZ7JFTES2AlVw5YOHNgyNnEYcpSxBujB98h3bhK2tiwyy7sEasrRpYea+ sgfOQN3xRmzouzyTyiMhYy+Ez/XDRTCuzDPBpnfuXICOw0zoQjLBoQWPg9vR/L+nCii0 bgmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=VwKnY+1IgXpvlla7/Vsb9u5qFB4I2Y8EFn85fywIH7o=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=jVlLbG4vEtfWIxB6WyiLBqgUSw8XNsjT3h8bmcGGTRE6COB1/WNvs+wkZAW6okuYiS DwrsWJA8j9h8kc46Op1vLuUXSYhIWoOPM7Iv68VwXnpPXJZWL/kfxqSH+ratW35mkIgy QibukNOnHrx5II8NrORKS1xIRaJ0ntV0MzMfCe7wVuVKSzKNfcCk1I3Gjtk6RRjU2H2t 5NHgrh/fKGEP3qbMkAj/mZw6KcdJvJ6RV0iOzSj2mlM9qqftR2TgC++qnDEz1ad6XepG ZfBnez8d26v1+Aj4kqEX4kh5ddYeQcefndlfMBggyE0MYigA5QYNwn+1CHS8xf2pKMV0 hC6w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J6oG9BIN; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7acb08c8e04si176568685a.275.2024.09.19.06.19.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Sep 2024 06:19:48 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J6oG9BIN; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1srGws-0006kj-TO; Thu, 19 Sep 2024 09:11:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1srGwV-0005NH-8v for qemu-devel@nongnu.org; Thu, 19 Sep 2024 09:11:32 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1srGwR-00014K-DT for qemu-devel@nongnu.org; Thu, 19 Sep 2024 09:11:30 -0400 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-374c180d123so519039f8f.3 for ; Thu, 19 Sep 2024 06:11:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726751485; x=1727356285; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=VwKnY+1IgXpvlla7/Vsb9u5qFB4I2Y8EFn85fywIH7o=; b=J6oG9BIN9S75Fvzra1bnZ7VORsjtVtVwNFnqG13oWDkuDjfhZGHS+d2bPF/ZQ+XnzA wm1vr2CmJk0uOiS3WmxqvCloA/gW3b/tFP1BeZ81rJH5paeoLVel7n4j37U9C2fejF9L 8uNuO+fKBbi9Cdnd+GuV43Fw2g027bAQInLM6yNLcnDwQjG4fVWGd4ynQmo9A/o9S2tn rcDb6jyvEru5nyXKU11m/qA9t4TaewjQGECpMplKQ5r4VPbwnpR5tHX/MC067dxTtEjg 6188uSlMj1JNJOf4lsEsCJUFNBBS7sOdTracXJTTS87Cs+uiWk/vFu3WdcxJejpG4t6s AcsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726751485; x=1727356285; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VwKnY+1IgXpvlla7/Vsb9u5qFB4I2Y8EFn85fywIH7o=; b=in5Nchr7QXfwy+rZFvbGyg78HibiabQfevxpHYRCz3CUrTMiaaSMP5FBZkJG7a7mcW We43Ln3G5IdiR0GfzxL43IPsZFjcHG5GQwZQkl+ZYk6Gb+5l+jX/DY/og2Cdp9/6PZQG eVqLB4gRLRQVXyroHgnsVlD3Fzd8WRJB0LeA57pP10j2iyiOqSttVLN+TQERAiiUJcmL bLi/Sqt4xCzNK1fC1Q8ziQMlXKD3+Cs2w7YbQAxRgjVbsxy+LSa/IHR0TuorxGF0UmdQ N8bK8K1SM+TD8pnFNe4d5SxvMNpFeBJWvSJIWFLYKC3KqqFoLYJWsWuZzCkztEmaIphH k7yA== X-Gm-Message-State: AOJu0YyhklA3JceKYJK1VH6k3t+7YWm/0YC/pwK0qT5hosHWYMxNVjJX O3dNVtOYoAyAsj1lvrowteR9UqS8jNW3cgML2sZU4j22LPXyX6HaVD/W1ZB3wKsa6o2fZBVSHV9 + X-Received: by 2002:a05:6000:1bca:b0:374:c847:85c with SMTP id ffacd0b85a97d-378d61e2c1fmr10713956f8f.24.1726751485348; Thu, 19 Sep 2024 06:11:25 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42e754091d3sm21667845e9.10.2024.09.19.06.11.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 06:11:25 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 30/38] hw/char/stm32l4x5_usart.c: Enable USART ACK bit response Date: Thu, 19 Sep 2024 14:10:58 +0100 Message-Id: <20240919131106.3362543-31-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240919131106.3362543-1-peter.maydell@linaro.org> References: <20240919131106.3362543-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Jacob Abrams SW modifying USART_CR1 TE bit should cuase HW to respond by altering USART_ISR TEACK bit, and likewise for RE and REACK bit. This resolves some but not all issues necessary for the official STM USART HAL driver to function as is. Fixes: 87b77e6e01ca ("hw/char/stm32l4x5_usart: Enable serial read and write") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2540 Signed-off-by: Jacob Abrams Message-id: 20240911043255.51966-1-satur9nine@gmail.com Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- hw/char/stm32l4x5_usart.c | 16 +++++++++++++ tests/qtest/stm32l4x5_usart-test.c | 36 +++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/hw/char/stm32l4x5_usart.c b/hw/char/stm32l4x5_usart.c index fc5dcac0c45..3cf200c080d 100644 --- a/hw/char/stm32l4x5_usart.c +++ b/hw/char/stm32l4x5_usart.c @@ -154,6 +154,21 @@ REG32(RDR, 0x24) REG32(TDR, 0x28) FIELD(TDR, TDR, 0, 9) +static void stm32l4x5_update_isr(Stm32l4x5UsartBaseState *s) +{ + if (s->cr1 & R_CR1_TE_MASK) { + s->isr |= R_ISR_TEACK_MASK; + } else { + s->isr &= ~R_ISR_TEACK_MASK; + } + + if (s->cr1 & R_CR1_RE_MASK) { + s->isr |= R_ISR_REACK_MASK; + } else { + s->isr &= ~R_ISR_REACK_MASK; + } +} + static void stm32l4x5_update_irq(Stm32l4x5UsartBaseState *s) { if (((s->isr & R_ISR_WUF_MASK) && (s->cr3 & R_CR3_WUFIE_MASK)) || @@ -456,6 +471,7 @@ static void stm32l4x5_usart_base_write(void *opaque, hwaddr addr, case A_CR1: s->cr1 = value; stm32l4x5_update_params(s); + stm32l4x5_update_isr(s); stm32l4x5_update_irq(s); return; case A_CR2: diff --git a/tests/qtest/stm32l4x5_usart-test.c b/tests/qtest/stm32l4x5_usart-test.c index c175ff3064f..64cebda60f0 100644 --- a/tests/qtest/stm32l4x5_usart-test.c +++ b/tests/qtest/stm32l4x5_usart-test.c @@ -36,6 +36,8 @@ REG32(GTPR, 0x10) REG32(RTOR, 0x14) REG32(RQR, 0x18) REG32(ISR, 0x1C) + FIELD(ISR, REACK, 22, 1) + FIELD(ISR, TEACK, 21, 1) FIELD(ISR, TXE, 7, 1) FIELD(ISR, RXNE, 5, 1) FIELD(ISR, ORE, 3, 1) @@ -191,7 +193,7 @@ static void init_uart(QTestState *qts) /* Enable the transmitter, the receiver and the USART. */ qtest_writel(qts, (USART1_BASE_ADDR + A_CR1), - R_CR1_UE_MASK | R_CR1_RE_MASK | R_CR1_TE_MASK); + cr1 | R_CR1_UE_MASK | R_CR1_RE_MASK | R_CR1_TE_MASK); } static void test_write_read(void) @@ -298,6 +300,37 @@ static void test_send_str(void) qtest_quit(qts); } +static void test_ack(void) +{ + uint32_t cr1; + uint32_t isr; + QTestState *qts = qtest_init("-M b-l475e-iot01a"); + + init_uart(qts); + + cr1 = qtest_readl(qts, (USART1_BASE_ADDR + A_CR1)); + + /* Disable the transmitter and receiver. */ + qtest_writel(qts, (USART1_BASE_ADDR + A_CR1), + cr1 & ~(R_CR1_RE_MASK | R_CR1_TE_MASK)); + + /* Test ISR ACK for transmitter and receiver disabled */ + isr = qtest_readl(qts, (USART1_BASE_ADDR + A_ISR)); + g_assert_false(isr & R_ISR_TEACK_MASK); + g_assert_false(isr & R_ISR_REACK_MASK); + + /* Enable the transmitter and receiver. */ + qtest_writel(qts, (USART1_BASE_ADDR + A_CR1), + cr1 | (R_CR1_RE_MASK | R_CR1_TE_MASK)); + + /* Test ISR ACK for transmitter and receiver disabled */ + isr = qtest_readl(qts, (USART1_BASE_ADDR + A_ISR)); + g_assert_true(isr & R_ISR_TEACK_MASK); + g_assert_true(isr & R_ISR_REACK_MASK); + + qtest_quit(qts); +} + int main(int argc, char **argv) { int ret; @@ -310,6 +343,7 @@ int main(int argc, char **argv) qtest_add_func("stm32l4x5/usart/send_char", test_send_char); qtest_add_func("stm32l4x5/usart/receive_str", test_receive_str); qtest_add_func("stm32l4x5/usart/send_str", test_send_str); + qtest_add_func("stm32l4x5/usart/ack", test_ack); ret = g_test_run(); return ret;