Merge pull request #230 from sg-/master

Create a platform specific file to override WEAK Handlers and pre-main hook mbed_sdk_init

I thought about a better solution for this problem, but I couldn't find one, so this is fine. Just one comment: I wouldn't name that file 'platform_init.c'. First, it might contain other code than just initialization code (for example, mbed_die is also declared as a weak function and we'll need to override it for NRF51822). Second, it doesn't realy send the "this file is special and should be treated as such" message. I'd call it something like 'mbed_overrides.c'. But I'll make this change later. Thanks for the pull request!
pull/234/head
Bogdan Marinescu 2014-03-25 09:26:08 +00:00
commit d4c04e866e
8 changed files with 121 additions and 29 deletions

View File

@ -173,12 +173,3 @@ void gpio_irq_disable(gpio_irq_t *obj) {
NVIC_DisableIRQ(PORTB_IRQn); NVIC_DisableIRQ(PORTB_IRQn);
} }
} }
// Change the NMI pin to an input. This allows NMI pin to
// be used as a low power mode wakeup. The application will
// need to change the pin back to NMI_b or wakeup only occurs once!
void NMI_Handler(void)
{
gpio_t gpio;
gpio_init_in(&gpio, PTA4);
}

View File

@ -0,0 +1,32 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gpio_api.h"
// called before main - implement here if board needs it ortherwise, let
// the application override this if necessary
//void mbed_sdk_init()
//{
//
//}
// Change the NMI pin to an input. This allows NMI pin to
// be used as a low power mode wakeup. The application will
// need to change the pin back to NMI_b or wakeup only occurs once!
void NMI_Handler(void)
{
gpio_t gpio;
gpio_init_in(&gpio, PTB5);
}

View File

@ -163,12 +163,3 @@ void gpio_irq_disable(gpio_irq_t *obj) {
NVIC_DisableIRQ(PORTD_IRQn); NVIC_DisableIRQ(PORTD_IRQn);
} }
} }
// Change the NMI pin to an input. This allows NMI pin to
// be used as a low power mode wakeup. The application will
// need to change the pin back to NMI_b or wakeup only occurs once!
void NMI_Handler(void)
{
gpio_t gpio;
gpio_init_in(&gpio, PTA4);
}

View File

@ -0,0 +1,32 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gpio_api.h"
// called before main - implement here if board needs it ortherwise, let
// the application override this if necessary
//void mbed_sdk_init()
//{
//
//}
// Change the NMI pin to an input. This allows NMI pin to
// be used as a low power mode wakeup. The application will
// need to change the pin back to NMI_b or wakeup only occurs once!
void NMI_Handler(void)
{
gpio_t gpio;
gpio_init_in(&gpio, PTA4);
}

View File

@ -183,12 +183,3 @@ void gpio_irq_disable(gpio_irq_t *obj) {
NVIC_DisableIRQ(PORTC_PORTD_IRQn); NVIC_DisableIRQ(PORTC_PORTD_IRQn);
} }
} }
// Change the NMI pin to an input. This allows NMI pin to
// be used as a low power mode wakeup. The application will
// need to change the pin back to NMI_b or wakeup only occurs once!
void NMI_Handler(void)
{
gpio_t gpio;
gpio_init_in(&gpio, PTA4);
}

View File

@ -0,0 +1,32 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gpio_api.h"
// called before main - implement here if board needs it ortherwise, let
// the application override this if necessary
//void mbed_sdk_init()
//{
//
//}
// Change the NMI pin to an input. This allows NMI pin to
// be used as a low power mode wakeup. The application will
// need to change the pin back to NMI_b or wakeup only occurs once!
void NMI_Handler(void)
{
gpio_t gpio;
gpio_init_in(&gpio, PTA4);
}

View File

@ -1,8 +1,22 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gpio_api.h" #include "gpio_api.h"
#include "wait_api.h" #include "wait_api.h"
// called before main // called before main
void mbed_sdk_init() void mbed_sdk_init()
{ {
gpio_t modemEn, modemRst, modemPwrOn, modemLvlOe, modemILvlOe, modemUsbDet; gpio_t modemEn, modemRst, modemPwrOn, modemLvlOe, modemILvlOe, modemUsbDet;

View File

@ -189,6 +189,15 @@ def build_mbed_libs(target, toolchain_name, options=None, verbose=False, clean=F
if o.endswith('retarget.o'): if o.endswith('retarget.o'):
retargeting = o retargeting = o
objects.remove(retargeting) objects.remove(retargeting)
# We need to have a file that overrides weak delcatations on a per board basis and the
# lesser evil is to pull in this file if it extist rather than add board specific
# startup code in the /targets/cmsis directory
platform_initialize = None
for p in objects:
if p.endswith('platform_init.o'):
platform_initialize = p
objects.remove(platform_initialize)
toolchain.build_library(objects, BUILD_TOOLCHAIN, "mbed") toolchain.build_library(objects, BUILD_TOOLCHAIN, "mbed")
toolchain.copy_files(retargeting, BUILD_TOOLCHAIN) toolchain.copy_files(retargeting, BUILD_TOOLCHAIN)
toolchain.copy_files(platform_initialize, BUILD_TOOLCHAIN)