Skip to content

Commit

Permalink
Merge 'devel' branch into master
Browse files Browse the repository at this point in the history
Several updates:

- Ethernet PLL configuration (CDCE906)
- CLI bugfixes
- Text input cleaning
- BSMP events dispatcher
- Reset hanging issue bugfix
  • Loading branch information
Henrique Silva committed Jul 20, 2018
1 parent 6627941 commit 1c6ae0f
Show file tree
Hide file tree
Showing 14 changed files with 1,446 additions and 159 deletions.
38 changes: 29 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ PROJECT := rffe-fw
###############################################################################
# Objects and Paths

OBJECTS += ./src/Drivers/ADT7320.o
OBJECTS += ./src/Drivers/LM71.o
OBJECTS += ./src/Drivers/feram.o
OBJECTS += ./src/Drivers/CDCE906.o
OBJECTS += ./src/Drivers/ADT7320.o
OBJECTS += ./src/Drivers/DAC7554.o
OBJECTS += ./src/PID/PID.o
OBJECTS += ./src/bsmp/bsmp.o
Expand All @@ -59,9 +59,14 @@ OBJECTS += ./src/cli.o
OBJECTS += ./src/main.o
OBJECTS += ./src/pcbnAPI.o
OBJECTS += ./src/util.o
OBJECTS += ./boot/IAP.o

BOOT_OBJECTS += ./boot/boot.o
BOOT_OBJECTS += ./boot/IAP.o

INCLUDE_PATHS += -I../
INCLUDE_PATHS += -I../.
INCLUDE_PATHS += -I.././boot
INCLUDE_PATHS += -I.././mbed-os
INCLUDE_PATHS += -I.././mbed-os/cmsis
INCLUDE_PATHS += -I.././mbed-os/cmsis/TARGET_CORTEX_M
Expand Down Expand Up @@ -143,9 +148,9 @@ INCLUDE_PATHS += -I.././src/PID
INCLUDE_PATHS += -I.././src/bsmp
INCLUDE_PATHS += -I.././src/bsmp/md5

LIBRARY_PATHS := -L./
LIBRARY_PATHS := -L./ -L../lib/
LIBRARIES := -lmbed-os
LINKER_SCRIPT ?= .././mbed-os/targets/TARGET_NXP/TARGET_LPC176X/device/TOOLCHAIN_GCC_ARM/LPC1768.ld
LINKER_SCRIPT ?= .././linker/LPC1768.ld

# Objects and Paths
###############################################################################
Expand Down Expand Up @@ -265,9 +270,11 @@ endif

ifeq ($(TEMP_SENSOR),LM71)
CXX_FLAGS += -DTEMP_SENSOR_LM71
OBJECTS += ./src/Drivers/LM71.o
else
ifeq ($(TEMP_SENSOR),ADT7320)
CXX_FLAGS += -DTEMP_SENSOR_ADT7320
OBJECTS += ./src/Drivers/ADT7320.o
endif
endif

Expand Down Expand Up @@ -295,15 +302,15 @@ ASM_FLAGS += -DARM_MATH_CM3

FW_VERSION := $(shell $(MACROS) -E -dM ../src/main.cpp $(CXX_FLAGS) $(INCLUDE_PATHS) | grep "\#define FW_VERSION " | grep -oP "(V\d\_\d\_\d)")

LD_FLAGS :=-Wl,--gc-sections -Wl,--wrap,main -Wl,--wrap,_memalign_r -Wl,--wrap,exit -Wl,--wrap,atexit -Wl,-n -mcpu=cortex-m3 -mthumb -Wl,-Map=$(FW_VERSION).map
LD_FLAGS :=-Wl,--gc-sections -Wl,--wrap,main -Wl,--wrap,_memalign_r -Wl,--wrap,exit -Wl,--wrap,atexit -Wl,-n -mcpu=cortex-m3 -mthumb
LD_SYS_LIBS :=-Wl,--start-group -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys -Wl,--end-group


# Tools and Flags
###############################################################################
# Rules

all: $(FW_VERSION).bin
all: $(FW_VERSION).bin bootloader.bin

mbed-os:
@$(MAKE) -C ../ -f mbed-os.mk
Expand Down Expand Up @@ -336,9 +343,9 @@ mbed-os:
$(FW_VERSION).link_script.ld: $(LINKER_SCRIPT)
@$(PREPROC) $< -o $@

$(FW_VERSION).elf: mbed-os $(OBJECTS) $(SYS_OBJECTS) $(FW_VERSION).link_script.ld
$(FW_VERSION).elf: $(OBJECTS) $(SYS_OBJECTS) $(FW_VERSION).link_script.ld
+@echo "link: $(notdir $@)"
@$(LD) $(LD_FLAGS) -T $(filter %.ld, $^) $(LIBRARY_PATHS) --output $@ $(filter %.o, $^) $(LIBRARIES) $(LD_SYS_LIBS)
$(LD) $(LD_FLAGS) -Wl,-Map=$(FW_VERSION).map -T $(filter %.ld, $^) $(LIBRARY_PATHS) --output $@ $(filter %.o, $^) $(LIBRARIES) $(LD_SYS_LIBS)

$(FW_VERSION).bin: $(FW_VERSION).elf
$(ELF2BIN) -O binary $< $@
Expand All @@ -347,7 +354,20 @@ $(FW_VERSION).bin: $(FW_VERSION).elf
$(FW_VERSION).hex: $(FW_VERSION).elf
$(ELF2BIN) -O ihex $< $@

.PHONY: all mbed-os
bootloader.elf: $(BOOT_OBJECTS) $(SYS_OBJECTS)
+@echo "link: $(notdir $@)"
$(LD) $(LD_FLAGS) -Wl,-Map=bootloader.map -T ../linker/bootloader.ld $(LIBRARY_PATHS) --output $@ $(filter %.o, $^) $(LIBRARIES) $(LD_SYS_LIBS)

bootloader.bin: bootloader.elf
$(ELF2BIN) -O binary $< $@
+@echo "===== bin file ready to flash: $(OBJDIR)/$@ ====="

full: bootloader.bin $(FW_VERSION).bin
+@dd if=/dev/zero bs=1 count=32768 | tr \"\\000\" \"\\377\" > bootloader_pad.bin
+@dd if=bootloader.bin of=bootloader_pad.bin conv=notrunc
+@cat bootloader_pad.bin $(FW_VERSION).bin > rffe_fw_full.bin

.PHONY: all mbed-os full

# Rules
###############################################################################
Expand Down
234 changes: 234 additions & 0 deletions boot/IAP.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
/** IAP : internal Flash memory access library
*
* The internal Flash memory access is described in the LPC1768 and LPC11U24 usermanual.
* http://www.nxp.com/documents/user_manual/UM10360.pdf
* http://www.nxp.com/documents/user_manual/UM10462.pdf
*
* LPC1768 --
* Chapter 2: "LPC17xx Memory map"
* Chapter 32: "LPC17xx Flash memory interface and programming"
* refering Rev. 01 - 4 January 2010
*
* LPC11U24 --
* Chapter 2: "LPC11Uxx Memory mapping"
* Chapter 20: "LPC11Uxx Flash programming firmware"
* refering Rev. 03 - 16 July 2012
*
* Released under the MIT License: http://mbed.org/license/mit
*
* revision 1.0 09-Mar-2010 1st release
* revision 1.1 12-Mar-2010 chaged: to make possible to reserve flash area for user
* it can be set by USER_FLASH_AREA_START and USER_FLASH_AREA_SIZE in IAP.h
* revision 2.0 26-Nov-2012 LPC11U24 code added
* revision 2.1 26-Nov-2012 EEPROM access code imported from Suga koubou san's (http://mbed.org/users/okini3939/) library
* http://mbed.org/users/okini3939/code/M0_EEPROM_test/
* revision 3.0 09-Jan-2015 LPC812 and LPC824 support added
* revision 3.1 13-Jan-2015 LPC1114 support added
* revision 3.1.1 16-Jan-2015 Target MCU name changed for better compatibility across the platforms
*/

#include "mbed.h"
#include "IAP.h"

/*
* Reserve of flash area is explained by Igor. Please refer next URL
* http://mbed.org/users/okano/notebook/iap-in-application-programming-internal-flash-eras/?page=1#comment-271
*/

//unsigned char user_area[ size ] __attribute__((section(".ARM.__at_0x78000"), zero_init));

/*
* IAP command codes
* Table 589. "IAP Command Summary", Chapter 8. "IAP commands", usermanual
*/

enum command_code {
IAPCommand_Prepare_sector_for_write_operation = 50,
IAPCommand_Copy_RAM_to_Flash,
IAPCommand_Erase_sector,
IAPCommand_Blank_check_sector,
IAPCommand_Read_part_ID,
IAPCommand_Read_Boot_Code_version,
IAPCommand_Compare,
IAPCommand_Reinvoke_ISP,
IAPCommand_Read_device_serial_number,
#if defined(TARGET_LPC11UXX)
IAPCommand_EEPROM_Write = 61,
IAPCommand_EEPROM_Read,
#elif defined(TARGET_LPC81X) || defined(TARGET_LPC82X)
IAPCommand_Erase_page = 59,
#endif
};

int IAP::reinvoke_isp( void ) {
__disable_irq();

IAP_command[ 0 ] = IAPCommand_Reinvoke_ISP;

iap_entry( IAP_command, IAP_result );

return ( (int)IAP_result[ 0 ] );
}

/** Read part identification number
*
* @return device ID
* @see read_serial()
*/
int IAP::read_ID( void )
{
IAP_command[ 0 ] = IAPCommand_Read_part_ID;

iap_entry( IAP_command, IAP_result );

return ( (int)IAP_result[ 1 ] ); // to return the number itself (this command always returns CMD_SUCCESS)
}

int *IAP::read_serial( void ) {
IAP_command[ 0 ] = IAPCommand_Read_device_serial_number;

iap_entry( IAP_command, IAP_result );

return ( (int *)&IAP_result[ 1 ] ); // to return the number itself (this command always returns CMD_SUCCESS)
}

int IAP::blank_check( int start, int end )
{
IAP_command[ 0 ] = IAPCommand_Blank_check_sector;
IAP_command[ 1 ] = (unsigned int)start; // Start Sector Number
IAP_command[ 2 ] = (unsigned int)end; // End Sector Number (should be greater than or equal to start sector number)

iap_entry( IAP_command, IAP_result );

return ( (int)IAP_result[ 0 ] );
}

int IAP::erase( int start, int end )
{
int err = prepare(start, end);

if (err != IAP_CMD_SUCCESS) {
return err;
}

IAP_command[ 0 ] = IAPCommand_Erase_sector;
IAP_command[ 1 ] = (unsigned int)start; // Start Sector Number
IAP_command[ 2 ] = (unsigned int)end; // End Sector Number (should be greater than or equal to start sector number)
IAP_command[ 3 ] = cclk_kHz; // CPU Clock Frequency (CCLK) in kHz

iap_entry( IAP_command, IAP_result );

return ( (int)IAP_result[ 0 ] );
}

int IAP::prepare( int start, int end )
{
IAP_command[ 0 ] = IAPCommand_Prepare_sector_for_write_operation;
IAP_command[ 1 ] = (unsigned int)start; // Start Sector Number
IAP_command[ 2 ] = (unsigned int)end; // End Sector Number (should be greater than or equal to start sector number).

iap_entry( IAP_command, IAP_result );

return ( (int)IAP_result[ 0 ] );
}

int IAP::write( uint32_t *source_addr, uint32_t *target_addr, int size )
{
uint32_t sector_start = find_sector((uint32_t)target_addr);
uint32_t sector_end = find_sector(((uint32_t)target_addr)+size);

if (size % 256) {
/* Data should be a 256 byte boundary */
return IAP_COUNT_ERROR;
}

int err = prepare(sector_start, sector_end);

if (err != IAP_CMD_SUCCESS) {
return err;
}

IAP_command[ 0 ] = IAPCommand_Copy_RAM_to_Flash;
IAP_command[ 1 ] = (unsigned int)target_addr; // Destination flash address where data bytes are to be written. This address should be a 256 byte boundary.
IAP_command[ 2 ] = (unsigned int)source_addr; // Source RAM address from which data bytes are to be read. This address should be a word boundary.
IAP_command[ 3 ] = size; // Number of bytes to be written. Should be 256 | 512 | 1024 | 4096.
IAP_command[ 4 ] = cclk_kHz; // CPU Clock Frequency (CCLK) in kHz.

iap_entry( IAP_command, IAP_result );

return ( (int)IAP_result[ 0 ] );
}

int IAP::compare( uint32_t *source_addr, uint32_t *target_addr, int size )
{
IAP_command[ 0 ] = IAPCommand_Compare;
IAP_command[ 1 ] = (unsigned int)target_addr; // Starting flash or RAM address of data bytes to be compared. This address should be a word boundary.
IAP_command[ 2 ] = (unsigned int)source_addr; // Starting flash or RAM address of data bytes to be compared. This address should be a word boundary.
IAP_command[ 3 ] = size; // Number of bytes to be compared; should be a multiple of 4.

iap_entry( IAP_command, IAP_result );

return ( (int)IAP_result[ 0 ] );
}

int IAP::read_BootVer(void)
{
IAP_command[0] = IAPCommand_Read_Boot_Code_version;
IAP_result[1] = 0; // not sure if in high or low bits.
iap_entry(IAP_command, IAP_result);
return ((int)IAP_result[1]);
}

int IAP::find_sector( uint32_t addr )
{
if (addr <= 0xFFFF) {
return ((addr >> 12) & 0xF);
} else {
return ((addr/32768)-2+16);
}
}

#if defined(TARGET_LPC11UXX)

int IAP::write_eeprom( uint32_t *source_addr, uint32_t *target_addr, int size )
{
IAP_command[ 0 ] = IAPCommand_EEPROM_Write;
IAP_command[ 1 ] = (unsigned int)target_addr; // Destination EEPROM address where data bytes are to be written. This address should be a 256 byte boundary.
IAP_command[ 2 ] = (unsigned int)source_addr; // Source RAM address from which data bytes are to be read. This address should be a word boundary.
IAP_command[ 3 ] = size; // Number of bytes to be written. Should be 256 | 512 | 1024 | 4096.
IAP_command[ 4 ] = cclk_kHz; // CPU Clock Frequency (CCLK) in kHz.

iap_entry( IAP_command, IAP_result );

return ( (int)IAP_result[ 0 ] );
}

int IAP::read_eeprom( uint32_t *source_addr, uint32_t *target_addr, int size )
{
IAP_command[ 0 ] = IAPCommand_EEPROM_Read;
IAP_command[ 1 ] = (unsigned int)source_addr; // Source EEPROM address from which data bytes are to be read. This address should be a word boundary.
IAP_command[ 2 ] = (unsigned int)target_addr; // Destination RAM address where data bytes are to be written. This address should be a 256 byte boundary.
IAP_command[ 3 ] = size; // Number of bytes to be written. Should be 256 | 512 | 1024 | 4096.
IAP_command[ 4 ] = cclk_kHz; // CPU Clock Frequency (CCLK) in kHz.

iap_entry( IAP_command, IAP_result );

return ( (int)IAP_result[ 0 ] );
}

#elif defined(TARGET_LPC81X) || defined(TARGET_LPC82X)

int IAP::erase_page( int start, int end )
{
IAP_command[ 0 ] = IAPCommand_Erase_page;
IAP_command[ 1 ] = (unsigned int)start; // Start Sector Number
IAP_command[ 2 ] = (unsigned int)end; // End Sector Number (should be greater than or equal to start sector number)
IAP_command[ 3 ] = cclk_kHz; // CPU Clock Frequency (CCLK) in kHz

iap_entry( IAP_command, IAP_result );

return ( (int)IAP_result[ 0 ] );
}

#endif

Loading

0 comments on commit 1c6ae0f

Please sign in to comment.