Skip to content

Commit

Permalink
small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
orgua committed Mar 30, 2023
1 parent fe1bb7d commit 0b0cdf7
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 14 deletions.
2 changes: 1 addition & 1 deletion software/firmware/lib/GCC/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ printEnd:
@stat -L -c %s $(TARGET_PATH)
@echo ''
@echo '************************************************************'
@echo 'Internal statistics of ELF'
@echo 'Statistics of ELF-Internals'
@echo ''
@$(CROSS_COMPILE)size $(TARGET_PATH)
@echo ''
Expand Down
1 change: 1 addition & 0 deletions software/firmware/lib/include/sys_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,6 @@ static inline gpio_state_t sys_gpio_get(const uint8_t pin)
#define SYS_GPIO_SET_DIR_OUT(mask) CT_GPIO0.GPIO_OE &= ~mask;
#define SYS_GPIO_SET_HIGH(mask) CT_GPIO0.GPIO_SETDATAOUT = mask;
#define SYS_GPIO_SET_LOW(mask) CT_GPIO0.GPIO_CLEARDATAOUT = mask;
// TODO: make FNs out of these and use them (saves 2 OPs per call)

#endif //PRU_SYS_GPIO_H
1 change: 1 addition & 0 deletions software/firmware/pru0-programmer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ folder_path := $(dir $(mkfile_path))
PROTO ?= SWD
PROJ_NAME = $(current_dir)-$(PROTO)
FW_NAME = programmer-$(PROTO)
# choose variant with "make PROTO=SWD|SBW"

BASE_PATH ?= ./..

Expand Down
2 changes: 1 addition & 1 deletion software/firmware/pru0-programmer/device_nrf52.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static int mem_write(uint32_t addr, uint32_t data)
* @param dst pointer to destination
* @param addr target memory address
*/
static int mem_read(uint32_t *dst, uint32_t addr)
static int mem_read(uint32_t *const dst, uint32_t addr)
{
int rc;

Expand Down
6 changes: 6 additions & 0 deletions software/firmware/pru0-programmer/include/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <stdint.h>


typedef enum
{
DRV_ERR_TIMEOUT = -3,
Expand Down Expand Up @@ -37,7 +38,12 @@ typedef struct
uint8_t word_width_bytes;
} device_driver_t;

#ifdef SWD_SUPPORT
extern device_driver_t nrf52_driver;
#endif
#ifdef SBW_SUPPORT
extern device_driver_t msp430fr_driver;
#endif


#endif /* __PROG_DEVICE_H_ */
11 changes: 6 additions & 5 deletions software/firmware/pru0-programmer/programmer.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#include "programmer.h"

// select a primary programming-mode when none is chosen
#if !(defined(SWD_SUPPORT) || defined(SBW_SUPPORT))
#define SWD_SUPPORT
#endif

#include "device.h"
#include "intelhex.h"
#include "swd_transport.h"
#include "sys_gpio.h"
#include <stdint.h>

#if !(defined(SWD_SUPPORT) || defined(SBW_SUPPORT))
// select a primary programming-mode when none is chosen
#define SWD_SUPPORT
#endif

/* Writes block from hex file to target via driver */
int write_to_target(device_driver_t *drv, ihex_mem_block_t *block)
{
Expand Down
20 changes: 16 additions & 4 deletions software/firmware/pru0-programmer/swd_dap.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
#include "swd_dap.h"
#include "swd_transport.h"

int dp_write(dp_reg_t reg, uint32_t val) { return swd_transport_write(SWD_PORT_DP, reg, val, 5u); }
int dp_write(const dp_reg_t reg, uint32_t val)
{
return swd_transport_write(SWD_PORT_DP, reg, val, 5u);
}

int ap_write(ap_reg_t reg, uint32_t val) { return swd_transport_write(SWD_PORT_AP, reg, val, 5u); }
int ap_write(const ap_reg_t reg, uint32_t val)
{
return swd_transport_write(SWD_PORT_AP, reg, val, 5u);
}

int dp_read(uint32_t *dst, dp_reg_t reg) { return swd_transport_read(dst, SWD_PORT_DP, reg, 5u); }
int dp_read(uint32_t *const dst, const dp_reg_t reg)
{
return swd_transport_read(dst, SWD_PORT_DP, reg, 5u);
}

int ap_read(uint32_t *dst, ap_reg_t reg) { return swd_transport_read(dst, SWD_PORT_AP, reg, 5u); }
int ap_read(uint32_t *const dst, const ap_reg_t reg)
{
return swd_transport_read(dst, SWD_PORT_AP, reg, 5u);
}

int ap_init()
{
Expand Down
7 changes: 4 additions & 3 deletions software/firmware/pru0-programmer/swd_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static void iotrn(gpio_dir_t dir)
* @param rw read or write access
* @param addr port address
*/
static int header_init(swd_header_t *header, const swd_port_t port, const swd_rw_t rw,
static int header_init(swd_header_t *const header, const swd_port_t port, const swd_rw_t rw,
const uint8_t addr)
{
*header = 0x81u | ((addr & 0xCu) << 1u) | (port << 1u) | (rw << 2u);
Expand Down Expand Up @@ -169,7 +169,8 @@ static int transceive(const swd_header_t *const header, uint32_t *const data)
return rc;
}

int swd_transport_read(uint32_t *dst, swd_port_t port, uint8_t addr, uint32_t retries)
int swd_transport_read(uint32_t *const dst, const swd_port_t port, const uint8_t addr,
uint32_t retries)
{
int rc;
header_init(&hdr, port, SWD_RW_R, addr);
Expand All @@ -183,7 +184,7 @@ int swd_transport_read(uint32_t *dst, swd_port_t port, uint8_t addr, uint32_t re
return -rc;
}

int swd_transport_write(swd_port_t port, uint8_t addr, uint32_t data, uint32_t retries)
int swd_transport_write(const swd_port_t port, const uint8_t addr, uint32_t data, uint32_t retries)
{
int rc;
header_init(&hdr, port, SWD_RW_W, addr);
Expand Down

0 comments on commit 0b0cdf7

Please sign in to comment.