Skip to content

Commit 0f0a461

Browse files
Merge pull request #4832 from OpenNuvoton/nuvoton
NUC472/M453: Fix several startup and hal bugs
2 parents 069b253 + 6b8724b commit 0f0a461

File tree

43 files changed

+232
-281
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+232
-281
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2015-2016 Nuvoton
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#ifndef MBEDTLS_DEVICE_H
17+
#define MBEDTLS_DEVICE_H
18+
19+
#define MBEDTLS_DES_ALT
20+
21+
#define MBEDTLS_SHA1_ALT
22+
#define MBEDTLS_SHA256_ALT
23+
24+
#define MBEDTLS_AES_ALT
25+
#define MBEDTLS_AES_SETKEY_ENC_ALT
26+
#define MBEDTLS_AES_SETKEY_DEC_ALT
27+
#define MBEDTLS_AES_ENCRYPT_ALT
28+
#define MBEDTLS_AES_DECRYPT_ALT
29+
30+
#endif /* MBEDTLS_DEVICE_H */

targets/TARGET_NUVOTON/TARGET_NUC472/crypto/aes/aes_alt.c renamed to features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/aes/aes_alt.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
* http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf
2222
*/
2323

24-
/* Compatible with mbed OS 2 which doesn't support mbedtls */
25-
#if MBED_CONF_RTOS_PRESENT
26-
2724
#if !defined(MBEDTLS_CONFIG_FILE)
2825
#include "mbedtls/config.h"
2926
#else
@@ -591,5 +588,3 @@ int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
591588

592589

593590
#endif /* MBEDTLS_AES_C */
594-
595-
#endif /* MBED_CONF_RTOS_PRESENT */

targets/TARGET_NUVOTON/TARGET_NUC472/crypto/aes/aes_alt.h renamed to features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/aes/aes_alt.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@
2121
* This file is part of mbed TLS (https://tls.mbed.org)
2222
*/
2323

24+
#ifndef MBEDTLS_AES_ALT_H
25+
#define MBEDTLS_AES_ALT_H
26+
27+
#if !defined(MBEDTLS_CONFIG_FILE)
28+
#include "mbedtls/config.h"
29+
#else
30+
#include MBEDTLS_CONFIG_FILE
31+
#endif
32+
33+
#if defined(MBEDTLS_AES_C)
2434
#if defined(MBEDTLS_AES_ALT)
2535
// Regular implementation
2636
//
@@ -270,5 +280,6 @@ void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
270280

271281

272282
#endif /* MBEDTLS_AES_ALT */
283+
#endif /* MBEDTLS_AES_C */
273284

274-
285+
#endif /* aes_alt.h */

targets/TARGET_NUVOTON/TARGET_NUC472/crypto/des/des_alt.c renamed to features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/des/des_alt.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
/* Compatible with mbed OS 2 which doesn't support mbedtls */
18-
#if MBED_CONF_RTOS_PRESENT
19-
2017
#if !defined(MBEDTLS_CONFIG_FILE)
2118
#include "mbedtls/config.h"
2219
#else
@@ -348,7 +345,7 @@ static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_S
348345

349346
uint32_t rmn = length;
350347
const unsigned char *in_pos = input;
351-
const unsigned char *out_pos = output;
348+
unsigned char *out_pos = output;
352349

353350
while (rmn) {
354351
uint32_t data_len = (rmn <= MAXSIZE_DMABUF) ? rmn : MAXSIZE_DMABUF;
@@ -411,5 +408,3 @@ static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_S
411408

412409
#endif /* MBEDTLS_DES_ALT */
413410
#endif /* MBEDTLS_DES_C */
414-
415-
#endif /* MBED_CONF_RTOS_PRESENT */

targets/TARGET_NUVOTON/TARGET_NUC472/crypto/des/des_alt.h renamed to features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/des/des_alt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include MBEDTLS_CONFIG_FILE
2424
#endif
2525

26+
#if defined(MBEDTLS_DES_C)
2627
#if defined(MBEDTLS_DES_ALT)
2728

2829
#include <stddef.h>
@@ -276,5 +277,6 @@ void mbedtls_des_setkey( uint32_t SK[32],
276277
#endif
277278

278279
#endif /* MBEDTLS_DES_ALT */
280+
#endif /* MBEDTLS_DES_C */
279281

280282
#endif /* des_alt.h */

targets/TARGET_NUVOTON/TARGET_NUC472/crypto/des/des_alt_sw.c renamed to features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/des/des_alt_sw.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
* http://csrc.nist.gov/publications/fips/fips46-3/fips46-3.pdf
2626
*/
2727

28-
/* Compatible with mbed OS 2 which doesn't support mbedtls */
29-
#if MBED_CONF_RTOS_PRESENT
30-
3128
#if !defined(MBEDTLS_CONFIG_FILE)
3229
#include "mbedtls/config.h"
3330
#else
@@ -798,5 +795,3 @@ int mbedtls_des3_sw_crypt_cbc( mbedtls_des3_sw_context *ctx,
798795

799796
#endif /* MBEDTLS_DES_ALT */
800797
#endif /* MBEDTLS_DES_C */
801-
802-
#endif /* MBED_CONF_RTOS_PRESENT */

targets/TARGET_NUVOTON/TARGET_NUC472/crypto/sha/sha1_alt.c renamed to features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/sha/sha1_alt.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
/* Compatible with mbed OS 2 which doesn't support mbedtls */
18-
#if MBED_CONF_RTOS_PRESENT
19-
2017
#if !defined(MBEDTLS_CONFIG_FILE)
2118
#include "mbedtls/config.h"
2219
#else
@@ -139,5 +136,3 @@ void mbedtls_sha1_process(mbedtls_sha1_context *ctx, const unsigned char data[64
139136

140137
#endif /* MBEDTLS_SHA1_ALT */
141138
#endif /* MBEDTLS_SHA1_C */
142-
143-
#endif /* MBED_CONF_RTOS_PRESENT */

targets/TARGET_NUVOTON/TARGET_NUC472/crypto/sha/sha1_alt_sw.c renamed to features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/sha/sha1_alt_sw.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
* http://www.itl.nist.gov/fipspubs/fip180-1.htm
2525
*/
2626

27-
/* Compatible with mbed OS 2 which doesn't support mbedtls */
28-
#if MBED_CONF_RTOS_PRESENT
29-
3027
#if !defined(MBEDTLS_CONFIG_FILE)
3128
#include "mbedtls/config.h"
3229
#else
@@ -346,5 +343,3 @@ void mbedtls_sha1_sw_finish( mbedtls_sha1_sw_context *ctx, unsigned char output[
346343
#endif /* MBEDTLS_SHA1_ALT */
347344

348345
#endif /* MBEDTLS_SHA1_C */
349-
350-
#endif /* MBED_CONF_RTOS_PRESENT */

targets/TARGET_NUVOTON/TARGET_NUC472/crypto/sha/sha256_alt.c renamed to features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/sha/sha256_alt.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
/* Compatible with mbed OS 2 which doesn't support mbedtls */
18-
#if MBED_CONF_RTOS_PRESENT
19-
2017
#if !defined(MBEDTLS_CONFIG_FILE)
2118
#include "mbedtls/config.h"
2219
#else
@@ -140,5 +137,3 @@ void mbedtls_sha256_process(mbedtls_sha256_context *ctx, const unsigned char dat
140137

141138
#endif /* MBEDTLS_SHA256_ALT */
142139
#endif /* MBEDTLS_SHA256_C */
143-
144-
#endif /* MBED_CONF_RTOS_PRESENT */

targets/TARGET_NUVOTON/TARGET_NUC472/crypto/sha/sha256_alt_sw.c renamed to features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/sha/sha256_alt_sw.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
* http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
2525
*/
2626

27-
/* Compatible with mbed OS 2 which doesn't support mbedtls */
28-
#if MBED_CONF_RTOS_PRESENT
29-
3027
#if !defined(MBEDTLS_CONFIG_FILE)
3128
#include "mbedtls/config.h"
3229
#else
@@ -320,5 +317,3 @@ void mbedtls_sha256_sw_finish( mbedtls_sha256_sw_context *ctx, unsigned char out
320317
#endif /* MBEDTLS_SHA256_ALT */
321318

322319
#endif /* MBEDTLS_SHA256_C */
323-
324-
#endif /* MBED_CONF_RTOS_PRESENT */

targets/TARGET_NUVOTON/TARGET_NUC472/crypto/sha/sha_alt_hw.c renamed to features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/sha/sha_alt_hw.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
/* Compatible with mbed OS 2 which doesn't support mbedtls */
18-
#if MBED_CONF_RTOS_PRESENT
19-
2017
#if !defined(MBEDTLS_CONFIG_FILE)
2118
#include "mbedtls/config.h"
2219
#else
@@ -51,6 +48,7 @@ void crypto_sha_getinternstate(unsigned char output[], size_t olen);
5148

5249
#endif /* MBEDTLS_SHA1_ALT || MBEDTLS_SHA256_ALT || MBEDTLS_SHA512_ALT */
5350

51+
#if defined(MBEDTLS_SHA1_C)
5452
#if defined(MBEDTLS_SHA1_ALT)
5553

5654
void mbedtls_sha1_hw_init(crypto_sha_context *ctx)
@@ -123,7 +121,9 @@ void mbedtls_sha1_hw_process(crypto_sha_context *ctx, const unsigned char data[6
123121
}
124122

125123
#endif /* MBEDTLS_SHA1_ALT */
124+
#endif /* MBEDTLS_SHA1_C */
126125

126+
#if defined(MBEDTLS_SHA256_C)
127127
#if defined(MBEDTLS_SHA256_ALT)
128128

129129
void mbedtls_sha256_hw_init(crypto_sha_context *ctx)
@@ -197,7 +197,9 @@ void mbedtls_sha256_hw_process(crypto_sha_context *ctx, const unsigned char data
197197
}
198198

199199
#endif /* MBEDTLS_SHA256_ALT */
200+
#endif /* MBEDTLS_SHA256_C */
200201

202+
#if defined(MBEDTLS_SHA1_C) || defined(MBEDTLS_SHA256_C) || defined(MBEDTLS_SHA512_C)
201203
#if defined(MBEDTLS_SHA1_ALT) || defined(MBEDTLS_SHA256_ALT) || defined(MBEDTLS_SHA512_ALT)
202204

203205
void crypto_sha_update(crypto_sha_context *ctx, const unsigned char *input, size_t ilen)
@@ -332,7 +334,6 @@ void crypto_sha_getinternstate(unsigned char output[], size_t olen)
332334
}
333335

334336
#endif /* MBEDTLS_SHA1_ALT || MBEDTLS_SHA256_ALT || MBEDTLS_SHA512_ALT */
335-
336337
#endif /* MBEDTLS_SHA1_C || MBEDTLS_SHA256_C || MBEDTLS_SHA512_C */
337338

338-
#endif /* MBED_CONF_RTOS_PRESENT */
339+
#endif /* MBEDTLS_SHA1_C || MBEDTLS_SHA256_C || MBEDTLS_SHA512_C */

targets/TARGET_NUVOTON/TARGET_NUC472/crypto/sha/sha_alt_hw.h renamed to features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/sha/sha_alt_hw.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#endif
2424

2525
#if defined(MBEDTLS_SHA1_C) || defined(MBEDTLS_SHA256_C) || defined(MBEDTLS_SHA512_C)
26+
#if defined(MBEDTLS_SHA1_ALT) || defined(MBEDTLS_SHA256_ALT) || defined(MBEDTLS_SHA512_ALT)
2627

2728
#include <stddef.h>
2829
#include <stdint.h>
@@ -50,6 +51,7 @@ void crypto_sha_update(crypto_sha_context *ctx, const unsigned char *input, size
5051
void crypto_sha_update_nobuf(crypto_sha_context *ctx, const unsigned char *input, size_t ilen, int islast);
5152
void crypto_sha_getinternstate(unsigned char output[], size_t olen);
5253

54+
#if defined(MBEDTLS_SHA1_C)
5355
#if defined(MBEDTLS_SHA1_ALT)
5456

5557
void mbedtls_sha1_hw_init( crypto_sha_context *ctx );
@@ -62,7 +64,9 @@ void mbedtls_sha1_hw_finish( crypto_sha_context *ctx, unsigned char output[20] )
6264
void mbedtls_sha1_hw_process( crypto_sha_context *ctx, const unsigned char data[64] );
6365

6466
#endif /* MBEDTLS_SHA1_ALT */
67+
#endif /* MBEDTLS_SHA1_C */
6568

69+
#if defined(MBEDTLS_SHA256_C)
6670
#if defined(MBEDTLS_SHA256_ALT)
6771

6872
void mbedtls_sha256_hw_init( crypto_sha_context *ctx );
@@ -76,11 +80,13 @@ void mbedtls_sha256_hw_finish( crypto_sha_context *ctx, unsigned char output[32]
7680
void mbedtls_sha256_hw_process( crypto_sha_context *ctx, const unsigned char data[64] );
7781

7882
#endif /* MBEDTLS_SHA256_ALT */
83+
#endif /* MBEDTLS_SHA256_C */
7984

8085
#ifdef __cplusplus
8186
}
8287
#endif
8388

84-
#endif /* MBEDTLS_SHA1_C || MBEDTLS_SHA256_C || MBEDTLS_SHA512_C*/
89+
#endif /* MBEDTLS_SHA1_ALT || MBEDTLS_SHA256_ALT || MBEDTLS_SHA512_ALT */
90+
#endif /* MBEDTLS_SHA1_C || MBEDTLS_SHA256_C || MBEDTLS_SHA512_C */
8591

8692
#endif /* sha_alt.h */

targets/TARGET_NUVOTON/TARGET_M451/TARGET_NUMAKER_PFM_M453/PinNames.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ typedef enum {
115115
LED1 = PD_2,
116116
LED2 = PD_3,
117117
LED3 = PD_7,
118-
LED4 = D0, // No real LED. Just for passing ATS.
118+
LED4 = LED1, // No real LED. Just for passing ATS.
119119
LED_RED = LED2,
120120
LED_GREEN = LED3,
121121
LED_BLUE = LED1,

targets/TARGET_NUVOTON/TARGET_M451/TARGET_NUMAKER_PFM_M453/mbed_overrides.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@
1616

1717
#include "analogin_api.h"
1818

19-
// NOTE: Ensurce mbed_sdk_init() will get called before C++ global object constructor.
20-
#if defined(__CC_ARM) || defined(__GNUC__)
21-
void mbed_sdk_init_forced(void) __attribute__((constructor(101)));
22-
#elif defined(__ICCARM__)
23-
// FIXME: How to achieve it in IAR?
24-
#endif
25-
26-
2719
void mbed_sdk_init(void)
2820
{
2921
// NOTE: Support singleton semantics to be called from other init functions
@@ -75,8 +67,3 @@ void mbed_sdk_init(void)
7567
/* Lock protected registers */
7668
SYS_LockReg();
7769
}
78-
79-
void mbed_sdk_init_forced(void)
80-
{
81-
mbed_sdk_init();
82-
}

targets/TARGET_NUVOTON/TARGET_M451/device/TOOLCHAIN_IAR/M453.icf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ define symbol __ICFEDIT_intvec_start__ = MBED_APP_START;
99
define symbol __ICFEDIT_region_ROM_start__ = MBED_APP_START;
1010
define symbol __ICFEDIT_region_ROM_end__ = MBED_APP_START + MBED_APP_SIZE - 1;
1111
define symbol __ICFEDIT_region_IRAM_start__ = 0x20000000;
12-
define symbol __ICFEDIT_region_IRAM_end__ = 0x20008000;
12+
define symbol __ICFEDIT_region_IRAM_end__ = 0x20008000 - 1;
1313
/*-Sizes-*/
1414
define symbol __ICFEDIT_size_cstack__ = 0x800;
1515
define symbol __ICFEDIT_size_heap__ = 0x4000;

targets/TARGET_NUVOTON/TARGET_M451/device/startup_M451Series.c

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,11 @@ extern uint32_t __bss_start__;
6161
extern uint32_t __bss_end__;
6262

6363
extern void uvisor_init(void);
64-
//#if defined(TOOLCHAIN_GCC_ARM)
65-
//extern void _start(void);
66-
//#endif
67-
extern void software_init_hook(void) __attribute__((weak));
68-
extern void __libc_init_array(void);
69-
extern int main(void);
64+
#if defined(TOOLCHAIN_GCC_ARM)
65+
extern void _start(void);
66+
#else
67+
#error("For GCC toolchain, only support GNU ARM Embedded")
68+
#endif
7069
#endif
7170

7271
/* Default empty handler */
@@ -271,14 +270,15 @@ void Reset_Handler(void)
271270
/* HXT Crystal Type Select: INV */
272271
CLK->PWRCTL &= ~CLK_PWRCTL_HXTSELTYP_Msk;
273272

274-
/* Enable register write-protection function */
275-
SYS_LockReg();
276-
277273
/**
278-
* Because EBI (external SRAM) init is done in SystemInit(), SystemInit() must be called at the very start.
274+
* NOTE 1: Unlock is required for perhaps some register access in SystemInit().
275+
* NOTE 2: Because EBI (external SRAM) init is done in SystemInit(), SystemInit() must be called at the very start.
279276
*/
280277
SystemInit();
281278

279+
/* Enable register write-protection function */
280+
SYS_LockReg();
281+
282282
#if defined(__CC_ARM)
283283
__main();
284284

@@ -306,19 +306,8 @@ void Reset_Handler(void)
306306
}
307307
}
308308

309-
//uvisor_init();
309+
_start();
310310

311-
if (software_init_hook) {
312-
/**
313-
* Give control to the RTOS via software_init_hook() which will also call __libc_init_array().
314-
* Assume software_init_hook() is defined in libraries/rtos/rtx/TARGET_CORTEX_M/RTX_CM_lib.h.
315-
*/
316-
software_init_hook();
317-
}
318-
else {
319-
__libc_init_array();
320-
main();
321-
}
322311
#endif
323312

324313
/* Infinite loop */

0 commit comments

Comments
 (0)