Skip to content

Commit 6b64dbc

Browse files
authored
Merge pull request #3434 from OpenNuvoton/nuvoton
[NUC472/M453] Fix stuck in lp_ticker_init and other updates
2 parents 19acef9 + 0053b70 commit 6b64dbc

File tree

22 files changed

+140
-477
lines changed

22 files changed

+140
-477
lines changed

features/FEATURE_LWIP/lwip-interface/lwip-eth/arch/TARGET_NUVOTON/TARGET_NUC472/nuc472_eth.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#define ETH_DISABLE_TX() do{EMAC->CTL &= ~EMAC_CTL_TXON;}while(0)
3434
#define ETH_DISABLE_RX() do{EMAC->CTL &= ~EMAC_CTL_RXON;}while(0)
3535

36+
3637
/*
3738
#ifdef __ICCARM__
3839
#pragma data_alignment=4
@@ -99,7 +100,7 @@ static int reset_phy(void)
99100
}
100101

101102
if(delay == 0) {
102-
printf("Reset phy failed\n");
103+
LWIP_DEBUGF(LWIP_DBG_LEVEL_SEVERE|LWIP_DBG_ON,("Reset phy failed\n"));
103104
return(-1);
104105
}
105106

@@ -120,23 +121,23 @@ static int reset_phy(void)
120121
}
121122

122123
if(delay == 0) {
123-
printf("AN failed. Set to 100 FULL\n");
124+
LWIP_DEBUGF(LWIP_DBG_LEVEL_SEVERE|LWIP_DBG_ON , ("AN failed. Set to 100 FULL\n"));
124125
EMAC->CTL |= (EMAC_CTL_OPMODE_Msk | EMAC_CTL_FUDUP_Msk);
125126
return(-1);
126127
} else {
127128
reg = mdio_read(CONFIG_PHY_ADDR, MII_LPA);
128129

129130
if(reg & ADVERTISE_100FULL) {
130-
printf("100 full\n");
131+
LWIP_DEBUGF(LWIP_DBG_LEVEL_ALL|LWIP_DBG_ON, ("100 full\n"));
131132
EMAC->CTL |= (EMAC_CTL_OPMODE_Msk | EMAC_CTL_FUDUP_Msk);
132133
} else if(reg & ADVERTISE_100HALF) {
133-
printf("100 half\n");
134+
LWIP_DEBUGF(LWIP_DBG_LEVEL_ALL|LWIP_DBG_ON, ("100 half\n"));
134135
EMAC->CTL = (EMAC->CTL & ~EMAC_CTL_FUDUP_Msk) | EMAC_CTL_OPMODE_Msk;
135136
} else if(reg & ADVERTISE_10FULL) {
136-
printf("10 full\n");
137+
LWIP_DEBUGF(LWIP_DBG_LEVEL_ALL|LWIP_DBG_ON, ("10 full\n"));
137138
EMAC->CTL = (EMAC->CTL & ~EMAC_CTL_OPMODE_Msk) | EMAC_CTL_FUDUP_Msk;
138139
} else {
139-
printf("10 half\n");
140+
LWIP_DEBUGF(LWIP_DBG_LEVEL_ALL|LWIP_DBG_ON, ("10 half\n"));
140141
EMAC->CTL &= ~(EMAC_CTL_OPMODE_Msk | EMAC_CTL_FUDUP_Msk);
141142
}
142143
}
@@ -267,7 +268,7 @@ void EMAC_RX_IRQHandler(void)
267268
EMAC->INTSTS = m_status;
268269
if (m_status & EMAC_INTSTS_RXBEIF_Msk) {
269270
// Shouldn't goes here, unless descriptor corrupted
270-
printf("RX descriptor corrupted \r\n");
271+
LWIP_DEBUGF(LWIP_DBG_LEVEL_SERIOUS|LWIP_DBG_ON, ("RX descriptor corrupted \r\n"));
271272
//return;
272273
}
273274
ack_emac_rx_isr();

features/FEATURE_LWIP/lwip-interface/lwip-eth/arch/TARGET_NUVOTON/TARGET_NUC472/nuc472_netif.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* search-and-replace for the word "ethernetif" to replace it with
4343
* something that better describes your network interface.
4444
*/
45-
45+
4646
#include "lwip/opt.h"
4747

4848
#include "lwip/def.h"
@@ -494,16 +494,15 @@ static void __phy_task(void *data) {
494494
// Compare with previous state
495495

496496
if( !(ETH_link_ok()) && (netif->flags & NETIF_FLAG_LINK_UP) ) {
497-
//tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_down, (void*) netif, 1);
497+
/* tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_down, (void*) netif, 1); */
498498
netif_set_link_down(netif);
499-
printf("Link Down\r\n");
499+
LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING|LWIP_DBG_ON, ("Link Down\r\n"));
500500
}else if ( ETH_link_ok() && !(netif->flags & NETIF_FLAG_LINK_UP) ) {
501-
//tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_up, (void*) netif, 1);
501+
/* tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_up, (void*) netif, 1); */
502502
netif_set_link_up(netif);
503-
printf("Link Up\r\n");
503+
LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING|LWIP_DBG_ON, ("Link Up\r\n"));
504504
}
505505

506-
// printf("-");
507506
osDelay(200);
508507
}
509508
}

targets/TARGET_NUVOTON/TARGET_M451/device/StdDriver/m451_can.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,9 @@ void CAN_WaitMsg(CAN_T *tCAN)
196196
}
197197

198198
if(tCAN->STATUS & CAN_STATUS_RXOK_Msk)
199+
{
199200
DEBUG_PRINTF("Rx OK\n");
200-
201+
}
201202
if(tCAN->STATUS & CAN_STATUS_LEC_Msk)
202203
{
203204
DEBUG_PRINTF("Error\n");

targets/TARGET_NUVOTON/TARGET_M451/device/StdDriver/m451_pwm.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ uint32_t PWM_ConfigCaptureChannel(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u
5555
{
5656
//clock source is from PCLK
5757
SystemCoreClockUpdate();
58-
u32PWMClockSrc = SystemCoreClock;
58+
if(pwm == PWM0)
59+
u32PWMClockSrc = CLK_GetPCLK0Freq();
60+
else//(pwm == PWM1)
61+
u32PWMClockSrc = CLK_GetPCLK1Freq();
62+
5963
}
6064

6165
u32PWMClockSrc /= 1000;
@@ -142,7 +146,11 @@ uint32_t PWM_ConfigOutputChannel2(PWM_T *pwm,
142146
{
143147
//clock source is from PCLK
144148
SystemCoreClockUpdate();
145-
u32PWMClockSrc = SystemCoreClock;
149+
if(pwm == PWM0)
150+
u32PWMClockSrc = CLK_GetPCLK0Freq();
151+
else//(pwm == PWM1)
152+
u32PWMClockSrc = CLK_GetPCLK1Freq();
153+
146154
}
147155

148156
for(u16Prescale = 1; u16Prescale < 0xFFF; u16Prescale++)//prescale could be 0~0xFFF

targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,14 @@ void lp_ticker_init(void)
9595
TIMER_EnableInt((TIMER_T *) NU_MODBASE(timer2_modinit.modname));
9696
TIMER_EnableWakeup((TIMER_T *) NU_MODBASE(timer2_modinit.modname));
9797

98-
// Schedule wakeup to match semantics of lp_ticker_get_compare_match()
99-
lp_ticker_set_interrupt(wakeup_tick);
98+
// NOTE: TIMER_Start() first and then lp_ticker_set_interrupt(); otherwise, we may get stuck in lp_ticker_read() because
99+
// timer is not running.
100100

101101
// Start timer
102102
TIMER_Start((TIMER_T *) NU_MODBASE(timer2_modinit.modname));
103+
104+
// Schedule wakeup to match semantics of lp_ticker_get_compare_match()
105+
lp_ticker_set_interrupt(wakeup_tick);
103106
}
104107

105108
timestamp_t lp_ticker_read()

targets/TARGET_NUVOTON/TARGET_M451/serial_api.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi
300300
MBED_ASSERT(uart_rts == obj->serial.uart);
301301
// Enable the pin for RTS function
302302
pinmap_pinout(rxflow, PinMap_UART_RTS);
303-
// nRTS pin output is high level active
304-
uart_base->MODEM = (uart_base->MODEM & ~UART_MODEM_RTSACTLV_Msk);
303+
// nRTS pin output is low level active
304+
uart_base->MODEM |= UART_MODEM_RTSACTLV_Msk;
305305
uart_base->FIFO = (uart_base->FIFO & ~UART_FIFO_RTSTRGLV_Msk) | UART_FIFO_RTSTRGLV_8BYTES;
306306
// Enable RTS
307307
uart_base->INTEN |= UART_INTEN_ATORTSEN_Msk;
@@ -313,8 +313,8 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi
313313
MBED_ASSERT(uart_cts == obj->serial.uart);
314314
// Enable the pin for CTS function
315315
pinmap_pinout(txflow, PinMap_UART_CTS);
316-
// nCTS pin input is high level active
317-
uart_base->MODEMSTS = (uart_base->MODEMSTS & ~UART_MODEMSTS_CTSACTLV_Msk);
316+
// nCTS pin input is low level active
317+
uart_base->MODEMSTS |= UART_MODEMSTS_CTSACTLV_Msk;
318318
// Enable CTS
319319
uart_base->INTEN |= UART_INTEN_ATOCTSEN_Msk;
320320
}
@@ -479,9 +479,6 @@ static void uart_irq(serial_t *obj)
479479
#if DEVICE_SERIAL_ASYNCH
480480
int serial_tx_asynch(serial_t *obj, const void *tx, size_t tx_length, uint8_t tx_width, uint32_t handler, uint32_t event, DMAUsage hint)
481481
{
482-
// NOTE: tx_width is deprecated. Assume its value is databits ceiled to the nearest number among 8, 16, and 32.
483-
tx_width = (obj->serial.databits <= 8) ? 8 : (obj->serial.databits <= 16) ? 16 : 32;
484-
485482
MBED_ASSERT(tx_width == 8 || tx_width == 16 || tx_width == 32);
486483

487484
obj->serial.dma_usage_tx = hint;
@@ -536,9 +533,6 @@ int serial_tx_asynch(serial_t *obj, const void *tx, size_t tx_length, uint8_t tx
536533

537534
void serial_rx_asynch(serial_t *obj, void *rx, size_t rx_length, uint8_t rx_width, uint32_t handler, uint32_t event, uint8_t char_match, DMAUsage hint)
538535
{
539-
// NOTE: rx_width is deprecated. Assume its value is databits ceiled to the nearest number among 8, 16, and 32.
540-
rx_width = (obj->serial.databits <= 8) ? 8 : (obj->serial.databits <= 16) ? 16 : 32;
541-
542536
MBED_ASSERT(rx_width == 8 || rx_width == 16 || rx_width == 32);
543537

544538
obj->serial.dma_usage_rx = hint;

targets/TARGET_NUVOTON/TARGET_NUC472/crypto/sha/sha1_alt.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ void mbedtls_sha1_clone(mbedtls_sha1_context *dst,
6666
{
6767
unsigned char output[20];
6868
crypto_sha_getinternstate(output, sizeof (output));
69-
dst->sw_ctx.state[0] = nu_get32_be(output);
70-
dst->sw_ctx.state[1] = nu_get32_be(output + 4);
71-
dst->sw_ctx.state[2] = nu_get32_be(output + 8);
72-
dst->sw_ctx.state[3] = nu_get32_be(output + 12);
73-
dst->sw_ctx.state[4] = nu_get32_be(output + 16);
69+
unsigned char *output_pos = output;
70+
unsigned char *output_end = output + (sizeof (output) / sizeof (output[0]));
71+
uint32_t *state_pos = (uint32_t *) &(dst->sw_ctx.state[0]);
72+
while (output_pos != output_end) {
73+
*state_pos ++ = nu_get32_be(output_pos);
74+
output_pos += 4;
75+
}
7476
}
7577
memcpy(dst->sw_ctx.buffer, src->hw_ctx.buffer, src->hw_ctx.buffer_left);
7678
if (src->hw_ctx.buffer_left == src->hw_ctx.blocksize) {

targets/TARGET_NUVOTON/TARGET_NUC472/crypto/sha/sha1_alt.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#if defined(MBEDTLS_SHA1_C)
2626
#if defined(MBEDTLS_SHA1_ALT)
2727

28-
#include "sha1.h"
2928
#include "sha_alt_hw.h"
3029
#include "sha1_alt_sw.h"
3130

targets/TARGET_NUVOTON/TARGET_NUC472/crypto/sha/sha1_alt_sw.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@
3636
#include "mbedtls/sha1.h"
3737

3838
#include <string.h>
39+
#if defined(MBEDTLS_SELF_TEST)
40+
#if defined(MBEDTLS_PLATFORM_C)
41+
#include "mbedtls/platform.h"
42+
#else
43+
#include <stdio.h>
44+
#define mbedtls_printf printf
45+
#endif /* MBEDTLS_PLATFORM_C */
46+
#endif /* MBEDTLS_SELF_TEST */
3947

4048
/* Implementation that should never be optimized out by the compiler */
4149
static void mbedtls_zeroize( void *v, size_t n ) {

targets/TARGET_NUVOTON/TARGET_NUC472/crypto/sha/sha256_alt.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,13 @@ void mbedtls_sha256_clone(mbedtls_sha256_context *dst,
6666
{
6767
unsigned char output[32];
6868
crypto_sha_getinternstate(output, sizeof (output));
69-
dst->sw_ctx.state[0] = nu_get32_be(output);
70-
dst->sw_ctx.state[1] = nu_get32_be(output + 4);
71-
dst->sw_ctx.state[2] = nu_get32_be(output + 8);
72-
dst->sw_ctx.state[3] = nu_get32_be(output + 12);
73-
dst->sw_ctx.state[4] = nu_get32_be(output + 16);
74-
dst->sw_ctx.state[5] = nu_get32_be(output + 20);
75-
dst->sw_ctx.state[6] = nu_get32_be(output + 24);
76-
dst->sw_ctx.state[7] = nu_get32_be(output + 28);
69+
unsigned char *output_pos = output;
70+
unsigned char *output_end = output + (sizeof (output) / sizeof (output[0]));
71+
uint32_t *state_pos = (uint32_t *) &(dst->sw_ctx.state[0]);
72+
while (output_pos != output_end) {
73+
*state_pos ++ = nu_get32_be(output_pos);
74+
output_pos += 4;
75+
}
7776
}
7877
memcpy(dst->sw_ctx.buffer, src->hw_ctx.buffer, src->hw_ctx.buffer_left);
7978
dst->sw_ctx.is224 = src->hw_ctx.is224;

targets/TARGET_NUVOTON/TARGET_NUC472/crypto/sha/sha256_alt.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222
#include MBEDTLS_CONFIG_FILE
2323
#endif
2424

25-
#if defined(MBEDTLS_SHA1_C)
25+
#if defined(MBEDTLS_SHA256_C)
2626
#if defined(MBEDTLS_SHA256_ALT)
2727

28-
#include "sha256.h"
2928
#include "sha_alt_hw.h"
3029
#include "sha256_alt_sw.h"
3130

@@ -103,6 +102,6 @@ void mbedtls_sha256_process( mbedtls_sha256_context *ctx, const unsigned char da
103102
#endif
104103

105104
#endif /* MBEDTLS_SHA256_ALT */
106-
#endif /* MBEDTLS_SHA1_C */
105+
#endif /* MBEDTLS_SHA256_C */
107106

108107
#endif /* sha256_alt.h */

targets/TARGET_NUVOTON/TARGET_NUC472/crypto/sha/sha256_alt_sw.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@
3636
#include "mbedtls/sha256.h"
3737

3838
#include <string.h>
39+
#if defined(MBEDTLS_SELF_TEST)
40+
#if defined(MBEDTLS_PLATFORM_C)
41+
#include "mbedtls/platform.h"
42+
#else
43+
#include <stdio.h>
44+
#include <stdlib.h>
45+
#define mbedtls_printf printf
46+
#define mbedtls_calloc calloc
47+
#define mbedtls_free free
48+
#endif /* MBEDTLS_PLATFORM_C */
49+
#endif /* MBEDTLS_SELF_TEST */
3950

4051
/* Implementation that should never be optimized out by the compiler */
4152
static void mbedtls_zeroize( void *v, size_t n ) {
@@ -303,6 +314,6 @@ void mbedtls_sha256_sw_finish( mbedtls_sha256_sw_context *ctx, unsigned char out
303314
PUT_UINT32_BE( ctx->state[7], output, 28 );
304315
}
305316

306-
#endif /* MBEDTLS_SHA1_ALT */
317+
#endif /* MBEDTLS_SHA256_ALT */
307318

308319
#endif /* MBEDTLS_SHA256_C */

targets/TARGET_NUVOTON/TARGET_NUC472/device/NUC472_442.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32574,7 +32574,7 @@ typedef volatile unsigned long vu32; ///< Define 32-bit unsigned volatile
3257432574
#include "nuc472_acmp.h"
3257532575
#include "nuc472_adc.h"
3257632576
#include "nuc472_eadc.h"
32577-
#include "nuc472_cap.h"
32577+
/* Disable Capture: #include "nuc472_cap.h" */
3257832578
#include "nuc472_crypto.h"
3257932579
#include "nuc472_pdma.h"
3258032580
#include "nuc472_ebi.h"

targets/TARGET_NUVOTON/TARGET_NUC472/device/StdDriver/nuc472_can.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ void CAN_WaitMsg(CAN_T *tCAN)
9999
DEBUG_PRINTF("New Data IN\n");
100100
break;
101101
}
102-
if(tCAN->STATUS & CAN_STATUS_RXOK_Msk)
102+
if(tCAN->STATUS & CAN_STATUS_RXOK_Msk) {
103103
DEBUG_PRINTF("Rx OK\n");
104-
104+
}
105105
if(tCAN->STATUS & CAN_STATUS_LEC_Msk) {
106106
DEBUG_PRINTF("Error\n");
107107
}

0 commit comments

Comments
 (0)