Skip to content

[NUC472/M453] Fix stuck in lp_ticker_init and other updates #3434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#define ETH_DISABLE_TX() do{EMAC->CTL &= ~EMAC_CTL_TXON;}while(0)
#define ETH_DISABLE_RX() do{EMAC->CTL &= ~EMAC_CTL_RXON;}while(0)


/*
#ifdef __ICCARM__
#pragma data_alignment=4
Expand Down Expand Up @@ -99,7 +100,7 @@ static int reset_phy(void)
}

if(delay == 0) {
printf("Reset phy failed\n");
LWIP_DEBUGF(LWIP_DBG_LEVEL_SEVERE|LWIP_DBG_ON,("Reset phy failed\n"));
return(-1);
}

Expand All @@ -120,23 +121,23 @@ static int reset_phy(void)
}

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

if(reg & ADVERTISE_100FULL) {
printf("100 full\n");
LWIP_DEBUGF(LWIP_DBG_LEVEL_ALL|LWIP_DBG_ON, ("100 full\n"));
EMAC->CTL |= (EMAC_CTL_OPMODE_Msk | EMAC_CTL_FUDUP_Msk);
} else if(reg & ADVERTISE_100HALF) {
printf("100 half\n");
LWIP_DEBUGF(LWIP_DBG_LEVEL_ALL|LWIP_DBG_ON, ("100 half\n"));
EMAC->CTL = (EMAC->CTL & ~EMAC_CTL_FUDUP_Msk) | EMAC_CTL_OPMODE_Msk;
} else if(reg & ADVERTISE_10FULL) {
printf("10 full\n");
LWIP_DEBUGF(LWIP_DBG_LEVEL_ALL|LWIP_DBG_ON, ("10 full\n"));
EMAC->CTL = (EMAC->CTL & ~EMAC_CTL_OPMODE_Msk) | EMAC_CTL_FUDUP_Msk;
} else {
printf("10 half\n");
LWIP_DEBUGF(LWIP_DBG_LEVEL_ALL|LWIP_DBG_ON, ("10 half\n"));
EMAC->CTL &= ~(EMAC_CTL_OPMODE_Msk | EMAC_CTL_FUDUP_Msk);
}
}
Expand Down Expand Up @@ -267,7 +268,7 @@ void EMAC_RX_IRQHandler(void)
EMAC->INTSTS = m_status;
if (m_status & EMAC_INTSTS_RXBEIF_Msk) {
// Shouldn't goes here, unless descriptor corrupted
printf("RX descriptor corrupted \r\n");
LWIP_DEBUGF(LWIP_DBG_LEVEL_SERIOUS|LWIP_DBG_ON, ("RX descriptor corrupted \r\n"));
//return;
}
ack_emac_rx_isr();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* search-and-replace for the word "ethernetif" to replace it with
* something that better describes your network interface.
*/

#include "lwip/opt.h"

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

if( !(ETH_link_ok()) && (netif->flags & NETIF_FLAG_LINK_UP) ) {
//tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_down, (void*) netif, 1);
/* tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_down, (void*) netif, 1); */
netif_set_link_down(netif);
printf("Link Down\r\n");
LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING|LWIP_DBG_ON, ("Link Down\r\n"));
}else if ( ETH_link_ok() && !(netif->flags & NETIF_FLAG_LINK_UP) ) {
//tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_up, (void*) netif, 1);
/* tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_up, (void*) netif, 1); */
netif_set_link_up(netif);
printf("Link Up\r\n");
LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING|LWIP_DBG_ON, ("Link Up\r\n"));
}

// printf("-");
osDelay(200);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,9 @@ void CAN_WaitMsg(CAN_T *tCAN)
}

if(tCAN->STATUS & CAN_STATUS_RXOK_Msk)
{
DEBUG_PRINTF("Rx OK\n");

}
if(tCAN->STATUS & CAN_STATUS_LEC_Msk)
{
DEBUG_PRINTF("Error\n");
Expand Down
12 changes: 10 additions & 2 deletions targets/TARGET_NUVOTON/TARGET_M451/device/StdDriver/m451_pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ uint32_t PWM_ConfigCaptureChannel(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u
{
//clock source is from PCLK
SystemCoreClockUpdate();
u32PWMClockSrc = SystemCoreClock;
if(pwm == PWM0)
u32PWMClockSrc = CLK_GetPCLK0Freq();
else//(pwm == PWM1)
u32PWMClockSrc = CLK_GetPCLK1Freq();

}

u32PWMClockSrc /= 1000;
Expand Down Expand Up @@ -142,7 +146,11 @@ uint32_t PWM_ConfigOutputChannel2(PWM_T *pwm,
{
//clock source is from PCLK
SystemCoreClockUpdate();
u32PWMClockSrc = SystemCoreClock;
if(pwm == PWM0)
u32PWMClockSrc = CLK_GetPCLK0Freq();
else//(pwm == PWM1)
u32PWMClockSrc = CLK_GetPCLK1Freq();

}

for(u16Prescale = 1; u16Prescale < 0xFFF; u16Prescale++)//prescale could be 0~0xFFF
Expand Down
7 changes: 5 additions & 2 deletions targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,14 @@ void lp_ticker_init(void)
TIMER_EnableInt((TIMER_T *) NU_MODBASE(timer2_modinit.modname));
TIMER_EnableWakeup((TIMER_T *) NU_MODBASE(timer2_modinit.modname));

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

// Start timer
TIMER_Start((TIMER_T *) NU_MODBASE(timer2_modinit.modname));

// Schedule wakeup to match semantics of lp_ticker_get_compare_match()
lp_ticker_set_interrupt(wakeup_tick);
}

timestamp_t lp_ticker_read()
Expand Down
14 changes: 4 additions & 10 deletions targets/TARGET_NUVOTON/TARGET_M451/serial_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi
MBED_ASSERT(uart_rts == obj->serial.uart);
// Enable the pin for RTS function
pinmap_pinout(rxflow, PinMap_UART_RTS);
// nRTS pin output is high level active
uart_base->MODEM = (uart_base->MODEM & ~UART_MODEM_RTSACTLV_Msk);
// nRTS pin output is low level active
uart_base->MODEM |= UART_MODEM_RTSACTLV_Msk;
uart_base->FIFO = (uart_base->FIFO & ~UART_FIFO_RTSTRGLV_Msk) | UART_FIFO_RTSTRGLV_8BYTES;
// Enable RTS
uart_base->INTEN |= UART_INTEN_ATORTSEN_Msk;
Expand All @@ -313,8 +313,8 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi
MBED_ASSERT(uart_cts == obj->serial.uart);
// Enable the pin for CTS function
pinmap_pinout(txflow, PinMap_UART_CTS);
// nCTS pin input is high level active
uart_base->MODEMSTS = (uart_base->MODEMSTS & ~UART_MODEMSTS_CTSACTLV_Msk);
// nCTS pin input is low level active
uart_base->MODEMSTS |= UART_MODEMSTS_CTSACTLV_Msk;
// Enable CTS
uart_base->INTEN |= UART_INTEN_ATOCTSEN_Msk;
}
Expand Down Expand Up @@ -479,9 +479,6 @@ static void uart_irq(serial_t *obj)
#if DEVICE_SERIAL_ASYNCH
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)
{
// NOTE: tx_width is deprecated. Assume its value is databits ceiled to the nearest number among 8, 16, and 32.
tx_width = (obj->serial.databits <= 8) ? 8 : (obj->serial.databits <= 16) ? 16 : 32;

MBED_ASSERT(tx_width == 8 || tx_width == 16 || tx_width == 32);

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

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)
{
// NOTE: rx_width is deprecated. Assume its value is databits ceiled to the nearest number among 8, 16, and 32.
rx_width = (obj->serial.databits <= 8) ? 8 : (obj->serial.databits <= 16) ? 16 : 32;

MBED_ASSERT(rx_width == 8 || rx_width == 16 || rx_width == 32);

obj->serial.dma_usage_rx = hint;
Expand Down
12 changes: 7 additions & 5 deletions targets/TARGET_NUVOTON/TARGET_NUC472/crypto/sha/sha1_alt.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ void mbedtls_sha1_clone(mbedtls_sha1_context *dst,
{
unsigned char output[20];
crypto_sha_getinternstate(output, sizeof (output));
dst->sw_ctx.state[0] = nu_get32_be(output);
dst->sw_ctx.state[1] = nu_get32_be(output + 4);
dst->sw_ctx.state[2] = nu_get32_be(output + 8);
dst->sw_ctx.state[3] = nu_get32_be(output + 12);
dst->sw_ctx.state[4] = nu_get32_be(output + 16);
unsigned char *output_pos = output;
unsigned char *output_end = output + (sizeof (output) / sizeof (output[0]));
uint32_t *state_pos = (uint32_t *) &(dst->sw_ctx.state[0]);
while (output_pos != output_end) {
*state_pos ++ = nu_get32_be(output_pos);
output_pos += 4;
}
}
memcpy(dst->sw_ctx.buffer, src->hw_ctx.buffer, src->hw_ctx.buffer_left);
if (src->hw_ctx.buffer_left == src->hw_ctx.blocksize) {
Expand Down
1 change: 0 additions & 1 deletion targets/TARGET_NUVOTON/TARGET_NUC472/crypto/sha/sha1_alt.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#if defined(MBEDTLS_SHA1_C)
#if defined(MBEDTLS_SHA1_ALT)

#include "sha1.h"
#include "sha_alt_hw.h"
#include "sha1_alt_sw.h"

Expand Down
8 changes: 8 additions & 0 deletions targets/TARGET_NUVOTON/TARGET_NUC472/crypto/sha/sha1_alt_sw.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
#include "mbedtls/sha1.h"

#include <string.h>
#if defined(MBEDTLS_SELF_TEST)
#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdio.h>
#define mbedtls_printf printf
#endif /* MBEDTLS_PLATFORM_C */
#endif /* MBEDTLS_SELF_TEST */

/* Implementation that should never be optimized out by the compiler */
static void mbedtls_zeroize( void *v, size_t n ) {
Expand Down
15 changes: 7 additions & 8 deletions targets/TARGET_NUVOTON/TARGET_NUC472/crypto/sha/sha256_alt.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,13 @@ void mbedtls_sha256_clone(mbedtls_sha256_context *dst,
{
unsigned char output[32];
crypto_sha_getinternstate(output, sizeof (output));
dst->sw_ctx.state[0] = nu_get32_be(output);
dst->sw_ctx.state[1] = nu_get32_be(output + 4);
dst->sw_ctx.state[2] = nu_get32_be(output + 8);
dst->sw_ctx.state[3] = nu_get32_be(output + 12);
dst->sw_ctx.state[4] = nu_get32_be(output + 16);
dst->sw_ctx.state[5] = nu_get32_be(output + 20);
dst->sw_ctx.state[6] = nu_get32_be(output + 24);
dst->sw_ctx.state[7] = nu_get32_be(output + 28);
unsigned char *output_pos = output;
unsigned char *output_end = output + (sizeof (output) / sizeof (output[0]));
uint32_t *state_pos = (uint32_t *) &(dst->sw_ctx.state[0]);
while (output_pos != output_end) {
*state_pos ++ = nu_get32_be(output_pos);
output_pos += 4;
}
}
memcpy(dst->sw_ctx.buffer, src->hw_ctx.buffer, src->hw_ctx.buffer_left);
dst->sw_ctx.is224 = src->hw_ctx.is224;
Expand Down
5 changes: 2 additions & 3 deletions targets/TARGET_NUVOTON/TARGET_NUC472/crypto/sha/sha256_alt.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
#include MBEDTLS_CONFIG_FILE
#endif

#if defined(MBEDTLS_SHA1_C)
#if defined(MBEDTLS_SHA256_C)
#if defined(MBEDTLS_SHA256_ALT)

#include "sha256.h"
#include "sha_alt_hw.h"
#include "sha256_alt_sw.h"

Expand Down Expand Up @@ -103,6 +102,6 @@ void mbedtls_sha256_process( mbedtls_sha256_context *ctx, const unsigned char da
#endif

#endif /* MBEDTLS_SHA256_ALT */
#endif /* MBEDTLS_SHA1_C */
#endif /* MBEDTLS_SHA256_C */

#endif /* sha256_alt.h */
13 changes: 12 additions & 1 deletion targets/TARGET_NUVOTON/TARGET_NUC472/crypto/sha/sha256_alt_sw.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@
#include "mbedtls/sha256.h"

#include <string.h>
#if defined(MBEDTLS_SELF_TEST)
#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdio.h>
#include <stdlib.h>
#define mbedtls_printf printf
#define mbedtls_calloc calloc
#define mbedtls_free free
#endif /* MBEDTLS_PLATFORM_C */
#endif /* MBEDTLS_SELF_TEST */

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

#endif /* MBEDTLS_SHA1_ALT */
#endif /* MBEDTLS_SHA256_ALT */

#endif /* MBEDTLS_SHA256_C */
2 changes: 1 addition & 1 deletion targets/TARGET_NUVOTON/TARGET_NUC472/device/NUC472_442.h
Original file line number Diff line number Diff line change
Expand Up @@ -32574,7 +32574,7 @@ typedef volatile unsigned long vu32; ///< Define 32-bit unsigned volatile
#include "nuc472_acmp.h"
#include "nuc472_adc.h"
#include "nuc472_eadc.h"
#include "nuc472_cap.h"
/* Disable Capture: #include "nuc472_cap.h" */
#include "nuc472_crypto.h"
#include "nuc472_pdma.h"
#include "nuc472_ebi.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ void CAN_WaitMsg(CAN_T *tCAN)
DEBUG_PRINTF("New Data IN\n");
break;
}
if(tCAN->STATUS & CAN_STATUS_RXOK_Msk)
if(tCAN->STATUS & CAN_STATUS_RXOK_Msk) {
DEBUG_PRINTF("Rx OK\n");

}
if(tCAN->STATUS & CAN_STATUS_LEC_Msk) {
DEBUG_PRINTF("Error\n");
}
Expand Down
Loading