Skip to content

Commit 7e29212

Browse files
committed
Update ADC v1/2, USART v2, SDIO LLD drivers.
1 parent 21e3235 commit 7e29212

File tree

5 files changed

+34
-40
lines changed

5 files changed

+34
-40
lines changed

os/hal/ports/AT32/LLD/ADCv1/hal_adc_lld.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3-
ChibiOS - Copyright (C) 2023..2025 HorrorTroll
4-
ChibiOS - Copyright (C) 2023..2025 Zhaqian
3+
ChibiOS - Copyright (C) 2023..2026 HorrorTroll
4+
ChibiOS - Copyright (C) 2023..2026 Zhaqian
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.
@@ -265,6 +265,7 @@ void adc_lld_start_conversion(ADCDriver *adcp) {
265265
is enabled in order to allow streaming processing.*/
266266
mode |= AT32_DMA_CCTRL_HDTIEN;
267267
}
268+
ctrl2 = 0U;
268269
}
269270
dmaStreamSetMemory0(adcp->dmastp, adcp->samples);
270271
dmaStreamSetTransactionSize(adcp->dmastp, (uint32_t)grpp->num_channels *
@@ -286,10 +287,12 @@ void adc_lld_start_conversion(ADCDriver *adcp) {
286287
adcp->adc->CTRL1 = grpp->ctrl1 | ADC_CTRL1_SQEN;
287288

288289
/* Enforcing the mandatory bits in CTRL2.*/
289-
ctrl2 = grpp->ctrl2 | ADC_CTRL2_OCDMAEN | ADC_CTRL2_ADCEN;
290+
ctrl2 |= grpp->ctrl2 | ADC_CTRL2_OCDMAEN | ADC_CTRL2_ADCEN;
290291

291-
if ((ctrl2 & (ADC_CTRL2_OCTEN | ADC_CTRL2_PCTEN)) == 0)
292+
if ((ctrl2 & (ADC_CTRL2_OCTEN | ADC_CTRL2_PCTEN)) == 0) {
292293
ctrl2 |= ADC_CTRL2_RPEN;
294+
}
295+
293296
adcp->adc->CTRL2 = grpp->ctrl2 | ctrl2;
294297

295298
/* ADC start by writing ADC_CTRL2_ADCEN a second time.*/

os/hal/ports/AT32/LLD/ADCv2/hal_adc_lld.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
22
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3-
ChibiOS - Copyright (C) 2023..2025 HorrorTroll
4-
ChibiOS - Copyright (C) 2023..2025 Zhaqian
5-
ChibiOS - Copyright (C) 2024..2025 Maxjta
3+
ChibiOS - Copyright (C) 2023..2026 HorrorTroll
4+
ChibiOS - Copyright (C) 2023..2026 Zhaqian
5+
ChibiOS - Copyright (C) 2024..2026 Maxjta
66
77
Licensed under the Apache License, Version 2.0 (the "License");
88
you may not use this file except in compliance with the License.
@@ -273,6 +273,7 @@ void adc_lld_start_conversion(ADCDriver *adcp) {
273273
is enabled in order to allow streaming processing.*/
274274
mode |= AT32_DMA_CCTRL_HDTIEN;
275275
}
276+
ctrl2 = 0U;
276277
}
277278
dmaStreamSetMemory0(adcp->dmastp, adcp->samples);
278279
dmaStreamSetTransactionSize(adcp->dmastp, (uint32_t)grpp->num_channels *
@@ -294,10 +295,12 @@ void adc_lld_start_conversion(ADCDriver *adcp) {
294295
adcp->adc->CTRL1 = grpp->ctrl1 | ADC_CTRL1_SQEN;
295296

296297
/* Enforcing the mandatory bits in CTRL2.*/
297-
ctrl2 = grpp->ctrl2 | ADC_CTRL2_OCDMAEN | ADC_CTRL2_ADCEN;
298+
ctrl2 |= grpp->ctrl2 | ADC_CTRL2_OCDMAEN | ADC_CTRL2_ADCEN;
298299

299-
if ((ctrl2 & (ADC_CTRL2_OCTEN | ADC_CTRL2_PCTEN)) == 0)
300+
if ((ctrl2 & (ADC_CTRL2_OCTEN | ADC_CTRL2_PCTEN)) == 0) {
300301
ctrl2 |= ADC_CTRL2_RPEN;
302+
}
303+
301304
adcp->adc->CTRL2 = grpp->ctrl2 | ctrl2;
302305

303306
/* ADC start by writing ADC_CTRL2_ADCEN a second time.*/

os/hal/ports/AT32/LLD/SDIOv1/hal_sdc_lld.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3-
ChibiOS - Copyright (C) 2023..2025 HorrorTroll
4-
ChibiOS - Copyright (C) 2023..2025 Zhaqian
3+
ChibiOS - Copyright (C) 2023..2026 HorrorTroll
4+
ChibiOS - Copyright (C) 2023..2026 Zhaqian
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.
@@ -278,22 +278,22 @@ static bool sdc_lld_wait_transaction_end(SDCDriver *sdcp, uint32_t n,
278278
osalThreadSuspendS(&sdcp->thread);
279279
}
280280

281-
/* Stopping operations, waiting for transfer completion at DMA level, then
282-
the stream is disabled and cleared.*/
283-
dmaWaitCompletion(sdcp->dma);
284-
sdcp->sdio->INTEN = 0U;
285-
sdcp->sdio->DTCTRL = 0U;
281+
/* Mask has now been set to zero by interrupt handler. */
282+
osalSysUnlock();
286283

284+
/* Data transfer not complete, let error cleanup stop DMA.*/
287285
if ((sdcp->sdio->STS & SDIO_STS_DTCMPL) == 0) {
288-
osalSysUnlock();
289286
return HAL_FAILED;
290287
}
291288

289+
/* Waiting for transfer completion at DMA level, then the stream is disabled
290+
and cleared.*/
291+
dmaWaitCompletion(sdcp->dma);
292+
sdcp->sdio->DTCTRL = 0U;
293+
292294
/* Clearing status.*/
293295
sdcp->sdio->INTCLR = SDIO_INTCLR_ALL_FLAGS;
294296

295-
osalSysUnlock();
296-
297297
/* Finalize transaction.*/
298298
if (n > 1U)
299299
return sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_STOP_TRANSMISSION, 0, resp);
@@ -766,16 +766,16 @@ bool sdc_lld_read_aligned(SDCDriver *sdcp, uint32_t startblk,
766766
SDIO_INTEN_DTCMPLIEN;
767767
sdcp->sdio->DTLEN = blocks * MMCSD_BLOCK_SIZE;
768768

769+
if (sdc_lld_prepare_read(sdcp, startblk, blocks, resp) == true)
770+
goto error;
771+
769772
/* Transaction starts just after TFREN bit setting.*/
770773
sdcp->sdio->DTCTRL = SDIO_DTCTRL_TFRDIR |
771774
SDIO_DTCTRL_BLKSIZE_3 |
772775
SDIO_DTCTRL_BLKSIZE_0 |
773776
SDIO_DTCTRL_DMAEN |
774777
SDIO_DTCTRL_TFREN;
775778

776-
if (sdc_lld_prepare_read(sdcp, startblk, blocks, resp) == true)
777-
goto error;
778-
779779
if (sdc_lld_wait_transaction_end(sdcp, blocks, resp) == true)
780780
goto error;
781781

os/hal/ports/AT32/LLD/SDIOv1/hal_sdc_lld.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3-
ChibiOS - Copyright (C) 2023..2025 HorrorTroll
4-
ChibiOS - Copyright (C) 2023..2025 Zhaqian
3+
ChibiOS - Copyright (C) 2023..2026 HorrorTroll
4+
ChibiOS - Copyright (C) 2023..2026 Zhaqian
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.
@@ -123,18 +123,6 @@
123123
#define AT32_DMA_REQUIRED
124124
#endif
125125

126-
/*
127-
* SDIO clock divider.
128-
*/
129-
#if AT32_HCLK > 48000000
130-
#define AT32_SDIO_DIV_HS 1
131-
#define AT32_SDIO_DIV_LS 178
132-
#else
133-
134-
#define AT32_SDIO_DIV_HS 0
135-
#define AT32_SDIO_DIV_LS 118
136-
#endif
137-
138126
/*===========================================================================*/
139127
/* Driver data structures and types. */
140128
/*===========================================================================*/

os/hal/ports/AT32/LLD/USARTv2/hal_sio_lld.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3-
ChibiOS - Copyright (C) 2023..2025 HorrorTroll
4-
ChibiOS - Copyright (C) 2023..2025 Zhaqian
3+
ChibiOS - Copyright (C) 2023..2026 HorrorTroll
4+
ChibiOS - Copyright (C) 2023..2026 Zhaqian
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.
@@ -553,7 +553,7 @@ sioevents_t sio_lld_get_events(SIODriver *siop) {
553553
* @param[in] buffer pointer to the buffer for read frames
554554
* @param[in] n maximum number of frames to be read
555555
* @return The number of frames copied from the buffer.
556-
* @retval 0 if the TX FIFO is full.
556+
* @retval 0 if the RX FIFO is empty.
557557
*/
558558
size_t sio_lld_read(SIODriver *siop, uint8_t *buffer, size_t n) {
559559
size_t rd;
@@ -732,7 +732,7 @@ void sio_lld_serve_interrupt(SIODriver *siop) {
732732
/* If there are no errors then we check for the other RX-related
733733
status flags.*/
734734
else {
735-
/* Idle RX flag.*/
735+
/* Idle RX flag. Note: At start the USART will produce an IDLEF interrupt.*/
736736
if ((sts & USART_STS_IDLEF) != 0U) {
737737

738738
/* Interrupt source disabled.*/

0 commit comments

Comments
 (0)