Skip to content

Commit 6c870ca

Browse files
committed
[NANO130] Fix issues in OS 5.5 Greentea test
1. Support CMSIS_VECTAB_VIRTUAL feature 2. Reduce the register sync waiting time in LP ticker 3. Adjust the stack and heap size in GCC and IAR toolchains
1 parent bc0fc2e commit 6c870ca

File tree

8 files changed

+73
-74
lines changed

8 files changed

+73
-74
lines changed

platform/mbed_retarget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,8 @@ extern "C" int errno;
671671
#if defined(TARGET_NUVOTON)
672672
// Overwrite _sbrk() to support two region model (heap and stack are two distinct regions).
673673
// __wrap__sbrk() is implemented in:
674-
// TARGET_NUMAKER_PFM_NUC472 hal/targets/cmsis/TARGET_NUVOTON/TARGET_NUC472/TARGET_NUMAKER_PFM_NUC472/TOOLCHAIN_GCC_ARM/retarget.c
675-
// TARGET_NUMAKER_PFM_M453 hal/targets/cmsis/TARGET_NUVOTON/TARGET_M451/TARGET_NUMAKER_PFM_M453/TOOLCHAIN_GCC_ARM/retarget.c
674+
// TARGET_NUMAKER_PFM_NUC472 targets/TARGET_NUVOTON/TARGET_NUC472/TARGET_NUMAKER_PFM_NUC472/TOOLCHAIN_GCC_ARM/nuc472_retarget.c
675+
// TARGET_NUMAKER_PFM_M453 targets/TARGET_NUVOTON/TARGET_M451/TARGET_NUMAKER_PFM_M453/TOOLCHAIN_GCC_ARM/m451_retarget.c
676676
extern "C" void *__wrap__sbrk(int incr);
677677
extern "C" caddr_t _sbrk(int incr) {
678678
return (caddr_t) __wrap__sbrk(incr);

targets/TARGET_NUVOTON/TARGET_NANO100/device/TOOLCHAIN_GCC_ARM/NANO130.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Nuvoton NANO130 GCC linker script file
33
*/
44

5-
StackSize = 0x800;
5+
StackSize = 0x600;
66

77
MEMORY
88
{

targets/TARGET_NUVOTON/TARGET_NANO100/device/TOOLCHAIN_IAR/NANO130.icf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ define symbol __ICFEDIT_region_IRAM_start__ = 0x20000000;
1010
define symbol __ICFEDIT_region_IRAM_end__ = 0x20004000 - 1;
1111
/*-Sizes-*/
1212
define symbol __ICFEDIT_size_cstack__ = 0x800;
13-
define symbol __ICFEDIT_size_heap__ = 0x1800;
13+
define symbol __ICFEDIT_size_heap__ = 0x1200;
1414
/**** End of ICF editor section. ###ICF###*/
1515

1616

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2015-2017 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+
#include "cmsis_nvic.h"
17+
#include "platform/mbed_error.h"
18+
19+
void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector)
20+
{
21+
// NOTE: On NANO130, relocating vector table is not supported due to just 16KB small SRAM.
22+
// Add guard code to prevent from unsupported relocating.
23+
uint32_t vector_static = NVIC_GetVector(IRQn);
24+
if (vector_static != vector) {
25+
error("No support for relocating vector table");
26+
}
27+
}
28+
29+
uint32_t NVIC_GetVector(IRQn_Type IRQn)
30+
{
31+
uint32_t *vectors = (uint32_t*) NVIC_FLASH_VECTOR_ADDRESS;
32+
33+
// Return the vector
34+
return vectors[IRQn + 16];
35+
}

targets/TARGET_NUVOTON/TARGET_NANO100/device/cmsis_nvic.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,31 @@
3333
#endif
3434

3535

36+
#define NVIC_FLASH_VECTOR_ADDRESS 0
37+
38+
#ifdef __cplusplus
39+
extern "C" {
40+
#endif
41+
42+
/** Set the ISR for IRQn
43+
*
44+
* Sets an Interrupt Service Routine vector for IRQn; if the feature is available, the vector table is relocated to SRAM
45+
* the first time this function is called
46+
* @param[in] IRQn The Interrupt Request number for which a vector will be registered
47+
* @param[in] vector The ISR vector to register for IRQn
48+
*/
49+
void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector);
50+
51+
/** Get the ISR registered for IRQn
52+
*
53+
* Reads the Interrupt Service Routine currently registered for IRQn
54+
* @param[in] IRQn The Interrupt Request number the vector of which will be read
55+
* @return Returns the ISR registered for IRQn
56+
*/
57+
uint32_t NVIC_GetVector(IRQn_Type IRQn);
58+
59+
#ifdef __cplusplus
60+
}
61+
#endif
62+
3663
#endif

targets/TARGET_NUVOTON/TARGET_NANO100/lp_ticker.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "nu_modutil.h"
2323
#include "nu_miscutil.h"
2424
#include "mbed_critical.h"
25+
#include "mbed_wait_api.h"
2526

2627
// lp_ticker tick = us = timestamp
2728
#define US_PER_TICK (1)
@@ -219,9 +220,6 @@ static void lp_ticker_arm_cd(void)
219220
uint32_t ctl_timer3 = timer3_base->CTL;
220221
ctl_timer3 &= ~TIMER_CTL_MODE_SEL_Msk;
221222
ctl_timer3 |= TIMER_ONESHOT_MODE;
222-
// Wait 3 cycles of engine clock to ensure previous CTL write action is finish
223-
nu_nop(SystemCoreClock / __LXT * 3);
224-
timer3_base->CTL = ctl_timer3;
225223
timer3_base->PRECNT = prescale_timer3;
226224

227225
cd_minor_clks = cd_major_minor_clks;
@@ -230,8 +228,8 @@ static void lp_ticker_arm_cd(void)
230228

231229
TIMER_EnableInt(timer3_base);
232230
TIMER_EnableWakeup((TIMER_T *) NU_MODBASE(timer3_modinit.modname));
233-
// Wait 3 cycles of engine clock to ensure previous CTL write action is finish
234-
nu_nop(SystemCoreClock / __LXT * 3);
235-
TIMER_Start(timer3_base);
231+
// Wait 2 cycles of engine clock to ensure previous CTL write action is finish
232+
wait_us(30 * 2);
233+
timer3_base->CTL = ctl_timer3 | TIMER_CTL_TMR_EN_Msk;
236234
}
237235
#endif

targets/TARGET_NUVOTON/mbed_rtx.h

Lines changed: 2 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include <stdint.h>
2121

22-
#if defined(TARGET_NUMAKER_PFM_NUC472)
22+
#if defined(TARGET_NUVOTON)
2323

2424
#if defined(__CC_ARM)
2525
extern uint32_t Image$$ARM_LIB_HEAP$$ZI$$Base[];
@@ -45,68 +45,6 @@
4545
#error "no toolchain defined"
4646
#endif
4747

48-
#elif defined(TARGET_NUMAKER_PFM_M453)
49-
50-
#if defined(__CC_ARM)
51-
extern uint32_t Image$$ARM_LIB_HEAP$$ZI$$Base[];
52-
extern uint32_t Image$$ARM_LIB_HEAP$$ZI$$Length[];
53-
extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Base[];
54-
extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Length[];
55-
#define HEAP_START ((unsigned char*) Image$$ARM_LIB_HEAP$$ZI$$Base)
56-
#define HEAP_SIZE ((uint32_t) Image$$ARM_LIB_HEAP$$ZI$$Length)
57-
#define ISR_STACK_START ((unsigned char*)Image$$ARM_LIB_STACK$$ZI$$Base)
58-
#define ISR_STACK_SIZE ((uint32_t)Image$$ARM_LIB_STACK$$ZI$$Length)
59-
#elif defined(__GNUC__)
60-
extern uint32_t __StackTop[];
61-
extern uint32_t __StackLimit[];
62-
extern uint32_t __end__[];
63-
extern uint32_t __HeapLimit[];
64-
#define HEAP_START ((unsigned char*)__end__)
65-
#define HEAP_SIZE ((uint32_t)((uint32_t)__HeapLimit - (uint32_t)HEAP_START))
66-
#define ISR_STACK_START ((unsigned char*)__StackLimit)
67-
#define ISR_STACK_SIZE ((uint32_t)((uint32_t)__StackTop - (uint32_t)__StackLimit))
68-
#elif defined(__ICCARM__)
69-
/* No region declarations needed */
70-
#else
71-
#error "no toolchain defined"
72-
#endif
73-
74-
#elif defined(TARGET_NUMAKER_PFM_NANO130)
75-
76-
#ifndef OS_TASKCNT
77-
#define OS_TASKCNT 6
78-
#endif
79-
#ifndef OS_MAINSTKSIZE
80-
#define OS_MAINSTKSIZE 128
81-
#endif
82-
#ifndef OS_CLOCK
83-
#define OS_CLOCK 42000000
84-
#endif
85-
86-
#if defined(__CC_ARM)
87-
extern uint32_t Image$$ARM_LIB_HEAP$$ZI$$Base[];
88-
extern uint32_t Image$$ARM_LIB_HEAP$$ZI$$Length[];
89-
extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Base[];
90-
extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Length[];
91-
#define HEAP_START ((unsigned char*) Image$$ARM_LIB_HEAP$$ZI$$Base)
92-
#define HEAP_SIZE ((uint32_t) Image$$ARM_LIB_HEAP$$ZI$$Length)
93-
#define ISR_STACK_START ((unsigned char*)Image$$ARM_LIB_STACK$$ZI$$Base)
94-
#define ISR_STACK_SIZE ((uint32_t)Image$$ARM_LIB_STACK$$ZI$$Length)
95-
#elif defined(__GNUC__)
96-
extern uint32_t __StackTop[];
97-
extern uint32_t __StackLimit[];
98-
extern uint32_t __end__[];
99-
extern uint32_t __HeapLimit[];
100-
#define HEAP_START ((unsigned char*)__end__)
101-
#define HEAP_SIZE ((uint32_t)((uint32_t)__HeapLimit - (uint32_t)HEAP_START))
102-
#define ISR_STACK_START ((unsigned char*)__StackLimit)
103-
#define ISR_STACK_SIZE ((uint32_t)((uint32_t)__StackTop - (uint32_t)__StackLimit))
104-
#elif defined(__ICCARM__)
105-
/* No region declarations needed */
106-
#else
107-
#error "no toolchain defined"
108-
#endif
109-
110-
#endif
48+
#endif // TARGET_NUVOTON
11149

11250
#endif // MBED_MBED_RTX_H

targets/targets.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2920,6 +2920,7 @@
29202920
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
29212921
"inherits": ["Target"],
29222922
"progen": {"target": "numaker-pfm-nano130"},
2923+
"macros": ["CMSIS_VECTAB_VIRTUAL", "CMSIS_VECTAB_VIRTUAL_HEADER_FILE=\"cmsis_nvic.h\""],
29232924
"device_has": ["ANALOGIN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "STDIO_MESSAGES", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH"],
29242925
"release_versions": ["5"],
29252926
"device_name": "NANO130KE3BN"

0 commit comments

Comments
 (0)